From b738cc038377d73094c4ead7e1f60d480c8fcf1c Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Sat, 8 Dec 2018 21:55:08 +0300 Subject: [PATCH] Make normal weapon resistance behavior closer to vanilla (bug #4384) Check both the ranged weapon and the projectile before modifying the damage Don't attempt to apply NPC-specific werewolf damage mult to damage to creatures --- CHANGELOG.md | 1 + apps/openmw/mwclass/creature.cpp | 1 - apps/openmw/mwclass/npc.cpp | 5 +---- apps/openmw/mwmechanics/combat.cpp | 26 ++++++++++++++------------ apps/openmw/mwmechanics/combat.hpp | 3 +-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c3eba7e5..f3e9f4267 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Bug #3733: Normal maps are inverted on mirrored UVs Bug #4329: Removed birthsign abilities are restored after reloading the save Bug #4383: Bow model obscures crosshair when arrow is drawn + Bug #4384: Resist Normal Weapons only checks ammunition for ranged weapons Bug #4411: Reloading a saved game while falling prevents damage in some cases Bug #4540: Rain delay when exiting water Bug #4701: PrisonMarker record is not hardcoded like other markers diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 0a652dfbf..94f75dfc6 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -308,7 +308,6 @@ namespace MWClass { damage = attack[0] + ((attack[1]-attack[0])*attackStrength); MWMechanics::adjustWeaponDamage(damage, weapon, ptr); - MWMechanics::applyWerewolfDamageMult(victim, weapon, damage); MWMechanics::resistNormalWeapon(victim, ptr, weapon, damage); MWMechanics::reduceWeaponCondition(damage, true, weapon, ptr); } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 9e2fe9097..471cb873f 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -604,7 +604,6 @@ namespace MWClass } bool healthdmg; - bool resisted = false; float damage = 0.0f; if(!weapon.isEmpty()) { @@ -620,7 +619,7 @@ namespace MWClass damage = attack[0] + ((attack[1]-attack[0])*attackStrength); } MWMechanics::adjustWeaponDamage(damage, weapon, ptr); - resisted = MWMechanics::resistNormalWeapon(victim, ptr, weapon, damage); + MWMechanics::resistNormalWeapon(victim, ptr, weapon, damage); MWMechanics::applyWerewolfDamageMult(victim, weapon, damage); MWMechanics::reduceWeaponCondition(damage, true, weapon, ptr); healthdmg = true; @@ -632,8 +631,6 @@ namespace MWClass if(ptr == MWMechanics::getPlayer()) { skillUsageSucceeded(ptr, weapskill, 0); - if (resisted) - MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResistsWeapons}"); const MWMechanics::AiSequence& seq = victim.getClass().getCreatureStats(victim).getAiSequence(); diff --git a/apps/openmw/mwmechanics/combat.cpp b/apps/openmw/mwmechanics/combat.cpp index 1ab8078cb..a3e5e532b 100644 --- a/apps/openmw/mwmechanics/combat.cpp +++ b/apps/openmw/mwmechanics/combat.cpp @@ -153,7 +153,7 @@ namespace MWMechanics if (weapon.isEmpty()) return false; - const int &flags = weapon.get()->mBase->mData.mFlags; + const int flags = weapon.get()->mBase->mData.mFlags; bool isSilver = flags & ESM::Weapon::Silver; bool isMagical = flags & ESM::Weapon::Magical; bool isEnchanted = !weapon.getClass().getEnchantment(weapon).empty(); @@ -161,10 +161,10 @@ namespace MWMechanics return !isSilver && !isMagical && (!isEnchanted || !Settings::Manager::getBool("enchanted weapons are magical", "Game")); } - bool resistNormalWeapon(const MWWorld::Ptr &actor, const MWWorld::Ptr& attacker, const MWWorld::Ptr &weapon, float &damage) + void resistNormalWeapon(const MWWorld::Ptr &actor, const MWWorld::Ptr& attacker, const MWWorld::Ptr &weapon, float &damage) { if (damage == 0 || weapon.isEmpty() || !isNormalWeapon(weapon)) - return false; + return; const MWMechanics::MagicEffects& effects = actor.getClass().getCreatureStats(actor).getMagicEffects(); const float resistance = effects.get(ESM::MagicEffect::ResistNormalWeapons).getMagnitude() / 100.f; @@ -172,19 +172,23 @@ namespace MWMechanics damage *= 1.f - std::min(1.f, resistance-weakness); - return (damage == 0); + if (damage == 0 && attacker == getPlayer()) + MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResistsWeapons}"); } void applyWerewolfDamageMult(const MWWorld::Ptr &actor, const MWWorld::Ptr &weapon, float &damage) { - if (damage == 0 || weapon.isEmpty()) + if (damage == 0 || weapon.isEmpty() || !actor.getClass().isNpc()) return; - const int &flags = weapon.get()->mBase->mData.mFlags; + const int flags = weapon.get()->mBase->mData.mFlags; bool isSilver = flags & ESM::Weapon::Silver; - if (isSilver && actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf()) - damage *= MWBase::Environment::get().getWorld()->getStore().get().find("fWereWolfSilverWeaponDamageMult")->mValue.getFloat(); + if (isSilver && actor.getClass().getNpcStats(actor).isWerewolf()) + { + const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); + damage *= store.get().find("fWereWolfSilverWeaponDamageMult")->mValue.getFloat(); + } } void projectileHit(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, MWWorld::Ptr weapon, const MWWorld::Ptr& projectile, @@ -223,14 +227,12 @@ namespace MWMechanics damage += attack[0] + ((attack[1] - attack[0]) * attackStrength); adjustWeaponDamage(damage, weapon, attacker); - bool resisted = resistNormalWeapon(victim, attacker, projectile, damage); + if (weapon == projectile || isNormalWeapon(weapon)) // NB: both the weapon and the projectile need to be normal + resistNormalWeapon(victim, attacker, projectile, damage); applyWerewolfDamageMult(victim, projectile, damage); if (attacker == getPlayer()) { - if (resisted) - MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResistsWeapons}"); - attacker.getClass().skillUsageSucceeded(attacker, weaponSkill, 0); const MWMechanics::AiSequence& sequence = victim.getClass().getCreatureStats(victim).getAiSequence(); diff --git a/apps/openmw/mwmechanics/combat.hpp b/apps/openmw/mwmechanics/combat.hpp index f7a8a555c..77dd2a722 100644 --- a/apps/openmw/mwmechanics/combat.hpp +++ b/apps/openmw/mwmechanics/combat.hpp @@ -15,8 +15,7 @@ bool blockMeleeAttack (const MWWorld::Ptr& attacker, const MWWorld::Ptr& blocker /// @return does normal weapon resistance and weakness apply to the weapon? bool isNormalWeapon (const MWWorld::Ptr& weapon); -/// @return was the damage fully resisted? -bool resistNormalWeapon (const MWWorld::Ptr& actor, const MWWorld::Ptr& attacker, const MWWorld::Ptr& weapon, float& damage); +void resistNormalWeapon (const MWWorld::Ptr& actor, const MWWorld::Ptr& attacker, const MWWorld::Ptr& weapon, float& damage); void applyWerewolfDamageMult (const MWWorld::Ptr& actor, const MWWorld::Ptr& weapon, float &damage);