mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
* Added night vision status effect added night vision reagent * removed empty line, updated ftl * leaf said no capital letters guh * i hate capital letters * added rad damage and altred recipe. princess said add to felinase * Update Resources/Prototypes/Reagents/narcotics.yml Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com> * Update Resources/Prototypes/Recipes/Reactions/chemicals.yml Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com> * doubled rad damage --------- Co-authored-by: Princess Cheeseballs <66055347+Princess-Cheeseballs@users.noreply.github.com>
135 lines
3.6 KiB
C#
135 lines
3.6 KiB
C#
using Content.Client.Overlays;
|
|
using Content.Shared.GameTicking;
|
|
using Content.Shared.NightVision;
|
|
using Content.Shared.Overlays;
|
|
using Content.Shared.StatusEffectNew;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Content.Client.NightVision;
|
|
|
|
/// <inheritdoc/>
|
|
public sealed partial class NightVisionSystem : SharedNightVisionSystem
|
|
{
|
|
[Dependency] private IOverlayManager _overlayMan = default!;
|
|
[Dependency] private IPlayerManager _player = default!;
|
|
|
|
private NightVisionOverlay _overlay = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
_overlay = new NightVisionOverlay();
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnPlayerAttached(LocalPlayerAttachedEvent args)
|
|
{
|
|
RefreshOverlay(args.Entity);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnPlayerDetached(LocalPlayerDetachedEvent args)
|
|
{
|
|
Deactivate(_player.LocalEntity);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnHandleState(Entity<NightVisionComponent> ent, ref AfterAutoHandleStateEvent args)
|
|
{
|
|
RefreshOverlay(ent);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnCompEquip(Entity<NightVisionComponent> ent, ref StatusEffectAppliedEvent args)
|
|
{
|
|
if (!ent.Comp.RelayOverlay)
|
|
return;
|
|
|
|
RefreshOverlay(args.Target);
|
|
}
|
|
|
|
[SubscribeLocalEvent]
|
|
private void OnCompEquip(Entity<NightVisionComponent> ent, ref StatusEffectRemovedEvent args)
|
|
{
|
|
if (!ent.Comp.RelayOverlay)
|
|
return;
|
|
|
|
RefreshOverlay(args.Target);
|
|
}
|
|
|
|
[SubscribeNetworkEvent]
|
|
private void OnRoundRestart(RoundRestartCleanupEvent args)
|
|
{
|
|
var localPlayer = _player.LocalSession?.AttachedEntity;
|
|
if (localPlayer != null)
|
|
Deactivate(localPlayer.Value);
|
|
}
|
|
|
|
private void Update(EntityUid entity, List<Entity<NightVisionComponent>> entities)
|
|
{
|
|
if (entity != _player.LocalSession?.AttachedEntity)
|
|
return;
|
|
|
|
// Find the component with the lowest noise.
|
|
NightVisionComponent? nvision = null;
|
|
var bestNoise = float.MaxValue;
|
|
foreach (var ent in entities)
|
|
{
|
|
if (!ent.Comp.Enabled)
|
|
continue;
|
|
|
|
if (ent.Comp.RelayOverlay == (ent.Owner == entity))
|
|
continue;
|
|
|
|
if (ent.Comp.Prioritized)
|
|
{
|
|
nvision = ent.Comp;
|
|
break;
|
|
}
|
|
|
|
var noise = ent.Comp.NoiseAmount * ent.Comp.NoiseMultiplier;
|
|
if (noise < bestNoise)
|
|
{
|
|
nvision = ent.Comp;
|
|
bestNoise = noise;
|
|
}
|
|
}
|
|
|
|
// There is no active night vision components, so we disable the overlay.
|
|
if (nvision == null)
|
|
{
|
|
Deactivate(entity);
|
|
return;
|
|
}
|
|
|
|
_overlay.SetParameters(nvision.OverlayColor, nvision.LightingColor, nvision.NoiseAmount, nvision.NoiseMultiplier);
|
|
|
|
if (!_overlayMan.HasOverlay<NightVisionOverlay>())
|
|
_overlayMan.AddOverlay(_overlay);
|
|
}
|
|
|
|
private void Deactivate(EntityUid? ent)
|
|
{
|
|
if (ent != _player.LocalSession?.AttachedEntity)
|
|
return;
|
|
|
|
_overlayMan.RemoveOverlay(_overlay);
|
|
}
|
|
|
|
protected override void RefreshOverlay(EntityUid target)
|
|
{
|
|
if (target != _player.LocalSession?.AttachedEntity)
|
|
return;
|
|
|
|
var ev = new RefreshNightVisionEvent();
|
|
RaiseLocalEvent(target, ref ev);
|
|
|
|
if (ev.Entities.Count > 0)
|
|
Update(target, ev.Entities);
|
|
else
|
|
Deactivate(target);
|
|
}
|
|
}
|