diff --git a/Content.Server/Mech/Systems/MechSystem.cs b/Content.Server/Mech/Systems/MechSystem.cs index 9e82a1085f..1a9b8ff4e0 100644 --- a/Content.Server/Mech/Systems/MechSystem.cs +++ b/Content.Server/Mech/Systems/MechSystem.cs @@ -6,12 +6,15 @@ using Content.Server.Mech.Components; using Content.Server.Power.Components; using Content.Server.Tools; using Content.Server.Wires; +using Content.Shared.ActionBlocker; using Content.Shared.Damage; using Content.Shared.FixedPoint; using Content.Shared.Interaction; using Content.Shared.Mech; using Content.Shared.Mech.Components; using Content.Shared.Mech.EntitySystems; +using Content.Shared.Movement.Components; +using Content.Shared.Movement.Events; using Content.Shared.Tools.Components; using Content.Shared.Verbs; using Robust.Server.Containers; @@ -29,6 +32,7 @@ public sealed class MechSystem : SharedMechSystem [Dependency] private readonly DoAfterSystem _doAfter = default!; [Dependency] private readonly IMapManager _map = default!; [Dependency] private readonly UserInterfaceSystem _ui = default!; + [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; private ISawmill _sawmill = default!; @@ -53,6 +57,9 @@ public sealed class MechSystem : SharedMechSystem SubscribeLocalEvent(OnDamageChanged); SubscribeLocalEvent(OnRemoveEquipmentMessage); + SubscribeLocalEvent(OnMechCanMoveEvent); + + SubscribeLocalEvent(OnToolUseAttempt); SubscribeLocalEvent(OnInhale); SubscribeLocalEvent(OnExhale); @@ -63,6 +70,11 @@ public sealed class MechSystem : SharedMechSystem #endregion } + private void OnMechCanMoveEvent(EntityUid uid, MechComponent component , UpdateCanMoveEvent args) + { + if (component.Broken || component.Integrity <= 0 || component.Energy <= 0) + args.Cancel(); + } private void OnInteractUsing(EntityUid uid, MechComponent component, InteractUsingEvent args) { if (TryComp(uid, out var wires) && !wires.IsPanelOpen) @@ -71,6 +83,7 @@ public sealed class MechSystem : SharedMechSystem if (component.BatterySlot.ContainedEntity == null && TryComp(args.Used, out var battery)) { InsertBattery(uid, args.Used, component, battery); + _actionBlocker.UpdateCanMove(uid); return; } @@ -93,8 +106,8 @@ public sealed class MechSystem : SharedMechSystem private void OnRemoveBatteryFinished(EntityUid uid, MechComponent component, MechRemoveBatteryFinishedEvent args) { component.EntryTokenSource = null; - RemoveBattery(uid, component); + _actionBlocker.UpdateCanMove(uid); } private void OnRemoveBatteryCancelled(EntityUid uid, MechComponent component, MechRemoveBatteryCancelledEvent args) @@ -119,6 +132,7 @@ public sealed class MechSystem : SharedMechSystem InsertBattery(uid, battery, component); } + _actionBlocker.UpdateCanMove(uid); Dirty(component); } @@ -212,6 +226,7 @@ public sealed class MechSystem : SharedMechSystem { component.EntryTokenSource = null; TryInsert(uid, args.User, component); + _actionBlocker.UpdateCanMove(uid); } private void OnExitFinished(EntityUid uid, MechComponent component, MechExitFinishedEvent args) @@ -345,6 +360,7 @@ public sealed class MechSystem : SharedMechSystem base.BreakMech(uid, component); _ui.TryCloseAll(uid, MechUiKey.Key); + _actionBlocker.UpdateCanMove(uid); } public override bool TryChangeEnergy(EntityUid uid, FixedPoint2 delta, SharedMechComponent? component = null) @@ -369,6 +385,7 @@ public sealed class MechSystem : SharedMechSystem component.Energy = batteryComp.CurrentCharge; Dirty(component); } + _actionBlocker.UpdateCanMove(uid); return true; } @@ -384,6 +401,8 @@ public sealed class MechSystem : SharedMechSystem component.Energy = battery.CurrentCharge; component.MaxEnergy = battery.MaxCharge; + _actionBlocker.UpdateCanMove(uid); + Dirty(component); UpdateUserInterface(uid, component); } @@ -397,6 +416,8 @@ public sealed class MechSystem : SharedMechSystem component.Energy = 0; component.MaxEnergy = 0; + _actionBlocker.UpdateCanMove(uid); + Dirty(component); UpdateUserInterface(uid, component); }