mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-22 16:17:00 +03:00
<!-- 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 https://github.com/Goob-Station/Goob-Station/pull/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:  Goggles still work:  </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 --> 🆑 Piras314, Aviu - fix: Fixed being able to get night vision from putting a mouse on your head. --------- Signed-off-by: VMSolidus <evilexecutive@gmail.com> Co-authored-by: Aviu00 <93730715+Aviu00@users.noreply.github.com> Co-authored-by: VMSolidus <evilexecutive@gmail.com> (cherry picked from commit 03b7a8a6bfbbc13bc9b7bd27fe414086500592be)
118 lines
3.7 KiB
C#
118 lines
3.7 KiB
C#
using Content.Shared.Inventory;
|
|
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>();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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();
|
|
|
|
_thermalOverlay.ResetLight(false);
|
|
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>>();
|
|
}
|
|
}
|