From 609e9b8f157435195c969749ce7b4a7b4d90e355 Mon Sep 17 00:00:00 2001 From: Rinary Date: Mon, 21 Oct 2024 21:48:04 +0300 Subject: [PATCH] upd --- .../Systems/NightVisionDeviceSystem.cs | 41 +++++++++++++++++-- .../Clothing/Eyes/night_vision_device.yml | 1 - 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Content.Shared/_Sunrise/Eye/NightVision/Systems/NightVisionDeviceSystem.cs b/Content.Shared/_Sunrise/Eye/NightVision/Systems/NightVisionDeviceSystem.cs index 33ec1e2c517..8a3317b62fb 100644 --- a/Content.Shared/_Sunrise/Eye/NightVision/Systems/NightVisionDeviceSystem.cs +++ b/Content.Shared/_Sunrise/Eye/NightVision/Systems/NightVisionDeviceSystem.cs @@ -4,6 +4,8 @@ using Content.Shared.Actions; using Content.Shared.Inventory.Events; using Content.Shared.Toggleable; +using Content.Shared.PowerCell; +using Content.Shared.PowerCell.Components; using Content.Shared.Popups; using Robust.Shared.Audio.Systems; using Robust.Shared.Network; @@ -20,6 +22,7 @@ public sealed class NightVisionDeviceSystem : EntitySystem [Dependency] private readonly SharedPointLightSystem _light = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; [Dependency] private readonly SharedPopupSystem _popup = default!; + [Dependency] private readonly SharedPowerCellSystem _cell = default!; public override void Initialize() { @@ -27,6 +30,9 @@ public override void Initialize() SubscribeLocalEvent>(OnNVDTrySee); SubscribeLocalEvent(OnNightVisionDeviceUpdateVisuals); + + SubscribeLocalEvent(OnPowerCellChanged); + SubscribeLocalEvent(OnPowerCellSlotEmpty); SubscribeLocalEvent(OnGetActions); SubscribeLocalEvent(OnToggleAction); @@ -56,7 +62,20 @@ private void OnShutdown(EntityUid uid, NightVisionDeviceComponent component, Com { _actionsSystem.RemoveAction(uid, component.ToggleActionEntity); } + + private void OnPowerCellSlotEmpty(Entity ent, ref PowerCellSlotEmptyEvent args) + { + if (ent.Comp.isPowered) + Toggle(ent); + } + private void OnPowerCellChanged(Entity ent, ref PowerCellChangedEvent args) + { + if (args.Ejected || !_powerCell.HasDrawCharge(ent)) + if (ent.Comp.isPowered) + Toggle(ent); + } + private void OnToggleAction(Entity ent, ref ToggleActionEvent args) { if (args.Handled) @@ -68,6 +87,13 @@ private void OnToggleAction(Entity ent, ref ToggleAc return; } + Toggle(ent); + + args.Handled = true; + } + + public void Toggle(Entity ent) + { var updVisEv = new NightVisionDeviceUpdateVisualsEvent(); RaiseLocalEvent(ent, ref updVisEv); @@ -81,15 +107,22 @@ private void OnToggleAction(Entity ent, ref ToggleAc if (!_light.TryGetLight(ent.Owner, out var light)) return; + + var draw = Comp(ent.Owner); + _cell.QueueUpdate((ent.Owner, draw)); + _cell.SetDrawEnabled((ent.Owner, draw), ent.Comp.Activated); _appearance.SetData(ent, ToggleableLightVisuals.Enabled, ent.Comp.Activated); _light.SetEnabled(ent.Owner, ent.Comp.Activated, comp: light); - var changeEv = new NightVisionDeviceToggledEvent(args.Performer); - RaiseLocalEvent(ent.Owner, ref changeEv); - Dirty(ent); + if (TryComp(ent.Owner, out var transform)) + { + var equipped = transform.ParentUid; - args.Handled = true; + var changeEv = new NightVisionDeviceToggledEvent(equipped); + RaiseLocalEvent(ent.Owner, ref changeEv); + } + Dirty(ent); } } diff --git a/Resources/Prototypes/_Sunrise/Entities/Clothing/Eyes/night_vision_device.yml b/Resources/Prototypes/_Sunrise/Entities/Clothing/Eyes/night_vision_device.yml index 4d0e582ce67..10f16f24a68 100644 --- a/Resources/Prototypes/_Sunrise/Entities/Clothing/Eyes/night_vision_device.yml +++ b/Resources/Prototypes/_Sunrise/Entities/Clothing/Eyes/night_vision_device.yml @@ -38,7 +38,6 @@ - type: PowerCellDraw drawRate: 0 useRate: 20 - - type: ToggleCellDraw - type: entity parent: [ClothingEyesNVD,ShowSecurityIcons]