Core/AI: Fix crashes caused by charmed Creatures having null AI for 1 map update tick (#27434)
Implement using ScheduledChangeAI instead of nullptr to signal a required AI change # Conflicts: # src/server/game/Entities/Unit/Unit.cpp # src/server/game/Entities/Unit/Unit.h
This commit is contained in:
1 parent
4f9c640161
commit
adde43e965
5 files changed
+86
-4
No files matched your search
@@ -65,6 +65,7 @@
|
||||
#include "PlayerAI.h"
|
||||
#include "QuestDef.h"
|
||||
#include "ReputationMgr.h"
|
||||
#include "ScheduledChangeAI.h"
|
||||
#include "Spell.h"
|
||||
#include "SpellAuraEffects.h"
|
||||
#include "SpellAuras.h"
|
||||
@@ -543,7 +544,7 @@ void Unit::Update(uint32 p_time)
|
||||
_healthRegenerationTimer += UNIT_HEALTH_REGENERATION_INTERVAL;
|
||||
}
|
||||
|
||||
if (!GetAI() && (GetTypeId() != TYPEID_PLAYER || IsCharmed()))
|
||||
if (HasScheduledAIChange() && (GetTypeId() != TYPEID_PLAYER || (IsCharmed() && GetCharmerGUID().IsCreature())))
|
||||
UpdateCharmAI();
|
||||
RefreshAI();
|
||||
}
|
||||
@@ -10354,11 +10355,11 @@ void Unit::ScheduleAIChange()
|
||||
bool const charmed = IsCharmed();
|
||||
|
||||
if (charmed)
|
||||
PushAI(nullptr);
|
||||
PushAI(GetScheduledChangeAI());
|
||||
else
|
||||
{
|
||||
RestoreDisabledAI();
|
||||
PushAI(nullptr); //This could actually be PopAI() to get the previous AI but it's required atm to trigger UpdateCharmAI()
|
||||
PushAI(GetScheduledChangeAI()); //This could actually be PopAI() to get the previous AI but it's required atm to trigger UpdateCharmAI()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10366,10 +10367,26 @@ void Unit::RestoreDisabledAI()
|
||||
{
|
||||
// Keep popping the stack until we either reach the bottom or find a valid AI
|
||||
while (PopAI())
|
||||
if (GetTopAI())
|
||||
if (GetTopAI() && dynamic_cast<ScheduledChangeAI*>(GetTopAI()) == nullptr)
|
||||
return;
|
||||
}
|
||||
|
||||
UnitAI* Unit::GetScheduledChangeAI()
|
||||
{
|
||||
if (Creature* creature = ToCreature())
|
||||
return new ScheduledChangeAI(creature);
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Unit::HasScheduledAIChange() const
|
||||
{
|
||||
if (UnitAI* ai = GetAI())
|
||||
return dynamic_cast<ScheduledChangeAI*>(ai) != nullptr;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
void Unit::AddToWorld()
|
||||
{
|
||||
WorldObject::AddToWorld();
|
||||
|
||||
Reference in new issue
Block a user