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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
/*
* The Mana Server
* Copyright (C) 2004-2010 The Mana World Development Team
*
* This file is part of The Mana Server.
*
* The Mana Server is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* The Mana Server is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with The Mana Server. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INVENTORY_H
#define INVENTORY_H
#include "game-server/character.h"
#include "net/messageout.h"
class ItemClass;
/**
* Class used to handle Character possessions and prepare outgoing messages.
*/
class Inventory
{
public:
/**
* Creates a view on the possessions of a character.
*/
explicit Inventory(Entity *);
Inventory(Entity *, Possessions &possessions);
/**
* Commits delayed changes if applicable.
* Sends the update message to the client.
*/
~Inventory()
{}
/**
* Sends complete inventory status to the client.
*/
void sendFull() const;
/**
* Ensures the inventory is sane and apply equipment modifiers.
* Should be run only once and the very first time.
*/
void initialize();
/**
* Equips item from given inventory slot.
* @param inventorySlot The slot in which the target item is in.
* @returns whether the item could be equipped.
*/
bool equip(int inventorySlot);
/**
* Unequips all the items with the given item if
* from given equipment slot.
* @param itemId The item Id to unequip.
* @returns whether all item id could be unequipped.
* @note returns true when no item with given ids were equipped.
*/
bool unequipItem(unsigned itemId);
/**
* Unequips item from given equipment slot.
* @param itemInstance The item instance id used to know what to unequip
* @returns Whether it was unequipped.
*/
bool unequip(unsigned itemInstance);
/**
* Gets the item instance from the given equipment slot.
* Return 0 if none.
*/
unsigned getSlotItemInstance(unsigned slot);
/**
* Inserts some items into the inventory.
* @return number of items not inserted (to be dropped on floor?).
*/
unsigned insert(unsigned itemId, unsigned amount);
/**
* Removes some items from inventory.
* @return number of items not removed.
*/
unsigned remove(unsigned itemId, unsigned amount);
/**
* Moves some items from the first slot to the second one.
* @returns number of items not moved.
*/
unsigned move(unsigned slot1, unsigned slot2,
unsigned amount);
/**
* Removes some items from inventory.
* @return number of items not removed.
*/
unsigned removeFromSlot(unsigned slot, unsigned amount);
/**
* Counts number of items with given Id.
* @param inInventory Search in player's inventory.
* @param inEquipment Search in player's equipment.
*/
unsigned count(unsigned itemId, bool inInventory = true,
bool inEquipment = true) const;
/**
* Gets the ID of the items in a given slot.
*/
unsigned getItem(unsigned slot) const;
/**
* Returns the first inventory slot with the given item Id.
* Returns -1 otherwise.
*/
int getFirstSlot(unsigned itemId);
private:
/**
* Tell whether the equipment slot has enough room in an equipment slot.
* @param equipmentSlot the slot in equipement to check.
* @param capacityRequested the capacity needed.
*/
bool checkEquipmentCapacity(unsigned equipmentSlot,
unsigned capacityRequested);
/**
* Test whether the inventory has enough space to welcome
* the willing-to-be equipment slot.
* @todo
*/
bool hasInventoryEnoughSpace(unsigned /* equipmentSlot */)
{ return true; }
/**
* Test the items unequipment requirements.
* This is especially useful for scripted equipment.
* @todo
*/
bool testUnequipScriptRequirements(unsigned /* equipementSlot */)
{ return true; }
/**
* Test the items equipment for scripted requirements.
* @todo
*/
bool testEquipScriptRequirements(unsigned /* itemId */)
{ return true; }
/**
* Return an equip item instance id unique to the item used,
* per character.
* This is used to differenciate some items that can be equipped
* multiple times, like one-handed weapons for instance.
*/
unsigned getNewEquipItemInstance();
/**
* Check the inventory is within the slot limit and capacity.
* Forcibly delete items from the end if it is not.
* @todo Drop items instead?
*/
void checkInventorySize();
/**
* Check potential visible character sprite changes.
*/
void checkLookchanges(unsigned slotTypeId);
/**
* Apply equipment triggers.
*/
void updateEquipmentTrigger(unsigned oldId, unsigned itemId);
void updateEquipmentTrigger(ItemClass *oldI, ItemClass *newI);
Possessions *mPoss; /**< Pointer to the modified possessions. */
Entity *mCharacter; /**< Character to notify. */
};
#endif
|