2013-11-13 13:02:15 +00:00
# include "actiontrap.hpp"
2017-05-25 21:21:24 +00:00
/*
Start of tes3mp addition
Include additional headers for multiplayer purposes
*/
# include "../mwmp/Main.hpp"
# include "../mwmp/Networking.hpp"
2018-05-12 21:42:24 +00:00
# include "../mwmp/ObjectList.hpp"
2017-05-25 21:21:24 +00:00
/*
End of tes3mp addition
*/
2013-11-17 22:15:57 +00:00
# include "../mwmechanics/spellcasting.hpp"
2016-07-04 05:39:44 +00:00
2015-02-17 09:14:25 +00:00
# include "../mwbase/environment.hpp"
# include "../mwbase/world.hpp"
2013-11-13 13:02:15 +00:00
namespace MWWorld
{
2016-07-08 14:07:07 +00:00
void ActionTrap : : executeImp ( const Ptr & actor )
2016-07-04 10:09:12 +00:00
{
2016-07-06 19:03:56 +00:00
osg : : Vec3f actorPosition ( actor . getRefData ( ) . getPosition ( ) . asVec3 ( ) ) ;
2015-06-01 19:41:13 +00:00
osg : : Vec3f trapPosition ( mTrapSource . getRefData ( ) . getPosition ( ) . asVec3 ( ) ) ;
2016-07-06 19:03:56 +00:00
float trapRange = MWBase : : Environment : : get ( ) . getWorld ( ) - > getMaxActivationDistance ( ) ;
2013-11-13 13:02:15 +00:00
2016-07-04 05:39:44 +00:00
// Note: can't just detonate the trap at the trapped object's location and use the blast
2015-02-17 09:14:25 +00:00
// radius, because for most trap spells this is 1 foot, much less than the activation distance.
2016-07-04 10:09:12 +00:00
// Using activation distance as the trap range.
2016-07-04 05:39:44 +00:00
2016-07-08 14:07:07 +00:00
if ( actor = = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) & & MWBase : : Environment : : get ( ) . getWorld ( ) - > getDistanceToFacedObject ( ) > trapRange ) // player activated object outside range of trap
2015-02-17 09:14:25 +00:00
{
MWMechanics : : CastSpell cast ( mTrapSource , mTrapSource ) ;
cast . mHitPosition = trapPosition ;
2016-07-07 12:46:58 +00:00
cast . cast ( mSpellId ) ;
2016-07-06 19:03:56 +00:00
}
2016-07-07 13:10:38 +00:00
else // player activated object within range of trap, or NPC activated trap
2016-07-06 19:03:56 +00:00
{
MWMechanics : : CastSpell cast ( mTrapSource , actor ) ;
cast . mHitPosition = actorPosition ;
2015-02-17 09:14:25 +00:00
cast . cast ( mSpellId ) ;
2018-07-07 23:38:10 +00:00
}
/*
Start of tes3mp change ( major )
Disable unilateral trap disarming on this client and expect the server ' s reply to our
packet to do it instead
*/
//mTrapSource.getCellRef().setTrap("");
/*
End of tes3mp change ( major )
*/
2017-05-25 21:21:24 +00:00
/*
Start of tes3mp addition
2017-05-25 22:28:43 +00:00
Send an ID_OBJECT_TRAP packet every time a trap is triggered
2017-05-25 21:21:24 +00:00
*/
2018-05-12 21:42:24 +00:00
mwmp : : ObjectList * objectList = mwmp : : Main : : get ( ) . getNetworking ( ) - > getObjectList ( ) ;
objectList - > reset ( ) ;
2018-07-22 22:39:43 +00:00
objectList - > packetOrigin = mwmp : : CLIENT_GAMEPLAY ;
2017-05-25 22:28:43 +00:00
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 ( ) ;
2018-05-12 21:42:24 +00:00
objectList - > addObjectTrap ( mTrapSource , pos , false ) ;
objectList - > sendObjectTrap ( ) ;
2017-05-25 21:21:24 +00:00
/*
End of tes3mp addition
*/
2013-11-13 13:02:15 +00:00
}
}