Skip to content

Commit

Permalink
Fix Night Vision (#1554)
Browse files Browse the repository at this point in the history
<!--
This is a semi-strict format, you can add/remove sections as needed but
the order/format should be kept the same
Remove these comments before submitting
-->

# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

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
Goob-Station/Goob-Station#1448

---


<!--
This is default collapsed, readers click to expand it and see all your
media
The PR media section can get very large at times, so this is a good way
to keep it clean
The title is written using HTML tags
The title must be within the <summary> tags or you won't see it
-->

<details><summary><h1>Media</h1></summary>
<p>

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)

</p>
</details>

---

# Changelog

<!--
You can add an author after the `:cl:` to change the name that appears
in the changelog (ex: `:cl: Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

:cl: Piras314, Aviu
- fix: Fixed being able to get night vision from putting a mouse on your
head.

---------

Signed-off-by: VMSolidus <[email protected]>
Co-authored-by: Aviu00 <[email protected]>
Co-authored-by: VMSolidus <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent a58fdc5 commit 03b7a8a
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Content.Client/Overlays/EquipmentHudSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ private void OnRoundRestart(RoundRestartCleanupEvent args)

protected virtual void OnRefreshEquipmentHud(EntityUid uid, T component, InventoryRelayedEvent<RefreshEquipmentHudEvent<T>> args)
{
OnRefreshComponentHud(uid, component, args.Args);
args.Args.Active = true;
args.Args.Components.Add(component);
}

protected virtual void OnRefreshComponentHud(EntityUid uid, T component, RefreshEquipmentHudEvent<T> args)
Expand Down
21 changes: 21 additions & 0 deletions Content.Client/Overlays/Switchable/NightVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Overlays.Switchable;
using Robust.Client.Graphics;
Expand All @@ -20,6 +21,26 @@ public override void Initialize()
_overlay = new BaseSwitchableOverlay<NightVisionComponent>();
}

protected override void OnRefreshComponentHud(EntityUid uid,
NightVisionComponent component,
RefreshEquipmentHudEvent<NightVisionComponent> args)
{
if (component.IsEquipment)
return;

base.OnRefreshComponentHud(uid, component, args);
}

protected override void OnRefreshEquipmentHud(EntityUid uid,
NightVisionComponent component,
InventoryRelayedEvent<RefreshEquipmentHudEvent<NightVisionComponent>> args)
{
if (!component.IsEquipment)
return;

base.OnRefreshEquipmentHud(uid, component, args);
}

private void OnToggle(Entity<NightVisionComponent> ent, ref SwitchableOverlayToggledEvent args)
{
RefreshOverlay(args.User);
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Overlays/Switchable/ThermalVisionOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions Content.Client/Overlays/Switchable/ThermalVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Overlays.Switchable;
using Robust.Client.Graphics;
Expand All @@ -21,6 +22,26 @@ public override void Initialize()
_overlay = new BaseSwitchableOverlay<ThermalVisionComponent>();
}

protected override void OnRefreshComponentHud(EntityUid uid,
ThermalVisionComponent component,
RefreshEquipmentHudEvent<ThermalVisionComponent> args)
{
if (component.IsEquipment)
return;

base.OnRefreshComponentHud(uid, component, args);
}

protected override void OnRefreshEquipmentHud(EntityUid uid,
ThermalVisionComponent component,
InventoryRelayedEvent<RefreshEquipmentHudEvent<ThermalVisionComponent>> args)
{
if (!component.IsEquipment)
return;

base.OnRefreshEquipmentHud(uid, component, args);
}

private void OnToggle(Entity<ThermalVisionComponent> ent, ref SwitchableOverlayToggledEvent args)
{
RefreshOverlay(args.User);
Expand Down Expand Up @@ -54,6 +75,7 @@ protected override void DeactivateInternal()
{
base.DeactivateInternal();

_thermalOverlay.ResetLight(false);
UpdateOverlay(null);
UpdateThermalOverlay(null, 0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public abstract partial class SwitchableOverlayComponent : BaseOverlayComponent
[DataField]
public bool DrawOverlay = true;

/// <summary>
/// Whether it should grant equipment enhanced vision or is it mob vision
/// </summary>
[DataField]
public bool IsEquipment;

/// <summary>
/// If it is greater than 0, overlay isn't toggled but pulsed instead
/// </summary>
Expand Down
12 changes: 8 additions & 4 deletions Content.Shared/Overlays/Switchable/SwitchableOverlaySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TComp> 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);
}

Expand All @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Resources/Prototypes/Entities/Clothing/Eyes/goggles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- type: Clothing
sprite: Clothing/Eyes/Goggles/nightvision.rsi
- type: NightVision
isEquipment: true
- type: IdentityBlocker
coverage: EYES

Expand Down Expand Up @@ -77,6 +78,7 @@
- type: Clothing
sprite: Clothing/Eyes/Goggles/thermal.rsi
- type: ThermalVision
isEquipment: true
pulseTime: 2
toggleAction: PulseThermalVision
- type: IdentityBlocker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@
Radiation: 0.80
Caustic: 0.95
- type: ThermalVision
isEquipment: true
color: "#98EEFB"
lightRadius: 15

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
- type: EyeProtection
- type: NightVision
isActive: true
isEquipment: true
toggleAction: null
activateSound: null
deactivateSound: null
Expand Down

0 comments on commit 03b7a8a

Please sign in to comment.