Merge pull request #1191 from Allofich/ai

Stop combat when adding an AI package to an actor
pull/127/head
scrawl 8 years ago committed by GitHub
commit edf04667e0

@ -84,15 +84,14 @@ public:
const std::string& sourceName, const std::string& sourceId, int casterActorId, const std::string& sourceName, const std::string& sourceId, int casterActorId,
float magnitude, float remainingTime = -1, float totalTime = -1) float magnitude, float remainingTime = -1, float totalTime = -1)
{ {
MWWorld::Ptr player = MWMechanics::getPlayer(); if (((key.mId == ESM::MagicEffect::CommandHumanoid && mActor.getClass().isNpc())
if ( ((key.mId == ESM::MagicEffect::CommandHumanoid && mActor.getClass().isNpc()) || (key.mId == ESM::MagicEffect::CommandCreature && mActor.getTypeName() == typeid(ESM::Creature).name()))
|| (key.mId == ESM::MagicEffect::CommandCreature && mActor.getTypeName() == typeid(ESM::Creature).name()))
&& casterActorId == player.getClass().getCreatureStats(player).getActorId()
&& magnitude >= mActor.getClass().getCreatureStats(mActor).getLevel()) && magnitude >= mActor.getClass().getCreatureStats(mActor).getLevel())
mCommanded = true; mCommanded = true;
} }
}; };
// Check for command effects having ended and remove package if necessary
void adjustCommandedActor (const MWWorld::Ptr& actor) void adjustCommandedActor (const MWWorld::Ptr& actor)
{ {
CheckActorCommanded check(actor); CheckActorCommanded check(actor);
@ -112,13 +111,7 @@ void adjustCommandedActor (const MWWorld::Ptr& actor)
} }
} }
if (check.mCommanded && !hasCommandPackage) if (!check.mCommanded && hasCommandPackage)
{
// FIXME: don't use refid string
MWMechanics::AiFollow package("player", true);
stats.getAiSequence().stack(package, actor);
}
else if (!check.mCommanded && hasCommandPackage)
{ {
stats.getAiSequence().erase(it); stats.getAiSequence().erase(it);
} }

@ -281,6 +281,10 @@ void AiSequence::stack (const AiPackage& package, const MWWorld::Ptr& actor)
} }
} }
// Stop combat when a non-combat AI package is added
if (isActualAiPackage(package.getTypeId()))
stopCombat();
// remove previous packages if required // remove previous packages if required
if (package.shouldCancelPreviousAi()) if (package.shouldCancelPreviousAi())
{ {

@ -27,6 +27,7 @@
#include "magiceffects.hpp" #include "magiceffects.hpp"
#include "npcstats.hpp" #include "npcstats.hpp"
#include "actorutil.hpp" #include "actorutil.hpp"
#include "aifollow.hpp"
namespace MWMechanics namespace MWMechanics
{ {
@ -490,6 +491,15 @@ namespace MWMechanics
appliedLastingEffects.push_back(effect); appliedLastingEffects.push_back(effect);
// Command spells should have their effect, including taking the target out of combat, each time the spell successfully affects the target
if (((effectIt->mEffectID == ESM::MagicEffect::CommandHumanoid && target.getClass().isNpc())
|| (effectIt->mEffectID == ESM::MagicEffect::CommandCreature && target.getTypeName() == typeid(ESM::Creature).name()))
&& !caster.isEmpty() && caster.getClass().isActor() && target != getPlayer() && magnitude >= target.getClass().getCreatureStats(target).getLevel())
{
MWMechanics::AiFollow package(caster.getCellRef().getRefId(), true);
target.getClass().getCreatureStats(target).getAiSequence().stack(package, target);
}
// For absorb effects, also apply the effect to the caster - but with a negative // For absorb effects, also apply the effect to the caster - but with a negative
// magnitude, since we're transferring stats from the target to the caster // magnitude, since we're transferring stats from the target to the caster
if (!caster.isEmpty() && caster.getClass().isActor()) if (!caster.isEmpty() && caster.getClass().isActor())

Loading…
Cancel
Save