summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpsi29a <psi29a@gmail.com>2022-01-04 08:48:19 +0000
committerpsi29a <psi29a@gmail.com>2022-01-04 08:48:19 +0000
commit74e1e1eefd5f92c23bb672492f801b3e0786b883 (patch)
tree21ed57b33c5dee3a26427bf285767b589ce5d9a3
parentd1252090a4fbc8ce67d3071d8adf46d1977fe735 (diff)
parentaab0473c2870e1fabe8cf6bf8e7372d54297b0b7 (diff)
Merge branch 'recast_my_friends' into 'master'
Only prevent recasting by the actor who cast the spell See merge request OpenMW/openmw!1525
-rw-r--r--apps/openmw/mwmechanics/spellpriority.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/apps/openmw/mwmechanics/spellpriority.cpp b/apps/openmw/mwmechanics/spellpriority.cpp
index acc9fc2a3f..b79af49b05 100644
--- a/apps/openmw/mwmechanics/spellpriority.cpp
+++ b/apps/openmw/mwmechanics/spellpriority.cpp
@@ -75,6 +75,16 @@ namespace
}
return duration;
}
+
+ bool isSpellActive(const MWWorld::Ptr& caster, const MWWorld::Ptr& target, const std::string& id)
+ {
+ int actorId = caster.getClass().getCreatureStats(caster).getActorId();
+ const auto& active = target.getClass().getCreatureStats(target).getActiveSpells();
+ return std::find_if(active.begin(), active.end(), [&](const auto& spell)
+ {
+ return spell.getCasterActorId() == actorId && Misc::StringUtils::ciEqual(spell.getId(), id);
+ }) != active.end();
+ }
}
namespace MWMechanics
@@ -105,8 +115,6 @@ namespace MWMechanics
float rateSpell(const ESM::Spell *spell, const MWWorld::Ptr &actor, const MWWorld::Ptr& enemy)
{
- const CreatureStats& stats = actor.getClass().getCreatureStats(actor);
-
float successChance = MWMechanics::getSpellSuccessChance(spell, actor);
if (successChance == 0.f)
return 0.f;
@@ -125,9 +133,9 @@ namespace MWMechanics
// Spells don't stack, so early out if the spell is still active on the target
int types = getRangeTypes(spell->mEffects);
- if ((types & Self) && stats.getActiveSpells().isSpellActive(spell->mId))
+ if ((types & Self) && isSpellActive(actor, actor, spell->mId))
return 0.f;
- if ( ((types & Touch) || (types & Target)) && enemy.getClass().getCreatureStats(enemy).getActiveSpells().isSpellActive(spell->mId))
+ if ( ((types & Touch) || (types & Target)) && isSpellActive(actor, enemy, spell->mId))
return 0.f;
return rateEffects(spell->mEffects, actor, enemy) * (successChance / 100.f);