-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventory.h
65 lines (51 loc) · 1.88 KB
/
Inventory.h
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
63
64
65
#pragma once
#include <cstdint>
#include <string>
#include <memory>
#include "Item.h"
#include "RegularItems.h"
#include "Equipment.h"
class Inventory {
private:
/**
* Scans the inventory for the first item of the given type. If it is NONE, ARMOR, or WEAPON, it does not scan.
*/
void findFirstItems(ItemType type);
protected:
size_t maxSlots = 30;
size_t curSlots = 0;
int64_t maxWeight = 50;
int64_t curWeight = 0;
std::vector<std::shared_ptr<Item>> backing;
int64_t gold = 0;
size_t firstHeal = SIZE_MAX;
size_t firstStatus = SIZE_MAX;
size_t firstAttack = SIZE_MAX;
public:
explicit Inventory(size_t max = 30);
// These copy constructors are deep copies - they copy the underlying items as well as the container.
Inventory(const Inventory&);
explicit Inventory(const std::vector<std::shared_ptr<Item>>&);
Inventory(std::initializer_list<const std::shared_ptr<Item>>);
[[nodiscard]] int64_t getGold() const;
[[nodiscard]] size_t getMaxSlots() const;
[[nodiscard]] size_t getUsedSlots() const;
[[nodiscard]] size_t getFirst(ItemType) const;
size_t GetPos(const std::shared_ptr<Item>&);
std::shared_ptr<Item> operator[] (size_t);
bool ReplaceItem(const std::shared_ptr<Item>&); // function called by AddItem when inventory is full. True if item is replaced, else false
std::unique_ptr<Item> RemoveItem(size_t pos, int64_t amnt = 0); // Used instead of ChangeAmount amount is to be removed. 0 in second integer removes all amount of the item
void AddGold(int64_t);
void changeWeight(int64_t);
/**
* Attempts to add the item to the inventory. Does not copy it, be careful!
*
* @return True if the item was added.
*/
bool AddItem(const std::shared_ptr<Item>&);
/**
* Prints the inventory.
*/
void print(bool numbered);
void GarbageCollection();
};