From 3722c7adc3095fedc25946955c2f97597d25a6c9 Mon Sep 17 00:00:00 2001 From: MiroslavR Date: Mon, 18 Aug 2014 15:33:12 +0200 Subject: [PATCH] Initial work on implementing corprus worsening effect --- apps/openmw/mwmechanics/actors.cpp | 19 +++++++++++++++ apps/openmw/mwmechanics/spells.cpp | 39 +++++++++++++++++++++++++++++- apps/openmw/mwmechanics/spells.hpp | 12 +++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index fbc840df82..6e11caee74 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -477,6 +477,25 @@ namespace MWMechanics creatureStats.setAttribute(i, stat); } + { + Spells & spells = creatureStats.getSpells(); + for (Spells::TIterator it = spells.begin(); it != spells.end(); ++it) + { + if (spells.mCorprusSpells.find(it->first) != spells.mCorprusSpells.end()) + { + const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find(it->first); + + if (MWBase::Environment::get().getWorld()->getTimeStamp() >= spells.mCorprusSpells[it->first].mNextWorsening) + { + spells.worsenCorprus(it->first); + + if (ptr.getRefData().getHandle() == "player") + MWBase::Environment::get().getWindowManager()->messageBox("#{sMagicCorprusWorsens}"); + } + } + } + } + // dynamic stats for(int i = 0;i < 3;++i) { diff --git a/apps/openmw/mwmechanics/spells.cpp b/apps/openmw/mwmechanics/spells.cpp index dee1a1b05d..da4fa65561 100644 --- a/apps/openmw/mwmechanics/spells.cpp +++ b/apps/openmw/mwmechanics/spells.cpp @@ -44,6 +44,25 @@ namespace MWMechanics } } + bool hasCorprusEffect = false; + for (std::vector::const_iterator effectIt = spell->mEffects.mList.begin(); effectIt != spell->mEffects.mList.end(); ++effectIt) + { + if (effectIt->mEffectID == ESM::MagicEffect::Corprus) + { + hasCorprusEffect = true; + break; + } + } + + if (hasCorprusEffect) + { + 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)); } } @@ -52,10 +71,14 @@ namespace MWMechanics { std::string lower = Misc::StringUtils::lowerCase(spellId); TContainer::iterator iter = mSpells.find (lower); + std::map::iterator corprusIt = mCorprusSpells.find(lower); if (iter!=mSpells.end()) mSpells.erase (iter); + if (corprusIt != mCorprusSpells.end()) + mCorprusSpells.erase(corprusIt); + if (spellId==mSelectedSpell) mSelectedSpell.clear(); } @@ -81,7 +104,15 @@ namespace MWMechanics if (iter->second.find(i) != iter->second.end()) random = iter->second.at(i); - effects.add (*it, it->mMagnMin + (it->mMagnMax - it->mMagnMin) * random); + int applyTimes = 1; + if (mCorprusSpells.find(spell->mId) != mCorprusSpells.end()) + { + const ESM::MagicEffect* effect = MWBase::Environment::get().getWorld()->getStore().get().find(spell->mEffects.mList.front().mEffectID); + if ((it->mEffectID != ESM::MagicEffect::Corprus) && (effect->mData.mFlags & ESM::MagicEffect::UncappedDamage)) // APPLIED_ONCE + applyTimes += mCorprusSpells.at(spell->mId).mWorsenings; + } + for (int j = 0; j < applyTimes; j++) + effects.add (*it, it->mMagnMin + (it->mMagnMax - it->mMagnMin) * random); ++i; } } @@ -216,6 +247,12 @@ namespace MWMechanics } } + void Spells::worsenCorprus(const std::string &corpSpellId) + { + mCorprusSpells[corpSpellId].mNextWorsening = MWBase::Environment::get().getWorld()->getTimeStamp() + CorprusStats::sWorseningPeriod; + mCorprusSpells[corpSpellId].mWorsenings++; + } + bool Spells::canUsePower(const std::string &power) const { std::map::const_iterator it = mUsedPowers.find(power); diff --git a/apps/openmw/mwmechanics/spells.hpp b/apps/openmw/mwmechanics/spells.hpp index 6997a9d7ab..039ad57fa7 100644 --- a/apps/openmw/mwmechanics/spells.hpp +++ b/apps/openmw/mwmechanics/spells.hpp @@ -44,6 +44,18 @@ namespace MWMechanics std::map mUsedPowers; + public: + struct CorprusStats + { + static const int sWorseningPeriod = 24; + + int mWorsenings; + MWWorld::TimeStamp mNextWorsening; + }; + + std::map mCorprusSpells; + void worsenCorprus(const std::string &corpSpellId); + public: bool canUsePower (const std::string& power) const;