mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 15:15:31 +00:00
Merge remote-tracking branch 'miroslavr/corprus'
This commit is contained in:
commit
7c1b32ae62
5 changed files with 223 additions and 3 deletions
|
@ -477,6 +477,23 @@ namespace MWMechanics
|
||||||
creatureStats.setAttribute(i, stat);
|
creatureStats.setAttribute(i, stat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
Spells & spells = creatureStats.getSpells();
|
||||||
|
for (Spells::TIterator it = spells.begin(); it != spells.end(); ++it)
|
||||||
|
{
|
||||||
|
if (spells.getCorprusSpells().find(it->first) != spells.getCorprusSpells().end())
|
||||||
|
{
|
||||||
|
if (MWBase::Environment::get().getWorld()->getTimeStamp() >= spells.getCorprusSpells().at(it->first).mNextWorsening)
|
||||||
|
{
|
||||||
|
spells.worsenCorprus(it->first);
|
||||||
|
|
||||||
|
if (ptr.getRefData().getHandle() == "player")
|
||||||
|
MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicCorprusWorsens}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// dynamic stats
|
// dynamic stats
|
||||||
for(int i = 0;i < 3;++i)
|
for(int i = 0;i < 3;++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,6 +44,15 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasCorprusEffect(spell))
|
||||||
|
{
|
||||||
|
CorprusStats corprus;
|
||||||
|
corprus.mWorsenings = 0;
|
||||||
|
corprus.mNextWorsening = MWBase::Environment::get().getWorld()->getTimeStamp() + CorprusStats::sWorseningPeriod;
|
||||||
|
|
||||||
|
mCorprusSpells[spellId] = corprus;
|
||||||
|
}
|
||||||
|
|
||||||
mSpells.insert (std::make_pair (Misc::StringUtils::lowerCase(spellId), random));
|
mSpells.insert (std::make_pair (Misc::StringUtils::lowerCase(spellId), random));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +61,24 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
std::string lower = Misc::StringUtils::lowerCase(spellId);
|
std::string lower = Misc::StringUtils::lowerCase(spellId);
|
||||||
TContainer::iterator iter = mSpells.find (lower);
|
TContainer::iterator iter = mSpells.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);
|
||||||
|
@ -87,6 +114,11 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (std::map<std::string, MagicEffects>::const_iterator it = mPermanentSpellEffects.begin(); it != mPermanentSpellEffects.end(); ++it)
|
||||||
|
{
|
||||||
|
effects += it->second;
|
||||||
|
}
|
||||||
|
|
||||||
return effects;
|
return effects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +186,7 @@ namespace MWMechanics
|
||||||
const ESM::Spell *spell =
|
const ESM::Spell *spell =
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (iter->first);
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (iter->first);
|
||||||
|
|
||||||
if (spell->mData.mType == ESM::Spell::ST_Blight)
|
if (spell->mData.mType == ESM::Spell::ST_Blight && !hasCorprusEffect(spell))
|
||||||
mSpells.erase(iter++);
|
mSpells.erase(iter++);
|
||||||
else
|
else
|
||||||
++iter;
|
++iter;
|
||||||
|
@ -168,7 +200,7 @@ namespace MWMechanics
|
||||||
const ESM::Spell *spell =
|
const ESM::Spell *spell =
|
||||||
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (iter->first);
|
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (iter->first);
|
||||||
|
|
||||||
if (Misc::StringUtils::ciEqual(spell->mId, "corprus"))
|
if (hasCorprusEffect(spell))
|
||||||
mSpells.erase(iter++);
|
mSpells.erase(iter++);
|
||||||
else
|
else
|
||||||
++iter;
|
++iter;
|
||||||
|
@ -216,6 +248,48 @@ namespace MWMechanics
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Spells::worsenCorprus(const std::string &corpSpellId)
|
||||||
|
{
|
||||||
|
mCorprusSpells[corpSpellId].mNextWorsening = MWBase::Environment::get().getWorld()->getTimeStamp() + CorprusStats::sWorseningPeriod;
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
for (std::vector<ESM::ENAMstruct>::const_iterator effectIt = spell->mEffects.mList.begin(); effectIt != spell->mEffects.mList.end(); ++effectIt)
|
||||||
|
{
|
||||||
|
if (effectIt->mEffectID == ESM::MagicEffect::Corprus)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::map<std::string, Spells::CorprusStats> &Spells::getCorprusSpells() const
|
||||||
|
{
|
||||||
|
return mCorprusSpells;
|
||||||
|
}
|
||||||
|
|
||||||
bool Spells::canUsePower(const std::string &power) const
|
bool Spells::canUsePower(const std::string &power) const
|
||||||
{
|
{
|
||||||
std::map<std::string, MWWorld::TimeStamp>::const_iterator it = mUsedPowers.find(power);
|
std::map<std::string, MWWorld::TimeStamp>::const_iterator it = mUsedPowers.find(power);
|
||||||
|
@ -252,6 +326,30 @@ namespace MWMechanics
|
||||||
// No need to discard spells here (doesn't really matter if non existent ids are kept)
|
// No need to discard spells here (doesn't really matter if non existent ids are kept)
|
||||||
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();
|
||||||
|
for (std::map<std::string, ESM::SpellState::CorprusStats>::const_iterator it = state.mCorprusSpells.begin(); it != state.mCorprusSpells.end(); ++it)
|
||||||
|
{
|
||||||
|
if (mSpells.find(it->first) != mSpells.end()) // Discard unavailable corprus spells
|
||||||
|
{
|
||||||
|
mCorprusSpells[it->first].mWorsenings = state.mCorprusSpells.at(it->first).mWorsenings;
|
||||||
|
mCorprusSpells[it->first].mNextWorsening = MWWorld::TimeStamp(state.mCorprusSpells.at(it->first).mNextWorsening);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spells::writeState(ESM::SpellState &state) const
|
void Spells::writeState(ESM::SpellState &state) const
|
||||||
|
@ -261,5 +359,26 @@ 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)
|
||||||
|
{
|
||||||
|
state.mCorprusSpells[it->first].mWorsenings = mCorprusSpells.at(it->first).mWorsenings;
|
||||||
|
state.mCorprusSpells[it->first].mNextWorsening = mCorprusSpells.at(it->first).mNextWorsening.toEsm();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,21 +31,37 @@ namespace MWMechanics
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
typedef std::map<std::string, std::map<const int, float> > TContainer; // ID, <effect index, normalised random magnitude>
|
typedef std::map<std::string, std::map<const int, float> > TContainer; // ID, <effect index, normalised random magnitude>
|
||||||
typedef TContainer::const_iterator TIterator;
|
typedef TContainer::const_iterator TIterator;
|
||||||
|
|
||||||
|
struct CorprusStats
|
||||||
|
{
|
||||||
|
static const int sWorseningPeriod = 24;
|
||||||
|
|
||||||
|
int mWorsenings;
|
||||||
|
MWWorld::TimeStamp mNextWorsening;
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
std::map<std::string, MWWorld::TimeStamp> mUsedPowers;
|
std::map<std::string, MWWorld::TimeStamp> mUsedPowers;
|
||||||
|
|
||||||
|
std::map<std::string, CorprusStats> mCorprusSpells;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
void worsenCorprus(const std::string &corpSpellId);
|
||||||
|
static bool hasCorprusEffect(const ESM::Spell *spell);
|
||||||
|
const std::map<std::string, CorprusStats> & getCorprusSpells() const;
|
||||||
|
|
||||||
bool canUsePower (const std::string& power) const;
|
bool canUsePower (const std::string& power) const;
|
||||||
void usePower (const std::string& power);
|
void usePower (const std::string& power);
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,34 @@ 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"))
|
||||||
|
{
|
||||||
|
std::string id = esm.getHString();
|
||||||
|
|
||||||
|
CorprusStats stats;
|
||||||
|
esm.getHNT(stats.mWorsenings, "WORS");
|
||||||
|
esm.getHNT(stats.mNextWorsening, "TIME");
|
||||||
|
|
||||||
|
mCorprusSpells[id] = stats;
|
||||||
|
}
|
||||||
|
|
||||||
while (esm.isNextSub("USED"))
|
while (esm.isNextSub("USED"))
|
||||||
{
|
{
|
||||||
std::string id = esm.getHString();
|
std::string id = esm.getHString();
|
||||||
|
@ -53,6 +81,28 @@ 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)
|
||||||
|
{
|
||||||
|
esm.writeHNString("CORP", it->first);
|
||||||
|
|
||||||
|
const CorprusStats & stats = it->second;
|
||||||
|
esm.writeHNT("WORS", stats.mWorsenings);
|
||||||
|
esm.writeHNT("TIME", stats.mNextWorsening);
|
||||||
|
}
|
||||||
|
|
||||||
for (std::map<std::string, TimeStamp>::const_iterator it = mUsedPowers.begin(); it != mUsedPowers.end(); ++it)
|
for (std::map<std::string, TimeStamp>::const_iterator it = mUsedPowers.begin(); it != mUsedPowers.end(); ++it)
|
||||||
{
|
{
|
||||||
esm.writeHNString("USED", it->first);
|
esm.writeHNString("USED", 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"
|
||||||
|
@ -13,9 +14,26 @@ namespace ESM
|
||||||
|
|
||||||
struct SpellState
|
struct SpellState
|
||||||
{
|
{
|
||||||
|
struct CorprusStats
|
||||||
|
{
|
||||||
|
int mWorsenings;
|
||||||
|
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, TimeStamp> mUsedPowers;
|
std::map<std::string, TimeStamp> mUsedPowers;
|
||||||
|
|
||||||
std::string mSelectedSpell;
|
std::string mSelectedSpell;
|
||||||
|
|
Loading…
Reference in a new issue