1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 00:49:54 +00:00
openmw-tes3mp/apps/openmw/mwmechanics/creaturestats.cpp

360 lines
8.6 KiB
C++
Raw Normal View History

2012-07-22 14:29:54 +00:00
#include "creaturestats.hpp"
#include <algorithm>
2012-10-01 15:17:04 +00:00
#include "../mwworld/esmstore.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
2012-07-22 14:29:54 +00:00
namespace MWMechanics
{
2012-09-15 15:12:42 +00:00
CreatureStats::CreatureStats()
2013-03-18 09:46:45 +00:00
: mLevel (0), mLevelHealthBonus(0.f), mDead (false), mDied (false), mFriendlyHits (0),
mTalkedTo (false), mAlarmed (false),
2013-07-13 21:24:52 +00:00
mAttacked (false), mHostile (false),
2013-08-09 12:14:58 +00:00
mAttackingOrSpell(false), mAttackType(AT_Chop),
mIsWerewolf(false)
2012-09-15 15:12:42 +00:00
{
for (int i=0; i<4; ++i)
mAiSettings[i] = 0;
2012-09-15 15:12:42 +00:00
}
float CreatureStats::getLevelHealthBonus () const
2012-09-15 15:12:42 +00:00
{
return mLevelHealthBonus;
2012-09-15 15:12:42 +00:00
}
void CreatureStats::levelUp()
2012-09-15 15:12:42 +00:00
{
const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
const int endurance = getAttribute(ESM::Attribute::Endurance).getBase();
// "When you gain a level, in addition to increasing three primary attributes, your Health
// will automatically increase by 10% of your Endurance attribute. If you increased Endurance this level,
// the Health increase is calculated from the increased Endurance"
mLevelHealthBonus += endurance * gmst.find("fLevelUpHealthEndMult")->getFloat();
updateHealth();
mLevel++;
2012-09-15 15:12:42 +00:00
}
void CreatureStats::updateHealth()
{
const int endurance = getAttribute(ESM::Attribute::Endurance).getBase();
const int strength = getAttribute(ESM::Attribute::Strength).getBase();
setHealth(static_cast<int> (0.5 * (strength + endurance)) + mLevelHealthBonus);
}
const AiSequence& CreatureStats::getAiSequence() const
{
return mAiSequence;
}
AiSequence& CreatureStats::getAiSequence()
{
return mAiSequence;
}
float CreatureStats::getFatigueTerm() const
{
int max = getFatigue().getModified();
int current = getFatigue().getCurrent();
float normalised = max==0 ? 1 : std::max (0.0f, static_cast<float> (current)/max);
const MWWorld::Store<ESM::GameSetting> &gmst =
MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
return gmst.find ("fFatigueBase")->getFloat()
- gmst.find ("fFatigueMult")->getFloat() * (1-normalised);
}
2012-09-13 08:52:34 +00:00
const Stat<int> &CreatureStats::getAttribute(int index) const
{
if (index < 0 || index > 7) {
throw std::runtime_error("attribute index is out of range");
}
2013-08-09 12:14:58 +00:00
return (!mIsWerewolf ? mAttributes[index] : mWerewolfAttributes[index]);
2012-09-13 08:52:34 +00:00
}
2012-09-15 15:12:42 +00:00
const DynamicStat<float> &CreatureStats::getHealth() const
2012-09-13 08:52:34 +00:00
{
return mDynamic[0];
}
2012-09-15 15:12:42 +00:00
const DynamicStat<float> &CreatureStats::getMagicka() const
2012-09-13 08:52:34 +00:00
{
return mDynamic[1];
}
2012-09-15 15:12:42 +00:00
const DynamicStat<float> &CreatureStats::getFatigue() const
2012-09-13 08:52:34 +00:00
{
return mDynamic[2];
}
const Spells &CreatureStats::getSpells() const
{
return mSpells;
}
const ActiveSpells &CreatureStats::getActiveSpells() const
{
return mActiveSpells;
}
const MagicEffects &CreatureStats::getMagicEffects() const
{
return mMagicEffects;
}
2013-08-04 02:29:44 +00:00
bool CreatureStats::getAttackingOrSpell() const
2013-07-13 21:24:52 +00:00
{
return mAttackingOrSpell;
}
2012-09-13 08:52:34 +00:00
int CreatureStats::getLevel() const
{
return mLevel;
}
int CreatureStats::getAiSetting (int index) const
2012-09-13 08:52:34 +00:00
{
assert (index>=0 && index<4);
return mAiSettings[index];
2012-09-13 08:52:34 +00:00
}
2012-09-13 08:52:34 +00:00
Stat<int> &CreatureStats::getAttribute(int index)
{
if (index < 0 || index > 7) {
throw std::runtime_error("attribute index is out of range");
}
2013-08-09 12:14:58 +00:00
return (!mIsWerewolf ? mAttributes[index] : mWerewolfAttributes[index]);
2012-09-13 08:52:34 +00:00
}
const DynamicStat<float> &CreatureStats::getDynamic(int index) const
2012-09-13 08:52:34 +00:00
{
if (index < 0 || index > 2) {
throw std::runtime_error("dynamic stat index is out of range");
}
return mDynamic[index];
}
Spells &CreatureStats::getSpells()
{
return mSpells;
}
void CreatureStats::setSpells(const Spells &spells)
{
mSpells = spells;
}
ActiveSpells &CreatureStats::getActiveSpells()
{
return mActiveSpells;
}
MagicEffects &CreatureStats::getMagicEffects()
{
return mMagicEffects;
}
void CreatureStats::setAttribute(int index, const Stat<int> &value)
{
if (index < 0 || index > 7) {
throw std::runtime_error("attribute index is out of range");
}
2013-08-09 12:14:58 +00:00
if(!mIsWerewolf)
mAttributes[index] = value;
else
mWerewolfAttributes[index] = value;
2012-09-13 08:52:34 +00:00
}
2012-09-15 15:12:42 +00:00
void CreatureStats::setHealth(const DynamicStat<float> &value)
2012-09-13 08:52:34 +00:00
{
setDynamic (0, value);
2012-09-13 08:52:34 +00:00
}
2012-09-15 15:12:42 +00:00
void CreatureStats::setMagicka(const DynamicStat<float> &value)
2012-09-13 08:52:34 +00:00
{
setDynamic (1, value);
2012-09-13 08:52:34 +00:00
}
2012-09-15 15:12:42 +00:00
void CreatureStats::setFatigue(const DynamicStat<float> &value)
2012-09-13 08:52:34 +00:00
{
setDynamic (2, value);
2012-09-13 08:52:34 +00:00
}
void CreatureStats::setDynamic (int index, const DynamicStat<float> &value)
{
if (index < 0 || index > 2)
throw std::runtime_error("dynamic stat index is out of range");
mDynamic[index] = value;
2012-10-25 10:22:48 +00:00
if (index==0 && mDynamic[index].getCurrent()<1)
2013-03-18 09:46:45 +00:00
{
if (!mDead)
mDied = true;
mDead = true;
2013-03-18 09:46:45 +00:00
}
}
2012-09-13 08:52:34 +00:00
void CreatureStats::setLevel(int level)
{
mLevel = level;
}
void CreatureStats::setActiveSpells(const ActiveSpells &active)
{
mActiveSpells = active;
}
void CreatureStats::setMagicEffects(const MagicEffects &effects)
{
mMagicEffects = effects;
}
2013-08-04 02:29:44 +00:00
void CreatureStats::setAttackingOrSpell(bool attackingOrSpell)
2013-07-13 21:24:52 +00:00
{
mAttackingOrSpell = attackingOrSpell;
}
void CreatureStats::setAiSetting (int index, int value)
2012-09-13 08:52:34 +00:00
{
assert (index>=0 && index<4);
mAiSettings[index] = value;
2012-09-13 08:52:34 +00:00
}
bool CreatureStats::isDead() const
{
return mDead;
}
2013-03-18 09:46:45 +00:00
bool CreatureStats::hasDied() const
{
return mDied;
}
void CreatureStats::clearHasDied()
{
mDied = false;
}
void CreatureStats::resurrect()
{
if (mDead)
{
if (mDynamic[0].getCurrent()<1)
mDynamic[0].setCurrent (1);
if (mDynamic[0].getCurrent()>=1)
mDead = false;
}
}
2012-11-09 17:16:29 +00:00
bool CreatureStats::hasCommonDisease() const
{
return mSpells.hasCommonDisease();
}
bool CreatureStats::hasBlightDisease() const
{
return mSpells.hasBlightDisease();
}
int CreatureStats::getFriendlyHits() const
{
return mFriendlyHits;
}
void CreatureStats::friendlyHit()
{
++mFriendlyHits;
}
bool CreatureStats::hasTalkedToPlayer() const
{
return mTalkedTo;
}
void CreatureStats::talkedToPlayer()
{
mTalkedTo = true;
}
bool CreatureStats::isAlarmed() const
{
return mAlarmed;
}
void CreatureStats::setAlarmed (bool alarmed)
{
mAlarmed = alarmed;
}
bool CreatureStats::getAttacked() const
{
return mAttacked;
}
void CreatureStats::setAttacked (bool attacked)
{
mAttacked = attacked;
}
bool CreatureStats::isHostile() const
{
return mHostile;
}
void CreatureStats::setHostile (bool hostile)
{
mHostile = hostile;
}
bool CreatureStats::getCreatureTargetted() const
{
return false;
}
2013-07-26 15:08:52 +00:00
2013-07-31 19:25:14 +00:00
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;
}
2013-07-26 15:08:52 +00:00
void CreatureStats::setLastHitObject(const std::string& objectid)
{
mLastHitObject = objectid;
}
const std::string &CreatureStats::getLastHitObject() const
{
return mLastHitObject;
}
bool CreatureStats::canUsePower(const std::string &power)
{
std::map<std::string, MWWorld::TimeStamp>::iterator it = mUsedPowers.find(power);
if (it == mUsedPowers.end() || it->second + 24 <= MWBase::Environment::get().getWorld()->getTimeStamp())
return true;
else
return false;
}
void CreatureStats::usePower(const std::string &power)
{
mUsedPowers[power] = MWBase::Environment::get().getWorld()->getTimeStamp();
}
2012-07-22 14:29:54 +00:00
}