Fallback to guncomp on the entity (#10659)

This commit is contained in:
metalgearsloth
2022-08-18 12:32:34 +10:00
committed by GitHub
parent 5eac94ddf9
commit 64a25dc8f6

View File

@@ -154,21 +154,20 @@ public abstract partial class SharedGunSystem : EntitySystem
public GunComponent? GetGun(EntityUid entity) public GunComponent? GetGun(EntityUid entity)
{ {
if (!EntityManager.TryGetComponent(entity, out SharedHandsComponent? hands) ||
hands.ActiveHandEntity is not { } held)
{
return null;
}
if (!EntityManager.TryGetComponent(held, out GunComponent? gun))
return null;
if (!_combatMode.IsInCombatMode(entity)) if (!_combatMode.IsInCombatMode(entity))
return null; return null;
if (EntityManager.TryGetComponent(entity, out SharedHandsComponent? hands) &&
hands.ActiveHandEntity is { } held &&
TryComp(held, out GunComponent? gun))
{
return gun; return gun;
} }
// Last resort is check if the entity itself is a gun.
return !TryComp(entity, out gun) ? null : gun;
}
private void StopShooting(GunComponent gun) private void StopShooting(GunComponent gun)
{ {
if (gun.ShotCounter == 0) return; if (gun.ShotCounter == 0) return;