summaryrefslogtreecommitdiff
path: root/src/account-server/character.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/account-server/character.cpp')
-rw-r--r--src/account-server/character.cpp53
1 files changed, 20 insertions, 33 deletions
diff --git a/src/account-server/character.cpp b/src/account-server/character.cpp
index 47bca5da..cafc256b 100644
--- a/src/account-server/character.cpp
+++ b/src/account-server/character.cpp
@@ -94,25 +94,21 @@ void CharacterData::serialize(MessageOut &msg)
// inventory - must be last because size isn't transmitted
const Possessions &poss = getPossessions();
const EquipData &equipData = poss.getEquipment();
- msg.writeInt16(equipData.size()); // number of equipment
- for (EquipData::const_iterator k = equipData.begin(),
- k_end = equipData.end(); k != k_end; ++k)
- {
- msg.writeInt16(k->first); // Equip slot id
- msg.writeInt16(k->second.itemId); // ItemId
- msg.writeInt16(k->second.itemInstance); // Item Instance id
- }
const InventoryData &inventoryData = poss.getInventory();
- for (InventoryData::const_iterator j = inventoryData.begin(),
- j_end = inventoryData.end(); j != j_end; ++j)
+ for (InventoryData::const_iterator itemIt = inventoryData.begin(),
+ itemIt_end = inventoryData.end(); itemIt != itemIt_end; ++itemIt)
{
- msg.writeInt16(j->first); // slot id
- msg.writeInt16(j->second.itemId); // item id
- msg.writeInt16(j->second.amount); // amount
+ int slot = itemIt->first;
+ msg.writeInt16(slot);
+ msg.writeInt16(itemIt->second.itemId);
+ msg.writeInt16(itemIt->second.amount);
+ if (equipData.find(itemIt->first) != equipData.end())
+ msg.writeInt8(1); // equipped
+ else
+ msg.writeInt8(0); // not equipped
}
}
-
void CharacterData::deserialize(MessageIn &msg)
{
// general character properties
@@ -170,33 +166,24 @@ void CharacterData::deserialize(MessageIn &msg)
giveAbility(id);
}
-
+ // inventory - must be last because size isn't transmitted
Possessions &poss = getPossessions();
- EquipData equipData;
- int equipSlotsSize = msg.readInt16();
- unsigned equipSlot;
- EquipmentItem equipItem;
- for (int j = 0; j < equipSlotsSize; ++j)
- {
- equipSlot = msg.readInt16();
- equipItem.itemId = msg.readInt16();
- equipItem.itemInstance = msg.readInt16();
- equipData.insert(equipData.end(),
- std::make_pair(equipSlot, equipItem));
- }
- poss.setEquipment(equipData);
- // Loads inventory - must be last because size isn't transmitted
InventoryData inventoryData;
+ EquipData equipmentData;
while (msg.getUnreadLength())
{
InventoryItem i;
- int slotId = msg.readInt16();
- i.itemId = msg.readInt16();
- i.amount = msg.readInt16();
- inventoryData.insert(inventoryData.end(), std::make_pair(slotId, i));
+ i.slot = msg.readInt16();
+ i.itemId = msg.readInt16();
+ i.amount = msg.readInt16();
+ i.equipmentSlot = msg.readInt8();
+ inventoryData.insert(std::make_pair(i.slot, i));
+ if (i.equipmentSlot != 0)
+ equipmentData.insert(i.slot);
}
poss.setInventory(inventoryData);
+ poss.setEquipment(equipmentData);
}
void CharacterData::setAccount(Account *acc)