From f8533686414c55152d942e0321d51098cbf0ed54 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 26 Dec 2018 12:24:26 +0200 Subject: [PATCH] [Client] Fix loss of player items in ContainerStore::unstack() Previously, unstacking items for a player led to a PlayerInventory packet being sent about the items' removal. This change makes it so both a packet about their re-addition and their removal are sent instead, cancelling each other out, which is inelegant, but arguably preferable to complicating the sending of PlayerInventory packets again. --- apps/openmw/mwworld/containerstore.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index 2d52f44a9..a4f550c6e 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -194,6 +194,25 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::unstack(const Ptr &ptr, if (ptr.getRefData().getCount() <= count) return end(); MWWorld::ContainerStoreIterator it = addNewStack(ptr, ptr.getRefData().getCount()-count); + + /* + Start of tes3mp addition + + Send an ID_PLAYER_INVENTORY packet every time an item stack gets added for a player here + */ + Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); + + if (container == player && this == &player.getClass().getContainerStore(player)) + { + mwmp::LocalPlayer *localPlayer = mwmp::Main::get().getLocalPlayer(); + + if (!localPlayer->isReceivingInventory) + localPlayer->sendItemChange(ptr, ptr.getRefData().getCount() - count, mwmp::InventoryChanges::ADD); + } + /* + End of tes3mp addition + */ + const std::string script = it->getClass().getScript(*it); if (!script.empty()) MWBase::Environment::get().getWorld()->getLocalScripts().add(script, *it);