From 943495922a791757b296f61751144f7a6031c6ec Mon Sep 17 00:00:00 2001 From: Rane <60792108+Elijahrane@users.noreply.github.com> Date: Fri, 20 Jan 2023 10:48:28 -0500 Subject: [PATCH] Let entities attack their outermost container (#13406) Closes https://github.com/space-wizards/space-station-14/issues/13405 closes https://github.com/space-wizards/space-station-14/issues/13403 --- Content.Shared/ActionBlocker/ActionBlockerSystem.cs | 3 ++- Content.Shared/Mech/EntitySystems/SharedMechSystem.cs | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs index 6cc80feb38..12310ce0f5 100644 --- a/Content.Shared/ActionBlocker/ActionBlockerSystem.cs +++ b/Content.Shared/ActionBlocker/ActionBlockerSystem.cs @@ -146,7 +146,8 @@ namespace Content.Shared.ActionBlocker public bool CanAttack(EntityUid uid, EntityUid? target = null) { - if (_container.IsEntityInContainer(uid)) + _container.TryGetOuterContainer(uid, Transform(uid), out var outerContainer); + if (target != null && target != outerContainer?.Owner && _container.IsEntityInContainer(uid)) { var containerEv = new CanAttackFromContainerEvent(uid, target); RaiseLocalEvent(uid, containerEv); diff --git a/Content.Shared/Mech/EntitySystems/SharedMechSystem.cs b/Content.Shared/Mech/EntitySystems/SharedMechSystem.cs index 00737f7443..4261567fa7 100644 --- a/Content.Shared/Mech/EntitySystems/SharedMechSystem.cs +++ b/Content.Shared/Mech/EntitySystems/SharedMechSystem.cs @@ -56,6 +56,7 @@ public abstract class SharedMechSystem : EntitySystem SubscribeLocalEvent(OnGetMeleeWeapon); SubscribeLocalEvent(OnCanAttackFromContainer); + SubscribeLocalEvent(OnAttackAttempt); } #region State Handling @@ -451,6 +452,12 @@ public abstract class SharedMechSystem : EntitySystem args.CanAttack = true; } + private void OnAttackAttempt(EntityUid uid, MechPilotComponent component, AttackAttemptEvent args) + { + if (args.Target == component.Mech) + args.Cancel(); + } + private void UpdateAppearance(EntityUid uid, SharedMechComponent ? component = null, AppearanceComponent? appearance = null) { if (!Resolve(uid, ref component, ref appearance, false))