mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-30 07:36:46 +00:00
Move getEvasion to CreatureStats
This commit is contained in:
parent
9e7d670745
commit
b70975a74d
5 changed files with 19 additions and 23 deletions
|
@ -331,18 +331,18 @@ namespace MWClass
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const MWWorld::Class &othercls = MWWorld::Class::get(victim);
|
const MWWorld::Class &othercls = MWWorld::Class::get(victim);
|
||||||
if(!othercls.isActor() || othercls.getCreatureStats(victim).isDead())
|
if(!othercls.isActor()) // Can't hit non-actors
|
||||||
{
|
return;
|
||||||
// Can't hit non-actors, or dead actors
|
MWMechanics::CreatureStats &otherstats = getCreatureStats(victim);
|
||||||
|
if(otherstats.isDead()) // Can't hit dead actors
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if(ptr.getRefData().getHandle() == "player")
|
if(ptr.getRefData().getHandle() == "player")
|
||||||
MWBase::Environment::get().getWindowManager()->setEnemy(victim);
|
MWBase::Environment::get().getWindowManager()->setEnemy(victim);
|
||||||
|
|
||||||
int weapskill = ESM::Skill::HandToHand;
|
int weapskill = ESM::Skill::HandToHand;
|
||||||
if(!weapon.isEmpty())
|
if(!weapon.isEmpty())
|
||||||
weapskill = MWWorld::Class::get(weapon).getEquipmentSkill(weapon);
|
weapskill = get(weapon).getEquipmentSkill(weapon);
|
||||||
|
|
||||||
MWMechanics::CreatureStats &crstats = getCreatureStats(ptr);
|
MWMechanics::CreatureStats &crstats = getCreatureStats(ptr);
|
||||||
MWMechanics::NpcStats &npcstats = getNpcStats(ptr);
|
MWMechanics::NpcStats &npcstats = getNpcStats(ptr);
|
||||||
|
@ -353,7 +353,7 @@ namespace MWClass
|
||||||
hitchance *= crstats.getFatigueTerm();
|
hitchance *= crstats.getFatigueTerm();
|
||||||
hitchance += mageffects.get(MWMechanics::EffectKey(ESM::MagicEffect::FortifyAttack)).mMagnitude -
|
hitchance += mageffects.get(MWMechanics::EffectKey(ESM::MagicEffect::FortifyAttack)).mMagnitude -
|
||||||
mageffects.get(MWMechanics::EffectKey(ESM::MagicEffect::Blind)).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)
|
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);
|
MWBase::Environment::get().getSoundManager()->playSound3D(victim, "critical damage", 1.0f, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
healthdmg = (othercls.getCreatureStats(victim).getFatigue().getCurrent() < 1.0f ||
|
healthdmg = (otherstats.getFatigue().getCurrent() < 1.0f || npcstats.isWerewolf());
|
||||||
npcstats.isWerewolf());
|
|
||||||
if(healthdmg)
|
if(healthdmg)
|
||||||
damage *= gmst.find("fHandtoHandHealthPer")->getFloat();
|
damage *= gmst.find("fHandtoHandHealthPer")->getFloat();
|
||||||
}
|
}
|
||||||
|
|
|
@ -319,6 +319,16 @@ namespace MWMechanics
|
||||||
return false;
|
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)
|
void CreatureStats::setLastHitObject(const std::string& objectid)
|
||||||
{
|
{
|
||||||
mLastHitObject = objectid;
|
mLastHitObject = objectid;
|
||||||
|
|
|
@ -158,6 +158,8 @@ namespace MWMechanics
|
||||||
|
|
||||||
bool getCreatureTargetted() const;
|
bool getCreatureTargetted() const;
|
||||||
|
|
||||||
|
float getEvasion() const;
|
||||||
|
|
||||||
void setLastHitObject(const std::string &objectid);
|
void setLastHitObject(const std::string &objectid);
|
||||||
const std::string &getLastHitObject() const;
|
const std::string &getLastHitObject() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -79,18 +79,6 @@ namespace MWWorld
|
||||||
throw std::runtime_error ("class does not have item health");
|
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
|
void Class::hit(const Ptr& ptr, int type) const
|
||||||
{
|
{
|
||||||
throw std::runtime_error("class cannot hit");
|
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
|
///< Return item max health or throw an exception, if class does not have item health
|
||||||
/// (default implementation: throw an exceoption)
|
/// (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;
|
virtual void hit(const Ptr& ptr, int type=-1) const;
|
||||||
///< Execute a melee hit, using the current weapon. This will check the relevant skills
|
///< Execute a melee hit, using the current weapon. This will check the relevant skills
|
||||||
/// of the given attacker, and whoever is hit.
|
/// of the given attacker, and whoever is hit.
|
||||||
|
|
Loading…
Reference in a new issue