Apply elemental shield magnitude to element resistance (Closes #1121)

This commit is contained in:
scrawl 2014-07-15 22:06:46 +02:00
parent 123157b216
commit 20a0040bdb
3 changed files with 28 additions and 17 deletions

View file

@ -286,13 +286,7 @@ namespace MWMechanics
if (i == 2) if (i == 2)
element = ESM::MagicEffect::FrostDamage; element = ESM::MagicEffect::FrostDamage;
short resistanceEffect = ESM::MagicEffect::getResistanceEffect(element); float elementResistance = MWMechanics::getEffectResistanceAttribute(element, &attackerStats.getMagicEffects());
short weaknessEffect = ESM::MagicEffect::getWeaknessEffect(element);
float elementResistance = 0;
if (resistanceEffect != -1)
elementResistance += attackerStats.getMagicEffects().get(resistanceEffect).mMagnitude;
if (weaknessEffect != -1)
elementResistance -= attackerStats.getMagicEffects().get(weaknessEffect).mMagnitude;
x = std::min(100.f, x + elementResistance); x = std::min(100.f, x + elementResistance);

View file

@ -148,6 +148,27 @@ namespace MWMechanics
return school; return school;
} }
float getEffectResistanceAttribute (short effectId, const MagicEffects* actorEffects)
{
short resistanceEffect = ESM::MagicEffect::getResistanceEffect(effectId);
short weaknessEffect = ESM::MagicEffect::getWeaknessEffect(effectId);
float resistance = 0;
if (resistanceEffect != -1)
resistance += actorEffects->get(resistanceEffect).mMagnitude;
if (weaknessEffect != -1)
resistance -= actorEffects->get(weaknessEffect).mMagnitude;
if (effectId == ESM::MagicEffect::FireDamage)
resistance += actorEffects->get(ESM::MagicEffect::FireShield).mMagnitude;
if (effectId == ESM::MagicEffect::ShockDamage)
resistance += actorEffects->get(ESM::MagicEffect::LightningShield).mMagnitude;
if (effectId == ESM::MagicEffect::FrostDamage)
resistance += actorEffects->get(ESM::MagicEffect::FrostShield).mMagnitude;
return resistance;
}
float getEffectResistance (short effectId, const MWWorld::Ptr& actor, const MWWorld::Ptr& caster, float getEffectResistance (short effectId, const MWWorld::Ptr& actor, const MWWorld::Ptr& caster,
const ESM::Spell* spell, const MagicEffects* effects) const ESM::Spell* spell, const MagicEffects* effects)
{ {
@ -163,16 +184,7 @@ namespace MWMechanics
float resisted = 0; float resisted = 0;
if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful) if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful)
{ {
float resistance = getEffectResistanceAttribute(effectId, magicEffects);
short resistanceEffect = ESM::MagicEffect::getResistanceEffect(effectId);
short weaknessEffect = ESM::MagicEffect::getWeaknessEffect(effectId);
float resistance = 0;
if (resistanceEffect != -1)
resistance += magicEffects->get(resistanceEffect).mMagnitude;
if (weaknessEffect != -1)
resistance -= magicEffects->get(weaknessEffect).mMagnitude;
float willpower = stats.getAttribute(ESM::Attribute::Willpower).getModified(); float willpower = stats.getAttribute(ESM::Attribute::Willpower).getModified();
float luck = stats.getAttribute(ESM::Attribute::Luck).getModified(); float luck = stats.getAttribute(ESM::Attribute::Luck).getModified();

View file

@ -35,6 +35,11 @@ namespace MWMechanics
int getSpellSchool(const std::string& spellId, const MWWorld::Ptr& actor); int getSpellSchool(const std::string& spellId, const MWWorld::Ptr& actor);
int getSpellSchool(const ESM::Spell* spell, const MWWorld::Ptr& actor); int getSpellSchool(const ESM::Spell* spell, const MWWorld::Ptr& actor);
/// Get the resistance attribute against an effect for a given actor. This will add together
/// ResistX and Weakness to X effects relevant against the given effect.
float getEffectResistanceAttribute (short effectId, const MagicEffects* actorEffects);
/// Get the effective resistance against an effect casted by the given actor in the given spell (optional).
/// @return >=100 for fully resisted. can also return negative value for damage amplification. /// @return >=100 for fully resisted. can also return negative value for damage amplification.
/// @param effects Override the actor's current magicEffects. Useful if there are effects currently /// @param effects Override the actor's current magicEffects. Useful if there are effects currently
/// being applied (but not applied yet) that should also be considered. /// being applied (but not applied yet) that should also be considered.