From 03b7a8a6bfbbc13bc9b7bd27fe414086500592be Mon Sep 17 00:00:00 2001 From: Piras314 Date: Wed, 15 Jan 2025 14:26:34 -0500 Subject: [PATCH] Fix Night Vision (#1554) # Description Fixes the bug where you could put a mouse on your head and get free night vision. This works by adding a bool to the SwitchableVisionOverlayComponent `IsEquipment` that will be checked for before granting the thermal/night vision action. Port of https://github.com/Goob-Station/Goob-Station/pull/1448 ---

Media

No night vision with the mouse on your head: ![image](https://github.com/user-attachments/assets/ccde942c-7f08-405f-9215-b904e0d4dd6a) Goggles still work: ![image](https://github.com/user-attachments/assets/a7c7e0f4-b49b-4255-86e3-511441234f02)

--- # Changelog :cl: Piras314, Aviu - fix: Fixed being able to get night vision from putting a mouse on your head. --------- Signed-off-by: VMSolidus Co-authored-by: Aviu00 <93730715+Aviu00@users.noreply.github.com> Co-authored-by: VMSolidus --- Content.Client/Overlays/EquipmentHudSystem.cs | 3 ++- .../Overlays/Switchable/NightVisionSystem.cs | 21 ++++++++++++++++++ .../Switchable/ThermalVisionOverlay.cs | 4 ++-- .../Switchable/ThermalVisionSystem.cs | 22 +++++++++++++++++++ .../Switchable/SwitchableOverlayComponent.cs | 6 +++++ .../Switchable/SwitchableOverlaySystem.cs | 12 ++++++---- .../Entities/Clothing/Eyes/glasses.yml | 1 + .../Entities/Clothing/Eyes/goggles.yml | 2 ++ .../Clothing/Head/hardsuit-helmets.yml | 1 + .../Entities/Clothing/Cult/armor.yml | 1 + 10 files changed, 66 insertions(+), 7 deletions(-) diff --git a/Content.Client/Overlays/EquipmentHudSystem.cs b/Content.Client/Overlays/EquipmentHudSystem.cs index 3672892ae3b..1e36f0a4d63 100644 --- a/Content.Client/Overlays/EquipmentHudSystem.cs +++ b/Content.Client/Overlays/EquipmentHudSystem.cs @@ -93,7 +93,8 @@ private void OnRoundRestart(RoundRestartCleanupEvent args) protected virtual void OnRefreshEquipmentHud(EntityUid uid, T component, InventoryRelayedEvent> args) { - OnRefreshComponentHud(uid, component, args.Args); + args.Args.Active = true; + args.Args.Components.Add(component); } protected virtual void OnRefreshComponentHud(EntityUid uid, T component, RefreshEquipmentHudEvent args) diff --git a/Content.Client/Overlays/Switchable/NightVisionSystem.cs b/Content.Client/Overlays/Switchable/NightVisionSystem.cs index c85b3758d8e..7764e39a0a8 100644 --- a/Content.Client/Overlays/Switchable/NightVisionSystem.cs +++ b/Content.Client/Overlays/Switchable/NightVisionSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared.Inventory; using Content.Shared.Inventory.Events; using Content.Shared.Overlays.Switchable; using Robust.Client.Graphics; @@ -20,6 +21,26 @@ public override void Initialize() _overlay = new BaseSwitchableOverlay(); } + protected override void OnRefreshComponentHud(EntityUid uid, + NightVisionComponent component, + RefreshEquipmentHudEvent args) + { + if (component.IsEquipment) + return; + + base.OnRefreshComponentHud(uid, component, args); + } + + protected override void OnRefreshEquipmentHud(EntityUid uid, + NightVisionComponent component, + InventoryRelayedEvent> args) + { + if (!component.IsEquipment) + return; + + base.OnRefreshEquipmentHud(uid, component, args); + } + private void OnToggle(Entity ent, ref SwitchableOverlayToggledEvent args) { RefreshOverlay(args.User); diff --git a/Content.Client/Overlays/Switchable/ThermalVisionOverlay.cs b/Content.Client/Overlays/Switchable/ThermalVisionOverlay.cs index eb12b33e3a7..010d1411702 100644 --- a/Content.Client/Overlays/Switchable/ThermalVisionOverlay.cs +++ b/Content.Client/Overlays/Switchable/ThermalVisionOverlay.cs @@ -143,9 +143,9 @@ private bool CanSee(EntityUid uid, SpriteComponent sprite) _stealth.GetVisibility(uid, stealth) > 0.5f); } - public void ResetLight() + public void ResetLight(bool checkFirstTimePredicted = true) { - if (_lightEntity == null || !_timing.IsFirstTimePredicted) + if (_lightEntity == null || checkFirstTimePredicted && !_timing.IsFirstTimePredicted) return; _entity.DeleteEntity(_lightEntity); diff --git a/Content.Client/Overlays/Switchable/ThermalVisionSystem.cs b/Content.Client/Overlays/Switchable/ThermalVisionSystem.cs index 9b6e5eed0f4..7c3f33d0680 100644 --- a/Content.Client/Overlays/Switchable/ThermalVisionSystem.cs +++ b/Content.Client/Overlays/Switchable/ThermalVisionSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared.Inventory; using Content.Shared.Inventory.Events; using Content.Shared.Overlays.Switchable; using Robust.Client.Graphics; @@ -21,6 +22,26 @@ public override void Initialize() _overlay = new BaseSwitchableOverlay(); } + protected override void OnRefreshComponentHud(EntityUid uid, + ThermalVisionComponent component, + RefreshEquipmentHudEvent args) + { + if (component.IsEquipment) + return; + + base.OnRefreshComponentHud(uid, component, args); + } + + protected override void OnRefreshEquipmentHud(EntityUid uid, + ThermalVisionComponent component, + InventoryRelayedEvent> args) + { + if (!component.IsEquipment) + return; + + base.OnRefreshEquipmentHud(uid, component, args); + } + private void OnToggle(Entity ent, ref SwitchableOverlayToggledEvent args) { RefreshOverlay(args.User); @@ -54,6 +75,7 @@ protected override void DeactivateInternal() { base.DeactivateInternal(); + _thermalOverlay.ResetLight(false); UpdateOverlay(null); UpdateThermalOverlay(null, 0f); } diff --git a/Content.Shared/Overlays/Switchable/SwitchableOverlayComponent.cs b/Content.Shared/Overlays/Switchable/SwitchableOverlayComponent.cs index 8565defe043..8589bdffd97 100644 --- a/Content.Shared/Overlays/Switchable/SwitchableOverlayComponent.cs +++ b/Content.Shared/Overlays/Switchable/SwitchableOverlayComponent.cs @@ -12,6 +12,12 @@ public abstract partial class SwitchableOverlayComponent : BaseOverlayComponent [DataField] public bool DrawOverlay = true; + /// + /// Whether it should grant equipment enhanced vision or is it mob vision + /// + [DataField] + public bool IsEquipment; + /// /// If it is greater than 0, overlay isn't toggled but pulsed instead /// diff --git a/Content.Shared/Overlays/Switchable/SwitchableOverlaySystem.cs b/Content.Shared/Overlays/Switchable/SwitchableOverlaySystem.cs index eb7b230cbc8..9048052a066 100644 --- a/Content.Shared/Overlays/Switchable/SwitchableOverlaySystem.cs +++ b/Content.Shared/Overlays/Switchable/SwitchableOverlaySystem.cs @@ -102,18 +102,22 @@ private void OnHandleState(EntityUid uid, TComp component, ref ComponentHandleSt component.IsActive = state.IsActive; - RaiseSwitchableOverlayToggledEvent(uid, uid, component.IsActive); - RaiseSwitchableOverlayToggledEvent(uid, Transform(uid).ParentUid, component.IsActive); + RaiseSwitchableOverlayToggledEvent(uid, + component.IsEquipment ? Transform(uid).ParentUid : uid, + component.IsActive); } private void OnGetItemActions(Entity ent, ref GetItemActionsEvent args) { - if (ent.Comp.ToggleAction != null && args.SlotFlags is not SlotFlags.POCKET and not null) + if (ent.Comp.IsEquipment && ent.Comp.ToggleAction != null && args.SlotFlags is not SlotFlags.POCKET and not null) args.AddAction(ref ent.Comp.ToggleActionEntity, ent.Comp.ToggleAction); } private void OnShutdown(EntityUid uid, TComp component, ComponentShutdown args) { + if (component.IsEquipment) + return; + _actions.RemoveAction(uid, component.ToggleActionEntity); } @@ -124,7 +128,7 @@ private void OnInit(EntityUid uid, TComp component, ComponentInit args) private void OnMapInit(EntityUid uid, TComp component, MapInitEvent args) { - if (component.ToggleActionEntity == null && component.ToggleAction != null) + if (component is { IsEquipment: false, ToggleActionEntity: null, ToggleAction: not null }) _actions.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction); } diff --git a/Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml b/Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml index cc1442e4e81..69d024ba418 100644 --- a/Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml +++ b/Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml @@ -412,6 +412,7 @@ sprite: Clothing/Eyes/Glasses/ninjavisor.rsi - type: FlashImmunity - type: NightVision + isEquipment: true - type: entity #Fake goggles, the latest in anti-valid hunting technology parent: ClothingEyesBase diff --git a/Resources/Prototypes/Entities/Clothing/Eyes/goggles.yml b/Resources/Prototypes/Entities/Clothing/Eyes/goggles.yml index 4348c87227d..41840b6bf70 100644 --- a/Resources/Prototypes/Entities/Clothing/Eyes/goggles.yml +++ b/Resources/Prototypes/Entities/Clothing/Eyes/goggles.yml @@ -11,6 +11,7 @@ - type: Clothing sprite: Clothing/Eyes/Goggles/nightvision.rsi - type: NightVision + isEquipment: true - type: IdentityBlocker coverage: EYES @@ -77,6 +78,7 @@ - type: Clothing sprite: Clothing/Eyes/Goggles/thermal.rsi - type: ThermalVision + isEquipment: true pulseTime: 2 toggleAction: PulseThermalVision - type: IdentityBlocker diff --git a/Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml b/Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml index 04f796591f8..7b75ad7bb03 100644 --- a/Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml +++ b/Resources/Prototypes/Entities/Clothing/Head/hardsuit-helmets.yml @@ -745,6 +745,7 @@ Radiation: 0.80 Caustic: 0.95 - type: ThermalVision + isEquipment: true color: "#98EEFB" lightRadius: 15 diff --git a/Resources/Prototypes/WhiteDream/Entities/Clothing/Cult/armor.yml b/Resources/Prototypes/WhiteDream/Entities/Clothing/Cult/armor.yml index bdbb4bac46d..88b578cb5ff 100644 --- a/Resources/Prototypes/WhiteDream/Entities/Clothing/Cult/armor.yml +++ b/Resources/Prototypes/WhiteDream/Entities/Clothing/Cult/armor.yml @@ -115,6 +115,7 @@ - type: EyeProtection - type: NightVision isActive: true + isEquipment: true toggleAction: null activateSound: null deactivateSound: null