Move getEvasion to CreatureStats

actorid
Chris Robinson 12 years ago
parent 9e7d670745
commit b70975a74d

@ -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();
}

@ -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;

@ -158,6 +158,8 @@ namespace MWMechanics
bool getCreatureTargetted() const;
float getEvasion() const;
void setLastHitObject(const std::string &objectid);
const std::string &getLastHitObject() const;
};

@ -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");

@ -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.

Loading…
Cancel
Save