Core/Creatures: Implemented CREATURE_STATIC_FLAG_4_NO_MELEE_APPROACH and fixed CREATURE_STATIC_FLAG_NO_MELEE_FLEE implementation (should cause fleeing from melee range)

Port From (https://github.com/TrinityCore/TrinityCore/commit/a748fddfa47216e1f516303e3bca9b5a86823748)
This commit is contained in:
hondacrx
2024-02-24 15:18:07 -05:00
parent dab3a891a7
commit 9d1589afd4
10 changed files with 93 additions and 34 deletions
+17 -2
View File
@@ -27,9 +27,9 @@ namespace Game.AI
protected TaskScheduler _scheduler = new();
protected InstanceScript _instanceScript;
public CreatureAI(Creature _creature) : base(_creature)
public CreatureAI(Creature creature) : base(creature)
{
me = _creature;
me = creature;
_moveInLOSLocked = false;
}
@@ -514,6 +514,21 @@ namespace Game.AI
// called when the corpse of this creature gets removed
public virtual void CorpseRemoved(long respawnDelay) { }
public override void AttackStart(Unit victim)
{
if (victim != null && me.Attack(victim, true))
{
// Clear distracted state on attacking
if (me.HasUnitState(UnitState.Distracted))
{
me.ClearUnitState(UnitState.Distracted);
me.GetMotionMaster().Clear();
}
me.StartDefaultCombatMovement(victim);
}
}
/// == Gossip system ================================
// Called when the dialog status between a player and the creature is requested.
+20 -13
View File
@@ -4,6 +4,7 @@
using Framework.Constants;
using Game.Entities;
using Game.Spells;
using System;
namespace Game.AI
{
@@ -92,28 +93,34 @@ namespace Game.AI
public class CritterAI : PassiveAI
{
public CritterAI(Creature c) : base(c)
TimeTracker _evadeTimer;
public CritterAI(Creature creature) : base(creature)
{
me.SetReactState(ReactStates.Passive);
_evadeTimer = new();
me.SetCanMelee(false, true);
}
public override void JustEngagedWith(Unit who)
{
if (!me.HasUnitState(UnitState.Fleeing))
me.SetControlled(true, UnitState.Fleeing);
me.StartDefaultCombatMovement(who);
_evadeTimer.Reset(TimeSpan.FromMilliseconds(WorldConfig.GetIntValue(WorldCfg.CreatureFamilyFleeDelay)));
}
public override void MovementInform(MovementGeneratorType type, uint id)
public override void UpdateAI(uint diff)
{
if (type == MovementGeneratorType.TimedFleeing)
EnterEvadeMode(EvadeReason.Other);
}
if (me.IsEngaged())
{
if (!me.IsInCombat())
{
EnterEvadeMode(EvadeReason.NoHostiles);
return;
}
public override void EnterEvadeMode(EvadeReason why)
{
if (me.HasUnitState(UnitState.Fleeing))
me.SetControlled(false, UnitState.Fleeing);
base.EnterEvadeMode(why);
_evadeTimer.Update(diff);
if (_evadeTimer.Passed())
EnterEvadeMode(EvadeReason.Other);
}
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ namespace Game.AI
public void DoStartMovement(Unit target, float distance = 0.0f, float angle = 0.0f)
{
if (target != null)
me.GetMotionMaster().MoveChase(target, distance, angle);
me.StartDefaultCombatMovement(target, distance, angle);
}
//Start no movement on victim
+2 -2
View File
@@ -618,7 +618,7 @@ namespace Game.AI
if (_canCombatMove)
{
SetRun(_run);
me.GetMotionMaster().MoveChase(who);
me.StartDefaultCombatMovement(who);
}
}
}
@@ -830,7 +830,7 @@ namespace Game.AI
}))
{
SetRun(_run);
me.GetMotionMaster().MoveChase(me.GetVictim());
me.StartDefaultCombatMovement(me.GetVictim());
}
}
else
+1 -1
View File
@@ -1515,7 +1515,7 @@ namespace Game.AI
if (creature != null)
if (IsSmart(creature) && creature.GetVictim() != null)
if (((SmartAI)creature.GetAI()).CanCombatMove())
creature.GetMotionMaster().MoveChase(creature.GetVictim(), attackDistance, attackAngle);
creature.StartDefaultCombatMovement(creature.GetVictim(), attackDistance, attackAngle);
}
break;
}