Core/AI: Clean up charm AI handling.

Port From (https://github.com/TrinityCore/TrinityCore/commit/e4e8c1c59c8b37216814526b4d2551f23934f465)
This commit is contained in:
hondacrx
2021-10-31 13:55:26 -04:00
parent 7050fda482
commit 26940fa650
33 changed files with 472 additions and 443 deletions
+4 -3
View File
@@ -322,11 +322,12 @@ namespace Game.AI
public override void AttackStart(Unit victim) { }
public override void OnCharmed(bool apply)
public override void OnCharmed(bool isNew)
{
if (!me.GetVehicleKit().IsVehicleInUse() && !apply && _hasConditions)//was used and has conditions
bool charmed = me.IsCharmed();
if (!me.GetVehicleKit().IsVehicleInUse() && !charmed && _hasConditions)//was used and has conditions
_doDismiss = true;//needs reset
else if (apply)
else if (charmed)
_doDismiss = false;//in use again
_dismissTimer = VEHICLE_DISMISS_TIME;//reset timer
+11 -4
View File
@@ -44,13 +44,20 @@ namespace Game.AI
_moveInLineOfSightLocked = false;
}
public override void OnCharmed(bool apply)
public override void OnCharmed(bool isNew)
{
if (apply)
if (isNew && !me.IsCharmed() && !me.LastCharmerGUID.IsEmpty())
{
me.NeedChangeAI = true;
me.IsAIEnabled = false;
if (!me.HasReactState(ReactStates.Passive))
{
Unit lastCharmer = Global.ObjAccessor.GetUnit(me, me.LastCharmerGUID);
if (lastCharmer != null)
me.EngageWithTarget(lastCharmer);
}
me.LastCharmerGUID.Clear();
}
base.OnCharmed(isNew);
}
public void Talk(uint id, WorldObject whisperTarget = null)
+1 -7
View File
@@ -76,12 +76,6 @@ namespace Game.AI
me.RemoveDynamicFlag(UnitDynFlags.Lootable);
}
public override void OnCharmed(bool apply)
{
me.NeedChangeAI = true;
me.IsAIEnabled = false;
}
public override void MoveInLineOfSight(Unit who) { }
public override void EnterEvadeMode(EvadeReason why) { }
@@ -98,7 +92,7 @@ namespace Game.AI
public override void AttackStart(Unit unit) { }
public override void UpdateAI(uint diff) { }
public override void EnterEvadeMode(EvadeReason why) { }
public override void OnCharmed(bool apply) { }
public override void OnCharmed(bool isNew) { }
}
public class CritterAI : PassiveAI
-6
View File
@@ -601,12 +601,6 @@ namespace Game.AI
}
}
public override void OnCharmed(bool apply)
{
me.NeedChangeAI = true;
me.IsAIEnabled = false;
}
void ClearCharmInfoFlags()
{
// Quick access to set all flags to FALSE
+12 -1
View File
@@ -463,7 +463,18 @@ namespace Game.AI
public virtual void Reset() { }
public virtual void OnCharmed(bool apply) { }
/// <summary>
// Called when unit's charm state changes with isNew = false
// Implementation should call me->ScheduleAIChange() if AI replacement is desired
// If this call is made, AI will be replaced on the next tick
// When replacement is made, OnCharmed is called with isNew = true
/// </summary>
/// <param name="apply"></param>
public virtual void OnCharmed(bool isNew)
{
if (!isNew)
me.ScheduleAIChange();
}
public virtual bool ShouldSparWith(Unit target) { return false; }