Stop NPC smashing if it fails (#17847)

This commit is contained in:
metalgearsloth
2023-07-06 14:42:17 +10:00
committed by GitHub
parent 02db31fdc6
commit 876beb9369
2 changed files with 23 additions and 16 deletions

View File

@@ -124,26 +124,31 @@ public sealed partial class NPCSteeringSystem
// Try smashing obstacles.
else if ((component.Flags & PathFlags.Smashing) != 0x0)
{
if (_melee.TryGetWeapon(uid, out var meleeUid, out var meleeWeapon) && meleeWeapon.NextAttack <= _timing.CurTime && TryComp<CombatModeComponent>(uid, out var combatMode))
if (_melee.TryGetWeapon(uid, out _, out var meleeWeapon) && meleeWeapon.NextAttack <= _timing.CurTime && TryComp<CombatModeComponent>(uid, out var combatMode))
{
_combat.SetInCombatMode(uid, true, combatMode);
var destructibleQuery = GetEntityQuery<DestructibleComponent>();
// TODO: This is a hack around grilles and windows.
_random.Shuffle(obstacleEnts);
var attackResult = false;
foreach (var ent in obstacleEnts)
{
// TODO: Validate we can damage it
if (destructibleQuery.HasComponent(ent))
{
_melee.AttemptLightAttack(uid, uid, meleeWeapon, ent);
attackResult = _melee.AttemptLightAttack(uid, uid, meleeWeapon, ent);
break;
}
}
_combat.SetInCombatMode(uid, false, combatMode);
// Blocked or the likes?
if (!attackResult)
return SteeringObstacleStatus.Failed;
if (obstacleEnts.Count == 0)
return SteeringObstacleStatus.Completed;