You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw-tes3mp/apps/openmw/mwworld/actiontrap.cpp

36 lines
1.3 KiB
C++

#include "actiontrap.hpp"
#include "../mwmechanics/spellcasting.hpp"
#include "../mwmechanics/actorutil.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
namespace MWWorld
{
9 years ago
void ActionTrap::executeImp(const Ptr &actor, float distance)
{
osg::Vec3f actorPosition(actor.getRefData().getPosition().asVec3());
osg::Vec3f trapPosition(mTrapSource.getRefData().getPosition().asVec3());
float trapRange = MWBase::Environment::get().getWorld()->getMaxActivationDistance();
// Note: can't just detonate the trap at the trapped object's location and use the blast
// radius, because for most trap spells this is 1 foot, much less than the activation distance.
9 years ago
// Using activation distance as the trap range.
if (distance > trapRange && actor == MWMechanics::getPlayer()) // player activated object outside range of trap
{
MWMechanics::CastSpell cast(mTrapSource, mTrapSource);
cast.mHitPosition = trapPosition;
9 years ago
cast.cast(mSpellId);
}
else // player activated object within range of trap, or NPC activated trap
{
MWMechanics::CastSpell cast(mTrapSource, actor);
cast.mHitPosition = actorPosition;
cast.cast(mSpellId);
9 years ago
}
mTrapSource.getCellRef().setTrap("");
}
}