From 32879adc5bfd4d442f7f208d4bb3a7ae7a74cfe7 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 26 May 2017 01:28:43 +0300 Subject: [PATCH] [General] Allow ObjectTrap to trigger traps, not just disarm them --- apps/openmw-mp/Script/Functions/World.cpp | 5 +++++ apps/openmw-mp/Script/Functions/World.hpp | 2 ++ apps/openmw/mwmp/WorldEvent.cpp | 13 ++++++++++++- apps/openmw/mwmp/WorldEvent.hpp | 2 +- apps/openmw/mwworld/actiontrap.cpp | 13 ++++++++++--- components/openmw-mp/Base/BaseEvent.hpp | 1 + .../openmw-mp/Packets/World/PacketObjectTrap.cpp | 4 ++++ 7 files changed, 35 insertions(+), 5 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/World.cpp b/apps/openmw-mp/Script/Functions/World.cpp index c534c4ad5..a807706a6 100644 --- a/apps/openmw-mp/Script/Functions/World.cpp +++ b/apps/openmw-mp/Script/Functions/World.cpp @@ -208,6 +208,11 @@ void WorldFunctions::SetObjectLockLevel(int lockLevel) noexcept tempWorldObject.lockLevel = lockLevel; } +void WorldFunctions::SetObjectDisarmState(bool disarmState) noexcept +{ + tempWorldObject.isDisarmed = disarmState; +} + void WorldFunctions::SetObjectPosition(double x, double y, double z) noexcept { tempWorldObject.position.pos[0] = x; diff --git a/apps/openmw-mp/Script/Functions/World.hpp b/apps/openmw-mp/Script/Functions/World.hpp index f9ef35a71..06316d1c5 100644 --- a/apps/openmw-mp/Script/Functions/World.hpp +++ b/apps/openmw-mp/Script/Functions/World.hpp @@ -43,6 +43,7 @@ {"SetObjectScale", WorldFunctions::SetObjectScale},\ {"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\ {"SetObjectLockLevel", WorldFunctions::SetObjectLockLevel},\ + {"SetObjectDisarmState", WorldFunctions::SetObjectDisarmState},\ {"SetObjectPosition", WorldFunctions::SetObjectPosition},\ {"SetObjectRotation", WorldFunctions::SetObjectRotation},\ \ @@ -110,6 +111,7 @@ public: static void SetObjectScale(double scale) noexcept; static void SetObjectDoorState(int doorState) noexcept; static void SetObjectLockLevel(int lockLevel) noexcept; + static void SetObjectDisarmState(bool disarmState) noexcept; static void SetObjectPosition(double x, double y, double z) noexcept; static void SetObjectRotation(double x, double y, double z) noexcept; diff --git a/apps/openmw/mwmp/WorldEvent.cpp b/apps/openmw/mwmp/WorldEvent.cpp index 15f6914ed..4b142afe9 100644 --- a/apps/openmw/mwmp/WorldEvent.cpp +++ b/apps/openmw/mwmp/WorldEvent.cpp @@ -12,6 +12,8 @@ #include "../mwbase/soundmanager.hpp" #include "../mwbase/windowmanager.hpp" +#include "../mwmechanics/spellcasting.hpp" + #include "../mwworld/class.hpp" #include "../mwworld/containerstore.hpp" #include "../mwworld/esmstore.hpp" @@ -224,6 +226,13 @@ void WorldEvent::triggerTrapObjects(MWWorld::CellStore* cellStore) LOG_APPEND(Log::LOG_VERBOSE, "-- Found %s, %i, %i", ptrFound.getCellRef().getRefId().c_str(), ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum()); + if (!worldObject.isDisarmed) + { + MWMechanics::CastSpell cast(ptrFound, ptrFound); + cast.mHitPosition = worldObject.position.asVec3(); + cast.cast(ptrFound.getCellRef().getTrap()); + } + ptrFound.getCellRef().setTrap(""); } } @@ -512,7 +521,7 @@ void WorldEvent::addObjectLock(const MWWorld::Ptr& ptr, int lockLevel) addObject(worldObject); } -void WorldEvent::addObjectTrap(const MWWorld::Ptr& ptr) +void WorldEvent::addObjectTrap(const MWWorld::Ptr& ptr, const ESM::Position& pos, bool isDisarmed) { cell = *ptr.getCell()->getCell(); @@ -520,6 +529,8 @@ void WorldEvent::addObjectTrap(const MWWorld::Ptr& ptr) worldObject.refId = ptr.getCellRef().getRefId(); worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; worldObject.mpNum = ptr.getCellRef().getMpNum(); + worldObject.isDisarmed = isDisarmed; + worldObject.position = pos; addObject(worldObject); } diff --git a/apps/openmw/mwmp/WorldEvent.hpp b/apps/openmw/mwmp/WorldEvent.hpp index b26f0234d..30fec4af4 100644 --- a/apps/openmw/mwmp/WorldEvent.hpp +++ b/apps/openmw/mwmp/WorldEvent.hpp @@ -41,7 +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 addObjectTrap(const MWWorld::Ptr& ptr, const ESM::Position& pos, bool isDisarmed); 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); diff --git a/apps/openmw/mwworld/actiontrap.cpp b/apps/openmw/mwworld/actiontrap.cpp index 00b8e984e..ad07b0715 100644 --- a/apps/openmw/mwworld/actiontrap.cpp +++ b/apps/openmw/mwworld/actiontrap.cpp @@ -46,12 +46,19 @@ namespace MWWorld /* 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 + Send an ID_OBJECT_TRAP packet every time a trap is triggered */ mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); worldEvent->reset(); - worldEvent->addObjectTrap(mTrapSource); + + ESM::Position pos; + + if (actor == MWBase::Environment::get().getWorld()->getPlayerPtr() && MWBase::Environment::get().getWorld()->getDistanceToFacedObject() > trapRange) + pos = mTrapSource.getRefData().getPosition(); + else + pos = actor.getRefData().getPosition(); + + worldEvent->addObjectTrap(mTrapSource, pos, false); worldEvent->sendObjectTrap(); /* End of tes3mp addition diff --git a/components/openmw-mp/Base/BaseEvent.hpp b/components/openmw-mp/Base/BaseEvent.hpp index 64ceb534a..aaab985d4 100644 --- a/components/openmw-mp/Base/BaseEvent.hpp +++ b/components/openmw-mp/Base/BaseEvent.hpp @@ -48,6 +48,7 @@ namespace mwmp std::string varName; bool isActor; + bool isDisarmed; std::vector containerItems; unsigned int containerItemCount; diff --git a/components/openmw-mp/Packets/World/PacketObjectTrap.cpp b/components/openmw-mp/Packets/World/PacketObjectTrap.cpp index cde4bbdc2..762d4e646 100644 --- a/components/openmw-mp/Packets/World/PacketObjectTrap.cpp +++ b/components/openmw-mp/Packets/World/PacketObjectTrap.cpp @@ -36,6 +36,10 @@ void PacketObjectTrap::Packet(RakNet::BitStream *bs, bool send) RW(worldObject.refId, send); RW(worldObject.refNumIndex, send); RW(worldObject.mpNum, send); + RW(worldObject.isDisarmed, send); + + if (!worldObject.isDisarmed) + RW(worldObject.position, send); if (!send) {