Avoid NPCs getting stuck around tables (#14807)

This commit is contained in:
metalgearsloth
2023-03-23 23:53:17 +11:00
committed by GitHub
parent 16cebe6601
commit b5a33ea7ab
4 changed files with 47 additions and 11 deletions

View File

@@ -17,6 +17,7 @@ public sealed class MoveToOperator : HTNOperator
[Dependency] private readonly IMapManager _mapManager = default!;
private NPCSteeringSystem _steering = default!;
private PathfindingSystem _pathfind = default!;
private SharedTransformSystem _transform = default!;
/// <summary>
/// Should we assume the MovementTarget is reachable during planning or should we pathfind to it?
@@ -55,6 +56,7 @@ public sealed class MoveToOperator : HTNOperator
base.Initialize(sysManager);
_pathfind = sysManager.GetEntitySystem<PathfindingSystem>();
_steering = sysManager.GetEntitySystem<NPCSteeringSystem>();
_transform = sysManager.GetEntitySystem<SharedTransformSystem>();
}
public override async Task<(bool Valid, Dictionary<string, object>? Effects)> Plan(NPCBlackboard blackboard,
@@ -126,9 +128,10 @@ public sealed class MoveToOperator : HTNOperator
// Need to remove the planning value for execution.
blackboard.Remove<EntityCoordinates>(NPCBlackboard.OwnerCoordinates);
var targetCoordinates = blackboard.GetValue<EntityCoordinates>(TargetKey);
var uid = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
// Re-use the path we may have if applicable.
var comp = _steering.Register(blackboard.GetValue<EntityUid>(NPCBlackboard.Owner), targetCoordinates);
var comp = _steering.Register(uid, targetCoordinates);
if (blackboard.TryGetValue<float>(RangeKey, out var range, _entManager))
{
@@ -139,8 +142,8 @@ public sealed class MoveToOperator : HTNOperator
{
if (blackboard.TryGetValue<EntityCoordinates>(NPCBlackboard.OwnerCoordinates, out var coordinates, _entManager))
{
var mapCoords = coordinates.ToMap(_entManager);
_steering.PrunePath(mapCoords, targetCoordinates.ToMapPos(_entManager) - mapCoords.Position, result.Path);
var mapCoords = coordinates.ToMap(_entManager, _transform);
_steering.PrunePath(uid, mapCoords, targetCoordinates.ToMapPos(_entManager, _transform) - mapCoords.Position, result.Path);
}
comp.CurrentPath = result.Path;