[General] Allow ObjectTrap to trigger traps, not just disarm them

This commit is contained in:
David Cernat 2017-05-26 01:28:43 +03:00
parent 93aa674eff
commit 32879adc5b
7 changed files with 35 additions and 5 deletions

View file

@ -208,6 +208,11 @@ void WorldFunctions::SetObjectLockLevel(int lockLevel) noexcept
tempWorldObject.lockLevel = lockLevel; tempWorldObject.lockLevel = lockLevel;
} }
void WorldFunctions::SetObjectDisarmState(bool disarmState) noexcept
{
tempWorldObject.isDisarmed = disarmState;
}
void WorldFunctions::SetObjectPosition(double x, double y, double z) noexcept void WorldFunctions::SetObjectPosition(double x, double y, double z) noexcept
{ {
tempWorldObject.position.pos[0] = x; tempWorldObject.position.pos[0] = x;

View file

@ -43,6 +43,7 @@
{"SetObjectScale", WorldFunctions::SetObjectScale},\ {"SetObjectScale", WorldFunctions::SetObjectScale},\
{"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\ {"SetObjectDoorState", WorldFunctions::SetObjectDoorState},\
{"SetObjectLockLevel", WorldFunctions::SetObjectLockLevel},\ {"SetObjectLockLevel", WorldFunctions::SetObjectLockLevel},\
{"SetObjectDisarmState", WorldFunctions::SetObjectDisarmState},\
{"SetObjectPosition", WorldFunctions::SetObjectPosition},\ {"SetObjectPosition", WorldFunctions::SetObjectPosition},\
{"SetObjectRotation", WorldFunctions::SetObjectRotation},\ {"SetObjectRotation", WorldFunctions::SetObjectRotation},\
\ \
@ -110,6 +111,7 @@ public:
static void SetObjectScale(double scale) noexcept; static void SetObjectScale(double scale) noexcept;
static void SetObjectDoorState(int doorState) noexcept; static void SetObjectDoorState(int doorState) noexcept;
static void SetObjectLockLevel(int lockLevel) 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 SetObjectPosition(double x, double y, double z) noexcept;
static void SetObjectRotation(double x, double y, double z) noexcept; static void SetObjectRotation(double x, double y, double z) noexcept;

View file

@ -12,6 +12,8 @@
#include "../mwbase/soundmanager.hpp" #include "../mwbase/soundmanager.hpp"
#include "../mwbase/windowmanager.hpp" #include "../mwbase/windowmanager.hpp"
#include "../mwmechanics/spellcasting.hpp"
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/containerstore.hpp" #include "../mwworld/containerstore.hpp"
#include "../mwworld/esmstore.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(), LOG_APPEND(Log::LOG_VERBOSE, "-- Found %s, %i, %i", ptrFound.getCellRef().getRefId().c_str(),
ptrFound.getCellRef().getRefNum(), ptrFound.getCellRef().getMpNum()); 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(""); ptrFound.getCellRef().setTrap("");
} }
} }
@ -512,7 +521,7 @@ void WorldEvent::addObjectLock(const MWWorld::Ptr& ptr, int lockLevel)
addObject(worldObject); 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(); cell = *ptr.getCell()->getCell();
@ -520,6 +529,8 @@ void WorldEvent::addObjectTrap(const MWWorld::Ptr& ptr)
worldObject.refId = ptr.getCellRef().getRefId(); worldObject.refId = ptr.getCellRef().getRefId();
worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex; worldObject.refNumIndex = ptr.getCellRef().getRefNum().mIndex;
worldObject.mpNum = ptr.getCellRef().getMpNum(); worldObject.mpNum = ptr.getCellRef().getMpNum();
worldObject.isDisarmed = isDisarmed;
worldObject.position = pos;
addObject(worldObject); addObject(worldObject);
} }

View file

@ -41,7 +41,7 @@ namespace mwmp
void addObjectPlace(const MWWorld::Ptr& ptr); void addObjectPlace(const MWWorld::Ptr& ptr);
void addObjectDelete(const MWWorld::Ptr& ptr); void addObjectDelete(const MWWorld::Ptr& ptr);
void addObjectLock(const MWWorld::Ptr& ptr, int lockLevel); 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 addObjectScale(const MWWorld::Ptr& ptr, float scale);
void addObjectAnimPlay(const MWWorld::Ptr& ptr, std::string group, int mode); void addObjectAnimPlay(const MWWorld::Ptr& ptr, std::string group, int mode);
void addDoorState(const MWWorld::Ptr& ptr, int state); void addDoorState(const MWWorld::Ptr& ptr, int state);

View file

@ -46,12 +46,19 @@ namespace MWWorld
/* /*
Start of tes3mp addition Start of tes3mp addition
Send an ID_OBJECT_TRAP packet every time an item is taken from the world Send an ID_OBJECT_TRAP packet every time a trap is triggered
by the player outside of the inventory screen
*/ */
mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent(); mwmp::WorldEvent *worldEvent = mwmp::Main::get().getNetworking()->getWorldEvent();
worldEvent->reset(); 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(); worldEvent->sendObjectTrap();
/* /*
End of tes3mp addition End of tes3mp addition

View file

@ -48,6 +48,7 @@ namespace mwmp
std::string varName; std::string varName;
bool isActor; bool isActor;
bool isDisarmed;
std::vector<ContainerItem> containerItems; std::vector<ContainerItem> containerItems;
unsigned int containerItemCount; unsigned int containerItemCount;

View file

@ -36,6 +36,10 @@ void PacketObjectTrap::Packet(RakNet::BitStream *bs, bool send)
RW(worldObject.refId, send); RW(worldObject.refId, send);
RW(worldObject.refNumIndex, send); RW(worldObject.refNumIndex, send);
RW(worldObject.mpNum, send); RW(worldObject.mpNum, send);
RW(worldObject.isDisarmed, send);
if (!worldObject.isDisarmed)
RW(worldObject.position, send);
if (!send) if (!send)
{ {