Core/SAI: Implement waiting for actions on action list to finish before continuing the action list

Port From (https://github.com/TrinityCore/TrinityCore/commit/5dfac0ef142c1b59e41c51ab2cca48083be4cb9e)
This commit is contained in:
Hondacrx
2024-08-08 17:28:27 -04:00
parent 0b1f2fe34e
commit 2f71dbfda0
18 changed files with 335 additions and 79 deletions
@@ -4,8 +4,8 @@
using Framework.Constants;
using Game.AI;
using Game.Entities;
using Game.Scripting.v2;
using System;
using System.Threading.Tasks;
namespace Game.Movement
{
@@ -14,7 +14,7 @@ namespace Game.Movement
public const float MIN_QUIET_DISTANCE = 28.0f;
public const float MAX_QUIET_DISTANCE = 43.0f;
public FleeingMovementGenerator(ObjectGuid fleeTargetGUID, TaskCompletionSource<MovementStopReason> scriptResult = null)
public FleeingMovementGenerator(ObjectGuid fleeTargetGUID, ActionResultSetter<MovementStopReason> scriptResult = null)
{
_fleeTargetGUID = fleeTargetGUID;
_timer = new TimeTracker();
@@ -197,7 +197,7 @@ namespace Game.Movement
public class TimedFleeingMovementGenerator : FleeingMovementGenerator
{
public TimedFleeingMovementGenerator(ObjectGuid fleeTargetGUID, TimeSpan time, TaskCompletionSource<MovementStopReason> scriptResult = null) : base(fleeTargetGUID, scriptResult)
public TimedFleeingMovementGenerator(ObjectGuid fleeTargetGUID, TimeSpan time, ActionResultSetter<MovementStopReason> scriptResult = null) : base(fleeTargetGUID, scriptResult)
{
_totalFleeTime = new TimeTracker(time);
}
@@ -5,11 +5,11 @@ using Framework.Constants;
using Game.DataStorage;
using Game.Entities;
using Game.Maps;
using Game.Scripting.v2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
namespace Game.Movement
{
@@ -25,7 +25,7 @@ namespace Game.Movement
int _currentNode;
List<TaxiNodeChangeInfo> _pointsForPathSwitch = new(); //! node indexes and costs where TaxiPath changes
public FlightPathMovementGenerator(float? speed, TaskCompletionSource<MovementStopReason> scriptResult)
public FlightPathMovementGenerator(float? speed, ActionResultSetter<MovementStopReason> scriptResult)
{
_speed = speed;
Mode = MovementGeneratorMode.Default;
@@ -4,6 +4,7 @@
using Framework.Constants;
using Game.AI;
using Game.Entities;
using Game.Scripting.v2;
using System;
using System.Threading.Tasks;
@@ -24,7 +25,7 @@ namespace Game.Movement
AbstractFollower _abstractFollower;
public FollowMovementGenerator(Unit target, float range, ChaseAngle angle, TimeSpan? duration, TaskCompletionSource<MovementStopReason> scriptResult = null)
public FollowMovementGenerator(Unit target, float range, ChaseAngle angle, TimeSpan? duration, ActionResultSetter<MovementStopReason> scriptResult = null)
{
_abstractFollower = new AbstractFollower(target);
_range = range;
@@ -3,8 +3,8 @@
using Framework.Constants;
using Game.Entities;
using Game.Scripting.v2;
using System;
using System.Threading.Tasks;
namespace Game.Movement
{
@@ -117,6 +117,6 @@ namespace Game.Movement
public uint? ArrivalSpellId;
public ObjectGuid? ArrivalSpellTarget;
public TimeSpan? Duration;
public TaskCompletionSource<MovementStopReason> ScriptResult;
public ActionResultSetter<MovementStopReason> ScriptResult;
}
}
@@ -3,8 +3,8 @@
using Framework.Constants;
using Game.Entities;
using Game.Scripting.v2;
using System;
using System.Threading.Tasks;
namespace Game.Movement
{
@@ -57,7 +57,7 @@ namespace Game.Movement
float? _totalTurnAngle;
uint _diffSinceLastUpdate;
public RotateMovementGenerator(uint id, RotateDirection direction, TimeSpan? duration, float? turnSpeed, float? totalTurnAngle, TaskCompletionSource<MovementStopReason> scriptResult)
public RotateMovementGenerator(uint id, RotateDirection direction, TimeSpan? duration, float? turnSpeed, float? totalTurnAngle, ActionResultSetter<MovementStopReason> scriptResult)
{
_id = id;
_direction = direction;
@@ -2,10 +2,9 @@
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
using Framework.Constants;
using Game.AI;
using Game.Entities;
using Game.Scripting.v2;
using System;
using System.Threading.Tasks;
namespace Game.Movement
{
@@ -15,7 +14,7 @@ namespace Game.Movement
public MovementGeneratorPriority Priority;
public MovementGeneratorFlags Flags;
public UnitState BaseUnitState;
public TaskCompletionSource<MovementStopReason> ScriptResult;
public ActionResultSetter<MovementStopReason> ScriptResult;
~MovementGenerator()
{
@@ -3,8 +3,8 @@
using Framework.Constants;
using Game.Entities;
using Game.Scripting.v2;
using System;
using System.Threading.Tasks;
namespace Game.Movement
{
@@ -22,7 +22,7 @@ namespace Game.Movement
float? _closeEnoughDistance;
public PointMovementGenerator(uint id, float x, float y, float z, bool generatePath, float? speed = null, float? finalOrient = null, Unit faceTarget = null, SpellEffectExtraData spellEffectExtraData = null,
MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode.Default, float? closeEnoughDistance = null, TaskCompletionSource<MovementStopReason> scriptResult = null)
MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode.Default, float? closeEnoughDistance = null, ActionResultSetter<MovementStopReason> scriptResult = null)
{
_movementId = id;
_destination = new Position(x, y, z);
@@ -207,7 +207,7 @@ namespace Game.Movement
}
public uint GetId() { return _movementId; }
public override MovementGeneratorType GetMovementGeneratorType()
{
return MovementGeneratorType.Point;
@@ -3,6 +3,7 @@
using Framework.Constants;
using Game.Entities;
using Game.Scripting.v2;
using System;
using System.Threading.Tasks;
@@ -17,7 +18,7 @@ namespace Game.Movement
float _wanderDistance;
uint _wanderSteps;
public RandomMovementGenerator(float spawnDist = 0.0f, TimeSpan? duration = null, TaskCompletionSource<MovementStopReason> scriptResult = null)
public RandomMovementGenerator(float spawnDist = 0.0f, TimeSpan? duration = null, ActionResultSetter<MovementStopReason> scriptResult = null)
{
_timer = new TimeTracker();
_reference = new();
@@ -4,10 +4,10 @@
using Framework.Constants;
using Game.AI;
using Game.Entities;
using Game.Scripting.v2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Game.Movement
{
@@ -31,7 +31,7 @@ namespace Game.Movement
bool _generatePath;
public WaypointMovementGenerator(uint pathId = 0, bool repeating = true, TimeSpan? duration = null, float? speed = null, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode.Default,
(TimeSpan min, TimeSpan max)? waitTimeRangeAtPathEnd = null, float? wanderDistanceAtPathEnds = null, bool? followPathBackwardsFromEndToStart = null, bool generatePath = true, TaskCompletionSource<MovementStopReason> scriptResult = null)
(TimeSpan min, TimeSpan max)? waitTimeRangeAtPathEnd = null, float? wanderDistanceAtPathEnds = null, bool? followPathBackwardsFromEndToStart = null, bool generatePath = true, ActionResultSetter<MovementStopReason> scriptResult = null)
{
_nextMoveTime = new TimeTracker(0);
_pathId = pathId;
@@ -56,7 +56,7 @@ namespace Game.Movement
}
public WaypointMovementGenerator(WaypointPath path, bool repeating = true, TimeSpan? duration = null, float? speed = null, MovementWalkRunSpeedSelectionMode speedSelectionMode = MovementWalkRunSpeedSelectionMode.Default,
(TimeSpan min, TimeSpan max)? waitTimeRangeAtPathEnd = null, float? wanderDistanceAtPathEnds = null, bool? followPathBackwardsFromEndToStart = null, bool generatePath = true, TaskCompletionSource<MovementStopReason> scriptResult = null)
(TimeSpan min, TimeSpan max)? waitTimeRangeAtPathEnd = null, float? wanderDistanceAtPathEnds = null, bool? followPathBackwardsFromEndToStart = null, bool generatePath = true, ActionResultSetter<MovementStopReason> scriptResult = null)
{
_nextMoveTime = new TimeTracker(0);
_repeating = repeating;