Core/Units: Fixed crash happening when charm was removed by its own charmed AI during update

Port From (https://github.com/TrinityCore/TrinityCore/commit/f3c1b27c266e2857214a087fdd9339e06dbedf5e)
This commit is contained in:
hondacrx
2021-11-16 23:26:08 -05:00
parent 705a2fe3a1
commit e8b8d2c1bb
2 changed files with 7 additions and 3 deletions
+1
View File
@@ -33,6 +33,7 @@ namespace Game.Entities
//AI
protected UnitAI i_AI;
protected UnitAI i_disabledAI;
UnitAI i_lockedAILifetimeExtension; // yes, this lifetime extension is terrible
bool m_aiLocked;
//Movement
+6 -3
View File
@@ -1188,12 +1188,15 @@ namespace Game.Entities
public void ScheduleAIChange()
{
Cypher.Assert(!m_aiLocked, "Attempt to schedule AI change during AI update tick");
bool charmed = IsCharmed();
// if charm is applied, we can't have disabled AI already, and vice versa
if (charmed)
Cypher.Assert(i_disabledAI == null, "Attempt to schedule charm AI change on unit that already has disabled AI");
else if (m_aiLocked)
{
Cypher.Assert(!i_lockedAILifetimeExtension, "Attempt to schedule multiple charm AI changes during one update");
i_lockedAILifetimeExtension = i_AI; // AI needs to live just a bit longer to finish its UpdateAI
}
else if (!IsPlayer())
Cypher.Assert(i_disabledAI != null, "Attempt to schedule charm ID change on unit that doesn't have disabled AI");
@@ -1205,9 +1208,9 @@ namespace Game.Entities
void RestoreDisabledAI()
{
Cypher.Assert(!m_aiLocked, "Attempt to restore AI during UpdateAI tick");
Cypher.Assert(IsPlayer() || i_disabledAI != null, "Attempt to restore disabled AI on creature without disabled AI");
i_AI = i_disabledAI;
i_lockedAILifetimeExtension = null;
}
public bool IsPossessing()