Add pathfinding support for NPCs climbing tables (#17415)

This commit is contained in:
Vordenburg
2023-07-28 02:37:29 -04:00
committed by GitHub
parent 494b9e5b93
commit 49f3f07e30
11 changed files with 114 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
using Content.Server.Destructible;
using Content.Server.NPC.Components;
using Content.Server.NPC.Pathfinding;
using Content.Shared.Climbing;
using Content.Shared.CombatMode;
using Content.Shared.DoAfter;
using Content.Shared.Doors.Components;
@@ -74,6 +75,7 @@ public sealed partial class NPCSteeringSystem
GetObstacleEntities(poly, mask, layer, obstacleEnts);
var isDoor = (poly.Data.Flags & PathfindingBreadcrumbFlag.Door) != 0x0;
var isAccessRequired = (poly.Data.Flags & PathfindingBreadcrumbFlag.Access) != 0x0;
var isClimbable = (poly.Data.Flags & PathfindingBreadcrumbFlag.Climb) != 0x0;
// Just walk into it stupid
if (isDoor && !isAccessRequired)
@@ -121,6 +123,38 @@ public sealed partial class NPCSteeringSystem
if (obstacleEnts.Count == 0)
return SteeringObstacleStatus.Completed;
}
// Try climbing obstacles
else if ((component.Flags & PathFlags.Climbing) != 0x0 && isClimbable)
{
if (TryComp<ClimbingComponent>(uid, out var climbing))
{
if (climbing.IsClimbing)
{
return SteeringObstacleStatus.Completed;
}
else if (climbing.OwnerIsTransitioning)
{
return SteeringObstacleStatus.Continuing;
}
var climbableQuery = GetEntityQuery<ClimbableComponent>();
// Get the relevant obstacle
foreach (var ent in obstacleEnts)
{
if (climbableQuery.TryGetComponent(ent, out var table) &&
_climb.CanVault(table, uid, uid, out _) &&
_climb.TryClimb(uid, uid, ent, out id, table, climbing))
{
component.DoAfterId = id;
return SteeringObstacleStatus.Continuing;
}
}
}
if (obstacleEnts.Count == 0)
return SteeringObstacleStatus.Completed;
}
// Try smashing obstacles.
else if ((component.Flags & PathFlags.Smashing) != 0x0)
{