diff --git a/apps/openmw/mwmp/LocalEvent.cpp b/apps/openmw/mwmp/LocalEvent.cpp index f3ae7baa8..b0ee78a6c 100644 --- a/apps/openmw/mwmp/LocalEvent.cpp +++ b/apps/openmw/mwmp/LocalEvent.cpp @@ -37,6 +37,11 @@ void LocalEvent::addObject(WorldObject worldObject) objectChanges.objects.push_back(worldObject); } +void LocalEvent::addContainerItem(ContainerItem containerItem) +{ + containerChanges.items.push_back(containerItem); +} + void LocalEvent::placeObjects(MWWorld::CellStore* cellStore) { WorldObject worldObject; diff --git a/apps/openmw/mwmp/LocalEvent.hpp b/apps/openmw/mwmp/LocalEvent.hpp index e33219667..365e8c6e3 100644 --- a/apps/openmw/mwmp/LocalEvent.hpp +++ b/apps/openmw/mwmp/LocalEvent.hpp @@ -16,6 +16,7 @@ namespace mwmp virtual ~LocalEvent(); void addObject(WorldObject worldObject); + void addContainerItem(ContainerItem containerItem); void placeObjects(MWWorld::CellStore* cellStore); void deleteObjects(MWWorld::CellStore* cellStore); diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index d29a086b1..9b215f68b 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -31,6 +31,17 @@ namespace mwmp std::string varName; }; + struct ContainerItem + { + std::string refId; + int count; + int health; + inline bool operator==(const ContainerItem& rhs) + { + return refId == rhs.refId && count == rhs.count && health == rhs.health; + } + }; + class WorldEvent { public: @@ -51,8 +62,15 @@ namespace mwmp unsigned int count; }; + struct ContainerChanges + { + std::vector items; + unsigned int count; + }; + RakNet::RakNetGUID guid; ObjectChanges objectChanges; + ContainerChanges containerChanges; ESM::Cell cell; }; diff --git a/components/openmw-mp/Packets/World/PacketContainer.cpp b/components/openmw-mp/Packets/World/PacketContainer.cpp index 2cb933225..ac065a132 100644 --- a/components/openmw-mp/Packets/World/PacketContainer.cpp +++ b/components/openmw-mp/Packets/World/PacketContainer.cpp @@ -11,4 +11,57 @@ PacketContainer::PacketContainer(RakNet::RakPeerInterface *peer) : WorldPacket(p void PacketContainer::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) { WorldPacket::Packet(bs, event, send); + + if (!send) + event->objectChanges.objects.clear(); + else + { + event->objectChanges.count = (unsigned int)(event->objectChanges.objects.size()); + event->containerChanges.count = (unsigned int)(event->containerChanges.items.size()); + } + + RW(event->objectChanges.count, send); + RW(event->containerChanges.count, send); + + RW(event->cell.mData.mFlags, send); + RW(event->cell.mData.mX, send); + RW(event->cell.mData.mY, send); + RW(event->cell.mName, send); + + WorldObject worldObject; + + for (unsigned int i = 0; i < event->objectChanges.count; i++) + { + if (send) + { + worldObject = event->objectChanges.objects[i]; + } + + RW(worldObject.refId, send); + RW(worldObject.refNumIndex, send); + + if (!send) + { + event->objectChanges.objects.push_back(worldObject); + } + } + + ContainerItem containerItem; + + for (unsigned int i = 0; i < event->containerChanges.count; i++) + { + if (send) + { + containerItem = event->containerChanges.items[i]; + } + + RW(containerItem.refId, send); + RW(containerItem.count, send); + + if (!send) + { + event->containerChanges.items.push_back(containerItem); + } + } + }