[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.
experimental-mono
David Cernat 5 years ago
parent 5e38e8abdb
commit f853368641

@ -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);

Loading…
Cancel
Save