Merged pull request #1659

pull/440/head
Marc Zinnschlag 7 years ago
commit 832b4bb778

@ -227,45 +227,42 @@ namespace MWMechanics
magicEffects = effects; magicEffects = effects;
float resisted = 0; float resisted = 0;
if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful) // Effects with no resistance attribute belonging to them can not be resisted
{ if (ESM::MagicEffect::getResistanceEffect(effectId) == -1)
// Effects with no resistance attribute belonging to them can not be resisted return 0.f;
if (ESM::MagicEffect::getResistanceEffect(effectId) == -1)
return 0.f;
float resistance = getEffectResistanceAttribute(effectId, magicEffects); float resistance = getEffectResistanceAttribute(effectId, magicEffects);
int willpower = stats.getAttribute(ESM::Attribute::Willpower).getModified(); int willpower = stats.getAttribute(ESM::Attribute::Willpower).getModified();
float luck = static_cast<float>(stats.getAttribute(ESM::Attribute::Luck).getModified()); float luck = static_cast<float>(stats.getAttribute(ESM::Attribute::Luck).getModified());
float x = (willpower + 0.1f * luck) * stats.getFatigueTerm(); float x = (willpower + 0.1f * luck) * stats.getFatigueTerm();
// This makes spells that are easy to cast harder to resist and vice versa // This makes spells that are easy to cast harder to resist and vice versa
float castChance = 100.f; float castChance = 100.f;
if (spell != NULL && !caster.isEmpty() && caster.getClass().isActor()) if (spell != NULL && !caster.isEmpty() && caster.getClass().isActor())
{ {
castChance = getSpellSuccessChance(spell, caster, NULL, false); // Uncapped casting chance castChance = getSpellSuccessChance(spell, caster, NULL, false); // Uncapped casting chance
} }
if (castChance > 0) if (castChance > 0)
x *= 50 / castChance; x *= 50 / castChance;
float roll = Misc::Rng::rollClosedProbability() * 100; float roll = Misc::Rng::rollClosedProbability() * 100;
if (magicEffect->mData.mFlags & ESM::MagicEffect::NoMagnitude) if (magicEffect->mData.mFlags & ESM::MagicEffect::NoMagnitude)
roll -= resistance; roll -= resistance;
if (x <= roll) if (x <= roll)
x = 0; x = 0;
else
{
if (magicEffect->mData.mFlags & ESM::MagicEffect::NoMagnitude)
x = 100;
else else
{ x = roll / std::min(x, 100.f);
if (magicEffect->mData.mFlags & ESM::MagicEffect::NoMagnitude) }
x = 100;
else
x = roll / std::min(x, 100.f);
}
x = std::min(x + resistance, 100.f); x = std::min(x + resistance, 100.f);
resisted = x; resisted = x;
}
return resisted; return resisted;
} }
@ -463,13 +460,11 @@ namespace MWMechanics
} }
float magnitudeMult = 1; float magnitudeMult = 1;
if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful && target.getClass().isActor())
{
if (absorbed)
continue;
// Try reflecting if (!absorbed)
if (!reflected && !caster.isEmpty() && caster != target && !(magicEffect->mData.mFlags & ESM::MagicEffect::Unreflectable)) {
// Reflect harmful effects
if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful && !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);
@ -493,16 +488,17 @@ namespace MWMechanics
else if (castByPlayer) else if (castByPlayer)
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResisted}"); MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResisted}");
} }
else if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful && castByPlayer && target != caster)
{
// If player is attempting to cast a harmful spell and it wasn't fully resisted, show the target's HP bar
MWBase::Environment::get().getWindowManager()->setEnemy(target);
}
if (target == getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState()) if (target == getPlayer() && MWBase::Environment::get().getWorld()->getGodModeState())
magnitudeMult = 0; magnitudeMult = 0;
// 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 // Notify the target actor they've been hit
if (target != caster && !caster.isEmpty()) if (target != caster && !caster.isEmpty() && magicEffect->mData.mFlags & ESM::MagicEffect::Harmful)
target.getClass().onHit(target, 0.0f, true, MWWorld::Ptr(), caster, osg::Vec3f(), true); target.getClass().onHit(target, 0.0f, true, MWWorld::Ptr(), caster, osg::Vec3f(), true);
} }

Loading…
Cancel
Save