diff options
author | Shauren <shauren.trinity@gmail.com> | 2018-02-05 20:52:19 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2018-02-05 20:52:19 +0100 |
commit | 2fd9dc2edb0355d15f5afd21cc6aa61d172d19cc (patch) | |
tree | d0c387387bc862ff1fd379a4056560f5626ed608 /src | |
parent | ed931cfa1963565e989cd99565fd360b1ab6ce55 (diff) |
Core/Scripts: Fixed ENSURE_AI assertion failures when used in Reset()/InitializeAI() hooks with hotswap
Updates #20727
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 13 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 2 | ||||
-rw-r--r-- | src/server/game/Scripting/ScriptMgr.cpp | 3 |
3 files changed, 16 insertions, 2 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index c7b25d610a2..4036a8743e0 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -981,7 +981,7 @@ bool Creature::AIM_Destroy() return true; } -bool Creature::AIM_Initialize(CreatureAI* ai) +bool Creature::AIM_Create(CreatureAI* ai /*= nullptr*/) { // make sure nothing can change the AI during AI update if (m_AI_locked) @@ -995,12 +995,23 @@ bool Creature::AIM_Initialize(CreatureAI* ai) Motion_Initialize(); i_AI = ai ? ai : FactorySelector::SelectAI(this); +} +void Creature::AI_InitializeAndEnable() +{ IsAIEnabled = true; i_AI->InitializeAI(); // Initialize vehicle if (GetVehicleKit()) GetVehicleKit()->Reset(); +} + +bool Creature::AIM_Initialize(CreatureAI* ai) +{ + if (!AIM_Create(ai)) + return false; + + AI_InitializeAndEnable(); return true; } diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 84d00777e9b..0aa74aabf58 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -130,6 +130,8 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma bool IsEvadingAttacks() const { return IsInEvadeMode() || CanNotReachTarget(); } bool AIM_Destroy(); + bool AIM_Create(CreatureAI* ai = nullptr); + void AI_InitializeAndEnable(); bool AIM_Initialize(CreatureAI* ai = nullptr); void Motion_Initialize(); diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 2b8acfa67d1..cbee458c9a0 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -421,7 +421,7 @@ class CreatureGameObjectScriptRegistrySwapHooks if (creature->IsAlive()) creature->ClearUnitState(UNIT_STATE_EVADE); - bool const created = creature->AIM_Initialize(); + bool const created = creature->AIM_Create(); ASSERT(created, "Creating the AI should never fail here!"); (void)created; @@ -432,6 +432,7 @@ class CreatureGameObjectScriptRegistrySwapHooks if (!creature->IsAlive()) return; + creature->AI_InitializeAndEnable(); creature->AI()->EnterEvadeMode(); // Cast a dummy visual spell asynchronously here to signal |