From 27b93574789b47179cc0fefaf0e366bcbb3bdf83 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 20 Jan 2020 01:40:44 +0200 Subject: [PATCH] [Client] Send Container packets when buying or selling items at merchant --- apps/openmw/mwgui/containeritemmodel.cpp | 65 +++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/containeritemmodel.cpp b/apps/openmw/mwgui/containeritemmodel.cpp index 267e3a781..0e16fa601 100644 --- a/apps/openmw/mwgui/containeritemmodel.cpp +++ b/apps/openmw/mwgui/containeritemmodel.cpp @@ -111,7 +111,37 @@ MWWorld::Ptr ContainerItemModel::copyItem (const ItemStack& item, size_t count, const MWWorld::Ptr& source = mItemSources[mItemSources.size()-1]; if (item.mBase.getContainerStore() == &source.getClass().getContainerStore(source)) throw std::runtime_error("Item to copy needs to be from a different container!"); - return *source.getClass().getContainerStore(source).add(item.mBase, count, source, allowAutoEquip); + + /* + Start of tes3mp addition + + Send an ID_CONTAINER packet every time an item is added to a container here + */ + mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); + objectList->reset(); + objectList->packetOrigin = mwmp::PACKET_ORIGIN::CLIENT_GAMEPLAY; + objectList->cell = *source.getCell()->getCell(); + objectList->action = mwmp::BaseObjectList::ADD; + objectList->containerSubAction = mwmp::BaseObjectList::NONE; + mwmp::BaseObject baseObject = objectList->getBaseObject(source); + objectList->addContainerItem(baseObject, item.mBase, count, 0); + objectList->addObject(baseObject); + objectList->sendContainer(); + /* + End of tes3mp addition + */ + + /* + Start of tes3mp change (major) + + Instead of unilaterally adding the item to this source's ContainerStore on this + client and returning the resulting Ptr, rely on the server to handle the item + transfer and just return the original item Ptr as a placeholder return value + */ + return item.mBase; + /* + End of tes3mp change (major) + */ } void ContainerItemModel::removeItem (const ItemStack& item, size_t count) @@ -126,7 +156,38 @@ void ContainerItemModel::removeItem (const ItemStack& item, size_t count) { if (stacks(*it, item.mBase)) { - toRemove -= store.remove(*it, toRemove, source); + /* + Start of tes3mp change (major) + + Send an ID_CONTAINER packet every time an item is removed here and prevent any + unilateral item removal on this client, as long as this isn't the player's + currently open container and doesn't require the drag and drop logic dealt with + in MWGui::ContainerWindow instead + */ + mwmp::CurrentContainer *currentContainer = &mwmp::Main::get().getLocalPlayer()->currentContainer; + + if (currentContainer->refNum != source.getCellRef().getRefNum().mIndex || + currentContainer->mpNum != source.getCellRef().getMpNum()) + { + mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); + objectList->reset(); + objectList->packetOrigin = mwmp::PACKET_ORIGIN::CLIENT_GAMEPLAY; + objectList->cell = *source.getCell()->getCell(); + objectList->action = mwmp::BaseObjectList::REMOVE; + objectList->containerSubAction = mwmp::BaseObjectList::NONE; + mwmp::BaseObject baseObject = objectList->getBaseObject(source); + objectList->addContainerItem(baseObject, *it, it->getRefData().getCount(), toRemove); + objectList->addObject(baseObject); + objectList->sendContainer(); + + toRemove -= it->getRefData().getCount(); + } + else + toRemove -= store.remove(*it, toRemove, source); + /* + End of tes3mp change (major) + */ + if (toRemove <= 0) return; }