fix: multi effect spell with different ranges (Fixes #2285)

Applies all effects for a spell with multiple effects, where not all effects have the same range.
celladd
dteviot 10 years ago
parent 41e15e0c2d
commit cdee6f41fc

@ -152,12 +152,7 @@ namespace MWMechanics
void ActiveSpells::addSpell(const std::string &id, bool stack, std::vector<ActiveEffect> effects,
const std::string &displayName, int casterActorId)
{
bool exists = false;
for (TContainer::const_iterator it = begin(); it != end(); ++it)
{
if (id == it->first)
exists = true;
}
TContainer::iterator it(mSpells.find(id));
ActiveSpellParams params;
params.mTimeStamp = MWBase::Environment::get().getWorld()->getTimeStamp();
@ -165,14 +160,44 @@ namespace MWMechanics
params.mDisplayName = displayName;
params.mCasterActorId = casterActorId;
if (!exists || stack)
mSpells.insert (std::make_pair(id, params));
if (it == end() || stack)
{
mSpells.insert(std::make_pair(id, params));
}
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;
}
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)
{
mSpells.erase(Misc::StringUtils::lowerCase(id));

@ -55,6 +55,9 @@ namespace MWMechanics
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;
///< Returns time (in in-game hours) until the spell pointed to by \a iterator
/// expires.

Loading…
Cancel
Save