I spent my whole day doing that, I think it works like 95% for me now.
The problems are:
1. Two-handed weapons. I do not know if I can deEquip both shield and weapon since player can have full bp and than some of those 2 items appear under him.
2. Also the problem can be also the item attributes since I do not copy them to new object. I do not use those attributes on my server so it is not important for me.
3. If you have two stacks of 50 arrows, only the first stack is equipped. (needs some more magic in code ;/ )
The whole function is 200 lines code which is pretty much but works.
Also I have written the function to send all the player objects which is called pretty often. It is based on Player::__getAllItemTypeCount. Can it have some performance impact ?
Code:
std::map<uint32_t, uint32_t>& Player::getAllItemClientIdCount(std::map<uint32_t, uint32_t>& countMap) const
{
for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; i++) {
Item* item = inventory[i];
if (!item) {
continue;
}
const ItemType& item_type = Item::items[item->getID()];
countMap[item_type.clientId] += Item::countByType(item, -1);
if (Container* container = item->getContainer()) {
for (ContainerIterator it = container->begin(), end = container->end(); it != end; ++it) {
const ItemType& item_type = Item::items[(*it)->getID()];
countMap[item_type.clientId] += Item::countByType(*it, -1);
}
}
}
return countMap;
}