diff --git a/source/WorldServer/Broker/BrokerManager.cpp b/source/WorldServer/Broker/BrokerManager.cpp index 84a7e53..ae9568b 100644 --- a/source/WorldServer/Broker/BrokerManager.cpp +++ b/source/WorldServer/Broker/BrokerManager.cpp @@ -236,15 +236,18 @@ void BrokerManager::SetSalePrice(int32 cid, int64 uid, int64 price) } } -void BrokerManager::RemoveItem(int32 cid, int64 uid, int16 qty) +void BrokerManager::RemoveItem(int32 cid, int64 uid, int16 qty, bool shouldDelete) { bool didDelete = false; - SaleItem snapshot; + std::optional snapshot; { std::unique_lock lock(mtx_); if (auto ait = active_items_by_char_.find(cid); ait != active_items_by_char_.end()) { auto& m = ait->second; if (auto it = m.find(uid); it != m.end()) { + if(shouldDelete) + qty = it->second.count; + it->second.count -= qty; if (it->second.count <= 0) { didDelete = true; @@ -258,14 +261,14 @@ void BrokerManager::RemoveItem(int32 cid, int64 uid, int16 qty) } } } - if (didDelete) { + if (didDelete || shouldDelete) { DeleteItemFromDB(cid, uid); peer_manager.sendPeersRemoveItemSale(cid, uid); } - else if (snapshot.count > 0) { - SaveItemToDB(snapshot); - peer_manager.sendPeersAddItemSale(snapshot.character_id, snapshot.house_id, snapshot.item_id, snapshot.unique_id, snapshot.cost_copper, snapshot.inv_slot_id, - snapshot.slot_id, snapshot.count, snapshot.from_inventory, snapshot.for_sale, snapshot.creator); + else if (snapshot) { + SaveItemToDB(*snapshot); + peer_manager.sendPeersAddItemSale(snapshot->character_id, snapshot->house_id, snapshot->item_id, snapshot->unique_id, snapshot->cost_copper, snapshot->inv_slot_id, + snapshot->slot_id, snapshot->count, snapshot->from_inventory, snapshot->for_sale, snapshot->creator); } } diff --git a/source/WorldServer/Broker/BrokerManager.h b/source/WorldServer/Broker/BrokerManager.h index d291a1c..afc1ea6 100644 --- a/source/WorldServer/Broker/BrokerManager.h +++ b/source/WorldServer/Broker/BrokerManager.h @@ -100,7 +100,7 @@ public: int64 GetSalePrice(int32 cid, int64 uid); //–– Remove quantity - void RemoveItem(int32 cid, int64 uid, int16 quantity = 1); + void RemoveItem(int32 cid, int64 uid, int16 quantity = 1, bool shouldDelete = false); //–– Attempt to buy (atomic DB + in-memory + broadcast) bool BuyItem(Client* buyer, int32 seller_cid, int64 uid, int32 quantity); diff --git a/source/WorldServer/Commands/Commands.cpp b/source/WorldServer/Commands/Commands.cpp index f969dc5..a69ea29 100644 --- a/source/WorldServer/Commands/Commands.cpp +++ b/source/WorldServer/Commands/Commands.cpp @@ -7115,7 +7115,7 @@ void Commands::Command_Inventory(Client* client, Seperator* sep, EQ2_RemoteComma return; } if(client->GetPlayer()->item_list.IsItemInSlotType(item, InventorySlotType::HOUSE_VAULT) || client->GetPlayer()->item_list.IsItemInSlotType(item, InventorySlotType::BASE_INVENTORY)) { - broker.RemoveItem(client->GetPlayer()->GetCharacterID(), item->details.unique_id, item->details.count); + broker.RemoveItem(client->GetPlayer()->GetCharacterID(), item->details.unique_id, item->details.count, true); } if(item->GetItemScript() && lua_interface) lua_interface->RunItemScript(item->GetItemScript(), "destroyed", item, client->GetPlayer());