forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
minion_equipment.cpp
57 lines (50 loc) · 1.61 KB
/
minion_equipment.cpp
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
#include "stdafx.h"
#include "minion_equipment.h"
#include "item.h"
#include "creature.h"
static vector<EffectType> combatConsumables {
EffectType::SPEED,
EffectType::SLOW,
EffectType::SLEEP,
EffectType::BLINDNESS,
EffectType::INVISIBLE,
EffectType::STR_BONUS,
EffectType::DEX_BONUS,
};
Optional<MinionEquipment::EquipmentType> MinionEquipment::getEquipmentType(const Item* it) {
if (contains({ItemType::WEAPON, ItemType::ARMOR}, it->getType()))
return MinionEquipment::ARMOR;
if (contains({ItemType::RANGED_WEAPON, ItemType::AMMO}, it->getType()))
return MinionEquipment::ARCHERY;
if (it->getEffectType() == EffectType::HEAL)
return MinionEquipment::HEALING;
if (contains(combatConsumables, it->getEffectType()))
return MinionEquipment::COMBAT_ITEM;
return Nothing();
}
bool MinionEquipment::isItemUseful(const Item* it) const {
return getEquipmentType(it) || contains({ItemType::POTION, ItemType::SCROLL}, it->getType());
}
bool MinionEquipment::needs(const Creature* c, const Item* it) {
EquipmentType type = *getEquipmentType(it);
return c->canEquip(it) || (type == ARCHERY && c->hasSkill(Skill::archery))
|| (type == HEALING && !c->isNotLiving())
|| type == COMBAT_ITEM;
}
bool MinionEquipment::needsItem(const Creature* c, const Item* it) {
if (owners.count(it)) {
if (owners.at(it) == c)
return true;
if (owners.at(it)->isDead())
owners.erase(it);
else
return false;
}
if (!getEquipmentType(it) || !c->isHumanoid())
return false;
if (needs(c, it)) {
owners[it] = c;
return true;
} else
return false;
}