forked from mirror/openmw-tes3mp
Implement removal of corprus spells
This commit is contained in:
parent
2cbe17ca0a
commit
85aa237baf
4 changed files with 114 additions and 12 deletions
|
@ -63,12 +63,26 @@ namespace MWMechanics
|
||||||
TContainer::iterator iter = mSpells.find (lower);
|
TContainer::iterator iter = mSpells.find (lower);
|
||||||
std::map<std::string, CorprusStats>::iterator corprusIt = mCorprusSpells.find(lower);
|
std::map<std::string, CorprusStats>::iterator corprusIt = mCorprusSpells.find(lower);
|
||||||
|
|
||||||
|
// if it's corprus, remove negative and keep positive effects
|
||||||
|
if (corprusIt != mCorprusSpells.end())
|
||||||
|
{
|
||||||
|
worsenCorprus(lower);
|
||||||
|
if (mPermanentSpellEffects.find(lower) != mPermanentSpellEffects.end())
|
||||||
|
{
|
||||||
|
MagicEffects & effects = mPermanentSpellEffects[lower];
|
||||||
|
for (MagicEffects::Collection::const_iterator effectIt = effects.begin(); effectIt != effects.end(); ++effectIt)
|
||||||
|
{
|
||||||
|
const ESM::MagicEffect * magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effectIt->first.mId);
|
||||||
|
if (magicEffect->mData.mFlags & ESM::MagicEffect::Harmful)
|
||||||
|
effects.remove(effectIt->first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mCorprusSpells.erase(corprusIt);
|
||||||
|
}
|
||||||
|
|
||||||
if (iter!=mSpells.end())
|
if (iter!=mSpells.end())
|
||||||
mSpells.erase (iter);
|
mSpells.erase (iter);
|
||||||
|
|
||||||
if (corprusIt != mCorprusSpells.end())
|
|
||||||
mCorprusSpells.erase(corprusIt);
|
|
||||||
|
|
||||||
if (spellId==mSelectedSpell)
|
if (spellId==mSelectedSpell)
|
||||||
mSelectedSpell.clear();
|
mSelectedSpell.clear();
|
||||||
}
|
}
|
||||||
|
@ -94,20 +108,17 @@ namespace MWMechanics
|
||||||
if (iter->second.find(i) != iter->second.end())
|
if (iter->second.find(i) != iter->second.end())
|
||||||
random = iter->second.at(i);
|
random = iter->second.at(i);
|
||||||
|
|
||||||
int magnMult = 1;
|
effects.add (*it, it->mMagnMin + (it->mMagnMax - it->mMagnMin) * random);
|
||||||
if (mCorprusSpells.find(spell->mId) != mCorprusSpells.end())
|
|
||||||
{
|
|
||||||
const ESM::MagicEffect* effect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(spell->mEffects.mList.front().mEffectID);
|
|
||||||
if ((it->mEffectID != ESM::MagicEffect::Corprus) && (effect->mData.mFlags & ESM::MagicEffect::UncappedDamage)) // APPLIED_ONCE
|
|
||||||
magnMult += mCorprusSpells.at(spell->mId).mWorsenings;
|
|
||||||
}
|
|
||||||
|
|
||||||
effects.add (*it, (it->mMagnMin + (it->mMagnMax - it->mMagnMin) * random) * magnMult);
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (std::map<std::string, MagicEffects>::const_iterator it = mPermanentSpellEffects.begin(); it != mPermanentSpellEffects.end(); ++it)
|
||||||
|
{
|
||||||
|
effects += it->second;
|
||||||
|
}
|
||||||
|
|
||||||
return effects;
|
return effects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,6 +252,25 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
mCorprusSpells[corpSpellId].mNextWorsening = MWBase::Environment::get().getWorld()->getTimeStamp() + CorprusStats::sWorseningPeriod;
|
mCorprusSpells[corpSpellId].mNextWorsening = MWBase::Environment::get().getWorld()->getTimeStamp() + CorprusStats::sWorseningPeriod;
|
||||||
mCorprusSpells[corpSpellId].mWorsenings++;
|
mCorprusSpells[corpSpellId].mWorsenings++;
|
||||||
|
|
||||||
|
// update worsened effects
|
||||||
|
mPermanentSpellEffects[corpSpellId] = MagicEffects();
|
||||||
|
const ESM::Spell * spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(corpSpellId);
|
||||||
|
int i=0;
|
||||||
|
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt = spell->mEffects.mList.begin(); effectIt != spell->mEffects.mList.end(); ++effectIt, ++i)
|
||||||
|
{
|
||||||
|
const ESM::MagicEffect * magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(effectIt->mEffectID);
|
||||||
|
if ((effectIt->mEffectID != ESM::MagicEffect::Corprus) && (magicEffect->mData.mFlags & ESM::MagicEffect::UncappedDamage)) // APPLIED_ONCE
|
||||||
|
{
|
||||||
|
float random = 1.f;
|
||||||
|
if (mSpells[corpSpellId].find(i) != mSpells[corpSpellId].end())
|
||||||
|
random = mSpells[corpSpellId].at(i);
|
||||||
|
|
||||||
|
float magnitude = effectIt->mMagnMin + (effectIt->mMagnMax - effectIt->mMagnMin) * random;
|
||||||
|
magnitude *= std::max(1, mCorprusSpells[corpSpellId].mWorsenings);
|
||||||
|
mPermanentSpellEffects[corpSpellId].add(MWMechanics::EffectKey(*effectIt), MWMechanics::EffectParam(magnitude));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Spells::hasCorprusEffect(const ESM::Spell *spell)
|
bool Spells::hasCorprusEffect(const ESM::Spell *spell)
|
||||||
|
@ -297,6 +327,20 @@ namespace MWMechanics
|
||||||
for (std::map<std::string, ESM::TimeStamp>::const_iterator it = state.mUsedPowers.begin(); it != state.mUsedPowers.end(); ++it)
|
for (std::map<std::string, ESM::TimeStamp>::const_iterator it = state.mUsedPowers.begin(); it != state.mUsedPowers.end(); ++it)
|
||||||
mUsedPowers[it->first] = MWWorld::TimeStamp(it->second);
|
mUsedPowers[it->first] = MWWorld::TimeStamp(it->second);
|
||||||
|
|
||||||
|
for (std::map<std::string, std::vector<ESM::SpellState::PermanentSpellEffectInfo> >::const_iterator it =
|
||||||
|
state.mPermanentSpellEffects.begin(); it != state.mPermanentSpellEffects.end(); ++it)
|
||||||
|
{
|
||||||
|
const ESM::Spell * spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(it->first);
|
||||||
|
if (!spell)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
mPermanentSpellEffects[it->first] = MagicEffects();
|
||||||
|
for (std::vector<ESM::SpellState::PermanentSpellEffectInfo>::const_iterator effectIt = it->second.begin(); effectIt != it->second.end(); ++effectIt)
|
||||||
|
{
|
||||||
|
mPermanentSpellEffects[it->first].add(EffectKey(effectIt->mId, effectIt->mArg), effectIt->mMagnitude);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mCorprusSpells.clear();
|
mCorprusSpells.clear();
|
||||||
for (std::map<std::string, ESM::SpellState::CorprusStats>::const_iterator it = state.mCorprusSpells.begin(); it != state.mCorprusSpells.end(); ++it)
|
for (std::map<std::string, ESM::SpellState::CorprusStats>::const_iterator it = state.mCorprusSpells.begin(); it != state.mCorprusSpells.end(); ++it)
|
||||||
{
|
{
|
||||||
|
@ -316,6 +360,21 @@ namespace MWMechanics
|
||||||
for (std::map<std::string, MWWorld::TimeStamp>::const_iterator it = mUsedPowers.begin(); it != mUsedPowers.end(); ++it)
|
for (std::map<std::string, MWWorld::TimeStamp>::const_iterator it = mUsedPowers.begin(); it != mUsedPowers.end(); ++it)
|
||||||
state.mUsedPowers[it->first] = it->second.toEsm();
|
state.mUsedPowers[it->first] = it->second.toEsm();
|
||||||
|
|
||||||
|
for (std::map<std::string, MagicEffects>::const_iterator it = mPermanentSpellEffects.begin(); it != mPermanentSpellEffects.end(); ++it)
|
||||||
|
{
|
||||||
|
std::vector<ESM::SpellState::PermanentSpellEffectInfo> effectList;
|
||||||
|
for (MagicEffects::Collection::const_iterator effectIt = it->second.begin(); effectIt != it->second.end(); ++effectIt)
|
||||||
|
{
|
||||||
|
ESM::SpellState::PermanentSpellEffectInfo info;
|
||||||
|
info.mId = effectIt->first.mId;
|
||||||
|
info.mArg = effectIt->first.mArg;
|
||||||
|
info.mMagnitude = effectIt->second.getModifier();
|
||||||
|
|
||||||
|
effectList.push_back(info);
|
||||||
|
}
|
||||||
|
state.mPermanentSpellEffects[it->first] = effectList;
|
||||||
|
}
|
||||||
|
|
||||||
for (std::map<std::string, CorprusStats>::const_iterator it = mCorprusSpells.begin(); it != mCorprusSpells.end(); ++it)
|
for (std::map<std::string, CorprusStats>::const_iterator it = mCorprusSpells.begin(); it != mCorprusSpells.end(); ++it)
|
||||||
{
|
{
|
||||||
state.mCorprusSpells[it->first].mWorsenings = mCorprusSpells.at(it->first).mWorsenings;
|
state.mCorprusSpells[it->first].mWorsenings = mCorprusSpells.at(it->first).mWorsenings;
|
||||||
|
|
|
@ -46,6 +46,9 @@ namespace MWMechanics
|
||||||
|
|
||||||
TContainer mSpells;
|
TContainer mSpells;
|
||||||
|
|
||||||
|
// spell-tied effects that will be applied even after removing the spell (currently used to keep positive effects when corprus is removed)
|
||||||
|
std::map<std::string, MagicEffects> mPermanentSpellEffects;
|
||||||
|
|
||||||
// Note: this is the spell that's about to be cast, *not* the spell selected in the GUI (which may be different)
|
// Note: this is the spell that's about to be cast, *not* the spell selected in the GUI (which may be different)
|
||||||
std::string mSelectedSpell;
|
std::string mSelectedSpell;
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,23 @@ namespace ESM
|
||||||
mSpells[id] = random;
|
mSpells[id] = random;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (esm.isNextSub("PERM"))
|
||||||
|
{
|
||||||
|
std::string spellId = esm.getHString();
|
||||||
|
|
||||||
|
std::vector<PermanentSpellEffectInfo> permEffectList;
|
||||||
|
while (esm.isNextSub("EFID"))
|
||||||
|
{
|
||||||
|
PermanentSpellEffectInfo info;
|
||||||
|
esm.getHT(info.mId);
|
||||||
|
esm.getHNT(info.mArg, "ARG_");
|
||||||
|
esm.getHNT(info.mMagnitude, "MAGN");
|
||||||
|
|
||||||
|
permEffectList.push_back(info);
|
||||||
|
}
|
||||||
|
mPermanentSpellEffects[spellId] = permEffectList;
|
||||||
|
}
|
||||||
|
|
||||||
while (esm.isNextSub("CORP"))
|
while (esm.isNextSub("CORP"))
|
||||||
{
|
{
|
||||||
std::string id = esm.getHString();
|
std::string id = esm.getHString();
|
||||||
|
@ -64,6 +81,19 @@ namespace ESM
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (std::map<std::string, std::vector<PermanentSpellEffectInfo> >::const_iterator it = mPermanentSpellEffects.begin(); it != mPermanentSpellEffects.end(); ++it)
|
||||||
|
{
|
||||||
|
esm.writeHNString("PERM", it->first);
|
||||||
|
|
||||||
|
const std::vector<PermanentSpellEffectInfo> & effects = it->second;
|
||||||
|
for (std::vector<PermanentSpellEffectInfo>::const_iterator effectIt = effects.begin(); effectIt != effects.end(); ++effectIt)
|
||||||
|
{
|
||||||
|
esm.writeHNT("EFID", effectIt->mId);
|
||||||
|
esm.writeHNT("ARG_", effectIt->mArg);
|
||||||
|
esm.writeHNT("MAGN", effectIt->mMagnitude);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (std::map<std::string, CorprusStats>::const_iterator it = mCorprusSpells.begin(); it != mCorprusSpells.end(); ++it)
|
for (std::map<std::string, CorprusStats>::const_iterator it = mCorprusSpells.begin(); it != mCorprusSpells.end(); ++it)
|
||||||
{
|
{
|
||||||
esm.writeHNString("CORP", it->first);
|
esm.writeHNString("CORP", it->first);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define OPENMW_ESM_SPELLSTATE_H
|
#define OPENMW_ESM_SPELLSTATE_H
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "defs.hpp"
|
#include "defs.hpp"
|
||||||
|
@ -19,9 +20,18 @@ namespace ESM
|
||||||
TimeStamp mNextWorsening;
|
TimeStamp mNextWorsening;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct PermanentSpellEffectInfo
|
||||||
|
{
|
||||||
|
int mId;
|
||||||
|
int mArg;
|
||||||
|
float mMagnitude;
|
||||||
|
};
|
||||||
|
|
||||||
typedef std::map<std::string, std::map<const int, float> > TContainer;
|
typedef std::map<std::string, std::map<const int, float> > TContainer;
|
||||||
TContainer mSpells;
|
TContainer mSpells;
|
||||||
|
|
||||||
|
std::map<std::string, std::vector<PermanentSpellEffectInfo> > mPermanentSpellEffects;
|
||||||
|
|
||||||
std::map<std::string, CorprusStats> mCorprusSpells;
|
std::map<std::string, CorprusStats> mCorprusSpells;
|
||||||
|
|
||||||
std::map<std::string, TimeStamp> mUsedPowers;
|
std::map<std::string, TimeStamp> mUsedPowers;
|
||||||
|
|
Loading…
Reference in a new issue