diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 16b38eaf9..4cdd8b137 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -12,7 +12,9 @@ #include "../mwworld/class.hpp" #include "../mwworld/inventorystore.hpp" +#include "../mwmechanics/aipackage.hpp" #include "../mwmechanics/creaturestats.hpp" +#include "../mwmechanics/summoning.hpp" #include "../mwscript/interpretercontext.hpp" @@ -264,6 +266,23 @@ namespace MWGui for (const auto& creature : creatureMap) MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(ptr, creature.second); 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); diff --git a/apps/openmw/mwmechanics/summoning.cpp b/apps/openmw/mwmechanics/summoning.cpp index 9f65f3d6c..d90545fc6 100644 --- a/apps/openmw/mwmechanics/summoning.cpp +++ b/apps/openmw/mwmechanics/summoning.cpp @@ -152,16 +152,10 @@ namespace MWMechanics continue; } MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->searchPtrViaActorId(it->second); - 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 - const ESM::SummonKey& key = it->first; - 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); + purgeSummonEffect(mActor, *it); creatureMap.erase(it++); } else @@ -169,4 +163,14 @@ namespace MWMechanics } } + void purgeSummonEffect(const MWWorld::Ptr& summoner, const std::pair& 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); + } } diff --git a/apps/openmw/mwmechanics/summoning.hpp b/apps/openmw/mwmechanics/summoning.hpp index 7e787499e..3c3e18a96 100644 --- a/apps/openmw/mwmechanics/summoning.hpp +++ b/apps/openmw/mwmechanics/summoning.hpp @@ -17,6 +17,8 @@ namespace MWMechanics std::string getSummonedCreature(int effectId); + void purgeSummonEffect(const MWWorld::Ptr& summoner, const std::pair& summon); + struct UpdateSummonedCreatures : public EffectSourceVisitor { UpdateSummonedCreatures(const MWWorld::Ptr& actor);