From 3614b21e10d0cb409b3dd374da16c0932906da64 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 6 Feb 2017 21:28:03 +0200 Subject: [PATCH] [General] Send charge and goldValue in ID_CONTAINER --- apps/openmw/mwgui/container.cpp | 11 +++++-- apps/openmw/mwmp/WorldEvent.cpp | 32 ++++++++++++++++--- components/openmw-mp/Base/BaseEvent.hpp | 9 ++++-- .../Packets/World/PacketContainer.cpp | 3 ++ 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 3c1b4961b..8880f388f 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -110,9 +110,14 @@ namespace MWGui worldObject.refNumIndex = mPtr.getCellRef().getRefNum().mIndex; event->addObject(worldObject); + MWWorld::Ptr itemPtr = mModel->getItem(mSelectedItem).mBase; + mwmp::ContainerItem containerItem; - containerItem.refId = mModel->getItem(mSelectedItem).mBase.getCellRef().getRefId(); - containerItem.count = count; + containerItem.refId =itemPtr.getCellRef().getRefId(); + containerItem.count = itemPtr.getRefData().getCount(); + containerItem.charge = itemPtr.getCellRef().getCharge(); + containerItem.goldValue = itemPtr.getCellRef().getGoldValue(); + containerItem.actionCount = count; event->addContainerItem(containerItem); event->containerChanges.action = mwmp::ContainerChanges::REMOVE; @@ -166,6 +171,8 @@ namespace MWGui 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(); event->addContainerItem(containerItem); event->containerChanges.action = mwmp::ContainerChanges::ADD; diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index 9d1d316e0..e3529e029 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -75,15 +75,40 @@ void WorldEvent::editContainer(MWWorld::CellStore* cellStore) for (unsigned int i = 0; i < containerChanges.count; i++) { - ContainerItem item = containerChanges.items.at(i); + ContainerItem containerItem = containerChanges.items.at(i); if (action == ContainerChanges::ADD || action == ContainerChanges::SET) { - containerStore.add(item.refId, item.count, mwmp::Players::getPlayer(guid)->getPtr()); + // Create a ManualRef to be able to set item charge + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), containerItem.refId, 1); + MWWorld::Ptr newPtr = ref.getPtr(); + + if (containerItem.count > 1) + newPtr.getRefData().setCount(containerItem.count); + + if (containerItem.charge > -1) + newPtr.getCellRef().setCharge(containerItem.charge); + + newPtr.getCellRef().setGoldValue(containerItem.goldValue); + + containerStore.add(newPtr, containerItem.count, mwmp::Players::getPlayer(guid)->getPtr(), true); } else if (action == ContainerChanges::REMOVE) { - containerStore.remove(item.refId, item.count, mwmp::Players::getPlayer(guid)->getPtr()); + // We have to find the right item ourselves because ContainerStore has no method + // accounting for charge + for (MWWorld::ContainerStoreIterator iter(containerStore.begin()); iter != containerStore.end(); ++iter) + { + if (Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), containerItem.refId)) + { + if (iter->getCellRef().getCharge() == containerItem.charge && + iter->getCellRef().getGoldValue() == containerItem.goldValue && + iter->getRefData().getCount() == containerItem.count) + { + containerStore.remove(*iter, containerItem.actionCount, mwmp::Players::getPlayer(guid)->getPtr()); + } + } + } } } @@ -119,7 +144,6 @@ void WorldEvent::placeObjects(MWWorld::CellStore* cellStore) worldObject.count); MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), worldObject.refId, 1); - MWWorld::Ptr newPtr = ref.getPtr(); if (worldObject.charge > -1) diff --git a/components/openmw-mp/Base/BaseEvent.hpp b/components/openmw-mp/Base/BaseEvent.hpp index 97cd868cf..7086a8e53 100644 --- a/components/openmw-mp/Base/BaseEvent.hpp +++ b/components/openmw-mp/Base/BaseEvent.hpp @@ -11,8 +11,8 @@ namespace mwmp { std::string refId; int refNumIndex; - int charge; int count; + int charge; int goldValue; ESM::Position pos; @@ -36,11 +36,14 @@ namespace mwmp { std::string refId; int count; - int health; + int charge; + int goldValue; + + int actionCount; inline bool operator==(const ContainerItem& rhs) { - return refId == rhs.refId && count == rhs.count && health == rhs.health; + return refId == rhs.refId && count == rhs.count && charge == rhs.charge && goldValue && rhs.goldValue; } }; diff --git a/components/openmw-mp/Packets/World/PacketContainer.cpp b/components/openmw-mp/Packets/World/PacketContainer.cpp index 517e541ad..06fb22e85 100644 --- a/components/openmw-mp/Packets/World/PacketContainer.cpp +++ b/components/openmw-mp/Packets/World/PacketContainer.cpp @@ -62,6 +62,9 @@ void PacketContainer::Packet(RakNet::BitStream *bs, BaseEvent *event, bool send) RW(containerItem.refId, send); RW(containerItem.count, send); + RW(containerItem.charge, send); + RW(containerItem.goldValue, send); + RW(containerItem.actionCount, send); if (!send) {