Files
wwdpublic/Content.Client/Overlays/Switchable/ThermalVisionSystem.cs
Spatison 2e649fd74b Night And Thermal Vision (#1462)
<!--
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]?
-->

Port from WWDP. Refactor from
[Goob](https://github.com/Goob-Station/Goob-Station/pull/1251)

---

<!--
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>

![image](https://github.com/user-attachments/assets/ee60eb59-0432-477e-8aee-25a56032e58e)

Night vision goggles:

![image](https://github.com/user-attachments/assets/f9269e1a-97ed-456f-bd45-7015b723fb3e)

Zealot's blindfold:

![image](https://github.com/user-attachments/assets/7c60011e-1d0a-4fb2-92cb-fded8c747555)

Animal vision:

![image](https://github.com/user-attachments/assets/14f1153d-b771-4316-9faa-fee951d884ce)

Thermal vision goggles:

![image](https://github.com/user-attachments/assets/b167ef8b-e1b7-477e-a08d-b217fd2e38c5)

Deathsquad helmet:

![image](https://github.com/user-attachments/assets/2e15ab15-6d23-45c2-b51e-3c16dc3a135d)

Xeno vision:

![image](https://github.com/user-attachments/assets/1677b69e-013f-464a-baaf-af3b5f1b6488)

</p>
</details>

---

# Changelog

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

🆑 @Aviu00, Spatison, @PuroSlavKing
- add: Added night vision goggle
- add: Added thermal vision goggle
- add: Deathsquad helmet now grants night and thermal vision.
- add: Ninja visor now grants night vision.
- tweak: Some animals have gained night vision.
- tweak: Xenos have gained night vision.

---------

Signed-off-by: Spatison <137375981+Spatison@users.noreply.github.com>
Co-authored-by: PuroSlavKing <103608145+puroslavking@users.noreply.github.com>

(cherry picked from commit 0f481422a54a197923f4bf03db1b5733e481965f)
2025-01-14 01:57:25 +03:00

96 lines
3.0 KiB
C#

using Content.Shared.Inventory.Events;
using Content.Shared.Overlays.Switchable;
using Robust.Client.Graphics;
namespace Content.Client.Overlays.Switchable;
public sealed class ThermalVisionSystem : EquipmentHudSystem<ThermalVisionComponent>
{
[Dependency] private readonly IOverlayManager _overlayMan = default!;
private ThermalVisionOverlay _thermalOverlay = default!;
private BaseSwitchableOverlay<ThermalVisionComponent> _overlay = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ThermalVisionComponent, SwitchableOverlayToggledEvent>(OnToggle);
_thermalOverlay = new ThermalVisionOverlay();
_overlay = new BaseSwitchableOverlay<ThermalVisionComponent>();
}
private void OnToggle(Entity<ThermalVisionComponent> ent, ref SwitchableOverlayToggledEvent args)
{
RefreshOverlay(args.User);
}
protected override void UpdateInternal(RefreshEquipmentHudEvent<ThermalVisionComponent> args)
{
base.UpdateInternal(args);
ThermalVisionComponent? tvComp = null;
var lightRadius = 0f;
foreach (var comp in args.Components)
{
if (!comp.IsActive && (comp.PulseTime <= 0f || comp.PulseAccumulator >= comp.PulseTime))
continue;
if (tvComp == null)
tvComp = comp;
else if (!tvComp.DrawOverlay && comp.DrawOverlay)
tvComp = comp;
else if (tvComp.DrawOverlay == comp.DrawOverlay && tvComp.PulseTime > 0f && comp.PulseTime <= 0f)
tvComp = comp;
lightRadius = MathF.Max(lightRadius, comp.LightRadius);
}
UpdateThermalOverlay(tvComp, lightRadius);
UpdateOverlay(tvComp);
}
protected override void DeactivateInternal()
{
base.DeactivateInternal();
UpdateOverlay(null);
UpdateThermalOverlay(null, 0f);
}
private void UpdateThermalOverlay(ThermalVisionComponent? comp, float lightRadius)
{
_thermalOverlay.LightRadius = lightRadius;
_thermalOverlay.Comp = comp;
switch (comp)
{
case not null when !_overlayMan.HasOverlay<ThermalVisionOverlay>():
_overlayMan.AddOverlay(_thermalOverlay);
break;
case null:
_overlayMan.RemoveOverlay(_thermalOverlay);
_thermalOverlay.ResetLight();
break;
}
}
private void UpdateOverlay(ThermalVisionComponent? tvComp)
{
_overlay.Comp = tvComp;
switch (tvComp)
{
case { DrawOverlay: true } when !_overlayMan.HasOverlay<BaseSwitchableOverlay<ThermalVisionComponent>>():
_overlayMan.AddOverlay(_overlay);
break;
case null or { DrawOverlay: false }:
_overlayMan.RemoveOverlay(_overlay);
break;
}
// Night vision overlay is prioritized
_overlay.IsActive = !_overlayMan.HasOverlay<BaseSwitchableOverlay<NightVisionComponent>>();
}
}