CatStation/Content.Shared/Eye/Blinding/Systems/BlurryVisionSystem.cs
DrSmugleaf 65f5f67cd5
Make every EntitySystem partial (#45220)
* Make every EntitySystem partial

* Oobs thats for a diff PR

* Also oops on that one

* Test systems

* git are we fr

* Update file templates

* cleanup empty classes while we are here

* forgor

---------

Co-authored-by: AJCM-git <ajcm_mail@disroot.org>
2026-08-14 18:24:47 +00:00

73 lines
2.3 KiB
C#

using Content.Shared.Eye.Blinding.Components;
using Content.Shared.Inventory.Events;
using Content.Shared.Inventory;
namespace Content.Shared.Eye.Blinding.Systems;
public sealed partial class BlurryVisionSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<VisionCorrectionComponent, GotEquippedEvent>(OnGlassesEquipped);
SubscribeLocalEvent<VisionCorrectionComponent, GotUnequippedEvent>(OnGlassesUnequipped);
SubscribeLocalEvent<VisionCorrectionComponent, InventoryRelayedEvent<GetBlurEvent>>(OnGetBlur);
}
private void OnGetBlur(Entity<VisionCorrectionComponent> glasses, ref InventoryRelayedEvent<GetBlurEvent> args)
{
args.Args.Blur += glasses.Comp.VisionBonus;
args.Args.CorrectionPower *= glasses.Comp.CorrectionPower;
}
/// <summary>
/// Update a blurry vision component according to a blindable component.
/// </summary>
/// <param name="ent">The entity with the component to update.</param>
public void UpdateBlurMagnitude(Entity<BlindableComponent?> ent)
{
if (!Resolve(ent.Owner, ref ent.Comp, false))
return;
var ev = new GetBlurEvent(ent.Comp.EyeDamage);
RaiseLocalEvent(ent, ev);
var blur = Math.Clamp(ev.Blur, 0, BlurryVisionComponent.MaxMagnitude);
if (blur <= 0)
{
RemCompDeferred<BlurryVisionComponent>(ent);
return;
}
var blurry = EnsureComp<BlurryVisionComponent>(ent);
blurry.Magnitude = blur;
blurry.CorrectionPower = ev.CorrectionPower;
Dirty(ent, blurry);
}
private void OnGlassesEquipped(Entity<VisionCorrectionComponent> glasses, ref GotEquippedEvent args)
{
UpdateBlurMagnitude(args.EquipTarget);
}
private void OnGlassesUnequipped(Entity<VisionCorrectionComponent> glasses, ref GotUnequippedEvent args)
{
UpdateBlurMagnitude(args.EquipTarget);
}
}
public sealed class GetBlurEvent : EntityEventArgs, IInventoryRelayEvent
{
public readonly float BaseBlur;
public float Blur;
public float CorrectionPower = BlurryVisionComponent.DefaultCorrectionPower;
public GetBlurEvent(float blur)
{
Blur = blur;
BaseBlur = blur;
}
public SlotFlags TargetSlots => SlotFlags.HEAD | SlotFlags.MASK | SlotFlags.EYES;
}