1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 21:59:55 +00:00

Remove spell effects when a summoned creature expires (Bug #3439)

This commit is contained in:
scrawl 2016-06-12 00:41:13 +02:00
parent b7e45b046d
commit 910ad76e29
4 changed files with 23 additions and 8 deletions

View file

@ -688,7 +688,9 @@ namespace MWMechanics
creatureStats.getActiveSpells().visitEffectSources(updateSummonedCreatures); creatureStats.getActiveSpells().visitEffectSources(updateSummonedCreatures);
if (ptr.getClass().hasInventoryStore(ptr)) if (ptr.getClass().hasInventoryStore(ptr))
ptr.getClass().getInventoryStore(ptr).visitEffectSources(updateSummonedCreatures); ptr.getClass().getInventoryStore(ptr).visitEffectSources(updateSummonedCreatures);
updateSummonedCreatures.finish(); std::set<int> deleted = updateSummonedCreatures.process();
for (std::set<int>::const_iterator it = deleted.begin(); it != deleted.end(); ++it)
purgeSpellEffects(*it);
} }
void Actors::calculateNpcStatModifiers (const MWWorld::Ptr& ptr, float duration) void Actors::calculateNpcStatModifiers (const MWWorld::Ptr& ptr, float duration)
@ -1242,11 +1244,7 @@ namespace MWMechanics
++mDeathCount[Misc::StringUtils::lowerCase(iter->first.getCellRef().getRefId())]; ++mDeathCount[Misc::StringUtils::lowerCase(iter->first.getCellRef().getRefId())];
// Make sure spell effects are removed // Make sure spell effects are removed
for (PtrActorMap::iterator iter2(mActors.begin());iter2 != mActors.end();++iter2) purgeSpellEffects(stats.getActorId());
{
MWMechanics::ActiveSpells& spells = iter2->first.getClass().getCreatureStats(iter2->first).getActiveSpells();
spells.purge(stats.getActorId());
}
if( iter->first == getPlayer()) if( iter->first == getPlayer())
{ {
@ -1261,6 +1259,15 @@ namespace MWMechanics
} }
} }
void Actors::purgeSpellEffects(int casterActorId)
{
for (PtrActorMap::iterator iter(mActors.begin());iter != mActors.end();++iter)
{
MWMechanics::ActiveSpells& spells = iter->first.getClass().getCreatureStats(iter->first).getActiveSpells();
spells.purge(casterActorId);
}
}
void Actors::restoreDynamicStats(bool sleep) void Actors::restoreDynamicStats(bool sleep)
{ {
for(PtrActorMap::iterator iter(mActors.begin());iter != mActors.end();++iter) for(PtrActorMap::iterator iter(mActors.begin());iter != mActors.end();++iter)

View file

@ -43,6 +43,8 @@ namespace MWMechanics
void killDeadActors (); void killDeadActors ();
void purgeSpellEffects (int casterActorId);
public: public:
Actors(); Actors();

View file

@ -61,8 +61,10 @@ namespace MWMechanics
} }
} }
void UpdateSummonedCreatures::finish() std::set<int> UpdateSummonedCreatures::process()
{ {
std::set<int> deletedCreatures;
static std::map<int, std::string> summonMap; static std::map<int, std::string> summonMap;
if (summonMap.empty()) if (summonMap.empty())
{ {
@ -101,6 +103,7 @@ namespace MWMechanics
{ {
// Effect has ended // Effect has ended
cleanupSummonedCreature(creatureStats, it->second); cleanupSummonedCreature(creatureStats, it->second);
deletedCreatures.insert(it->second);
creatureMap.erase(it++); creatureMap.erase(it++);
continue; continue;
} }
@ -188,6 +191,8 @@ namespace MWMechanics
else else
++it; ++it;
} }
return deletedCreatures;
} }
} }

View file

@ -21,7 +21,8 @@ namespace MWMechanics
float magnitude, float remainingTime = -1, float totalTime = -1); float magnitude, float remainingTime = -1, float totalTime = -1);
/// To call after all effect sources have been visited /// To call after all effect sources have been visited
void finish(); /// Returns list of actorIds for creatures that have been deleted due to the magic effect having expired
std::set<int> process();
private: private:
MWWorld::Ptr mActor; MWWorld::Ptr mActor;