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
This commit is contained in:
Rane 2023-01-20 10:48:28 -05:00 committed by GitHub
parent f0429edbb1
commit 943495922a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -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);

View File

@ -56,6 +56,7 @@ public abstract class SharedMechSystem : EntitySystem
SubscribeLocalEvent<MechPilotComponent, GetMeleeWeaponEvent>(OnGetMeleeWeapon);
SubscribeLocalEvent<MechPilotComponent, CanAttackFromContainerEvent>(OnCanAttackFromContainer);
SubscribeLocalEvent<MechPilotComponent, AttackAttemptEvent>(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))