From 8910ed791a1cd1bb292c23c4918dc008acd0c77d Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 24 Aug 2024 09:34:02 +0100 Subject: [PATCH 01/10] remove ItemToggle from PowerCellDraw query --- Content.Server/PowerCell/PowerCellSystem.Draw.cs | 8 ++++---- Content.Shared/PowerCell/PowerCellDrawComponent.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Content.Server/PowerCell/PowerCellSystem.Draw.cs b/Content.Server/PowerCell/PowerCellSystem.Draw.cs index 9ebd677f47337b..94e15f2f490127 100644 --- a/Content.Server/PowerCell/PowerCellSystem.Draw.cs +++ b/Content.Server/PowerCell/PowerCellSystem.Draw.cs @@ -14,11 +14,11 @@ public sealed partial class PowerCellSystem public override void Update(float frameTime) { base.Update(frameTime); - var query = EntityQueryEnumerator(); + var query = EntityQueryEnumerator(); - while (query.MoveNext(out var uid, out var comp, out var slot, out var toggle)) + while (query.MoveNext(out var uid, out var comp, out var slot)) { - if (!comp.Enabled || !toggle.Activated) + if (!comp.Enabled || !Toggle.IsActivated(uid)) continue; if (Timing.CurTime < comp.NextUpdateTime) @@ -32,7 +32,7 @@ public override void Update(float frameTime) if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate, battery)) continue; - Toggle.TryDeactivate((uid, toggle)); + Toggle.TryDeactivate(uid, predicted: false); var ev = new PowerCellSlotEmptyEvent(); RaiseLocalEvent(uid, ref ev); diff --git a/Content.Shared/PowerCell/PowerCellDrawComponent.cs b/Content.Shared/PowerCell/PowerCellDrawComponent.cs index 94de7c77878375..791745c34722e1 100644 --- a/Content.Shared/PowerCell/PowerCellDrawComponent.cs +++ b/Content.Shared/PowerCell/PowerCellDrawComponent.cs @@ -8,7 +8,7 @@ namespace Content.Shared.PowerCell; /// /// /// With ActivatableUI it will activate and deactivate when the ui is opened and closed, drawing power inbetween. -/// Requires to work. +/// If it has it must also be toggled to work. /// [RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause] public sealed partial class PowerCellDrawComponent : Component From 153acd12cd7c708d431e46092ee13d014fa78450 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 24 Aug 2024 09:45:37 +0100 Subject: [PATCH 02/10] add EntityQuery for resolves, make them all optional --- Content.Shared/Item/ItemToggle/ItemToggleSystem.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Content.Shared/Item/ItemToggle/ItemToggleSystem.cs b/Content.Shared/Item/ItemToggle/ItemToggleSystem.cs index 6b969d1d62b7ed..37d55a0c835e3e 100644 --- a/Content.Shared/Item/ItemToggle/ItemToggleSystem.cs +++ b/Content.Shared/Item/ItemToggle/ItemToggleSystem.cs @@ -23,10 +23,14 @@ public sealed class ItemToggleSystem : EntitySystem [Dependency] private readonly SharedPointLightSystem _light = default!; [Dependency] private readonly SharedPopupSystem _popup = default!; + private EntityQuery _query; + public override void Initialize() { base.Initialize(); + _query = GetEntityQuery(); + SubscribeLocalEvent(OnStartup); SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(TurnOffOnUnwielded); @@ -69,7 +73,7 @@ private void OnUseInHand(Entity ent, ref UseInHandEvent arg /// Same as public bool Toggle(Entity ent, EntityUid? user = null, bool predicted = true) { - if (!Resolve(ent, ref ent.Comp)) + if (!_query.Resolve(ent, ref ent.Comp, false)) return false; return TrySetActive(ent, !ent.Comp.Activated, user, predicted); @@ -92,7 +96,7 @@ public bool TrySetActive(Entity ent, bool active, EntityUi /// public bool TryActivate(Entity ent, EntityUid? user = null, bool predicted = true) { - if (!Resolve(ent, ref ent.Comp)) + if (!_query.Resolve(ent, ref ent.Comp, false)) return false; var uid = ent.Owner; @@ -135,7 +139,7 @@ public bool TryActivate(Entity ent, EntityUid? user = null /// public bool TryDeactivate(Entity ent, EntityUid? user = null, bool predicted = true) { - if (!Resolve(ent, ref ent.Comp)) + if (!_query.Resolve(ent, ref ent.Comp, false)) return false; var uid = ent.Owner; @@ -230,7 +234,7 @@ private void TurnOnOnWielded(Entity ent, ref ItemWieldedEve public bool IsActivated(Entity ent) { - if (!Resolve(ent, ref ent.Comp, false)) + if (!_query.Resolve(ent, ref ent.Comp, false)) return true; // assume always activated if no component return ent.Comp.Activated; From 34a0947b8101f3714b30b1caed4fcd0ef301ddd6 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 24 Aug 2024 10:12:38 +0100 Subject: [PATCH 03/10] move integration to ToggleCellDraw --- .../PowerCell/PowerCellSystem.Draw.cs | 10 ++--- .../Components/ToggleCellDrawComponent.cs | 10 +++++ .../PowerCell/PowerCellDrawComponent.cs | 4 +- .../PowerCell/SharedPowerCellSystem.cs | 21 +++------ .../PowerCell/ToggleCellDrawSystem.cs | 43 +++++++++++++++++++ 5 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 Content.Shared/PowerCell/Components/ToggleCellDrawComponent.cs create mode 100644 Content.Shared/PowerCell/ToggleCellDrawSystem.cs diff --git a/Content.Server/PowerCell/PowerCellSystem.Draw.cs b/Content.Server/PowerCell/PowerCellSystem.Draw.cs index 94e15f2f490127..ae43b6dae9d2fa 100644 --- a/Content.Server/PowerCell/PowerCellSystem.Draw.cs +++ b/Content.Server/PowerCell/PowerCellSystem.Draw.cs @@ -1,5 +1,4 @@ using Content.Server.Power.Components; -using Content.Shared.Item.ItemToggle.Components; using Content.Shared.PowerCell; using Content.Shared.PowerCell.Components; @@ -18,7 +17,7 @@ public override void Update(float frameTime) while (query.MoveNext(out var uid, out var comp, out var slot)) { - if (!comp.Enabled || !Toggle.IsActivated(uid)) + if (!comp.Enabled) continue; if (Timing.CurTime < comp.NextUpdateTime) @@ -32,8 +31,6 @@ public override void Update(float frameTime) if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate, battery)) continue; - Toggle.TryDeactivate(uid, predicted: false); - var ev = new PowerCellSlotEmptyEvent(); RaiseLocalEvent(uid, ref ev); } @@ -60,7 +57,10 @@ private void OnDrawCellChanged(EntityUid uid, PowerCellDrawComponent component, var canUse = !args.Ejected && HasActivatableCharge(uid, component); if (!canDraw) - Toggle.TryDeactivate(uid); + { + var ev = new PowerCellSlotEmptyEvent(); + RaiseLocalEvent(uid, ref ev); + } if (canUse != component.CanUse || canDraw != component.CanDraw) { diff --git a/Content.Shared/PowerCell/Components/ToggleCellDrawComponent.cs b/Content.Shared/PowerCell/Components/ToggleCellDrawComponent.cs new file mode 100644 index 00000000000000..20e2d4fe02ee10 --- /dev/null +++ b/Content.Shared/PowerCell/Components/ToggleCellDrawComponent.cs @@ -0,0 +1,10 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.PowerCell.Components; + +/// +/// Integrate PowerCellDraw and ItemToggle. +/// Make toggling this item require power, and deactivates the item when power runs out. +/// +[RegisterComponent, NetworkedComponent] +public sealed partial class ToggleCellDrawComponent : Component; diff --git a/Content.Shared/PowerCell/PowerCellDrawComponent.cs b/Content.Shared/PowerCell/PowerCellDrawComponent.cs index 791745c34722e1..9c2f72661de74b 100644 --- a/Content.Shared/PowerCell/PowerCellDrawComponent.cs +++ b/Content.Shared/PowerCell/PowerCellDrawComponent.cs @@ -8,7 +8,6 @@ namespace Content.Shared.PowerCell; /// /// /// With ActivatableUI it will activate and deactivate when the ui is opened and closed, drawing power inbetween. -/// If it has it must also be toggled to work. /// [RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause] public sealed partial class PowerCellDrawComponent : Component @@ -30,9 +29,8 @@ public sealed partial class PowerCellDrawComponent : Component #endregion /// - /// Whether drawing is enabled, regardless of ItemToggle. + /// Whether drawing is enabled. /// Having no cell will still disable it. - /// Only use this if you really don't want it to use power for some time. /// [DataField, AutoNetworkedField] public bool Enabled = true; diff --git a/Content.Shared/PowerCell/SharedPowerCellSystem.cs b/Content.Shared/PowerCell/SharedPowerCellSystem.cs index 2b2a836633cc1e..ab05ef5efa9d8a 100644 --- a/Content.Shared/PowerCell/SharedPowerCellSystem.cs +++ b/Content.Shared/PowerCell/SharedPowerCellSystem.cs @@ -1,6 +1,4 @@ using Content.Shared.Containers.ItemSlots; -using Content.Shared.Item.ItemToggle; -using Content.Shared.Item.ItemToggle.Components; using Content.Shared.PowerCell.Components; using Content.Shared.Rejuvenate; using Robust.Shared.Containers; @@ -13,7 +11,6 @@ public abstract class SharedPowerCellSystem : EntitySystem [Dependency] protected readonly IGameTiming Timing = default!; [Dependency] private readonly ItemSlotsSystem _itemSlots = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; - [Dependency] protected readonly ItemToggleSystem Toggle = default!; public override void Initialize() { @@ -23,9 +20,6 @@ public override void Initialize() SubscribeLocalEvent(OnCellInserted); SubscribeLocalEvent(OnCellRemoved); SubscribeLocalEvent(OnCellInsertAttempt); - - SubscribeLocalEvent(OnActivateAttempt); - SubscribeLocalEvent(OnToggled); } private void OnRejuvenate(EntityUid uid, PowerCellSlotComponent component, RejuvenateEvent args) @@ -70,16 +64,13 @@ protected virtual void OnCellRemoved(EntityUid uid, PowerCellSlotComponent compo RaiseLocalEvent(uid, new PowerCellChangedEvent(true), false); } - private void OnActivateAttempt(Entity ent, ref ItemToggleActivateAttemptEvent args) - { - if (!HasDrawCharge(ent, ent.Comp, user: args.User) - || !HasActivatableCharge(ent, ent.Comp, user: args.User)) - args.Cancelled = true; - } - - private void OnToggled(Entity ent, ref ItemToggledEvent args) + /// + /// Makes the draw logic update in the next tick. + /// + public void QueueUpdate(Entity ent) { - ent.Comp.NextUpdateTime = Timing.CurTime; + if (Resolve(ent, ref ent.Comp)) + ent.Comp.NextUpdateTime = Timing.CurTime; } public void SetDrawEnabled(Entity ent, bool enabled) diff --git a/Content.Shared/PowerCell/ToggleCellDrawSystem.cs b/Content.Shared/PowerCell/ToggleCellDrawSystem.cs new file mode 100644 index 00000000000000..c42a1bfb7b31c6 --- /dev/null +++ b/Content.Shared/PowerCell/ToggleCellDrawSystem.cs @@ -0,0 +1,43 @@ +using Content.Shared.Item.ItemToggle; +using Content.Shared.Item.ItemToggle.Components; +using Content.Shared.PowerCell.Components; + +namespace Content.Shared.PowerCell; + +/// +/// Handles events to integrate PowerCellDraw with ItemToggle +/// +public sealed class ToggleCellDrawSystem : EntitySystem +{ + [Dependency] private readonly ItemToggleSystem _toggle = default!; + [Dependency] private readonly SharedPowerCellSystem _cell = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnActivateAttempt); + SubscribeLocalEvent(OnToggled); + SubscribeLocalEvent(OnEmpty); + } + + private void OnActivateAttempt(Entity ent, ref ItemToggleActivateAttemptEvent args) + { + if (!_cell.HasDrawCharge(ent, ent.Comp, user: args.User) + || !_cell.HasActivatableCharge(ent, ent.Comp, user: args.User)) + args.Cancelled = true; + } + + private void OnToggled(Entity ent, ref ItemToggledEvent args) + { + var uid = ent.Owner; + var draw = Comp(uid); + _cell.QueueUpdate((uid, draw)); + _cell.SetDrawEnabled((uid, draw), args.Activated); + } + + private void OnEmpty(Entity ent, ref PowerCellSlotEmptyEvent args) + { + _toggle.TryDeactivate(ent.Owner); + } +} From 1979e352043be3500a8d63222ebe4a58f600d637 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 24 Aug 2024 10:16:36 +0100 Subject: [PATCH 04/10] add ToggleCellDraw to almost every PowerCellDraw prototype --- Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml | 1 + Resources/Prototypes/Entities/Clothing/Shoes/misc.yml | 1 + .../Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml | 1 + Resources/Prototypes/Entities/Objects/Devices/base_handheld.yml | 1 + .../Entities/Objects/Specific/Medical/healthanalyzer.yml | 1 + .../Prototypes/Entities/Objects/Specific/Research/anomaly.yml | 2 ++ .../Prototypes/Entities/Objects/Tools/handheld_mass_scanner.yml | 1 + .../Entities/Objects/Weapons/Guns/Launchers/launchers.yml | 2 ++ 8 files changed, 10 insertions(+) diff --git a/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml b/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml index a04bdde31fbeee..0f1b9536da6118 100644 --- a/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml +++ b/Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml @@ -160,6 +160,7 @@ lastVisibility: 0.1 - type: PowerCellDraw drawRate: 1.8 # 200 seconds on the default cell + - type: ToggleCellDraw # throwing star ability - type: ItemCreator action: ActionCreateThrowingStar diff --git a/Resources/Prototypes/Entities/Clothing/Shoes/misc.yml b/Resources/Prototypes/Entities/Clothing/Shoes/misc.yml index fae8717223806b..ea4c9d9c7cdd78 100644 --- a/Resources/Prototypes/Entities/Clothing/Shoes/misc.yml +++ b/Resources/Prototypes/Entities/Clothing/Shoes/misc.yml @@ -116,6 +116,7 @@ price: 500 - type: PowerCellDraw drawRate: 4 + - type: ToggleCellDraw - type: ItemSlots slots: cell_slot: diff --git a/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml b/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml index b701bbd8f48041..15f34bd81f8a2b 100644 --- a/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml +++ b/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml @@ -126,6 +126,7 @@ # TODO: or just have sentient speedboots be fast idk - type: PowerCellDraw drawRate: 0.6 + # no ToggleCellDraw since dont want to lose access when power is gone - type: ItemSlots slots: cell_slot: diff --git a/Resources/Prototypes/Entities/Objects/Devices/base_handheld.yml b/Resources/Prototypes/Entities/Objects/Devices/base_handheld.yml index 259323fede3d55..c377519ddb4437 100644 --- a/Resources/Prototypes/Entities/Objects/Devices/base_handheld.yml +++ b/Resources/Prototypes/Entities/Objects/Devices/base_handheld.yml @@ -9,3 +9,4 @@ - type: PowerCellDraw drawRate: 0 useRate: 20 + - type: ToggleCellDraw diff --git a/Resources/Prototypes/Entities/Objects/Specific/Medical/healthanalyzer.yml b/Resources/Prototypes/Entities/Objects/Specific/Medical/healthanalyzer.yml index 97a41a50df499e..e3f2e1cd1e7a01 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Medical/healthanalyzer.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Medical/healthanalyzer.yml @@ -47,6 +47,7 @@ components: - type: PowerCellDraw drawRate: 1.2 #Calculated for 5 minutes on a small cell + - type: ToggleCellDraw - type: ActivatableUIRequiresPowerCell - type: entity diff --git a/Resources/Prototypes/Entities/Objects/Specific/Research/anomaly.yml b/Resources/Prototypes/Entities/Objects/Specific/Research/anomaly.yml index 929f509710ec25..ff53218e22259b 100644 --- a/Resources/Prototypes/Entities/Objects/Specific/Research/anomaly.yml +++ b/Resources/Prototypes/Entities/Objects/Specific/Research/anomaly.yml @@ -68,6 +68,7 @@ - type: PowerCellDraw drawRate: 1 useRate: 0 + - type: ToggleCellDraw - type: entity id: AnomalyLocatorEmpty @@ -101,6 +102,7 @@ - type: PowerCellDraw drawRate: 1 useRate: 0 + - type: ToggleCellDraw - type: entity id: AnomalyLocatorWideEmpty diff --git a/Resources/Prototypes/Entities/Objects/Tools/handheld_mass_scanner.yml b/Resources/Prototypes/Entities/Objects/Tools/handheld_mass_scanner.yml index de45119cddd18d..e10c5b84af5f2e 100644 --- a/Resources/Prototypes/Entities/Objects/Tools/handheld_mass_scanner.yml +++ b/Resources/Prototypes/Entities/Objects/Tools/handheld_mass_scanner.yml @@ -26,6 +26,7 @@ False: { visible: false } - type: PowerCellDraw drawRate: 1.5 + - type: ToggleCellDraw - type: ActivatableUI key: enum.RadarConsoleUiKey.Key inHandsOnly: true diff --git a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Launchers/launchers.yml b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Launchers/launchers.yml index 3abb32a37fbd2b..5ea853cd8d141d 100644 --- a/Resources/Prototypes/Entities/Objects/Weapons/Guns/Launchers/launchers.yml +++ b/Resources/Prototypes/Entities/Objects/Weapons/Guns/Launchers/launchers.yml @@ -169,6 +169,7 @@ - type: ItemToggle onUse: false - type: PowerCellDraw + - type: ToggleCellDraw - type: Sprite sprite: Objects/Weapons/Guns/Launchers/tether_gun.rsi layers: @@ -216,6 +217,7 @@ - type: ItemToggle onUse: false - type: PowerCellDraw + - type: ToggleCellDraw - type: Sprite sprite: Objects/Weapons/Guns/Launchers/force_gun.rsi layers: From 0069ba95caf48d09d752bf9da63c6a0785b5db4f Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 24 Aug 2024 10:17:33 +0100 Subject: [PATCH 05/10] :trollface: --- Content.Shared/Item/ItemToggle/ItemToggleSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/Item/ItemToggle/ItemToggleSystem.cs b/Content.Shared/Item/ItemToggle/ItemToggleSystem.cs index 37d55a0c835e3e..1cc8699d70c425 100644 --- a/Content.Shared/Item/ItemToggle/ItemToggleSystem.cs +++ b/Content.Shared/Item/ItemToggle/ItemToggleSystem.cs @@ -23,7 +23,7 @@ public sealed class ItemToggleSystem : EntitySystem [Dependency] private readonly SharedPointLightSystem _light = default!; [Dependency] private readonly SharedPopupSystem _popup = default!; - private EntityQuery _query; + private EntityQuery _query; public override void Initialize() { From f4100b87368c728a7b95b1ea7cb5b974af2ace81 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 24 Aug 2024 10:19:31 +0100 Subject: [PATCH 06/10] :trollface: --- Content.Shared/PowerCell/ToggleCellDrawSystem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Content.Shared/PowerCell/ToggleCellDrawSystem.cs b/Content.Shared/PowerCell/ToggleCellDrawSystem.cs index c42a1bfb7b31c6..9cd14cd3921951 100644 --- a/Content.Shared/PowerCell/ToggleCellDrawSystem.cs +++ b/Content.Shared/PowerCell/ToggleCellDrawSystem.cs @@ -23,8 +23,8 @@ public override void Initialize() private void OnActivateAttempt(Entity ent, ref ItemToggleActivateAttemptEvent args) { - if (!_cell.HasDrawCharge(ent, ent.Comp, user: args.User) - || !_cell.HasActivatableCharge(ent, ent.Comp, user: args.User)) + if (!_cell.HasDrawCharge(ent, user: args.User) + || !_cell.HasActivatableCharge(ent user: args.User)) args.Cancelled = true; } From 725a5d50356c3f694f8ebeb218b49967dfc87f18 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 24 Aug 2024 10:20:15 +0100 Subject: [PATCH 07/10] :trollface: --- Content.Shared/PowerCell/ToggleCellDrawSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/PowerCell/ToggleCellDrawSystem.cs b/Content.Shared/PowerCell/ToggleCellDrawSystem.cs index 9cd14cd3921951..e43830cee4ec1a 100644 --- a/Content.Shared/PowerCell/ToggleCellDrawSystem.cs +++ b/Content.Shared/PowerCell/ToggleCellDrawSystem.cs @@ -24,7 +24,7 @@ public override void Initialize() private void OnActivateAttempt(Entity ent, ref ItemToggleActivateAttemptEvent args) { if (!_cell.HasDrawCharge(ent, user: args.User) - || !_cell.HasActivatableCharge(ent user: args.User)) + || !_cell.HasActivatableCharge(ent, user: args.User)) args.Cancelled = true; } From 52d22eba6573eb3fc392641455d754ce25c68db2 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 24 Aug 2024 10:27:39 +0100 Subject: [PATCH 08/10] let it disable on mapinit --- Content.Shared/PowerCell/ToggleCellDrawSystem.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Content.Shared/PowerCell/ToggleCellDrawSystem.cs b/Content.Shared/PowerCell/ToggleCellDrawSystem.cs index e43830cee4ec1a..6711e734860d0a 100644 --- a/Content.Shared/PowerCell/ToggleCellDrawSystem.cs +++ b/Content.Shared/PowerCell/ToggleCellDrawSystem.cs @@ -16,11 +16,17 @@ public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnActivateAttempt); SubscribeLocalEvent(OnToggled); SubscribeLocalEvent(OnEmpty); } + private void OnMapInit(Entity ent, ref MapInitEvent args) + { + _cell.SetDrawEnabled(uid, _toggle.IsActivated(ent.Owner)); + } + private void OnActivateAttempt(Entity ent, ref ItemToggleActivateAttemptEvent args) { if (!_cell.HasDrawCharge(ent, user: args.User) From a3764ad23c2b6b8e1d622f83ee8f1572d94769ac Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 24 Aug 2024 10:38:58 +0100 Subject: [PATCH 09/10] set update time on mapinit, make borg power logic consistent now --- Content.Server/Silicons/Borgs/BorgSystem.cs | 2 ++ Content.Shared/PowerCell/SharedPowerCellSystem.cs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/Content.Server/Silicons/Borgs/BorgSystem.cs b/Content.Server/Silicons/Borgs/BorgSystem.cs index 3f32afbffbde9b..bd85282a0f5e0a 100644 --- a/Content.Server/Silicons/Borgs/BorgSystem.cs +++ b/Content.Server/Silicons/Borgs/BorgSystem.cs @@ -282,6 +282,7 @@ public void BorgActivate(EntityUid uid, BorgChassisComponent component) { Popup.PopupEntity(Loc.GetString("borg-mind-added", ("name", Identity.Name(uid, EntityManager))), uid); Toggle.TryActivate(uid); + _powerCell.SetDrawEnabled(uid, _mobState.IsAlive(uid)); _appearance.SetData(uid, BorgVisuals.HasPlayer, true); } @@ -292,6 +293,7 @@ public void BorgDeactivate(EntityUid uid, BorgChassisComponent component) { Popup.PopupEntity(Loc.GetString("borg-mind-removed", ("name", Identity.Name(uid, EntityManager))), uid); Toggle.TryDeactivate(uid); + _powerCell.SetDrawEnabled(uid, false); _appearance.SetData(uid, BorgVisuals.HasPlayer, false); } diff --git a/Content.Shared/PowerCell/SharedPowerCellSystem.cs b/Content.Shared/PowerCell/SharedPowerCellSystem.cs index ab05ef5efa9d8a..f098f575c4eac3 100644 --- a/Content.Shared/PowerCell/SharedPowerCellSystem.cs +++ b/Content.Shared/PowerCell/SharedPowerCellSystem.cs @@ -16,12 +16,19 @@ public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnMapInit); + SubscribeLocalEvent(OnRejuvenate); SubscribeLocalEvent(OnCellInserted); SubscribeLocalEvent(OnCellRemoved); SubscribeLocalEvent(OnCellInsertAttempt); } + private void OnMapInit(Entity ent, ref MapInitEvent args) + { + QueueUpdate((ent, ent.Comp)); + } + private void OnRejuvenate(EntityUid uid, PowerCellSlotComponent component, RejuvenateEvent args) { if (!_itemSlots.TryGetSlot(uid, component.CellSlotId, out var itemSlot) || !itemSlot.Item.HasValue) From 195c4db524178958b76779c2084c74375ef21893 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 24 Aug 2024 10:39:15 +0100 Subject: [PATCH 10/10] :trollface: --- Content.Shared/PowerCell/ToggleCellDrawSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/PowerCell/ToggleCellDrawSystem.cs b/Content.Shared/PowerCell/ToggleCellDrawSystem.cs index 6711e734860d0a..070937b8b49ed1 100644 --- a/Content.Shared/PowerCell/ToggleCellDrawSystem.cs +++ b/Content.Shared/PowerCell/ToggleCellDrawSystem.cs @@ -24,7 +24,7 @@ public override void Initialize() private void OnMapInit(Entity ent, ref MapInitEvent args) { - _cell.SetDrawEnabled(uid, _toggle.IsActivated(ent.Owner)); + _cell.SetDrawEnabled(ent.Owner, _toggle.IsActivated(ent.Owner)); } private void OnActivateAttempt(Entity ent, ref ItemToggleActivateAttemptEvent args)