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; }
+12 -5
View File
@@ -655,8 +655,6 @@ namespace Game.AI
return null;
}
public override void OnCharmed(bool apply) { }
// helper functions to determine player info
public bool IsHealer(Player who = null)
{
@@ -710,7 +708,14 @@ namespace Game.AI
{
Unit charmer = me.GetCharmer();
if (charmer)
return charmer.IsAIEnabled ? charmer.GetAI().SelectTarget(SelectAggroTarget.Random, 0, new ValidTargetSelectPredicate(this)) : charmer.GetVictim();
{
UnitAI charmerAI = charmer.GetAI();
if (charmerAI != null)
return charmerAI.SelectTarget(SelectAggroTarget.Random, 0, new ValidTargetSelectPredicate(this));
return charmer.GetVictim();
}
return null;
}
@@ -1344,9 +1349,9 @@ namespace Game.AI
}
}
public override void OnCharmed(bool apply)
public override void OnCharmed(bool isNew)
{
if (apply)
if (me.IsCharmed())
{
me.CastStop();
me.AttackStop();
@@ -1362,6 +1367,8 @@ namespace Game.AI
me.GetMotionMaster().Clear();
me.StopMoving();
}
base.OnCharmed(isNew);
}
}
+2 -2
View File
@@ -673,7 +673,7 @@ namespace Game.AI
foreach (var id in this)
{
Creature summon = ObjectAccessor.GetCreature(_me, id);
if (summon && summon.IsAIEnabled && (entry == 0 || summon.GetEntry() == entry))
if (summon && summon.IsAIEnabled() && (entry == 0 || summon.GetEntry() == entry))
{
summon.GetAI().DoZoneInCombat(null);
}
@@ -760,7 +760,7 @@ namespace Game.AI
foreach (var guid in summons)
{
Creature summon = ObjectAccessor.GetCreature(_me, guid);
if (summon && summon.IsAIEnabled)
if (summon && summon.IsAIEnabled())
summon.GetAI().DoAction(action);
}
}
+6 -5
View File
@@ -714,17 +714,18 @@ namespace Game.AI
GetScript().ProcessEventsFor(apply ? SmartEvents.PassengerBoarded : SmartEvents.PassengerRemoved, passenger, (uint)seatId, 0, apply);
}
public override void OnCharmed(bool apply)
public override void OnCharmed(bool isNew)
{
if (apply) // do this before we change charmed state, as charmed state might prevent these things from processing
bool charmed = me.IsCharmed();
if (charmed) // do this before we change charmed state, as charmed state might prevent these things from processing
{
if (HasEscortState(SmartEscortState.Escorting | SmartEscortState.Paused | SmartEscortState.Returning))
EndPath(true);
}
_isCharmed = apply;
_isCharmed = charmed;
if (!apply && !me.IsInEvadeMode())
if (!charmed && !me.IsInEvadeMode())
{
if (_repeatWaypointPath)
StartPath(_run, GetScript().GetPathId(), true);
@@ -736,7 +737,7 @@ namespace Game.AI
AttackStart(charmer);
}
GetScript().ProcessEventsFor(SmartEvents.Charmed, null, 0, 0, apply);
GetScript().ProcessEventsFor(SmartEvents.Charmed, null, 0, 0, charmed);
}
public override void DoAction(int param)
+1 -1
View File
@@ -958,7 +958,7 @@ namespace Game.AI
}
case SmartActions.SetInCombatWithZone:
{
if (_me != null && _me.IsAIEnabled)
if (_me != null && _me.IsAIEnabled())
{
_me.GetAI().DoZoneInCombat();
Log.outDebug(LogFilter.ScriptsAi, $"SmartScript.ProcessAction: SMART_ACTION_SET_IN_COMBAT_WITH_ZONE: Creature: {_me.GetGUID()}");