Mechs now subscribe and handle UpdateCanMove Events. (#13507)
This commit is contained in:
@@ -6,12 +6,15 @@ using Content.Server.Mech.Components;
|
|||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using Content.Server.Tools;
|
using Content.Server.Tools;
|
||||||
using Content.Server.Wires;
|
using Content.Server.Wires;
|
||||||
|
using Content.Shared.ActionBlocker;
|
||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Mech;
|
using Content.Shared.Mech;
|
||||||
using Content.Shared.Mech.Components;
|
using Content.Shared.Mech.Components;
|
||||||
using Content.Shared.Mech.EntitySystems;
|
using Content.Shared.Mech.EntitySystems;
|
||||||
|
using Content.Shared.Movement.Components;
|
||||||
|
using Content.Shared.Movement.Events;
|
||||||
using Content.Shared.Tools.Components;
|
using Content.Shared.Tools.Components;
|
||||||
using Content.Shared.Verbs;
|
using Content.Shared.Verbs;
|
||||||
using Robust.Server.Containers;
|
using Robust.Server.Containers;
|
||||||
@@ -29,6 +32,7 @@ public sealed class MechSystem : SharedMechSystem
|
|||||||
[Dependency] private readonly DoAfterSystem _doAfter = default!;
|
[Dependency] private readonly DoAfterSystem _doAfter = default!;
|
||||||
[Dependency] private readonly IMapManager _map = default!;
|
[Dependency] private readonly IMapManager _map = default!;
|
||||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||||
|
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
|
||||||
|
|
||||||
private ISawmill _sawmill = default!;
|
private ISawmill _sawmill = default!;
|
||||||
|
|
||||||
@@ -53,6 +57,9 @@ public sealed class MechSystem : SharedMechSystem
|
|||||||
SubscribeLocalEvent<MechComponent, DamageChangedEvent>(OnDamageChanged);
|
SubscribeLocalEvent<MechComponent, DamageChangedEvent>(OnDamageChanged);
|
||||||
SubscribeLocalEvent<MechComponent, MechEquipmentRemoveMessage>(OnRemoveEquipmentMessage);
|
SubscribeLocalEvent<MechComponent, MechEquipmentRemoveMessage>(OnRemoveEquipmentMessage);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<MechComponent, UpdateCanMoveEvent>(OnMechCanMoveEvent);
|
||||||
|
|
||||||
|
|
||||||
SubscribeLocalEvent<MechPilotComponent, ToolUserAttemptUseEvent>(OnToolUseAttempt);
|
SubscribeLocalEvent<MechPilotComponent, ToolUserAttemptUseEvent>(OnToolUseAttempt);
|
||||||
SubscribeLocalEvent<MechPilotComponent, InhaleLocationEvent>(OnInhale);
|
SubscribeLocalEvent<MechPilotComponent, InhaleLocationEvent>(OnInhale);
|
||||||
SubscribeLocalEvent<MechPilotComponent, ExhaleLocationEvent>(OnExhale);
|
SubscribeLocalEvent<MechPilotComponent, ExhaleLocationEvent>(OnExhale);
|
||||||
@@ -63,6 +70,11 @@ public sealed class MechSystem : SharedMechSystem
|
|||||||
#endregion
|
#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)
|
private void OnInteractUsing(EntityUid uid, MechComponent component, InteractUsingEvent args)
|
||||||
{
|
{
|
||||||
if (TryComp<WiresComponent>(uid, out var wires) && !wires.IsPanelOpen)
|
if (TryComp<WiresComponent>(uid, out var wires) && !wires.IsPanelOpen)
|
||||||
@@ -71,6 +83,7 @@ public sealed class MechSystem : SharedMechSystem
|
|||||||
if (component.BatterySlot.ContainedEntity == null && TryComp<BatteryComponent>(args.Used, out var battery))
|
if (component.BatterySlot.ContainedEntity == null && TryComp<BatteryComponent>(args.Used, out var battery))
|
||||||
{
|
{
|
||||||
InsertBattery(uid, args.Used, component, battery);
|
InsertBattery(uid, args.Used, component, battery);
|
||||||
|
_actionBlocker.UpdateCanMove(uid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +106,8 @@ public sealed class MechSystem : SharedMechSystem
|
|||||||
private void OnRemoveBatteryFinished(EntityUid uid, MechComponent component, MechRemoveBatteryFinishedEvent args)
|
private void OnRemoveBatteryFinished(EntityUid uid, MechComponent component, MechRemoveBatteryFinishedEvent args)
|
||||||
{
|
{
|
||||||
component.EntryTokenSource = null;
|
component.EntryTokenSource = null;
|
||||||
|
|
||||||
RemoveBattery(uid, component);
|
RemoveBattery(uid, component);
|
||||||
|
_actionBlocker.UpdateCanMove(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnRemoveBatteryCancelled(EntityUid uid, MechComponent component, MechRemoveBatteryCancelledEvent args)
|
private void OnRemoveBatteryCancelled(EntityUid uid, MechComponent component, MechRemoveBatteryCancelledEvent args)
|
||||||
@@ -119,6 +132,7 @@ public sealed class MechSystem : SharedMechSystem
|
|||||||
InsertBattery(uid, battery, component);
|
InsertBattery(uid, battery, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_actionBlocker.UpdateCanMove(uid);
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,6 +226,7 @@ public sealed class MechSystem : SharedMechSystem
|
|||||||
{
|
{
|
||||||
component.EntryTokenSource = null;
|
component.EntryTokenSource = null;
|
||||||
TryInsert(uid, args.User, component);
|
TryInsert(uid, args.User, component);
|
||||||
|
_actionBlocker.UpdateCanMove(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnExitFinished(EntityUid uid, MechComponent component, MechExitFinishedEvent args)
|
private void OnExitFinished(EntityUid uid, MechComponent component, MechExitFinishedEvent args)
|
||||||
@@ -345,6 +360,7 @@ public sealed class MechSystem : SharedMechSystem
|
|||||||
base.BreakMech(uid, component);
|
base.BreakMech(uid, component);
|
||||||
|
|
||||||
_ui.TryCloseAll(uid, MechUiKey.Key);
|
_ui.TryCloseAll(uid, MechUiKey.Key);
|
||||||
|
_actionBlocker.UpdateCanMove(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool TryChangeEnergy(EntityUid uid, FixedPoint2 delta, SharedMechComponent? component = null)
|
public override bool TryChangeEnergy(EntityUid uid, FixedPoint2 delta, SharedMechComponent? component = null)
|
||||||
@@ -369,6 +385,7 @@ public sealed class MechSystem : SharedMechSystem
|
|||||||
component.Energy = batteryComp.CurrentCharge;
|
component.Energy = batteryComp.CurrentCharge;
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
}
|
}
|
||||||
|
_actionBlocker.UpdateCanMove(uid);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,6 +401,8 @@ public sealed class MechSystem : SharedMechSystem
|
|||||||
component.Energy = battery.CurrentCharge;
|
component.Energy = battery.CurrentCharge;
|
||||||
component.MaxEnergy = battery.MaxCharge;
|
component.MaxEnergy = battery.MaxCharge;
|
||||||
|
|
||||||
|
_actionBlocker.UpdateCanMove(uid);
|
||||||
|
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
UpdateUserInterface(uid, component);
|
UpdateUserInterface(uid, component);
|
||||||
}
|
}
|
||||||
@@ -397,6 +416,8 @@ public sealed class MechSystem : SharedMechSystem
|
|||||||
component.Energy = 0;
|
component.Energy = 0;
|
||||||
component.MaxEnergy = 0;
|
component.MaxEnergy = 0;
|
||||||
|
|
||||||
|
_actionBlocker.UpdateCanMove(uid);
|
||||||
|
|
||||||
Dirty(component);
|
Dirty(component);
|
||||||
UpdateUserInterface(uid, component);
|
UpdateUserInterface(uid, component);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user