From d8a9a5f6c928abe1c3da1697da5a1882f6ac59d6 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 6 Feb 2017 22:45:23 +0200 Subject: [PATCH] [General] Send item owner in ID_CONTAINER --- apps/openmw/mwgui/container.cpp | 12 ++++++++---- apps/openmw/mwmp/WorldEvent.cpp | 15 ++++++++++----- components/openmw-mp/Base/BaseEvent.hpp | 1 + .../openmw-mp/Packets/World/PacketContainer.cpp | 1 + 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 8880f388f..89738e3e8 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -117,6 +117,7 @@ namespace MWGui containerItem.count = itemPtr.getRefData().getCount(); containerItem.charge = itemPtr.getCellRef().getCharge(); containerItem.goldValue = itemPtr.getCellRef().getGoldValue(); + containerItem.owner = itemPtr.getCellRef().getOwner(); containerItem.actionCount = count; event->addContainerItem(containerItem); event->containerChanges.action = mwmp::ContainerChanges::REMOVE; @@ -168,11 +169,14 @@ namespace MWGui worldObject.refNumIndex = mPtr.getCellRef().getRefNum().mIndex; event->addObject(worldObject); + MWWorld::Ptr itemPtr = mDragAndDrop->mItem.mBase; + mwmp::ContainerItem containerItem; - containerItem.refId = mDragAndDrop->mItem.mBase.getCellRef().getRefId(); - containerItem.count = mDragAndDrop->mItem.mBase.getRefData().getCount(); - containerItem.charge = mDragAndDrop->mItem.mBase.getCellRef().getCharge(); - containerItem.goldValue = mDragAndDrop->mItem.mBase.getCellRef().getGoldValue(); + containerItem.refId = itemPtr.getCellRef().getRefId(); + containerItem.count = itemPtr.getRefData().getCount(); + containerItem.charge = itemPtr.getCellRef().getCharge(); + containerItem.goldValue = itemPtr.getCellRef().getGoldValue(); + containerItem.owner = itemPtr.getCellRef().getOwner(); event->addContainerItem(containerItem); event->containerChanges.action = mwmp::ContainerChanges::ADD; diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index e3529e029..b40e56708 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -76,6 +76,10 @@ void WorldEvent::editContainer(MWWorld::CellStore* cellStore) for (unsigned int i = 0; i < containerChanges.count; i++) { ContainerItem containerItem = containerChanges.items.at(i); + MWWorld::Ptr ownerPtr = MWBase::Environment::get().getWorld()->searchPtr(containerItem.owner, false); + + if (ownerPtr.isEmpty()) + ownerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr(); if (action == ContainerChanges::ADD || action == ContainerChanges::SET) { @@ -91,7 +95,7 @@ void WorldEvent::editContainer(MWWorld::CellStore* cellStore) newPtr.getCellRef().setGoldValue(containerItem.goldValue); - containerStore.add(newPtr, containerItem.count, mwmp::Players::getPlayer(guid)->getPtr(), true); + containerStore.add(newPtr, containerItem.count, ownerPtr, true); } else if (action == ContainerChanges::REMOVE) { @@ -103,9 +107,10 @@ void WorldEvent::editContainer(MWWorld::CellStore* cellStore) { if (iter->getCellRef().getCharge() == containerItem.charge && iter->getCellRef().getGoldValue() == containerItem.goldValue && - iter->getRefData().getCount() == containerItem.count) + iter->getRefData().getCount() == containerItem.count && + iter->getCellRef().getOwner() == containerItem.owner) { - containerStore.remove(*iter, containerItem.actionCount, mwmp::Players::getPlayer(guid)->getPtr()); + containerStore.remove(*iter, containerItem.actionCount, ownerPtr); } } } @@ -478,9 +483,9 @@ void WorldEvent::setMemberShorts() worldObject.shortVal); // Mimic the way a Ptr is fetched in InterpreterContext for similar situations - MWWorld::Ptr ptrFound = MWBase::Environment::get().getWorld()->getPtr(worldObject.refId, false); + MWWorld::Ptr ptrFound = MWBase::Environment::get().getWorld()->searchPtr(worldObject.refId, false); - if (ptrFound) + if (!ptrFound.isEmpty()) { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i", ptrFound.getCellRef().getRefId().c_str(), diff --git a/components/openmw-mp/Base/BaseEvent.hpp b/components/openmw-mp/Base/BaseEvent.hpp index 7086a8e53..49ea46b4f 100644 --- a/components/openmw-mp/Base/BaseEvent.hpp +++ b/components/openmw-mp/Base/BaseEvent.hpp @@ -39,6 +39,7 @@ namespace mwmp int charge; int goldValue; + std::string owner; int actionCount; inline bool operator==(const ContainerItem& rhs) diff --git a/components/openmw-mp/Packets/World/PacketContainer.cpp b/components/openmw-mp/Packets/World/PacketContainer.cpp index 06fb22e85..5ac903af4 100644 --- a/components/openmw-mp/Packets/World/PacketContainer.cpp +++ b/components/openmw-mp/Packets/World/PacketContainer.cpp @@ -64,6 +64,7 @@ void PacketContainer::Packet(RakNet::BitStream *bs, BaseEvent *event, bool send) RW(containerItem.count, send); RW(containerItem.charge, send); RW(containerItem.goldValue, send); + RW(containerItem.owner, send); RW(containerItem.actionCount, send); if (!send)