Purge summon effects on dispose

pull/593/head
Evil Eye 4 years ago
parent 004660be3d
commit 89e0bfd1a4

@ -12,7 +12,9 @@
#include "../mwworld/class.hpp" #include "../mwworld/class.hpp"
#include "../mwworld/inventorystore.hpp" #include "../mwworld/inventorystore.hpp"
#include "../mwmechanics/aipackage.hpp"
#include "../mwmechanics/creaturestats.hpp" #include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/summoning.hpp"
#include "../mwscript/interpretercontext.hpp" #include "../mwscript/interpretercontext.hpp"
@ -264,6 +266,23 @@ namespace MWGui
for (const auto& creature : creatureMap) for (const auto& creature : creatureMap)
MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(ptr, creature.second); MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(ptr, creature.second);
creatureMap.clear(); creatureMap.clear();
// Check if we are a summon and inform our master we've bit the dust
for(const auto& package : creatureStats.getAiSequence())
{
if(package->followTargetThroughDoors() && !package->getTarget().isEmpty())
{
const auto& summoner = package->getTarget();
auto& summons = summoner.getClass().getCreatureStats(summoner).getSummonedCreatureMap();
auto it = std::find_if(summons.begin(), summons.end(), [&] (const auto& entry) { return entry.second == creatureStats.getActorId(); });
if(it != summons.end())
{
MWMechanics::purgeSummonEffect(summoner, *it);
summons.erase(it);
break;
}
}
}
} }
MWBase::Environment::get().getWorld()->deleteObject(ptr); MWBase::Environment::get().getWorld()->deleteObject(ptr);

@ -155,13 +155,7 @@ namespace MWMechanics
if (!ptr.isEmpty() && ptr.getClass().getCreatureStats(ptr).isDead() && ptr.getClass().getCreatureStats(ptr).isDeathAnimationFinished()) if (!ptr.isEmpty() && ptr.getClass().getCreatureStats(ptr).isDead() && ptr.getClass().getCreatureStats(ptr).isDeathAnimationFinished())
{ {
// Purge the magic effect so a new creature can be summoned if desired // Purge the magic effect so a new creature can be summoned if desired
const ESM::SummonKey& key = it->first; purgeSummonEffect(mActor, *it);
creatureStats.getActiveSpells().purgeEffect(key.mEffectId, key.mSourceId, key.mEffectIndex);
creatureStats.getSpells().purgeEffect(key.mEffectId, key.mSourceId);
if (mActor.getClass().hasInventoryStore(mActor))
mActor.getClass().getInventoryStore(mActor).purgeEffect(key.mEffectId, key.mSourceId, false, key.mEffectIndex);
MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(mActor, it->second);
creatureMap.erase(it++); creatureMap.erase(it++);
} }
else else
@ -169,4 +163,14 @@ namespace MWMechanics
} }
} }
void purgeSummonEffect(const MWWorld::Ptr& summoner, const std::pair<const ESM::SummonKey, int>& summon)
{
auto& creatureStats = summoner.getClass().getCreatureStats(summoner);
creatureStats.getActiveSpells().purgeEffect(summon.first.mEffectId, summon.first.mSourceId, summon.first.mEffectIndex);
creatureStats.getSpells().purgeEffect(summon.first.mEffectId, summon.first.mSourceId);
if (summoner.getClass().hasInventoryStore(summoner))
summoner.getClass().getInventoryStore(summoner).purgeEffect(summon.first.mEffectId, summon.first.mSourceId, false, summon.first.mEffectIndex);
MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(summoner, summon.second);
}
} }

@ -17,6 +17,8 @@ namespace MWMechanics
std::string getSummonedCreature(int effectId); std::string getSummonedCreature(int effectId);
void purgeSummonEffect(const MWWorld::Ptr& summoner, const std::pair<const ESM::SummonKey, int>& summon);
struct UpdateSummonedCreatures : public EffectSourceVisitor struct UpdateSummonedCreatures : public EffectSourceVisitor
{ {
UpdateSummonedCreatures(const MWWorld::Ptr& actor); UpdateSummonedCreatures(const MWWorld::Ptr& actor);

Loading…
Cancel
Save