diff --git a/Content.Client/_DV/Silicons/Charge/SiliconChargeSystem.cs b/Content.Client/_DV/Silicons/Charge/SiliconChargeSystem.cs new file mode 100644 index 0000000000..4d0c4b5806 --- /dev/null +++ b/Content.Client/_DV/Silicons/Charge/SiliconChargeSystem.cs @@ -0,0 +1,31 @@ +using Content.Client.Alerts; +using Content.Shared._EE.Silicon.Components; +using Content.Shared._EE.Silicon.Systems; + +namespace Content.Client._DV.Silicon.Charge; + +public sealed class SiliconChargeSystem : SharedSiliconChargeSystem +{ + [Dependency] private readonly ClientAlertsSystem _alerts = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnSiliconInit); + SubscribeLocalEvent(OnSiliconChargeStateUpdate); + } + + private void OnSiliconInit(EntityUid uid, SiliconComponent component, ComponentInit args) + { + if (!component.BatteryPowered) + return; + + _alerts.ShowAlert(uid, component.BatteryAlert, component.ChargeState); + } + + private void OnSiliconChargeStateUpdate(EntityUid uid, SiliconComponent component, SiliconChargeStateUpdateEvent ev) + { + _alerts.ShowAlert(uid, component.BatteryAlert, ev.ChargePercent); + } +} diff --git a/Content.Client/_DV/Silicons/Charge/SiliconDrainSystem.cs b/Content.Client/_DV/Silicons/Charge/SiliconDrainSystem.cs new file mode 100644 index 0000000000..89b34518ae --- /dev/null +++ b/Content.Client/_DV/Silicons/Charge/SiliconDrainSystem.cs @@ -0,0 +1,29 @@ +using Content.Client.Alerts; +using Content.Shared._EE.Silicon.Components; +using Content.Shared._DV.Silicons.Charge; + +namespace Content.Client._DV.Silicon.Charge; + +public sealed class SiliconDrainSystem : SharedSiliconDrainSystem +{ + [Dependency] private readonly ClientAlertsSystem _alerts = default!; + + protected override void UpdateChargeIcon(Entity ent, short chargePercent) + { + // If you can't find a battery, set the indicator and skip it. + if (!TryGetSiliconBattery(ent, out _)) + { + if (_alerts.IsShowingAlert(ent.Owner, ent.Comp.BatteryAlert)) + { + _alerts.ClearAlert(ent.Owner, ent.Comp.BatteryAlert); + _alerts.ShowAlert(ent.Owner, ent.Comp.NoBatteryAlert); + } + } + // If the battery was replaced and the no battery indicator is showing, replace the indicator + else if (_alerts.IsShowingAlert(ent.Owner, ent.Comp.NoBatteryAlert)) + { + _alerts.ClearAlert(ent.Owner, ent.Comp.NoBatteryAlert); + _alerts.ShowAlert(ent.Owner, ent.Comp.BatteryAlert, chargePercent); + } + } +} diff --git a/Content.Server/_DV/Silicons/Charge/SiliconChargeSystem.cs b/Content.Server/_DV/Silicons/Charge/SiliconChargeSystem.cs new file mode 100644 index 0000000000..36ca1a5af4 --- /dev/null +++ b/Content.Server/_DV/Silicons/Charge/SiliconChargeSystem.cs @@ -0,0 +1,5 @@ +using Content.Shared._EE.Silicon.Systems; + +namespace Content.Server._DV.Silicon.Charge; + +public sealed class SiliconChargeSystem : SharedSiliconChargeSystem; diff --git a/Content.Server/_DV/Silicons/Charge/SiliconDrainSystem.cs b/Content.Server/_DV/Silicons/Charge/SiliconDrainSystem.cs new file mode 100644 index 0000000000..7273375f73 --- /dev/null +++ b/Content.Server/_DV/Silicons/Charge/SiliconDrainSystem.cs @@ -0,0 +1,12 @@ +using Content.Shared._DV.Silicons.Charge; +using Content.Shared._EE.Silicon.Components; + +namespace Content.Server._DV.Silicons.Charge; + +public sealed class SiliconDrainSystem : SharedSiliconDrainSystem +{ + protected override void UpdateChargeIcon(Entity ent, short chargePercent) + { + // No-op on Server + } +} diff --git a/Content.Server/_EE/Silicon/DeadStartupButton/DeadStartupButtonSystem.cs b/Content.Server/_EE/Silicon/DeadStartupButton/DeadStartupButtonSystem.cs index 2cca1a65d9..5c00451bbd 100644 --- a/Content.Server/_EE/Silicon/DeadStartupButton/DeadStartupButtonSystem.cs +++ b/Content.Server/_EE/Silicon/DeadStartupButton/DeadStartupButtonSystem.cs @@ -1,7 +1,7 @@ using Content.Server.Chat.Systems; using Content.Server.Lightning; using Content.Server.Popups; -using Content.Shared._DV.Silicons.Charge.Systems; // DeltaV - Moved IPC charge to shared +using Content.Server._DV.Silicons.Charge; // DeltaV - Moved IPC charge to shared and split into server/client using Content.Shared._EE.Silicon.DeadStartupButton; using Content.Shared.Audio; using Content.Shared.Damage; @@ -26,7 +26,7 @@ public sealed class DeadStartupButtonSystem : SharedDeadStartupButtonSystem [Dependency] private readonly PopupSystem _popup = default!; [Dependency] private readonly IRobustRandom _robustRandom = default!; [Dependency] private readonly LightningSystem _lightning = default!; - [Dependency] private readonly SiliconChargeSystem _siliconChargeSystem = default!; + [Dependency] private readonly SiliconDrainSystem _siliconChargeSystem = default!; // DeltaV - Renamed type from "Charge" to "Drain" to disambiguate [Dependency] private readonly PowerCellSystem _powerCell = default!; [Dependency] private readonly SharedBatterySystem _battery = default!; diff --git a/Content.Server/_EE/Silicon/Death/Systems/SiliconChargeDeathSystem.cs b/Content.Server/_EE/Silicon/Death/Systems/SiliconChargeDeathSystem.cs index 50fb2a3880..92cfcc8fd0 100644 --- a/Content.Server/_EE/Silicon/Death/Systems/SiliconChargeDeathSystem.cs +++ b/Content.Server/_EE/Silicon/Death/Systems/SiliconChargeDeathSystem.cs @@ -1,7 +1,7 @@ using Content.Shared.Power.Components; using Content.Shared._EE.Silicon.Systems; using Content.Shared.Bed.Sleep; -using Content.Shared._DV.Silicons.Charge.Systems; // DeltaV - Moved IPC charge to shared +using Content.Server._DV.Silicons.Charge; // DeltaV - Moved IPC charge to shared and split into server/client using Content.Server.Humanoid; using Content.Shared.Humanoid; @@ -10,7 +10,7 @@ namespace Content.Server._EE.Silicon.Death; public sealed class SiliconDeathSystem : EntitySystem { [Dependency] private readonly SleepingSystem _sleep = default!; - [Dependency] private readonly SiliconChargeSystem _silicon = default!; + [Dependency] private readonly SiliconDrainSystem _silicon = default!; // DeltaV - Renamed type from "Charge" to "Drain" to disambiguate [Dependency] private readonly HumanoidAppearanceSystem _humanoidAppearanceSystem = default!; public override void Initialize() diff --git a/Content.Shared/_DV/Silicons/Charge/Systems/SiliconChargeSystem.cs b/Content.Shared/_DV/Silicons/Charge/SharedSiliconDrainSystem.cs similarity index 88% rename from Content.Shared/_DV/Silicons/Charge/Systems/SiliconChargeSystem.cs rename to Content.Shared/_DV/Silicons/Charge/SharedSiliconDrainSystem.cs index 5ecd88d46e..c015758e3f 100644 --- a/Content.Shared/_DV/Silicons/Charge/Systems/SiliconChargeSystem.cs +++ b/Content.Shared/_DV/Silicons/Charge/SharedSiliconDrainSystem.cs @@ -20,16 +20,15 @@ using Content.Shared.Movement.Components; using Robust.Shared.Physics.Components; // End TheDen -namespace Content.Shared._DV.Silicons.Charge.Systems; +namespace Content.Shared._DV.Silicons.Charge; -public sealed class SiliconChargeSystem : EntitySystem +public abstract class SharedSiliconDrainSystem : EntitySystem { [Dependency] private readonly MobStateSystem _mobState = default!; [Dependency] private readonly MovementSpeedModifierSystem _moveMod = default!; [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IConfigurationManager _config = default!; [Dependency] private readonly PowerCellSystem _powerCell = default!; - [Dependency] private readonly AlertsSystem _alerts = default!; [Dependency] private readonly SharedJetpackSystem _jetpack = default!; // TheDen - IPC Dynamic Power draw [Dependency] private readonly SharedBatterySystem _battery = default!; public override void Initialize() @@ -96,11 +95,6 @@ public sealed class SiliconChargeSystem : EntitySystem if (!TryGetSiliconBattery(silicon, out var batteryComp)) { UpdateChargeState(silicon, 0, siliconComp); - if (_alerts.IsShowingAlert(silicon, siliconComp.BatteryAlert)) - { - _alerts.ClearAlert(silicon, siliconComp.BatteryAlert); - _alerts.ShowAlert(silicon, siliconComp.NoBatteryAlert); - } continue; } @@ -135,12 +129,19 @@ public sealed class SiliconChargeSystem : EntitySystem _powerCell.TryUseCharge(silicon, frameTime * drainRate); // Figure out the current state of the Silicon. - var chargePercent = (short) MathF.Round(_battery.GetCharge(batteryComp.Value.AsNullable()) / batteryComp.Value.Comp.MaxCharge * 10f); + var chargePercent = (short)MathF.Round(_battery.GetCharge(batteryComp.Value.AsNullable()) / batteryComp.Value.Comp.MaxCharge * 10f); UpdateChargeState(silicon, chargePercent, siliconComp); } } + /// + ///Makes sure the entity is showing the right charge alert + /// + /// The silicon whose charge to check + /// Charge level, normalized to range 0-100 + protected abstract void UpdateChargeIcon(Entity ent, short chargePercent); + /// /// Checks if anything needs to be updated, and updates it. /// @@ -151,13 +152,7 @@ public sealed class SiliconChargeSystem : EntitySystem RaiseLocalEvent(uid, new SiliconChargeStateUpdateEvent(chargePercent)); _moveMod.RefreshMovementSpeedModifiers(uid); - - // If the battery was replaced and the no battery indicator is showing, replace the indicator - if (_alerts.IsShowingAlert(uid, component.NoBatteryAlert) && chargePercent != 0) - { - _alerts.ClearAlert(uid, component.NoBatteryAlert); - _alerts.ShowAlert(uid, component.BatteryAlert, chargePercent); - } + UpdateChargeIcon((uid, component), chargePercent); } // TheDen - IPC Dynamic Power draw diff --git a/Content.Shared/_EE/Silicon/SharedSiliconSystem.cs b/Content.Shared/_EE/Silicon/SharedSiliconSystem.cs index a92b271c29..dcd20ea06f 100644 --- a/Content.Shared/_EE/Silicon/SharedSiliconSystem.cs +++ b/Content.Shared/_EE/Silicon/SharedSiliconSystem.cs @@ -9,17 +9,19 @@ using Content.Shared.PowerCell.Components; namespace Content.Shared._EE.Silicon.Systems; -public sealed class SharedSiliconChargeSystem : EntitySystem +public abstract class SharedSiliconChargeSystem : EntitySystem // DeltaV - Make class abstract to split into Client/Server { - [Dependency] private readonly AlertsSystem _alertsSystem = default!; + // [Dependency] private readonly AlertsSystem _alertsSystem = default!; // DeltaV - Moved alert handling to Client [Dependency] private readonly ItemSlotsSystem _itemSlots = default!; public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnSiliconInit); - SubscribeLocalEvent(OnSiliconChargeStateUpdate); + // Begin DeltaV - Moved alert handling to Client + // SubscribeLocalEvent(OnSiliconInit); + // SubscribeLocalEvent(OnSiliconChargeStateUpdate); + // End DeltaV - Moved alert handling to Client SubscribeLocalEvent(OnRefreshMovespeed); SubscribeLocalEvent(OnItemSlotInsertAttempt); SubscribeLocalEvent(OnItemSlotEjectAttempt); @@ -48,18 +50,20 @@ public sealed class SharedSiliconChargeSystem : EntitySystem args.Cancelled = true; } - private void OnSiliconInit(EntityUid uid, SiliconComponent component, ComponentInit args) - { - if (!component.BatteryPowered) - return; + // Begin DeltaV - Moved alert handling to Client + // private void OnSiliconInit(EntityUid uid, SiliconComponent component, ComponentInit args) + // { + // if (!component.BatteryPowered) + // return; - _alertsSystem.ShowAlert(uid, component.BatteryAlert, component.ChargeState); - } + // _alertsSystem.ShowAlert(uid, component.BatteryAlert, component.ChargeState); + // } - private void OnSiliconChargeStateUpdate(EntityUid uid, SiliconComponent component, SiliconChargeStateUpdateEvent ev) - { - _alertsSystem.ShowAlert(uid, component.BatteryAlert, ev.ChargePercent); - } + // private void OnSiliconChargeStateUpdate(EntityUid uid, SiliconComponent component, SiliconChargeStateUpdateEvent ev) + // { + // _alertsSystem.ShowAlert(uid, component.BatteryAlert, ev.ChargePercent); + // } + // End DeltaV - Moved alert handling to Client private void OnRefreshMovespeed(EntityUid uid, SiliconComponent component, RefreshMovementSpeedModifiersEvent args) {