Core/Movement: MotionMaster reimplementation

Port From (https://github.com/TrinityCore/TrinityCore/commit/426f9f2f92b26fbb68e7cda9290ccbd586c6af4e)
This commit is contained in:
hondacrx
2021-09-29 18:24:37 -04:00
parent cf13f32062
commit a968772bad
47 changed files with 1954 additions and 1227 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ namespace Game.AI
return new NullCreatureAI(creature);
}
public static IMovementGenerator SelectMovementAI(Unit unit)
public static MovementGenerator SelectMovementGenerator(Unit unit)
{
MovementGeneratorType type = unit.GetDefaultMovementType();
Creature creature = unit.ToCreature();
+3 -5
View File
@@ -156,9 +156,7 @@ namespace Game.AI
me.SendAIReaction(AiReaction.Alert);
// Face the unit (stealthed player) and set distracted state for 5 seconds
me.GetMotionMaster().MoveDistract(5 * Time.InMilliseconds);
me.StopMoving();
me.SetFacingTo(me.GetAbsoluteAngle(who));
me.GetMotionMaster().MoveDistract(5 * Time.InMilliseconds, me.GetAbsoluteAngle(who));
}
// Called for reaction at stopping attack at no attackers or targets
@@ -174,8 +172,8 @@ namespace Game.AI
Unit owner = me.GetCharmerOrOwner();
if (owner != null)
{
me.GetMotionMaster().Clear(false);
me.GetMotionMaster().MoveFollow(owner, SharedConst.PetFollowDist, me.GetFollowAngle(), MovementSlot.Active);
me.GetMotionMaster().Clear();
me.GetMotionMaster().MoveFollow(owner, SharedConst.PetFollowDist, me.GetFollowAngle());
}
else
{
+3 -18
View File
@@ -44,21 +44,6 @@ namespace Game.AI
return Global.ObjAccessor.GetPlayer(me, _playerGUID);
}
public override void AttackStart(Unit target)
{
if (target == null)
return;
if (me.Attack(target, true))
{
if (me.GetMotionMaster().GetCurrentMovementGeneratorType() == MovementGeneratorType.Point)
me.GetMotionMaster().MovementExpired();
if (IsCombatMovementAllowed())
me.GetMotionMaster().MoveChase(target);
}
}
//see followerAI
bool AssistPlayerInCombatAgainst(Unit who)
{
@@ -236,7 +221,7 @@ namespace Game.AI
else if (_resume)
{
_resume = false;
IMovementGenerator movementGenerator = me.GetMotionMaster().GetMotionSlot(MovementSlot.Idle);
MovementGenerator movementGenerator = me.GetMotionMaster().GetCurrentMovementGenerator(MovementSlot.Default);
if (movementGenerator != null)
movementGenerator.Resume(0);
}
@@ -436,7 +421,7 @@ namespace Game.AI
Log.outError(LogFilter.Scripts, $"EscortAI.Start: (script: {me.GetScriptName()}, creature entry: {me.GetEntry()}) is set to return home after waypoint end and instant respawn at waypoint end. Creature will never despawn.");
me.GetMotionMaster().MoveIdle();
me.GetMotionMaster().Clear(MovementSlot.Active);
me.GetMotionMaster().Clear(MovementGeneratorPriority.Normal);
//disable npcflags
me.SetNpcFlags(NPCFlags.None);
@@ -464,7 +449,7 @@ namespace Game.AI
if (on)
{
AddEscortState(EscortState.Paused);
IMovementGenerator movementGenerator = me.GetMotionMaster().GetMotionSlot(MovementSlot.Idle);
MovementGenerator movementGenerator = me.GetMotionMaster().GetCurrentMovementGenerator(MovementSlot.Default);
if (movementGenerator != null)
movementGenerator.Pause(0);
}
+20 -9
View File
@@ -158,7 +158,7 @@ namespace Game.AI
{
if (!HasEscortState(SmartEscortState.Escorting))
{
me.PauseMovement(delay, MovementSlot.Idle, forced);
me.PauseMovement(delay, MovementSlot.Default, forced);
if (me.GetMotionMaster().GetCurrentMovementGeneratorType() == MovementGeneratorType.Waypoint)
{
var (nodeId, pathId) = me.GetCurrentWaypointInfo();
@@ -597,8 +597,11 @@ namespace Game.AI
CreatureGroup formation = me.GetFormation();
if (formation == null || formation.GetLeader() == me || !formation.IsFormed())
{
if (me.GetMotionMaster().GetMotionSlotType(MovementSlot.Idle) != MovementGeneratorType.Waypoint && me.GetWaypointPath() != 0)
me.GetMotionMaster().MovePath(me.GetWaypointPath(), true);
if (me.GetMotionMaster().GetCurrentMovementGeneratorType(MovementSlot.Default) != MovementGeneratorType.Waypoint)
{
if (me.GetWaypointPath() != 0)
me.GetMotionMaster().MovePath(me.GetWaypointPath(), true);
}
else
me.ResumeMovement();
}
@@ -644,7 +647,8 @@ namespace Game.AI
if (who != null && me.Attack(who, _canAutoAttack))
{
me.GetMotionMaster().Clear(MovementSlot.Active);
me.GetMotionMaster().Clear(MovementGeneratorPriority.Normal);
me.PauseMovement();
if (_canCombatMove)
{
@@ -826,13 +830,20 @@ namespace Game.AI
if (me.IsEngaged())
{
if (on && !me.HasReactState(ReactStates.Passive) && me.GetVictim() && me.GetMotionMaster().GetMotionSlotType(MovementSlot.Active) == MovementGeneratorType.Max)
if (on)
{
SetRun(_run);
me.GetMotionMaster().MoveChase(me.GetVictim());
if (!me.HasReactState(ReactStates.Passive) && me.GetVictim() && !me.GetMotionMaster().HasMovementGenerator(movement => movement.Mode == MovementGeneratorMode.Default && movement.Priority == MovementGeneratorPriority.Normal))
{
SetRun(_run);
me.GetMotionMaster().MoveChase(me.GetVictim());
}
}
else
{
var movement = me.GetMotionMaster().GetMovementGenerator(a => a.GetMovementGeneratorType() == MovementGeneratorType.Chase && a.Mode == MovementGeneratorMode.Default && a.Priority == MovementGeneratorPriority.Normal);
if (movement != null)
me.GetMotionMaster().Remove(movement);
}
else if (!on && me.GetMotionMaster().GetMotionSlotType(MovementSlot.Active) == MovementGeneratorType.Chase)
me.GetMotionMaster().Clear(MovementSlot.Active);
}
}
@@ -1511,7 +1511,7 @@ namespace Game.AI
case SmartActions.RemoveAllGameobjects:
case SmartActions.SpawnSpawngroup:
case SmartActions.DespawnSpawngroup:
case SmartActions.StopMotion:
case SmartActions.RemoveMovement:
break;
default:
Log.outError(LogFilter.ScriptsAi, "SmartAIMgr: Not handled action_type({0}), event_type({1}), Entry {2} SourceType {3} Event {4}, skipped.", e.GetActionType(), e.GetEventType(), e.EntryOrGuid, e.GetScriptType(), e.EventId);
@@ -2515,7 +2515,7 @@ namespace Game.AI
public RandomTimedEvent randomTimedEvent;
[FieldOffset(4)]
public StopMotion stopMotion;
public RemoveMovement removeMovement;
[FieldOffset(4)]
public RespawnData respawnData;
@@ -3022,10 +3022,10 @@ namespace Game.AI
public uint minId;
public uint maxId;
}
public struct StopMotion
public struct RemoveMovement
{
public uint stopMovement;
public uint movementExpired;
public uint movementType;
public uint forced;
}
public struct RespawnData
{
+4 -4
View File
@@ -2293,16 +2293,16 @@ namespace Game.AI
break;
}
case SmartActions.StopMotion:
case SmartActions.RemoveMovement:
{
foreach (var target in targets)
{
if (IsUnit(target))
{
if (e.Action.stopMotion.stopMovement != 0)
if (e.Action.removeMovement.movementType != 0 && e.Action.removeMovement.movementType < (uint)MovementGeneratorType.Max)
target.ToUnit().GetMotionMaster().Remove((MovementGeneratorType)e.Action.removeMovement.movementType);
if (e.Action.removeMovement.forced != 0)
target.ToUnit().StopMoving();
if (e.Action.stopMotion.movementExpired != 0)
target.ToUnit().GetMotionMaster().MovementExpired();
}
}