diff --git a/Source/Game/AI/CoreAI/ScheduledChangeAI.cs b/Source/Game/AI/CoreAI/ScheduledChangeAI.cs new file mode 100644 index 000000000..c9e49741c --- /dev/null +++ b/Source/Game/AI/CoreAI/ScheduledChangeAI.cs @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2012-2020 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 . + */ + +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) { } + } +} diff --git a/Source/Game/Entities/Unit/Unit.cs b/Source/Game/Entities/Unit/Unit.cs index 54c824d0e..3ff8a9f54 100644 --- a/Source/Game/Entities/Unit/Unit.cs +++ b/Source/Game/Entities/Unit/Unit.cs @@ -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();