Core/Creatures: Moved autoattack handling from scripts to game

Port From (https://github.com/TrinityCore/TrinityCore/commit/605e5f94c0d71cad8e83fa5a07eaec4e6bed9cc3)
This commit is contained in:
hondacrx
2024-02-05 18:18:30 -05:00
parent aa696fb176
commit 437fe2d8fd
94 changed files with 192 additions and 358 deletions
+4 -10
View File
@@ -71,8 +71,6 @@ namespace Game.AI
if (info != null)
_events.ScheduleEvent(spellId, info.cooldown, info.cooldown * 2);
}
else
DoMeleeAttackIfReady();
}
public override void SpellInterrupted(uint spellId, uint unTimeMs)
@@ -87,10 +85,7 @@ namespace Game.AI
public override void UpdateAI(uint diff)
{
if (!UpdateVictim())
return;
DoMeleeAttackIfReady();
UpdateVictim();
}
}
@@ -193,6 +188,7 @@ namespace Game.AI
_minRange = spellInfo != null ? spellInfo.GetMinRange(false) : 0;
creature.m_CombatDistance = spellInfo != null ? spellInfo.GetMaxRange(false) : 0;
creature.m_SightDistance = creature.m_CombatDistance;
creature.SetCanMelee(false);
}
public override bool CanAIAttack(Unit victim)
@@ -234,6 +230,7 @@ namespace Game.AI
LoadConditions();
_doDismiss = false;
_dismissTimer = VEHICLE_DISMISS_TIME;
me.SetCanMelee(false);
}
public override void UpdateAI(uint diff)
@@ -315,10 +312,7 @@ namespace Game.AI
public override void UpdateAI(uint diff)
{
if (!UpdateVictim())
return;
DoMeleeAttackIfReady();
UpdateVictim();
}
}
}
+1 -4
View File
@@ -12,10 +12,7 @@ namespace Game.AI
public override void UpdateAI(uint diff)
{
if (!UpdateVictim())
return;
DoMeleeAttackIfReady();
UpdateVictim();
}
public override bool CanSeeAlways(WorldObject obj)
+2 -3
View File
@@ -11,7 +11,8 @@ namespace Game.AI
{
public PassiveAI(Creature creature) : base(creature)
{
creature.SetReactState(ReactStates.Passive);
me.SetReactState(ReactStates.Passive);
me.SetCanMelee(false);
}
public override void UpdateAI(uint diff)
@@ -43,8 +44,6 @@ namespace Game.AI
{
if (!me.IsValidAttackTarget(me.GetVictim()))
me.AttackStop();
else
DoMeleeAttackIfReady();
}
}
-9
View File
@@ -50,15 +50,6 @@ namespace Game.AI
StopAttack();
return;
}
// Check before attacking to prevent pets from leaving stay position
if (me.GetCharmInfo().HasCommandState(CommandStates.Stay))
{
if (me.GetCharmInfo().IsCommandAttack() || (me.GetCharmInfo().IsAtStay() && me.IsWithinMeleeRange(me.GetVictim())))
DoMeleeAttackIfReady();
}
else
DoMeleeAttackIfReady();
}
else
{
-35
View File
@@ -52,41 +52,6 @@ namespace Game.AI
targets.Sort(new ObjectDistanceOrderPred(me, ascending));
}
public void DoMeleeAttackIfReady()
{
if (me.IsCreature() && !me.ToCreature().CanMelee())
return;
if (me.HasUnitState(UnitState.Casting))
{
Spell channeledSpell = me.GetCurrentSpell(CurrentSpellTypes.Channeled);
if (channeledSpell == null || !channeledSpell.GetSpellInfo().HasAttribute(SpellAttr5.AllowActionsDuringChannel))
return;
}
Unit victim = me.GetVictim();
if (!me.IsWithinMeleeRange(victim))
return;
// Check that the victim is in front of the unit
if (!me.HasInArc(2 * MathF.PI / 3, victim))
return;
//Make sure our attack is ready and we aren't currently casting before checking distance
if (me.IsAttackReady())
{
me.AttackerStateUpdate(victim);
me.ResetAttackTimer();
}
if (me.HaveOffhandWeapon() && me.IsAttackReady(WeaponAttackType.OffAttack))
{
me.AttackerStateUpdate(victim, WeaponAttackType.OffAttack);
me.ResetAttackTimer(WeaponAttackType.OffAttack);
}
}
public bool DoSpellAttackIfReady(uint spellId)
{
if (me.HasUnitState(UnitState.Casting) || !me.IsAttackReady())
-2
View File
@@ -573,8 +573,6 @@ namespace Game.AI
{
if (IsRangedAttacker())
DoRangedAttackIfReady();
else
DoMeleeAttackIfReady();
}
public void CancelAllShapeshifts()
+1 -8
View File
@@ -45,10 +45,7 @@ namespace Game.AI
public override void UpdateAI(uint diff)
{
//Check if we have a current target
if (!UpdateVictim())
return;
DoMeleeAttackIfReady();
UpdateVictim();
}
//Start movement toward victim
@@ -655,8 +652,6 @@ namespace Game.AI
if (me.HasUnitState(UnitState.Casting))
return;
});
DoMeleeAttackIfReady();
}
public void _DespawnAtEvade()
@@ -766,8 +761,6 @@ namespace Game.AI
if (me.HasUnitState(UnitState.Casting))
return;
});
DoMeleeAttackIfReady();
}
// Hook used to execute events scheduled into EventMap without the need
@@ -261,10 +261,7 @@ namespace Game.AI
public virtual void UpdateEscortAI(uint diff)
{
if (!UpdateVictim())
return;
DoMeleeAttackIfReady();
UpdateVictim();
}
public override void MovementInform(MovementGeneratorType moveType, uint Id)
@@ -158,10 +158,7 @@ namespace Game.AI
void UpdateFollowerAI(uint diff)
{
if (!UpdateVictim())
return;
DoMeleeAttackIfReady();
UpdateVictim();
}
public void StartFollow(Player player, uint factionForFollower = 0, Quest quest = null)
+1 -9
View File
@@ -310,21 +310,13 @@ namespace Game.AI
CheckConditions(diff);
bool hasVictim = UpdateVictim();
UpdateVictim();
GetScript().OnUpdate(diff);
UpdatePath(diff);
UpdateFollow(diff);
UpdateDespawn(diff);
if (!IsAIControlled())
return;
if (!hasVictim)
return;
DoMeleeAttackIfReady();
}
bool IsEscortInvokerInRange()