|
|
|
@ -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));
|
|
|
|
|