diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index b425a4147..4dd4f6f36 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -331,18 +331,18 @@ namespace MWClass return; const MWWorld::Class &othercls = MWWorld::Class::get(victim); - if(!othercls.isActor() || othercls.getCreatureStats(victim).isDead()) - { - // Can't hit non-actors, or dead actors + if(!othercls.isActor()) // Can't hit non-actors + return; + MWMechanics::CreatureStats &otherstats = getCreatureStats(victim); + if(otherstats.isDead()) // Can't hit dead actors return; - } if(ptr.getRefData().getHandle() == "player") MWBase::Environment::get().getWindowManager()->setEnemy(victim); int weapskill = ESM::Skill::HandToHand; if(!weapon.isEmpty()) - weapskill = MWWorld::Class::get(weapon).getEquipmentSkill(weapon); + weapskill = get(weapon).getEquipmentSkill(weapon); MWMechanics::CreatureStats &crstats = getCreatureStats(ptr); MWMechanics::NpcStats &npcstats = getNpcStats(ptr); @@ -353,7 +353,7 @@ namespace MWClass hitchance *= crstats.getFatigueTerm(); hitchance += mageffects.get(MWMechanics::EffectKey(ESM::MagicEffect::FortifyAttack)).mMagnitude - mageffects.get(MWMechanics::EffectKey(ESM::MagicEffect::Blind)).mMagnitude; - hitchance -= othercls.getEvasion(victim); + hitchance -= otherstats.getEvasion(); if((::rand()/(RAND_MAX+1.0)) > hitchance/100.0f) { @@ -412,8 +412,7 @@ namespace MWClass MWBase::Environment::get().getSoundManager()->playSound3D(victim, "critical damage", 1.0f, 1.0f); } - healthdmg = (othercls.getCreatureStats(victim).getFatigue().getCurrent() < 1.0f || - npcstats.isWerewolf()); + healthdmg = (otherstats.getFatigue().getCurrent() < 1.0f || npcstats.isWerewolf()); if(healthdmg) damage *= gmst.find("fHandtoHandHealthPer")->getFloat(); } diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index 9f1f1fa31..93fe495c9 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -319,6 +319,16 @@ namespace MWMechanics return false; } + float CreatureStats::getEvasion() const + { + float evasion = (getAttribute(ESM::Attribute::Agility).getModified() / 5.0f) + + (getAttribute(ESM::Attribute::Luck).getModified() / 10.0f); + evasion *= getFatigueTerm(); + evasion += mMagicEffects.get(EffectKey(ESM::MagicEffect::Sanctuary)).mMagnitude; + + return evasion; + } + void CreatureStats::setLastHitObject(const std::string& objectid) { mLastHitObject = objectid; diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index fe46ed072..4e18faf9a 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -158,6 +158,8 @@ namespace MWMechanics bool getCreatureTargetted() const; + float getEvasion() const; + void setLastHitObject(const std::string &objectid); const std::string &getLastHitObject() const; }; diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 2c264020c..296008578 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -79,18 +79,6 @@ namespace MWWorld throw std::runtime_error ("class does not have item health"); } - float Class::getEvasion(const Ptr& ptr) const - { - MWMechanics::CreatureStats &crstats = getCreatureStats(ptr); - const MWMechanics::MagicEffects &mageffects = crstats.getMagicEffects(); - float evasion = (crstats.getAttribute(ESM::Attribute::Agility).getModified() / 5.0f) + - (crstats.getAttribute(ESM::Attribute::Luck).getModified() / 10.0f); - evasion *= crstats.getFatigueTerm(); - evasion += mageffects.get(MWMechanics::EffectKey(ESM::MagicEffect::Sanctuary)).mMagnitude; - - return evasion; - } - void Class::hit(const Ptr& ptr, int type) const { throw std::runtime_error("class cannot hit"); diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index edffd7d23..2751a4130 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -105,9 +105,6 @@ namespace MWWorld ///< Return item max health or throw an exception, if class does not have item health /// (default implementation: throw an exceoption) - virtual float getEvasion(const Ptr& ptr) const; - ///< Gets the chance the given object can evade an attack - virtual void hit(const Ptr& ptr, int type=-1) const; ///< Execute a melee hit, using the current weapon. This will check the relevant skills /// of the given attacker, and whoever is hit.