mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +00:00
Make AI response to spell hits more like original MW
This commit is contained in:
parent
85c7d014d3
commit
266ec1aadc
1 changed files with 18 additions and 23 deletions
|
@ -336,7 +336,6 @@ namespace MWMechanics
|
||||||
|
|
||||||
ESM::EffectList reflectedEffects;
|
ESM::EffectList reflectedEffects;
|
||||||
std::vector<ActiveSpells::ActiveEffect> appliedLastingEffects;
|
std::vector<ActiveSpells::ActiveEffect> appliedLastingEffects;
|
||||||
bool anyHarmfulEffect = false;
|
|
||||||
|
|
||||||
// HACK: cache target's magic effects here, and add any applied effects to it. Use the cached effects for determining resistance.
|
// HACK: cache target's magic effects here, and add any applied effects to it. Use the cached effects for determining resistance.
|
||||||
// This is required for Weakness effects in a spell to apply to any subsequent effects in the spell.
|
// This is required for Weakness effects in a spell to apply to any subsequent effects in the spell.
|
||||||
|
@ -412,17 +411,11 @@ namespace MWMechanics
|
||||||
float magnitudeMult = 1;
|
float magnitudeMult = 1;
|
||||||
if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful && target.getClass().isActor())
|
if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful && target.getClass().isActor())
|
||||||
{
|
{
|
||||||
anyHarmfulEffect = true;
|
if (absorbed)
|
||||||
|
|
||||||
if (absorbed) // Absorbed, and we know there was a harmful effect (figuring that out is the only reason we are in this loop)
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// If player is attempting to cast a harmful spell, show the target's HP bar
|
|
||||||
if (castByPlayer && target != caster)
|
|
||||||
MWBase::Environment::get().getWindowManager()->setEnemy(target);
|
|
||||||
|
|
||||||
// Try reflecting
|
// Try reflecting
|
||||||
if (!reflected && magnitudeMult > 0 && !caster.isEmpty() && caster != target && !(magicEffect->mData.mFlags & ESM::MagicEffect::Unreflectable))
|
if (!reflected && !caster.isEmpty() && caster != target && !(magicEffect->mData.mFlags & ESM::MagicEffect::Unreflectable))
|
||||||
{
|
{
|
||||||
float reflect = target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::Reflect).getMagnitude();
|
float reflect = target.getClass().getCreatureStats(target).getMagicEffects().get(ESM::MagicEffect::Reflect).getMagnitude();
|
||||||
bool isReflected = (Misc::Rng::roll0to99() < reflect);
|
bool isReflected = (Misc::Rng::roll0to99() < reflect);
|
||||||
|
@ -433,12 +426,11 @@ namespace MWMechanics
|
||||||
"meshes\\" + reflectStatic->mModel, ESM::MagicEffect::Reflect, false, "");
|
"meshes\\" + reflectStatic->mModel, ESM::MagicEffect::Reflect, false, "");
|
||||||
reflectedEffects.mList.push_back(*effectIt);
|
reflectedEffects.mList.push_back(*effectIt);
|
||||||
magnitudeMult = 0;
|
magnitudeMult = 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try resisting
|
// Try resisting
|
||||||
if (magnitudeMult > 0 && target.getClass().isActor())
|
|
||||||
{
|
|
||||||
magnitudeMult = MWMechanics::getEffectMultiplier(effectIt->mEffectID, target, caster, spell, &targetEffects);
|
magnitudeMult = MWMechanics::getEffectMultiplier(effectIt->mEffectID, target, caster, spell, &targetEffects);
|
||||||
if (magnitudeMult == 0)
|
if (magnitudeMult == 0)
|
||||||
{
|
{
|
||||||
|
@ -448,7 +440,14 @@ namespace MWMechanics
|
||||||
else if (castByPlayer)
|
else if (castByPlayer)
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResisted}");
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResisted}");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// If player is attempting to cast a harmful spell, show the target's HP bar
|
||||||
|
if (castByPlayer && target != caster)
|
||||||
|
MWBase::Environment::get().getWindowManager()->setEnemy(target);
|
||||||
|
|
||||||
|
// Notify the target actor they've been hit
|
||||||
|
if (target != caster && !caster.isEmpty())
|
||||||
|
target.getClass().onHit(target, 0.0f, true, MWWorld::Ptr(), caster, osg::Vec3f(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (magnitudeMult > 0 && !absorbed)
|
if (magnitudeMult > 0 && !absorbed)
|
||||||
|
@ -567,10 +566,6 @@ namespace MWMechanics
|
||||||
target.getClass().getCreatureStats(target).getActiveSpells().addSpell(mId, mStack, appliedLastingEffects,
|
target.getClass().getCreatureStats(target).getActiveSpells().addSpell(mId, mStack, appliedLastingEffects,
|
||||||
mSourceName, casterActorId);
|
mSourceName, casterActorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify the target actor they've been hit
|
|
||||||
if (anyHarmfulEffect && target.getClass().isActor() && target != caster && !caster.isEmpty() && caster.getClass().isActor())
|
|
||||||
target.getClass().onHit(target, 0.0f, true, MWWorld::Ptr(), caster, osg::Vec3f(), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CastSpell::applyInstantEffect(const MWWorld::Ptr &target, const MWWorld::Ptr &caster, const MWMechanics::EffectKey& effect, float magnitude)
|
bool CastSpell::applyInstantEffect(const MWWorld::Ptr &target, const MWWorld::Ptr &caster, const MWMechanics::EffectKey& effect, float magnitude)
|
||||||
|
|
Loading…
Reference in a new issue