Core/AI: Fix crashes caused by charmed Creatures having null AI for 1 map update tick
Port From (https://github.com/TrinityCore/TrinityCore/commit/8c25abca72772e2962bac7f460a567a943388a05)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2020 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.Entities;
|
||||
|
||||
namespace Game.AI
|
||||
{
|
||||
class ScheduledChangeAI : CreatureAI
|
||||
{
|
||||
public ScheduledChangeAI(Creature creature) : base(creature) { }
|
||||
|
||||
public override void MoveInLineOfSight(Unit unit) { }
|
||||
|
||||
public override void AttackStart(Unit unit) { }
|
||||
|
||||
public override void JustStartedThreateningMe(Unit unit) { }
|
||||
|
||||
public override void JustEnteredCombat(Unit unit) { }
|
||||
|
||||
public override void UpdateAI(uint diff) { }
|
||||
|
||||
public override void JustAppeared() { }
|
||||
|
||||
public override void EnterEvadeMode(EvadeReason why) { }
|
||||
|
||||
public override void OnCharmed(bool isNew) { }
|
||||
}
|
||||
}
|
||||
@@ -196,7 +196,7 @@ namespace Game.Entities
|
||||
// All position info based actions have been executed, reset info
|
||||
_positionUpdateInfo.Reset();
|
||||
|
||||
if (GetAI() == null && (!IsPlayer() || (IsCharmed() && GetCharmerGUID().IsCreature())))
|
||||
if (HasScheduledAIChange() && (!IsPlayer() || (IsCharmed() && GetCharmerGUID().IsCreature())))
|
||||
UpdateCharmAI();
|
||||
|
||||
RefreshAI();
|
||||
@@ -1223,11 +1223,11 @@ namespace Game.Entities
|
||||
bool charmed = IsCharmed();
|
||||
|
||||
if (charmed)
|
||||
PushAI(null);
|
||||
PushAI(GetScheduledChangeAI());
|
||||
else
|
||||
{
|
||||
RestoreDisabledAI();
|
||||
PushAI(null); //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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1235,10 +1235,28 @@ namespace Game.Entities
|
||||
{
|
||||
// Keep popping the stack until we either reach the bottom or find a valid AI
|
||||
while (PopAI())
|
||||
if (GetTopAI() != null)
|
||||
if (GetTopAI() != null && GetTopAI() is not ScheduledChangeAI)
|
||||
return;
|
||||
}
|
||||
|
||||
UnitAI GetScheduledChangeAI()
|
||||
{
|
||||
Creature creature = ToCreature();
|
||||
if (creature != null)
|
||||
return new ScheduledChangeAI(creature);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
bool HasScheduledAIChange()
|
||||
{
|
||||
UnitAI ai = GetAI();
|
||||
if (ai != null)
|
||||
return ai is ScheduledChangeAI;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsPossessedByPlayer()
|
||||
{
|
||||
return HasUnitState(UnitState.Possessed) && GetCharmerGUID().IsPlayer();
|
||||
|
||||
Reference in New Issue
Block a user