* Use new Subs.CVar helper Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe. This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown. * Fix a bunch of warnings * More warning fixes * Use new DateTime serializer to get rid of ISerializationHooks in changelog code. * Get rid of some more ISerializationHooks for enums * And a little more * Apply suggestions from code review Co-authored-by: 0x6273 <0x40@keemail.me> --------- Co-authored-by: 0x6273 <0x40@keemail.me>
70 lines
2.1 KiB
C#
70 lines
2.1 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 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;
|
|
}
|
|
|
|
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.Equipee);
|
|
}
|
|
|
|
private void OnGlassesUnequipped(Entity<VisionCorrectionComponent> glasses, ref GotUnequippedEvent args)
|
|
{
|
|
UpdateBlurMagnitude(args.Equipee);
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|