forked from mirror/openmw-tes3mp
Merge remote-tracking branch 'dteviot/Bug2367'
This commit is contained in:
commit
185757da43
5 changed files with 59 additions and 21 deletions
|
@ -152,12 +152,7 @@ namespace MWMechanics
|
||||||
void ActiveSpells::addSpell(const std::string &id, bool stack, std::vector<ActiveEffect> effects,
|
void ActiveSpells::addSpell(const std::string &id, bool stack, std::vector<ActiveEffect> effects,
|
||||||
const std::string &displayName, int casterActorId)
|
const std::string &displayName, int casterActorId)
|
||||||
{
|
{
|
||||||
bool exists = false;
|
TContainer::iterator it(mSpells.find(id));
|
||||||
for (TContainer::const_iterator it = begin(); it != end(); ++it)
|
|
||||||
{
|
|
||||||
if (id == it->first)
|
|
||||||
exists = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ActiveSpellParams params;
|
ActiveSpellParams params;
|
||||||
params.mTimeStamp = MWBase::Environment::get().getWorld()->getTimeStamp();
|
params.mTimeStamp = MWBase::Environment::get().getWorld()->getTimeStamp();
|
||||||
|
@ -165,14 +160,44 @@ namespace MWMechanics
|
||||||
params.mDisplayName = displayName;
|
params.mDisplayName = displayName;
|
||||||
params.mCasterActorId = casterActorId;
|
params.mCasterActorId = casterActorId;
|
||||||
|
|
||||||
if (!exists || stack)
|
if (it == end() || stack)
|
||||||
mSpells.insert (std::make_pair(id, params));
|
{
|
||||||
|
mSpells.insert(std::make_pair(id, params));
|
||||||
|
}
|
||||||
else
|
else
|
||||||
mSpells.find(id)->second = params;
|
{
|
||||||
|
// addSpell() is called with effects for a range.
|
||||||
|
// but a spell may have effects with different ranges (e.g. Touch & Target)
|
||||||
|
// so, if we see new effects for same spell assume additional
|
||||||
|
// spell effects and add to existing effects of spell
|
||||||
|
mergeEffects(params.mEffects, it->second.mEffects);
|
||||||
|
it->second = params;
|
||||||
|
}
|
||||||
|
|
||||||
mSpellsChanged = true;
|
mSpellsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ActiveSpells::mergeEffects(std::vector<ActiveEffect>& addTo, const std::vector<ActiveEffect>& from)
|
||||||
|
{
|
||||||
|
for (std::vector<ActiveEffect>::const_iterator effect(from.begin()); effect != from.end(); ++effect)
|
||||||
|
{
|
||||||
|
// if effect is not in addTo, add it
|
||||||
|
bool missing = true;
|
||||||
|
for (std::vector<ActiveEffect>::const_iterator iter(addTo.begin()); iter != addTo.end(); ++iter)
|
||||||
|
{
|
||||||
|
if (effect->mEffectId == iter->mEffectId)
|
||||||
|
{
|
||||||
|
missing = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (missing)
|
||||||
|
{
|
||||||
|
addTo.push_back(*effect);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ActiveSpells::removeEffects(const std::string &id)
|
void ActiveSpells::removeEffects(const std::string &id)
|
||||||
{
|
{
|
||||||
mSpells.erase(Misc::StringUtils::lowerCase(id));
|
mSpells.erase(Misc::StringUtils::lowerCase(id));
|
||||||
|
|
|
@ -55,6 +55,9 @@ namespace MWMechanics
|
||||||
|
|
||||||
void rebuildEffects() const;
|
void rebuildEffects() const;
|
||||||
|
|
||||||
|
/// Add any effects that are in "from" and not in "addTo" to "addTo"
|
||||||
|
void mergeEffects(std::vector<ActiveEffect>& addTo, const std::vector<ActiveEffect>& from);
|
||||||
|
|
||||||
double timeToExpire (const TIterator& iterator) const;
|
double timeToExpire (const TIterator& iterator) const;
|
||||||
///< Returns time (in in-game hours) until the spell pointed to by \a iterator
|
///< Returns time (in in-game hours) until the spell pointed to by \a iterator
|
||||||
/// expires.
|
/// expires.
|
||||||
|
|
|
@ -515,8 +515,8 @@ namespace MWMechanics
|
||||||
for(int i = 0;i < ESM::Attribute::Length;++i)
|
for(int i = 0;i < ESM::Attribute::Length;++i)
|
||||||
{
|
{
|
||||||
AttributeValue stat = creatureStats.getAttribute(i);
|
AttributeValue stat = creatureStats.getAttribute(i);
|
||||||
stat.setModifier(effects.get(EffectKey(ESM::MagicEffect::FortifyAttribute, i)).getMagnitude() -
|
stat.setModifiers(effects.get(EffectKey(ESM::MagicEffect::FortifyAttribute, i)).getMagnitude(),
|
||||||
effects.get(EffectKey(ESM::MagicEffect::DrainAttribute, i)).getMagnitude() -
|
effects.get(EffectKey(ESM::MagicEffect::DrainAttribute, i)).getMagnitude(),
|
||||||
effects.get(EffectKey(ESM::MagicEffect::AbsorbAttribute, i)).getMagnitude());
|
effects.get(EffectKey(ESM::MagicEffect::AbsorbAttribute, i)).getMagnitude());
|
||||||
|
|
||||||
stat.damage(effects.get(EffectKey(ESM::MagicEffect::DamageAttribute, i)).getMagnitude() * duration * 1.5);
|
stat.damage(effects.get(EffectKey(ESM::MagicEffect::DamageAttribute, i)).getMagnitude() * duration * 1.5);
|
||||||
|
@ -782,8 +782,8 @@ namespace MWMechanics
|
||||||
for(int i = 0;i < ESM::Skill::Length;++i)
|
for(int i = 0;i < ESM::Skill::Length;++i)
|
||||||
{
|
{
|
||||||
SkillValue& skill = npcStats.getSkill(i);
|
SkillValue& skill = npcStats.getSkill(i);
|
||||||
skill.setModifier(effects.get(EffectKey(ESM::MagicEffect::FortifySkill, i)).getMagnitude() -
|
skill.setModifiers(effects.get(EffectKey(ESM::MagicEffect::FortifySkill, i)).getMagnitude(),
|
||||||
effects.get(EffectKey(ESM::MagicEffect::DrainSkill, i)).getMagnitude() -
|
effects.get(EffectKey(ESM::MagicEffect::DrainSkill, i)).getMagnitude(),
|
||||||
effects.get(EffectKey(ESM::MagicEffect::AbsorbSkill, i)).getMagnitude());
|
effects.get(EffectKey(ESM::MagicEffect::AbsorbSkill, i)).getMagnitude());
|
||||||
|
|
||||||
skill.damage(effects.get(EffectKey(ESM::MagicEffect::DamageSkill, i)).getMagnitude() * duration * 1.5);
|
skill.damage(effects.get(EffectKey(ESM::MagicEffect::DamageSkill, i)).getMagnitude() * duration * 1.5);
|
||||||
|
|
|
@ -15,6 +15,11 @@ void MWMechanics::AttributeValue::readState (const ESM::StatState<int>& state)
|
||||||
mDamage = state.mDamage;
|
mDamage = state.mDamage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MWMechanics::AttributeValue::setModifiers(int fortify, int drain, int absorb)
|
||||||
|
{
|
||||||
|
mFortified = fortify;
|
||||||
|
mModifier = (fortify - drain) - absorb;
|
||||||
|
}
|
||||||
|
|
||||||
void MWMechanics::SkillValue::writeState (ESM::StatState<int>& state) const
|
void MWMechanics::SkillValue::writeState (ESM::StatState<int>& state) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -235,26 +235,29 @@ namespace MWMechanics
|
||||||
class AttributeValue
|
class AttributeValue
|
||||||
{
|
{
|
||||||
int mBase;
|
int mBase;
|
||||||
int mModifier;
|
int mFortified;
|
||||||
|
int mModifier; // net effect of Fortified, Drain & Absorb
|
||||||
float mDamage; // needs to be float to allow continuous damage
|
float mDamage; // needs to be float to allow continuous damage
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AttributeValue() : mBase(0), mModifier(0), mDamage(0) {}
|
AttributeValue() : mBase(0), mFortified(0), mModifier(0), mDamage(0) {}
|
||||||
|
|
||||||
int getModified() const { return std::max(0, mBase - (int) mDamage + mModifier); }
|
int getModified() const { return std::max(0, mBase - (int) mDamage + mModifier); }
|
||||||
int getBase() const { return mBase; }
|
int getBase() const { return mBase; }
|
||||||
int getModifier() const { return mModifier; }
|
int getModifier() const { return mModifier; }
|
||||||
|
|
||||||
void setBase(int base) { mBase = std::max(0, base); }
|
void setBase(int base) { mBase = std::max(0, base); }
|
||||||
void setModifier(int mod) { mModifier = mod; }
|
void setModifiers(int fortify, int drain, int absorb);
|
||||||
|
|
||||||
void damage(float damage) { mDamage += damage; }
|
void damage(float damage) { mDamage = std::min(mDamage + damage, (float)(mBase + mFortified)); }
|
||||||
void restore(float amount) { mDamage -= std::min(mDamage, amount); }
|
void restore(float amount) { mDamage -= std::min(mDamage, amount); }
|
||||||
int getDamage() const { return mDamage; }
|
int getDamage() const { return mDamage; }
|
||||||
|
|
||||||
void writeState (ESM::StatState<int>& state) const;
|
void writeState (ESM::StatState<int>& state) const;
|
||||||
|
|
||||||
void readState (const ESM::StatState<int>& state);
|
void readState (const ESM::StatState<int>& state);
|
||||||
|
|
||||||
|
friend bool operator== (const AttributeValue& left, const AttributeValue& right);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SkillValue : public AttributeValue
|
class SkillValue : public AttributeValue
|
||||||
|
@ -268,13 +271,16 @@ namespace MWMechanics
|
||||||
void writeState (ESM::StatState<int>& state) const;
|
void writeState (ESM::StatState<int>& state) const;
|
||||||
|
|
||||||
void readState (const ESM::StatState<int>& state);
|
void readState (const ESM::StatState<int>& state);
|
||||||
|
|
||||||
|
friend bool operator== (const SkillValue& left, const SkillValue& right);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator== (const AttributeValue& left, const AttributeValue& right)
|
inline bool operator== (const AttributeValue& left, const AttributeValue& right)
|
||||||
{
|
{
|
||||||
return left.getBase() == right.getBase()
|
return left.getBase() == right.getBase()
|
||||||
|
&& left.mFortified == right.mFortified
|
||||||
&& left.getModifier() == right.getModifier()
|
&& left.getModifier() == right.getModifier()
|
||||||
&& left.getDamage() == right.getDamage();
|
&& left.mDamage == right.mDamage;
|
||||||
}
|
}
|
||||||
inline bool operator!= (const AttributeValue& left, const AttributeValue& right)
|
inline bool operator!= (const AttributeValue& left, const AttributeValue& right)
|
||||||
{
|
{
|
||||||
|
@ -283,9 +289,8 @@ namespace MWMechanics
|
||||||
|
|
||||||
inline bool operator== (const SkillValue& left, const SkillValue& right)
|
inline bool operator== (const SkillValue& left, const SkillValue& right)
|
||||||
{
|
{
|
||||||
return left.getBase() == right.getBase()
|
// delegate to base class for most of the work
|
||||||
&& left.getModifier() == right.getModifier()
|
return (static_cast<const AttributeValue&>(left) == right)
|
||||||
&& left.getDamage() == right.getDamage()
|
|
||||||
&& left.getProgress() == right.getProgress();
|
&& left.getProgress() == right.getProgress();
|
||||||
}
|
}
|
||||||
inline bool operator!= (const SkillValue& left, const SkillValue& right)
|
inline bool operator!= (const SkillValue& left, const SkillValue& right)
|
||||||
|
|
Loading…
Reference in a new issue