mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-29 09:45:34 +00:00
Refactor normal weapon resistance
This commit is contained in:
parent
cb5a57e41b
commit
808b8ce8db
4 changed files with 36 additions and 16 deletions
|
@ -308,6 +308,7 @@ namespace MWClass
|
|||
{
|
||||
damage = attack[0] + ((attack[1]-attack[0])*attackStrength);
|
||||
MWMechanics::adjustWeaponDamage(damage, weapon, ptr);
|
||||
MWMechanics::resistNormalWeapon(victim, ptr, weapon, damage);
|
||||
MWMechanics::reduceWeaponCondition(damage, true, weapon, ptr);
|
||||
}
|
||||
|
||||
|
@ -382,9 +383,6 @@ namespace MWClass
|
|||
if (!object.isEmpty())
|
||||
stats.setLastHitObject(object.getCellRef().getRefId());
|
||||
|
||||
if (damage > 0.0f && !object.isEmpty())
|
||||
MWMechanics::resistNormalWeapon(ptr, attacker, object, damage);
|
||||
|
||||
if (damage < 0.001f)
|
||||
damage = 0;
|
||||
|
||||
|
|
|
@ -604,6 +604,7 @@ namespace MWClass
|
|||
}
|
||||
|
||||
bool healthdmg;
|
||||
bool resisted = false;
|
||||
float damage = 0.0f;
|
||||
if(!weapon.isEmpty())
|
||||
{
|
||||
|
@ -619,6 +620,7 @@ namespace MWClass
|
|||
damage = attack[0] + ((attack[1]-attack[0])*attackStrength);
|
||||
}
|
||||
MWMechanics::adjustWeaponDamage(damage, weapon, ptr);
|
||||
resisted = MWMechanics::resistNormalWeapon(victim, ptr, weapon, damage);
|
||||
MWMechanics::reduceWeaponCondition(damage, true, weapon, ptr);
|
||||
healthdmg = true;
|
||||
}
|
||||
|
@ -629,6 +631,8 @@ 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();
|
||||
|
||||
|
|
|
@ -148,28 +148,38 @@ namespace MWMechanics
|
|||
return false;
|
||||
}
|
||||
|
||||
void resistNormalWeapon(const MWWorld::Ptr &actor, const MWWorld::Ptr& attacker, const MWWorld::Ptr &weapon, float &damage)
|
||||
bool isNormalWeapon(const MWWorld::Ptr &weapon)
|
||||
{
|
||||
const MWMechanics::MagicEffects& effects = actor.getClass().getCreatureStats(actor).getMagicEffects();
|
||||
float resistance = std::min(100.f, effects.get(ESM::MagicEffect::ResistNormalWeapons).getMagnitude()
|
||||
- effects.get(ESM::MagicEffect::WeaknessToNormalWeapons).getMagnitude());
|
||||
if (weapon.isEmpty())
|
||||
return false;
|
||||
|
||||
float multiplier = 1.f - resistance / 100.f;
|
||||
const int &flags = weapon.get<ESM::Weapon>()->mBase->mData.mFlags;
|
||||
bool isSilver = flags & ESM::Weapon::Silver;
|
||||
bool isMagical = flags & ESM::Weapon::Magical;
|
||||
bool isEnchanted = !weapon.getClass().getEnchantment(weapon).empty();
|
||||
|
||||
if (!(weapon.get<ESM::Weapon>()->mBase->mData.mFlags & ESM::Weapon::Silver
|
||||
|| weapon.get<ESM::Weapon>()->mBase->mData.mFlags & ESM::Weapon::Magical))
|
||||
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)
|
||||
{
|
||||
if (damage == 0)
|
||||
return false;
|
||||
|
||||
if (isNormalWeapon(weapon))
|
||||
{
|
||||
if (weapon.getClass().getEnchantment(weapon).empty()
|
||||
|| !Settings::Manager::getBool("enchanted weapons are magical", "Game"))
|
||||
damage *= multiplier;
|
||||
const MWMechanics::MagicEffects& effects = actor.getClass().getCreatureStats(actor).getMagicEffects();
|
||||
const float resistance = effects.get(ESM::MagicEffect::ResistNormalWeapons).getMagnitude() / 100.f;
|
||||
const float weakness = effects.get(ESM::MagicEffect::WeaknessToNormalWeapons).getMagnitude() / 100.f;
|
||||
|
||||
damage *= 1.f - std::min(1.f, resistance-weakness);
|
||||
}
|
||||
|
||||
if ((weapon.get<ESM::Weapon>()->mBase->mData.mFlags & ESM::Weapon::Silver)
|
||||
&& actor.getClass().isNpc() && actor.getClass().getNpcStats(actor).isWerewolf())
|
||||
damage *= MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fWereWolfSilverWeaponDamageMult")->mValue.getFloat();
|
||||
|
||||
if (damage == 0 && attacker == getPlayer())
|
||||
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicTargetResistsWeapons}");
|
||||
return (damage == 0);
|
||||
}
|
||||
|
||||
void projectileHit(const MWWorld::Ptr& attacker, const MWWorld::Ptr& victim, MWWorld::Ptr weapon, const MWWorld::Ptr& projectile,
|
||||
|
@ -208,9 +218,13 @@ namespace MWMechanics
|
|||
damage += attack[0] + ((attack[1] - attack[0]) * attackStrength);
|
||||
|
||||
adjustWeaponDamage(damage, weapon, attacker);
|
||||
bool resisted = resistNormalWeapon(victim, attacker, 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();
|
||||
|
||||
|
|
|
@ -12,7 +12,11 @@ bool applyOnStrikeEnchantment(const MWWorld::Ptr& attacker, const MWWorld::Ptr&
|
|||
/// @return can we block the attack?
|
||||
bool blockMeleeAttack (const MWWorld::Ptr& attacker, const MWWorld::Ptr& blocker, const MWWorld::Ptr& weapon, float damage, float attackStrength);
|
||||
|
||||
void resistNormalWeapon (const MWWorld::Ptr& actor, const MWWorld::Ptr& attacker, const MWWorld::Ptr& weapon, float& damage);
|
||||
/// @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);
|
||||
|
||||
/// @note for a thrown weapon, \a weapon == \a projectile, for bows/crossbows, \a projectile is the arrow/bolt
|
||||
/// @note \a victim may be empty (e.g. for a hit on terrain), a non-actor (environment objects) or an actor
|
||||
|
|
Loading…
Reference in a new issue