mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-05-10 04:27:14 +00:00
TU19: merge Minecraft.World/Enchantments
This commit is contained in:
parent
7d05b36f85
commit
405a87e078
|
|
@ -23,15 +23,16 @@ int DamageEnchantment::getMaxCost(int level) {
|
|||
|
||||
int DamageEnchantment::getMaxLevel() { return 5; }
|
||||
|
||||
int DamageEnchantment::getDamageBonus(int level, std::shared_ptr<Mob> target) {
|
||||
float DamageEnchantment::getDamageBonus(int level,
|
||||
std::shared_ptr<LivingEntity> target) {
|
||||
if (type == ALL) {
|
||||
return Mth::floor(level * 2.75f);
|
||||
return level * 1.25f;
|
||||
}
|
||||
if (type == UNDEAD && target->getMobType() == UNDEAD) {
|
||||
return Mth::floor(level * 4.5f);
|
||||
return level * 2.5f;
|
||||
}
|
||||
if (type == ARTHROPODS && target->getMobType() == ARTHROPOD) {
|
||||
return Mth::floor(level * 4.5f);
|
||||
return level * 2.5f;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@ public:
|
|||
virtual int getMinCost(int level);
|
||||
virtual int getMaxCost(int level);
|
||||
virtual int getMaxLevel();
|
||||
virtual int getDamageBonus(int level, std::shared_ptr<Mob> target);
|
||||
virtual float getDamageBonus(int level,
|
||||
std::shared_ptr<LivingEntity> target);
|
||||
virtual int getDescriptionId();
|
||||
virtual bool isCompatibleWith(Enchantment* other) const;
|
||||
virtual bool canEnchant(std::shared_ptr<ItemInstance> item);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "../Platform/stdafx.h"
|
||||
#include "../Headers/net.minecraft.world.item.enchantment.h"
|
||||
#include "../Headers/net.minecraft.world.item.h"
|
||||
#include "Enchantment.h"
|
||||
|
||||
// Enchantment *Enchantment::enchantments[256];
|
||||
|
|
@ -119,8 +120,9 @@ int Enchantment::getDamageProtection(int level, DamageSource* source) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Enchantment::getDamageBonus(int level, std::shared_ptr<Mob> target) {
|
||||
return 0;
|
||||
float Enchantment::getDamageBonus(int level,
|
||||
std::shared_ptr<LivingEntity> target) {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
bool Enchantment::isCompatibleWith(Enchantment* other) const {
|
||||
|
|
@ -134,14 +136,12 @@ Enchantment* Enchantment::setDescriptionId(int id) {
|
|||
|
||||
int Enchantment::getDescriptionId() { return descriptionId; }
|
||||
|
||||
std::wstring Enchantment::getFullname(int level, std::wstring& unformatted) {
|
||||
HtmlString Enchantment::getFullname(int level) {
|
||||
wchar_t formatted[256];
|
||||
swprintf(formatted, 256, L"%ls %ls", app.GetString(getDescriptionId()),
|
||||
getLevelString(level).c_str());
|
||||
unformatted = formatted;
|
||||
swprintf(formatted, 256, L"<font color=\"#%08x\">%ls</font>",
|
||||
app.GetHTMLColour(eHTMLColor_f), unformatted.c_str());
|
||||
return formatted;
|
||||
|
||||
return HtmlString(formatted, eHTMLColor_f);
|
||||
}
|
||||
|
||||
bool Enchantment::canEnchant(std::shared_ptr<ItemInstance> item) {
|
||||
|
|
|
|||
|
|
@ -74,12 +74,12 @@ public:
|
|||
virtual int getMinCost(int level);
|
||||
virtual int getMaxCost(int level);
|
||||
virtual int getDamageProtection(int level, DamageSource* source);
|
||||
virtual int getDamageBonus(int level, std::shared_ptr<Mob> target);
|
||||
virtual float getDamageBonus(int level,
|
||||
std::shared_ptr<LivingEntity> target);
|
||||
virtual bool isCompatibleWith(Enchantment* other) const;
|
||||
virtual Enchantment* setDescriptionId(int id);
|
||||
virtual int getDescriptionId();
|
||||
virtual std::wstring getFullname(
|
||||
int level, std::wstring& unformatted); // 4J Stu added unformatted
|
||||
virtual HtmlString getFullname(int level);
|
||||
virtual bool canEnchant(std::shared_ptr<ItemInstance> item);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ void EnchantmentHelper::setEnchantments(
|
|||
|
||||
int EnchantmentHelper::getEnchantmentLevel(int enchantmentId,
|
||||
ItemInstanceArray inventory) {
|
||||
if (inventory.data == NULL) return 0;
|
||||
int bestLevel = 0;
|
||||
// for (ItemInstance piece : inventory)
|
||||
for (unsigned int i = 0; i < inventory.length; ++i) {
|
||||
|
|
@ -142,12 +143,12 @@ EnchantmentHelper::GetDamageProtectionIteration
|
|||
* @param source
|
||||
* @return
|
||||
*/
|
||||
int EnchantmentHelper::getDamageProtection(std::shared_ptr<Inventory> inventory,
|
||||
int EnchantmentHelper::getDamageProtection(ItemInstanceArray armor,
|
||||
DamageSource* source) {
|
||||
getDamageProtectionIteration.sum = 0;
|
||||
getDamageProtectionIteration.source = source;
|
||||
|
||||
runIterationOnInventory(getDamageProtectionIteration, inventory->armor);
|
||||
runIterationOnInventory(getDamageProtectionIteration, armor);
|
||||
|
||||
if (getDamageProtectionIteration.sum > 25) {
|
||||
getDamageProtectionIteration.sum = 25;
|
||||
|
|
@ -172,75 +173,72 @@ EnchantmentHelper::GetDamageBonusIteration
|
|||
* @param target
|
||||
* @return
|
||||
*/
|
||||
int EnchantmentHelper::getDamageBonus(std::shared_ptr<Inventory> inventory,
|
||||
std::shared_ptr<Mob> target) {
|
||||
float EnchantmentHelper::getDamageBonus(std::shared_ptr<LivingEntity> source,
|
||||
std::shared_ptr<LivingEntity> target) {
|
||||
getDamageBonusIteration.sum = 0;
|
||||
getDamageBonusIteration.target = target;
|
||||
|
||||
runIterationOnItem(getDamageBonusIteration, inventory->getSelected());
|
||||
runIterationOnItem(getDamageBonusIteration, source->getCarriedItem());
|
||||
|
||||
if (getDamageBonusIteration.sum > 0) {
|
||||
return 1 + random.nextInt(getDamageBonusIteration.sum);
|
||||
}
|
||||
return 0;
|
||||
return getDamageBonusIteration.sum;
|
||||
}
|
||||
|
||||
int EnchantmentHelper::getKnockbackBonus(std::shared_ptr<Inventory> inventory,
|
||||
std::shared_ptr<Mob> target) {
|
||||
int EnchantmentHelper::getKnockbackBonus(std::shared_ptr<LivingEntity> source,
|
||||
std::shared_ptr<LivingEntity> target) {
|
||||
return getEnchantmentLevel(Enchantment::knockback->id,
|
||||
inventory->getSelected());
|
||||
source->getCarriedItem());
|
||||
}
|
||||
|
||||
int EnchantmentHelper::getFireAspect(std::shared_ptr<Mob> source) {
|
||||
int EnchantmentHelper::getFireAspect(std::shared_ptr<LivingEntity> source) {
|
||||
return getEnchantmentLevel(Enchantment::fireAspect->id,
|
||||
source->getCarriedItem());
|
||||
}
|
||||
|
||||
int EnchantmentHelper::getOxygenBonus(std::shared_ptr<Inventory> inventory) {
|
||||
int EnchantmentHelper::getOxygenBonus(std::shared_ptr<LivingEntity> source) {
|
||||
return getEnchantmentLevel(Enchantment::drownProtection->id,
|
||||
inventory->armor);
|
||||
source->getEquipmentSlots());
|
||||
}
|
||||
|
||||
int EnchantmentHelper::getDiggingBonus(std::shared_ptr<Inventory> inventory) {
|
||||
int EnchantmentHelper::getDiggingBonus(std::shared_ptr<LivingEntity> source) {
|
||||
return getEnchantmentLevel(Enchantment::diggingBonus->id,
|
||||
inventory->getSelected());
|
||||
source->getCarriedItem());
|
||||
}
|
||||
|
||||
int EnchantmentHelper::getDigDurability(std::shared_ptr<Inventory> inventory) {
|
||||
int EnchantmentHelper::getDigDurability(std::shared_ptr<LivingEntity> source) {
|
||||
return getEnchantmentLevel(Enchantment::digDurability->id,
|
||||
inventory->getSelected());
|
||||
source->getCarriedItem());
|
||||
}
|
||||
|
||||
bool EnchantmentHelper::hasSilkTouch(std::shared_ptr<Inventory> inventory) {
|
||||
bool EnchantmentHelper::hasSilkTouch(std::shared_ptr<LivingEntity> source) {
|
||||
return getEnchantmentLevel(Enchantment::untouching->id,
|
||||
inventory->getSelected()) > 0;
|
||||
source->getCarriedItem()) > 0;
|
||||
}
|
||||
|
||||
int EnchantmentHelper::getDiggingLootBonus(
|
||||
std::shared_ptr<Inventory> inventory) {
|
||||
std::shared_ptr<LivingEntity> source) {
|
||||
return getEnchantmentLevel(Enchantment::resourceBonus->id,
|
||||
inventory->getSelected());
|
||||
source->getCarriedItem());
|
||||
}
|
||||
|
||||
int EnchantmentHelper::getKillingLootBonus(
|
||||
std::shared_ptr<Inventory> inventory) {
|
||||
std::shared_ptr<LivingEntity> source) {
|
||||
return getEnchantmentLevel(Enchantment::lootBonus->id,
|
||||
inventory->getSelected());
|
||||
source->getCarriedItem());
|
||||
}
|
||||
|
||||
bool EnchantmentHelper::hasWaterWorkerBonus(
|
||||
std::shared_ptr<Inventory> inventory) {
|
||||
return getEnchantmentLevel(Enchantment::waterWorker->id, inventory->armor) >
|
||||
0;
|
||||
std::shared_ptr<LivingEntity> source) {
|
||||
return getEnchantmentLevel(Enchantment::waterWorker->id,
|
||||
source->getEquipmentSlots()) > 0;
|
||||
}
|
||||
|
||||
int EnchantmentHelper::getArmorThorns(std::shared_ptr<Mob> source) {
|
||||
int EnchantmentHelper::getArmorThorns(std::shared_ptr<LivingEntity> source) {
|
||||
return getEnchantmentLevel(Enchantment::thorns->id,
|
||||
source->getEquipmentSlots());
|
||||
}
|
||||
|
||||
std::shared_ptr<ItemInstance> EnchantmentHelper::getRandomItemWith(
|
||||
Enchantment* enchantment, std::shared_ptr<Mob> source) {
|
||||
Enchantment* enchantment, std::shared_ptr<LivingEntity> source) {
|
||||
ItemInstanceArray items = source->getEquipmentSlots();
|
||||
for (unsigned int i = 0; i < items.length; ++i) {
|
||||
std::shared_ptr<ItemInstance> item = items[i];
|
||||
|
|
|
|||
|
|
@ -50,14 +50,14 @@ private:
|
|||
* @return
|
||||
*/
|
||||
public:
|
||||
static int getDamageProtection(std::shared_ptr<Inventory> inventory,
|
||||
static int getDamageProtection(ItemInstanceArray armor,
|
||||
DamageSource* source);
|
||||
|
||||
private:
|
||||
class GetDamageBonusIteration : public EnchantmentIterationMethod {
|
||||
public:
|
||||
int sum;
|
||||
std::shared_ptr<Mob> target;
|
||||
float sum;
|
||||
std::shared_ptr<LivingEntity> target;
|
||||
|
||||
virtual void doEnchantment(Enchantment* enchantment, int level);
|
||||
};
|
||||
|
|
@ -71,21 +71,21 @@ private:
|
|||
* @return
|
||||
*/
|
||||
public:
|
||||
static int getDamageBonus(std::shared_ptr<Inventory> inventory,
|
||||
std::shared_ptr<Mob> target);
|
||||
static int getKnockbackBonus(std::shared_ptr<Inventory> inventory,
|
||||
std::shared_ptr<Mob> target);
|
||||
static int getFireAspect(std::shared_ptr<Mob> source);
|
||||
static int getOxygenBonus(std::shared_ptr<Inventory> inventory);
|
||||
static int getDiggingBonus(std::shared_ptr<Inventory> inventory);
|
||||
static int getDigDurability(std::shared_ptr<Inventory> inventory);
|
||||
static bool hasSilkTouch(std::shared_ptr<Inventory> inventory);
|
||||
static int getDiggingLootBonus(std::shared_ptr<Inventory> inventory);
|
||||
static int getKillingLootBonus(std::shared_ptr<Inventory> inventory);
|
||||
static bool hasWaterWorkerBonus(std::shared_ptr<Inventory> inventory);
|
||||
static int getArmorThorns(std::shared_ptr<Mob> source);
|
||||
static float getDamageBonus(std::shared_ptr<LivingEntity> source,
|
||||
std::shared_ptr<LivingEntity> target);
|
||||
static int getKnockbackBonus(std::shared_ptr<LivingEntity> source,
|
||||
std::shared_ptr<LivingEntity> target);
|
||||
static int getFireAspect(std::shared_ptr<LivingEntity> source);
|
||||
static int getOxygenBonus(std::shared_ptr<LivingEntity> source);
|
||||
static int getDiggingBonus(std::shared_ptr<LivingEntity> source);
|
||||
static int getDigDurability(std::shared_ptr<LivingEntity> source);
|
||||
static bool hasSilkTouch(std::shared_ptr<LivingEntity> source);
|
||||
static int getDiggingLootBonus(std::shared_ptr<LivingEntity> source);
|
||||
static int getKillingLootBonus(std::shared_ptr<LivingEntity> source);
|
||||
static bool hasWaterWorkerBonus(std::shared_ptr<LivingEntity> source);
|
||||
static int getArmorThorns(std::shared_ptr<LivingEntity> source);
|
||||
static std::shared_ptr<ItemInstance> getRandomItemWith(
|
||||
Enchantment* enchantment, std::shared_ptr<Mob> source);
|
||||
Enchantment* enchantment, std::shared_ptr<LivingEntity> source);
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ int ProtectionEnchantment::getDamageProtection(int level,
|
|||
if (type == FIRE && source->isFire()) return Mth::floor(protect * 1.25f);
|
||||
if (type == FALL && source == DamageSource::fall)
|
||||
return Mth::floor(protect * 2.5f);
|
||||
if (type == EXPLOSION && source == DamageSource::explosion)
|
||||
if (type == EXPLOSION && source->isExplosion())
|
||||
return Mth::floor(protect * 1.5f);
|
||||
if (type == PROJECTILE && source->isProjectile())
|
||||
return Mth::floor(protect * 1.5f);
|
||||
|
|
@ -51,10 +51,10 @@ int ProtectionEnchantment::getDescriptionId() { return names[type]; }
|
|||
bool ProtectionEnchantment::isCompatibleWith(Enchantment* other) const {
|
||||
ProtectionEnchantment* pe = dynamic_cast<ProtectionEnchantment*>(other);
|
||||
if (pe != NULL) {
|
||||
if (pe->type == this->type) {
|
||||
if (pe->type == type) {
|
||||
return false;
|
||||
}
|
||||
if (this->type == FALL || pe->type == FALL) {
|
||||
if (type == FALL || pe->type == FALL) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ int ThornsEnchantment::getDamage(int level, Random* random) {
|
|||
}
|
||||
}
|
||||
|
||||
void ThornsEnchantment::doThornsAfterAttack(std::shared_ptr<Entity> source,
|
||||
std::shared_ptr<Mob> target,
|
||||
Random* random) {
|
||||
void ThornsEnchantment::doThornsAfterAttack(
|
||||
std::shared_ptr<Entity> source, std::shared_ptr<LivingEntity> target,
|
||||
Random* random) {
|
||||
int level = EnchantmentHelper::getArmorThorns(target);
|
||||
std::shared_ptr<ItemInstance> item =
|
||||
EnchantmentHelper::getRandomItemWith(Enchantment::thorns, target);
|
||||
|
|
@ -51,11 +51,11 @@ void ThornsEnchantment::doThornsAfterAttack(std::shared_ptr<Entity> source,
|
|||
source->playSound(eSoundType_DAMAGE_THORNS, .5f, 1.0f);
|
||||
|
||||
if (item != NULL) {
|
||||
item->hurt(3, target);
|
||||
item->hurtAndBreak(3, target);
|
||||
}
|
||||
} else {
|
||||
if (item != NULL) {
|
||||
item->hurt(1, target);
|
||||
item->hurtAndBreak(1, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,6 @@ public:
|
|||
static bool shouldHit(int level, Random* random);
|
||||
static int getDamage(int level, Random* random);
|
||||
static void doThornsAfterAttack(std::shared_ptr<Entity> source,
|
||||
std::shared_ptr<Mob> target,
|
||||
std::shared_ptr<LivingEntity> target,
|
||||
Random* random);
|
||||
};
|
||||
Loading…
Reference in a new issue