From 266ec1aadcf0e6863a6607f08222fce697c5c311 Mon Sep 17 00:00:00 2001 From: Allofich Date: Sat, 1 Oct 2016 21:14:26 +0900 Subject: [PATCH 1/4] Make AI response to spell hits more like original MW --- apps/openmw/mwmechanics/spellcasting.cpp | 41 +++++++++++------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index a02ee37b27..f2d82383c6 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -336,7 +336,6 @@ namespace MWMechanics ESM::EffectList reflectedEffects; std::vector 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. // 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; if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful && target.getClass().isActor()) { - anyHarmfulEffect = true; - - if (absorbed) // Absorbed, and we know there was a harmful effect (figuring that out is the only reason we are in this loop) + if (absorbed) 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 - 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(); bool isReflected = (Misc::Rng::roll0to99() < reflect); @@ -433,22 +426,28 @@ namespace MWMechanics "meshes\\" + reflectStatic->mModel, ESM::MagicEffect::Reflect, false, ""); reflectedEffects.mList.push_back(*effectIt); magnitudeMult = 0; + break; } } // Try resisting - if (magnitudeMult > 0 && target.getClass().isActor()) + magnitudeMult = MWMechanics::getEffectMultiplier(effectIt->mEffectID, target, caster, spell, &targetEffects); + if (magnitudeMult == 0) { - magnitudeMult = MWMechanics::getEffectMultiplier(effectIt->mEffectID, target, caster, spell, &targetEffects); - if (magnitudeMult == 0) - { - // Fully resisted, show message - if (target == getPlayer()) - MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicPCResisted}"); - else if (castByPlayer) - MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResisted}"); - } + // Fully resisted, show message + if (target == getPlayer()) + MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicPCResisted}"); + else if (castByPlayer) + 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) @@ -567,10 +566,6 @@ namespace MWMechanics target.getClass().getCreatureStats(target).getActiveSpells().addSpell(mId, mStack, appliedLastingEffects, 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) From fa177847223de9c22af602fb4aad858b31b31ac0 Mon Sep 17 00:00:00 2001 From: Allofich Date: Sat, 1 Oct 2016 23:09:39 +0900 Subject: [PATCH 2/4] Change breaks to continues --- apps/openmw/mwmechanics/spellcasting.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index f2d82383c6..e3e1550a62 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -412,7 +412,7 @@ namespace MWMechanics if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful && target.getClass().isActor()) { if (absorbed) - break; + continue; // Try reflecting if (!reflected && !caster.isEmpty() && caster != target && !(magicEffect->mData.mFlags & ESM::MagicEffect::Unreflectable)) @@ -426,7 +426,7 @@ namespace MWMechanics "meshes\\" + reflectStatic->mModel, ESM::MagicEffect::Reflect, false, ""); reflectedEffects.mList.push_back(*effectIt); magnitudeMult = 0; - break; + continue; } } From a81a04e6d0c05425258301f1dfd842a4dd1badcb Mon Sep 17 00:00:00 2001 From: Allofich Date: Sun, 2 Oct 2016 01:11:01 +0900 Subject: [PATCH 3/4] Remove unused line --- apps/openmw/mwmechanics/spellcasting.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index e3e1550a62..ed60bbd882 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -425,7 +425,6 @@ namespace MWMechanics MWBase::Environment::get().getWorld()->getAnimation(target)->addEffect( "meshes\\" + reflectStatic->mModel, ESM::MagicEffect::Reflect, false, ""); reflectedEffects.mList.push_back(*effectIt); - magnitudeMult = 0; continue; } } From e78f02aaf2c621b93cb924f57d8bcdb179716350 Mon Sep 17 00:00:00 2001 From: Allofich Date: Sun, 2 Oct 2016 16:08:24 +0900 Subject: [PATCH 4/4] Consider reflected/absorbed hostile spells as assaults --- apps/openmw/mwmechanics/spellcasting.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index ed60bbd882..ad05ca41f5 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -411,6 +411,10 @@ namespace MWMechanics float magnitudeMult = 1; if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful && target.getClass().isActor()) { + // 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 (absorbed) continue; @@ -443,10 +447,6 @@ namespace MWMechanics // 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)