summaryrefslogtreecommitdiffstats
path: root/src/game-server/inventory.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-07-27 14:46:41 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-07-27 14:46:41 +0200
commit8aaa341a8ee51853737eabf52fe369f75be07e93 (patch)
tree2fe6df6d53955da0f06d175db303df40751faa84 /src/game-server/inventory.cpp
parent006a213747eb8063ad543211b9776caba027ea4a (diff)
downloadmanaserv-8aaa341a8ee51853737eabf52fe369f75be07e93.tar.gz
manaserv-8aaa341a8ee51853737eabf52fe369f75be07e93.tar.xz
manaserv-8aaa341a8ee51853737eabf52fe369f75be07e93.zip
Begun Applying the new equipment slot handling design.
now, the equipment slots are independant from the inventory slots according to the inventory and equipment data. This will permit to avoid checking the equipment each time one touches the inventory and vice versa, and make the former delayed mode useless. Also, note that equipped items will be removed from inventory and readded once unequipped. The design will permit the following, even if not implemented yet: - To make equipment items stackable again, if wanted. - Have more than one item with the same id equipped on different slots using the itemInstance field. Note: I didn't add the database structure updates yet, to see whether other changes may later go along with those.
Diffstat (limited to 'src/game-server/inventory.cpp')
-rw-r--r--src/game-server/inventory.cpp50
1 files changed, 11 insertions, 39 deletions
diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp
index e218a91..8689f29 100644
--- a/src/game-server/inventory.cpp
+++ b/src/game-server/inventory.cpp
@@ -54,8 +54,9 @@ void Inventory::sendFull() const
k != k_end;
++k)
{
- m.writeInt8(k->first); // equip slot
- m.writeInt16(k->second); // inventory slot
+ m.writeInt16(k->first); // Equip slot id
+ m.writeInt16(k->second.itemId); // Item id
+ m.writeInt16(k->second.itemInstance); // Item instance
}
gameHandler->sendTo(mCharacter, m);
@@ -106,7 +107,7 @@ void Inventory::initialize()
*/
for (it2 = mPoss->equipSlots.begin(); it2 != it2_end; ++it2)
{
- if (equipment.insert(it2->second).second)
+ if (equipment.insert(it2->second.itemInstance).second)
{
/*
* Perform checks for equipped items
@@ -117,7 +118,7 @@ void Inventory::initialize()
/*
* Apply all equip triggers.
*/
- itemManager->getItem(mPoss->inventory.at(it2->second).itemId)
+ itemManager->getItem(it2->second.itemId)
->useTrigger(mCharacter, ITT_EQUIP);
}
}
@@ -239,8 +240,7 @@ unsigned int Inventory::count(unsigned int itemId) const
unsigned int Inventory::remove(unsigned int itemId, unsigned int amount, bool force)
{
- bool inv = false,
- eq = !itemManager->getItem(itemId)->getItemEquipData().empty();
+ bool inv = false;
MessageOut invMsg(GPMSG_INVENTORY);
bool triggerLeaveInventory = true;
@@ -251,26 +251,6 @@ unsigned int Inventory::remove(unsigned int itemId, unsigned int amount, bool fo
{
if (amount)
{
- if (eq)
- {
- // If the item is equippable,
- // we have additional checks to make.
- bool ch = false;
- for (EquipData::iterator it2 = mPoss->equipSlots.begin(),
- it2_end = mPoss->equipSlots.end();
- it2 != it2_end;
- ++it2)
- if (it2->second == it->first)
- {
- if (force)
- unequip(it2);
- else
- ch = inv = true;
- break;
- }
- if (ch && !force)
- continue;
- }
unsigned int sub = std::min(amount, it->second.amount);
amount -= sub;
it->second.amount -= sub;
@@ -320,15 +300,6 @@ unsigned int Inventory::move(unsigned int slot1, unsigned int slot2,
if (it1 == inv_end)
return amount;
- EquipData::iterator it, it_end = mPoss->equipSlots.end();
- for (it = mPoss->equipSlots.begin();
- it != it_end;
- ++it)
- if (it->second == slot1)
- // Bad things will happen when you can stack multiple equippable
- // items in the same slot anyway.
- it->second = slot2;
-
MessageOut invMsg(GPMSG_INVENTORY);
unsigned int nb = std::min(amount, it1->second.amount);
@@ -538,9 +509,10 @@ bool Inventory::equip(int slot, bool override)
* compile time options optimising for other usage.
* For now, this is adequate assuming `normal' usage.
*/
- for (unsigned int i = 0; i < it3->second; ++i)
+ /** Part disabled until reimplemented*/
+ /*for (unsigned int i = 0; i < it3->second; ++i)
mPoss->equipSlots.insert(
- std::make_pair(it3->first, slot));
+ std::make_pair(it3->first, slot));*/
}
changeEquipment(0, it->second.itemId);
@@ -598,7 +570,7 @@ bool Inventory::equip(int slot, bool override)
bool Inventory::unequip(EquipData::iterator it)
{
- return unequip(it->second, &it);
+ return unequip(it->first, &it);
}
bool Inventory::unequip(unsigned int slot, EquipData::iterator *itp)
@@ -611,7 +583,7 @@ bool Inventory::unequip(unsigned int slot, EquipData::iterator *itp)
// Erase all equip entries that point to the given inventory slot
while (it != it_end)
{
- if (it->second == slot)
+ if (it->first == slot)
{
changed = true;
mPoss->equipSlots.erase(it++);