void Container::removeThing(Thing* thing, uint32_t count) { Item* item = thing->getItem(); if (item == nullptr) { return /*RETURNVALUE_NOTPOSSIBLE*/; } int32_t index = getThingIndex(thing); if (index == -1) { return /*RETURNVALUE_NOTPOSSIBLE*/; } if (item->isStackable() && count != item->getItemCount()) { uint8_t newCount = static_cast<uint8_t>(std::max<int32_t>(0, item->getItemCount() - count)); const int32_t oldWeight = item->getWeight(); item->setItemCount(newCount); updateItemWeight(-oldWeight + item->getWeight()); //send change to client if (getParent()) { onUpdateContainerItem(index, item, item); } } else { updateItemWeight(-static_cast<int32_t>(item->getWeight())); //send change to client if (getParent()) { onRemoveContainerItem(index, item); } item->setParent(nullptr); itemlist.erase(itemlist.begin() + index); } }
void Container::__removeThing(Thing* thing, uint32_t count) { Item* item = thing->getItem(); if (item == NULL) { return /*RET_NOTPOSSIBLE*/; } int32_t index = __getIndexOfThing(thing); if (index == -1) { return /*RET_NOTPOSSIBLE*/; } if (item->isStackable() && count != item->getItemCount()) { uint8_t newCount = (uint8_t)std::max<int32_t>(0, item->getItemCount() - count); const double oldWeight = -item->getWeight(); item->setItemCount(newCount); const double diffWeight = oldWeight + item->getWeight(); totalWeight += diffWeight; //send change to client if (getParent()) { if (Container* parentContainer = getParentContainer()) { parentContainer->updateItemWeight(diffWeight); } const ItemType& it = Item::items[item->getID()]; onUpdateContainerItem(index, item, it, item, it); } } else { //send change to client if (getParent()) { if (Container* parentContainer = getParentContainer()) { parentContainer->updateItemWeight(-item->getWeight()); } onRemoveContainerItem(index, item); } totalWeight -= item->getWeight(); item->setParent(NULL); itemlist.erase(itemlist.begin() + index); } }
void Container::__removeThing(Thing* thing, uint32_t count) { Item* item = thing->getItem(); if(!item) { #ifdef __DEBUG_MOVESYS__ std::clog << "Failure: [Container::__removeThing] item == NULL" << std::endl; #endif return /*RET_NOTPOSSIBLE*/; } int32_t index = __getIndexOfThing(thing); if(index == -1) { #ifdef __DEBUG_MOVESYS__ std::clog << "Failure: [Container::__removeThing] index == -1" << std::endl; #endif return /*RET_NOTPOSSIBLE*/; } ItemList::iterator cit = std::find(itemlist.begin(), itemlist.end(), thing); if(cit == itemlist.end()) { #ifdef __DEBUG_MOVESYS__ std::clog << "Failure: [Container::__removeThing] item not found" << std::endl; #endif return /*RET_NOTPOSSIBLE*/; } if(item->isStackable() && count != item->getItemCount()) { const double oldWeight = -item->getWeight(); item->setItemCount(std::max(0, (int32_t)(item->getItemCount() - count))); const double diffWeight = oldWeight + item->getWeight(); totalWeight += diffWeight; //send change to client if(getParent()) { if(Container* parentContainer = getParentContainer()) parentContainer->updateItemWeight(diffWeight); const ItemType& it = Item::items[item->getID()]; onUpdateContainerItem(index, item, it, item, it); } } else { //send change to client if(getParent()) { if(Container* parentContainer = getParentContainer()) parentContainer->updateItemWeight(-item->getWeight()); onRemoveContainerItem(index, item); } totalWeight -= item->getWeight(); item->setParent(NULL); itemlist.erase(cit); } }