forked from miki151/keeperrl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequipment.cpp
59 lines (48 loc) · 1.19 KB
/
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
57
58
#include "stdafx.h"
#include "equipment.h"
using namespace std;
class Item;
Item* Equipment::getItem(EquipmentSlot slot) const {
if (items.count(slot) > 0)
return items.at(slot);
else
return nullptr;
}
bool Equipment::isEquiped(const Item* item) const {
for (auto elem : items)
if (elem.second == item) {
return true;
}
return false;
}
EquipmentSlot Equipment::getSlot(const Item* item) const {
for (auto elem : items)
if (elem.second == item) {
return elem.first;
}
FAIL << "Item not in any slot " << item->getAName();
return EquipmentSlot::WEAPON;
}
void Equipment::equip(Item* item, EquipmentSlot slot) {
items[slot] = item;
CHECK(hasItem(item));
}
void Equipment::unequip(EquipmentSlot slot) {
CHECK(items.count(slot) > 0);
items.erase(slot);
}
PItem Equipment::removeItem(Item* item) {
if (isEquiped(item))
unequip(getSlot(item));
return Inventory::removeItem(item);
}
vector<PItem> Equipment::removeItems(const vector<Item*>& items) {
vector<PItem> ret;
for (Item* it : items)
ret.push_back(removeItem(it));
return ret;
}
vector<PItem> Equipment::removeAllItems() {
items.clear();
return Inventory::removeAllItems();
}