Increase NPC chase persistence (#12850)

This commit is contained in:
metalgearsloth
2022-12-07 10:34:23 +11:00
committed by GitHub
parent dd384c55a0
commit 540a3d9028
3 changed files with 17 additions and 8 deletions

View File

@@ -232,7 +232,7 @@ public sealed partial class PathfindingSystem
private bool IsBodyRelevant(PhysicsComponent body) private bool IsBodyRelevant(PhysicsComponent body)
{ {
if (!body.Hard || !body.CanCollide || body.BodyType != BodyType.Static) if (!body.Hard || body.BodyType != BodyType.Static)
{ {
return false; return false;
} }
@@ -262,7 +262,8 @@ public sealed partial class PathfindingSystem
private void OnBodyTypeChange(ref PhysicsBodyTypeChangedEvent ev) private void OnBodyTypeChange(ref PhysicsBodyTypeChangedEvent ev)
{ {
if (IsBodyRelevant(ev.Component) && if (ev.Component.CanCollide &&
IsBodyRelevant(ev.Component) &&
TryComp<TransformComponent>(ev.Entity, out var xform) && TryComp<TransformComponent>(ev.Entity, out var xform) &&
xform.GridUid != null) xform.GridUid != null)
{ {

View File

@@ -87,13 +87,20 @@ public sealed partial class NPCCombatSystem
return; return;
} }
if (TryComp<NPCSteeringComponent>(component.Owner, out var steering) &&
steering.Status == SteeringStatus.NoPath)
{
component.Status = CombatStatus.TargetUnreachable;
return;
}
if (distance > weapon.Range) if (distance > weapon.Range)
{ {
component.Status = CombatStatus.TargetOutOfRange; component.Status = CombatStatus.TargetOutOfRange;
return; return;
} }
var steering = EnsureComp<NPCSteeringComponent>(component.Owner); steering = EnsureComp<NPCSteeringComponent>(component.Owner);
steering.Range = MathF.Max(0.2f, weapon.Range - 0.4f); steering.Range = MathF.Max(0.2f, weapon.Range - 0.4f);
// Gets unregistered on component shutdown. // Gets unregistered on component shutdown.

View File

@@ -243,11 +243,6 @@ namespace Content.Server.NPC.Systems
var direction = targetMap.Position - ourMap.Position; var direction = targetMap.Position - ourMap.Position;
if (steering.Owner == new EntityUid(15315))
{
}
// Are we in range // Are we in range
if (direction.Length <= arrivalDistance) if (direction.Length <= arrivalDistance)
{ {
@@ -318,6 +313,12 @@ namespace Content.Server.NPC.Systems
// TODO: Probably need partial planning support i.e. patch from the last node to where the target moved to. // TODO: Probably need partial planning support i.e. patch from the last node to where the target moved to.
CheckPath(steering, xform, needsPath, distance); CheckPath(steering, xform, needsPath, distance);
if (steering.Pathfind && steering.CurrentPath.Count == 0)
{
SetDirection(mover, steering, Vector2.Zero, false);
return;
}
modifierQuery.TryGetComponent(steering.Owner, out var modifier); modifierQuery.TryGetComponent(steering.Owner, out var modifier);
var moveSpeed = GetSprintSpeed(steering.Owner, modifier); var moveSpeed = GetSprintSpeed(steering.Owner, modifier);