using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
+using Content.Shared.Mech.EntitySystems;
using Content.Shared.Mobs;
using Content.Shared.Popups;
using Robust.Shared.Audio.Systems;
SubscribeLocalEvent<GuardianHostComponent, GuardianToggleActionEvent>(OnPerformAction);
SubscribeLocalEvent<GuardianComponent, AttackAttemptEvent>(OnGuardianAttackAttempt);
+
+ SubscribeLocalEvent<GuardianHostComponent, MechPilotRelayedEvent<GettingAttackedAttemptEvent>>(OnPilotAttackAttempt);
}
private void OnGuardianShutdown(EntityUid uid, GuardianComponent component, ComponentShutdown args)
args.Cancel();
}
+ private void OnPilotAttackAttempt(Entity<GuardianHostComponent> uid, ref MechPilotRelayedEvent<GettingAttackedAttemptEvent> args)
+ {
+ if (args.Args.Cancelled)
+ return;
+
+ _popupSystem.PopupCursor(Loc.GetString("guardian-attack-host"), args.Args.Attacker, PopupType.LargeCaution);
+
+ args.Args.Cancelled = true;
+ }
+
public void ToggleGuardian(EntityUid user, GuardianHostComponent hostComponent)
{
if (!TryComp<GuardianComponent>(hostComponent.HostedGuardian, out var guardianComponent))
-using Content.Shared.DoAfter;
+using Content.Shared.DoAfter;
using Robust.Shared.Serialization;
namespace Content.Shared.Guardian;
--- /dev/null
+using Content.Shared.Interaction.Events;
+using Content.Shared.Mech.Components;
+
+namespace Content.Shared.Mech.EntitySystems;
+
+public abstract partial class SharedMechSystem
+{
+ private void InitializeRelay()
+ {
+ SubscribeLocalEvent<MechComponent, GettingAttackedAttemptEvent>(RelayRefToPilot);
+ }
+
+ private void RelayToPilot<T>(Entity<MechComponent> uid, T args) where T : class
+ {
+ if (uid.Comp.PilotSlot.ContainedEntity is not { } pilot)
+ return;
+
+ var ev = new MechPilotRelayedEvent<T>(args);
+
+ RaiseLocalEvent(pilot, ref ev);
+ }
+
+ private void RelayRefToPilot<T>(Entity<MechComponent> uid, ref T args) where T :struct
+ {
+ if (uid.Comp.PilotSlot.ContainedEntity is not { } pilot)
+ return;
+
+ var ev = new MechPilotRelayedEvent<T>(args);
+
+ RaiseLocalEvent(pilot, ref ev);
+
+ args = ev.Args;
+ }
+}
+
+[ByRefEvent]
+public record struct MechPilotRelayedEvent<TEvent>(TEvent Args)
+{
+ public TEvent Args = Args;
+}
/// <summary>
/// Handles all of the interactions, UI handling, and items shennanigans for <see cref="MechComponent"/>
/// </summary>
-public abstract class SharedMechSystem : EntitySystem
+public abstract partial class SharedMechSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly INetManager _net = default!;
SubscribeLocalEvent<MechPilotComponent, GetMeleeWeaponEvent>(OnGetMeleeWeapon);
SubscribeLocalEvent<MechPilotComponent, CanAttackFromContainerEvent>(OnCanAttackFromContainer);
SubscribeLocalEvent<MechPilotComponent, AttackAttemptEvent>(OnAttackAttempt);
+
+ InitializeRelay();
}
private void OnToggleEquipmentAction(EntityUid uid, MechComponent component, MechToggleEquipmentEvent args)