diff --git a/apps/openmw/mwmp/LocalEvent.cpp b/apps/openmw/mwmp/LocalEvent.cpp index 1ce76aed7..8cb1577bf 100644 --- a/apps/openmw/mwmp/LocalEvent.cpp +++ b/apps/openmw/mwmp/LocalEvent.cpp @@ -1,6 +1,8 @@ #include "LocalEvent.hpp" -#include "Networking.hpp" #include "Main.hpp" +#include "Networking.hpp" +#include "LocalPlayer.hpp" +#include "DedicatedPlayer.hpp" #include @@ -11,6 +13,7 @@ #include "../mwbase/windowmanager.hpp" #include "../mwworld/class.hpp" +#include "../mwworld/containerstore.hpp" #include "../mwworld/esmstore.hpp" #include "../mwworld/manualref.hpp" @@ -42,6 +45,55 @@ void LocalEvent::addContainerItem(ContainerItem containerItem) containerChanges.items.push_back(containerItem); } +void LocalEvent::editContainer(MWWorld::CellStore* cellStore) +{ + WorldObject worldObject; + + for (unsigned int i = 0; i < objectChanges.count; i++) + { + worldObject = objectChanges.objects[i]; + + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s, %i\n- cell: %s", + worldObject.refId.c_str(), + worldObject.refNumIndex, + cell.getDescription().c_str()); + + MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex); + + if (ptrFound) + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i", + ptrFound.getCellRef().getRefId().c_str(), + ptrFound.getCellRef().getRefNum()); + + MWWorld::ContainerStore& containerStore = ptrFound.getClass().getContainerStore(ptrFound); + + for (unsigned int i = 0; i < containerChanges.count; i++) + { + ContainerItem item = containerChanges.items.at(i); + + if (containerChanges.action == ContainerChanges::REMOVE) + { + containerStore.remove(item.refId, item.count, mwmp::Players::getPlayer(guid)->getPtr()); + } + } + + // If we are in a container, and it happens to be this container, update its view + if (MWBase::Environment::get().getWindowManager()->containsMode(MWGui::GM_Container)) + { + CurrentContainer *currentContainer = &mwmp::Main::get().getLocalPlayer()->currentContainer; + + if (currentContainer->refNumIndex == ptrFound.getCellRef().getRefNum().mIndex && + Misc::StringUtils::ciEqual(currentContainer->refId, ptrFound.getCellRef().getRefId())) + { + MWBase::Environment::get().getWindowManager()->removeGuiMode(MWGui::GM_Container); + MWBase::Environment::get().getWindowManager()->openContainer(ptrFound, currentContainer->loot); + } + } + } + } +} + void LocalEvent::placeObjects(MWWorld::CellStore* cellStore) { WorldObject worldObject; diff --git a/apps/openmw/mwmp/LocalEvent.hpp b/apps/openmw/mwmp/LocalEvent.hpp index 365e8c6e3..3484dc327 100644 --- a/apps/openmw/mwmp/LocalEvent.hpp +++ b/apps/openmw/mwmp/LocalEvent.hpp @@ -18,6 +18,7 @@ namespace mwmp void addObject(WorldObject worldObject); void addContainerItem(ContainerItem containerItem); + void editContainer(MWWorld::CellStore* cellStore); void placeObjects(MWWorld::CellStore* cellStore); void deleteObjects(MWWorld::CellStore* cellStore); void lockObjects(MWWorld::CellStore* cellStore); diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 5f91884af..753e98ba1 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -1096,6 +1096,12 @@ void LocalPlayer::clearCellStates() cellStateChanges.cellStates.clear(); } +void LocalPlayer::clearCurrentContainer() +{ + currentContainer.refId = ""; + currentContainer.refNumIndex = 0; +} + void LocalPlayer::storeCellState(ESM::Cell cell, int stateType) { std::vector::iterator iter; @@ -1119,6 +1125,13 @@ void LocalPlayer::storeCellState(ESM::Cell cell, int stateType) cellStateChanges.cellStates.push_back(cellState); } +void LocalPlayer::storeCurrentContainer(const MWWorld::Ptr &container, bool loot) +{ + currentContainer.refId = container.getCellRef().getRefId(); + currentContainer.refNumIndex = container.getCellRef().getRefNum().mIndex; + currentContainer.loot = loot; +} + void LocalPlayer::prepareAttack(Attack::TYPE type, bool state) { if (attack.pressed == state && type != Attack::MAGIC) diff --git a/apps/openmw/mwmp/LocalPlayer.hpp b/apps/openmw/mwmp/LocalPlayer.hpp index 7f4e82e43..54830df43 100644 --- a/apps/openmw/mwmp/LocalPlayer.hpp +++ b/apps/openmw/mwmp/LocalPlayer.hpp @@ -68,8 +68,10 @@ namespace mwmp void sendAttack(Attack::TYPE type); void clearCellStates(); + void clearCurrentContainer(); void storeCellState(ESM::Cell cell, int stateType); + void storeCurrentContainer(const MWWorld::Ptr& container, bool loot); void prepareAttack(Attack::TYPE type, bool state); diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index f3bc942ce..1f1cf532e 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -739,6 +739,17 @@ void Networking::processWorldPacket(RakNet::Packet *packet) switch (packet->data[0]) { + case ID_CONTAINER: + { + MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(event->cell); + + if (!ptrCellStore) return; + + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_CONTAINER"); + event->editContainer(ptrCellStore); + + break; + } case ID_OBJECT_PLACE: { MWWorld::CellStore *ptrCellStore = Main::get().getWorldController()->getCell(event->cell); diff --git a/apps/openmw/mwmp/WorldController.cpp b/apps/openmw/mwmp/WorldController.cpp index a1f7889e9..3596649f7 100644 --- a/apps/openmw/mwmp/WorldController.cpp +++ b/apps/openmw/mwmp/WorldController.cpp @@ -44,6 +44,9 @@ MWWorld::CellStore *mwmp::WorldController::getCell(const ESM::Cell& cell) void mwmp::WorldController::openContainer(const MWWorld::Ptr &container, bool loot) { + // Record this as the player's current open container + mwmp::Main::get().getLocalPlayer()->storeCurrentContainer(container, loot); + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is opened. Loot: %s", container.getCellRef().getRefId().c_str(), container.getCellRef().getRefNum().mIndex, @@ -65,6 +68,8 @@ void mwmp::WorldController::openContainer(const MWWorld::Ptr &container, bool lo void mwmp::WorldController::closeContainer(const MWWorld::Ptr &container) { + mwmp::Main::get().getLocalPlayer()->clearCurrentContainer(); + LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Container \"%s\" (%d) is closed.", container.getCellRef().getRefId().c_str(), container.getCellRef().getRefNum().mIndex); diff --git a/components/openmw-mp/Base/BasePlayer.hpp b/components/openmw-mp/Base/BasePlayer.hpp index 5739de103..e30cb09ed 100644 --- a/components/openmw-mp/Base/BasePlayer.hpp +++ b/components/openmw-mp/Base/BasePlayer.hpp @@ -35,6 +35,13 @@ namespace mwmp char knockdown; }; + struct CurrentContainer + { + std::string refId; + int refNumIndex; + bool loot; + }; + struct Item { std::string refId; @@ -160,13 +167,16 @@ namespace mwmp int month; int day; double hour; + InventoryChanges inventoryChanges; SpellbookChanges spellbookChanges; JournalChanges journalChanges; CellStateChanges cellStateChanges; + ESM::ActiveSpells activeSpells; + CurrentContainer currentContainer; + bool consoleAllowed; bool ignorePosPacket; - ESM::ActiveSpells activeSpells; ESM::Position position; ESM::Position direction;