Files
MinecraftConsoles/Minecraft.World/DamageEnchantment.cpp
ModMaker101 a9be52c41a Project modernization (#630)
* Fixed boats falling and a TP glitch #266

* Replaced every C-style cast with C++ ones

* Replaced every C-style cast with C++ ones

* Fixed boats falling and a TP glitch #266

* Updated NULL to nullptr and fixing some type issues

* Modernized and fixed a few bugs

- Replaced most instances of `NULL` with `nullptr`.
- Replaced most `shared_ptr(new ...)` with `make_shared`.
- Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances.

* Fixing more conflicts

* Replace int loops with size_t and start work on overrides
2026-03-08 09:56:03 +07:00

62 lines
1.5 KiB
C++

#include "stdafx.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.item.h"
#include "DamageEnchantment.h"
const int DamageEnchantment::names[] = {IDS_ENCHANTMENT_DAMAGE_ALL, IDS_ENCHANTMENT_DAMAGE_UNDEAD, IDS_ENCHANTMENT_DAMAGE_ARTHROPODS};
const int DamageEnchantment::minCost[] = {1, 5, 5};
const int DamageEnchantment::levelCost[] = {11, 8, 8};
const int DamageEnchantment::levelCostSpan[] = {20, 20, 20};
DamageEnchantment::DamageEnchantment(int id, int frequency, int type) : Enchantment(id, frequency, EnchantmentCategory::weapon), type(type)
{
}
int DamageEnchantment::getMinCost(int level)
{
return minCost[type] + (level - 1) * levelCost[type];
}
int DamageEnchantment::getMaxCost(int level)
{
return getMinCost(level) + levelCostSpan[type];
}
int DamageEnchantment::getMaxLevel()
{
return 5;
}
float DamageEnchantment::getDamageBonus(int level, shared_ptr<LivingEntity> target)
{
if (type == ALL)
{
return level *1.25f;
}
if (type == UNDEAD && target->getMobType() == UNDEAD)
{
return level * 2.5f;
}
if (type == ARTHROPODS && target->getMobType() == ARTHROPOD)
{
return level * 2.5f;
}
return 0;
}
int DamageEnchantment::getDescriptionId()
{
return names[type];
}
bool DamageEnchantment::isCompatibleWith(Enchantment *other) const
{
return dynamic_cast<DamageEnchantment *>(other) == nullptr;
}
bool DamageEnchantment::canEnchant(shared_ptr<ItemInstance> item)
{
HatchetItem *hatchet = dynamic_cast<HatchetItem *>(item->getItem());
if (hatchet) return true;
return Enchantment::canEnchant(item);
}