using Content.Shared._Sunrise.ThermalVision; using Content.Shared.Eye.Blinding.Components; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Client.Player; using Robust.Shared.Player; using Robust.Shared.Prototypes; namespace Content.Client._Sunrise.ThermalVision; public sealed class ThermalVisionSystem : EntitySystem { [Dependency] private readonly IPlayerManager _player = default!; [Dependency] private readonly IOverlayManager _overlayMan = default!; [Dependency] private readonly TransformSystem _xformSys = default!; private ThroughWallsVisionOverlay _throughWallsOverlay = default!; private ThermalVisionOverlay _overlay = default!; private EntityUid? _effect = null; private readonly EntProtoId _effectPrototype = "EffectThermalVision"; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnVisionInit); SubscribeLocalEvent(OnVisionShutdown); SubscribeLocalEvent(OnPlayerAttached); SubscribeLocalEvent(OnPlayerDetached); _throughWallsOverlay = new(); _overlay = new(); } private void OnPlayerAttached(Entity ent, ref LocalPlayerAttachedEvent args) { if (_effect == null) AddNightVision(ent.Owner); else if (HasComp(ent.Owner)) RemoveNightVision(); } private void OnPlayerDetached(Entity ent, ref LocalPlayerDetachedEvent args) { RemoveNightVision(); } private void OnVisionInit(Entity ent, ref ComponentInit args) { if (_player.LocalEntity != ent.Owner) return; if (_effect == null) AddNightVision(ent.Owner); else if (HasComp(ent.Owner)) RemoveNightVision(); } private void OnVisionShutdown(Entity ent, ref ComponentShutdown args) { if (_player.LocalEntity != ent.Owner) return; RemoveNightVision(); } private void AddNightVision(EntityUid uid) { if (HasComp(uid)) return; _overlayMan.AddOverlay(_throughWallsOverlay); _overlayMan.AddOverlay(_overlay); _effect = SpawnAttachedTo(_effectPrototype, Transform(uid).Coordinates); _xformSys.SetParent(_effect.Value, uid); } private void RemoveNightVision() { _overlayMan.RemoveOverlay(_throughWallsOverlay); _overlayMan.RemoveOverlay(_overlay); Del(_effect); _effect = null; } }