mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
Purge summon effects on dispose
This commit is contained in:
parent
004660be3d
commit
89e0bfd1a4
3 changed files with 32 additions and 7 deletions
|
@ -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);
|
||||
|
|
|
@ -155,13 +155,7 @@ namespace MWMechanics
|
|||
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<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);
|
||||
|
||||
void purgeSummonEffect(const MWWorld::Ptr& summoner, const std::pair<const ESM::SummonKey, int>& summon);
|
||||
|
||||
struct UpdateSummonedCreatures : public EffectSourceVisitor
|
||||
{
|
||||
UpdateSummonedCreatures(const MWWorld::Ptr& actor);
|
||||
|
|
Loading…
Reference in a new issue