diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index fe8b0f75f..15f6914ed 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -207,6 +207,28 @@ void WorldEvent::lockObjects(MWWorld::CellStore* cellStore) } } +void WorldEvent::triggerTrapObjects(MWWorld::CellStore* cellStore) +{ + WorldObject worldObject; + + for (unsigned int i = 0; i < worldObjectCount; i++) + { + worldObject = worldObjects.at(i); + + LOG_APPEND(Log::LOG_VERBOSE, "- cellRef: %s, %i, %i", worldObject.refId.c_str(), worldObject.refNumIndex, worldObject.mpNum); + + MWWorld::Ptr ptrFound = cellStore->searchExact(worldObject.refId, worldObject.refNumIndex, worldObject.mpNum); + + if (ptrFound) + { + LOG_APPEND(Log::LOG_VERBOSE, "-- Found %s, %i, %i", ptrFound.getCellRef().getRefId().c_str(), + ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum()); + + ptrFound.getCellRef().setTrap(""); + } + } +} + void WorldEvent::scaleObjects(MWWorld::CellStore* cellStore) { WorldObject worldObject; @@ -490,6 +512,17 @@ void WorldEvent::addObjectLock(const MWWorld::Ptr& ptr, int lockLevel) addObject(worldObject); } +void WorldEvent::addObjectTrap(const MWWorld::Ptr& ptr) +{ + cell = *ptr.getCell()->getCell(); + + mwmp::WorldObject worldObject; + worldObject.refId = ptr.getCellRef().getRefId(); + worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; + worldObject.mpNum = ptr.getCellRef().getMpNum(); + addObject(worldObject); +} + void WorldEvent::addObjectScale(const MWWorld::Ptr& ptr, float scale) { cell = *ptr.getCell()->getCell(); @@ -613,6 +646,12 @@ void WorldEvent::sendObjectLock() mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_LOCK)->Send(); } +void WorldEvent::sendObjectTrap() +{ + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_TRAP)->setEvent(this); + mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_TRAP)->Send(); +} + void WorldEvent::sendObjectScale() { mwmp::Main::get().getNetworking()->getWorldPacket(ID_OBJECT_SCALE)->setEvent(this); diff --git a/apps/openmw/mwmp/WorldEvent.hpp b/apps/openmw/mwmp/WorldEvent.hpp index 1fe739940..b26f0234d 100644 --- a/apps/openmw/mwmp/WorldEvent.hpp +++ b/apps/openmw/mwmp/WorldEvent.hpp @@ -23,6 +23,7 @@ namespace mwmp void placeObjects(MWWorld::CellStore* cellStore); void deleteObjects(MWWorld::CellStore* cellStore); void lockObjects(MWWorld::CellStore* cellStore); + void triggerTrapObjects(MWWorld::CellStore* cellStore); void scaleObjects(MWWorld::CellStore* cellStore); void moveObjects(MWWorld::CellStore* cellStore); void rotateObjects(MWWorld::CellStore* cellStore); @@ -40,6 +41,7 @@ namespace mwmp void addObjectPlace(const MWWorld::Ptr& ptr); void addObjectDelete(const MWWorld::Ptr& ptr); void addObjectLock(const MWWorld::Ptr& ptr, int lockLevel); + void addObjectTrap(const MWWorld::Ptr& ptr); void addObjectScale(const MWWorld::Ptr& ptr, float scale); void addObjectAnimPlay(const MWWorld::Ptr& ptr, std::string group, int mode); void addDoorState(const MWWorld::Ptr& ptr, int state); @@ -53,6 +55,7 @@ namespace mwmp void sendObjectPlace(); void sendObjectDelete(); void sendObjectLock(); + void sendObjectTrap(); void sendObjectScale(); void sendObjectAnimPlay(); void sendDoorState(); diff --git a/apps/openmw/mwmp/processors/world/ProcessorObjectTrap.hpp b/apps/openmw/mwmp/processors/world/ProcessorObjectTrap.hpp index a52839992..dcd0b92b0 100644 --- a/apps/openmw/mwmp/processors/world/ProcessorObjectTrap.hpp +++ b/apps/openmw/mwmp/processors/world/ProcessorObjectTrap.hpp @@ -18,7 +18,7 @@ namespace mwmp { BaseObjectProcessor::Do(packet, event); - //event.setObjectTraps(ptrCellStore); + event.triggerTrapObjects(ptrCellStore); } }; } diff --git a/apps/openmw/mwworld/actiontake.cpp b/apps/openmw/mwworld/actiontake.cpp index b7ea08692..c9c83e8b9 100644 --- a/apps/openmw/mwworld/actiontake.cpp +++ b/apps/openmw/mwworld/actiontake.cpp @@ -5,12 +5,10 @@ Include additional headers for multiplayer purposes */ -#include #include "../mwmp/Main.hpp" #include "../mwmp/Networking.hpp" #include "../mwmp/WorldEvent.hpp" #include "../mwmp/LocalPlayer.hpp" -#include "../mwworld/cellstore.hpp" /* End of tes3mp addition */ diff --git a/apps/openmw/mwworld/actiontrap.cpp b/apps/openmw/mwworld/actiontrap.cpp index cdabaf8c8..00b8e984e 100644 --- a/apps/openmw/mwworld/actiontrap.cpp +++ b/apps/openmw/mwworld/actiontrap.cpp @@ -1,5 +1,17 @@ #include "actiontrap.hpp" +/* + Start of tes3mp addition + + Include additional headers for multiplayer purposes +*/ +#include "../mwmp/Main.hpp" +#include "../mwmp/Networking.hpp" +#include "../mwmp/WorldEvent.hpp" +/* + End of tes3mp addition +*/ + #include "../mwmechanics/spellcasting.hpp" #include "../mwbase/environment.hpp" @@ -30,5 +42,19 @@ namespace MWWorld cast.cast(mSpellId); } mTrapSource.getCellRef().setTrap(""); + + /* + Start of tes3mp addition + + Send an ID_OBJECT_TRAP packet every time an item is taken from the world + by the player outside of the inventory screen + */ + mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); + worldEvent->reset(); + worldEvent->addObjectTrap(mTrapSource); + worldEvent->sendObjectTrap(); + /* + End of tes3mp addition + */ } }