aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/DamageEnchantment.cpp
blob: 4ca8c9a6ba59dd6cd0d754313d9c55894c2375cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#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);
}