Fix NPC obstacle handling (#13007)
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
using Content.Server.CombatMode;
|
||||
using Content.Server.Destructible;
|
||||
using Content.Server.NPC.Components;
|
||||
using Content.Server.NPC.Pathfinding;
|
||||
using Content.Shared.Doors.Components;
|
||||
using Content.Shared.NPC;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.NPC.Systems;
|
||||
|
||||
@@ -33,9 +34,7 @@ public sealed partial class NPCSteeringSystem
|
||||
|
||||
private SteeringObstacleStatus TryHandleFlags(NPCSteeringComponent component, PathPoly poly, EntityQuery<PhysicsComponent> bodyQuery)
|
||||
{
|
||||
if (poly.Data.IsFreeSpace)
|
||||
return SteeringObstacleStatus.Completed;
|
||||
|
||||
DebugTools.Assert(!poly.Data.IsFreeSpace);
|
||||
// TODO: Store PathFlags on the steering comp
|
||||
// and be able to re-check it.
|
||||
|
||||
@@ -111,26 +110,35 @@ public sealed partial class NPCSteeringSystem
|
||||
return SteeringObstacleStatus.Completed;
|
||||
}
|
||||
// Try smashing obstacles.
|
||||
else if ((component.Flags & PathFlags.Smashing) != 0x0 && TryComp<NPCMeleeCombatComponent>(component.Owner, out var melee) &&
|
||||
TryComp<MeleeWeaponComponent>(melee.Weapon, out var meleeWeapon))
|
||||
else if ((component.Flags & PathFlags.Smashing) != 0x0)
|
||||
{
|
||||
var destructibleQuery = GetEntityQuery<DestructibleComponent>();
|
||||
var meleeWeapon = _melee.GetWeapon(component.Owner);
|
||||
|
||||
// TODO: This is a hack around grilles and windows.
|
||||
_random.Shuffle(obstacleEnts);
|
||||
|
||||
foreach (var ent in obstacleEnts)
|
||||
if (meleeWeapon != null && meleeWeapon.NextAttack <= _timing.CurTime && TryComp<CombatModeComponent>(component.Owner, out var combatMode))
|
||||
{
|
||||
// TODO: Validate we can damage it
|
||||
if (destructibleQuery.HasComponent(ent))
|
||||
{
|
||||
_melee.AttemptLightAttack(component.Owner, meleeWeapon, ent);
|
||||
return SteeringObstacleStatus.Continuing;
|
||||
}
|
||||
}
|
||||
combatMode.IsInCombatMode = true;
|
||||
var destructibleQuery = GetEntityQuery<DestructibleComponent>();
|
||||
|
||||
if (obstacleEnts.Count == 0)
|
||||
return SteeringObstacleStatus.Completed;
|
||||
// TODO: This is a hack around grilles and windows.
|
||||
_random.Shuffle(obstacleEnts);
|
||||
|
||||
foreach (var ent in obstacleEnts)
|
||||
{
|
||||
// TODO: Validate we can damage it
|
||||
if (destructibleQuery.HasComponent(ent))
|
||||
{
|
||||
_melee.AttemptLightAttack(component.Owner, meleeWeapon, ent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
combatMode.IsInCombatMode = false;
|
||||
|
||||
if (obstacleEnts.Count == 0)
|
||||
return SteeringObstacleStatus.Completed;
|
||||
|
||||
return SteeringObstacleStatus.Continuing;
|
||||
}
|
||||
}
|
||||
|
||||
return SteeringObstacleStatus.Failed;
|
||||
|
||||
Reference in New Issue
Block a user