Blindness refactor (#15705)
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
using Content.Shared.Eye.Blinding.EyeProtection; // why aren't tools predicted 🙂
|
||||
using Content.Shared.Eye.Blinding;
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Server.Tools;
|
||||
using Content.Shared.Eye.Blinding.Components;
|
||||
using Content.Shared.Eye.Blinding.Systems;
|
||||
using Content.Shared.Tools.Components;
|
||||
|
||||
namespace Content.Server.Eye.Blinding.EyeProtection
|
||||
@@ -12,15 +11,26 @@ namespace Content.Server.Eye.Blinding.EyeProtection
|
||||
public sealed class EyeProtectionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
|
||||
[Dependency] private readonly SharedBlindingSystem _blindingSystem = default!;
|
||||
[Dependency] private readonly BlindableSystem _blindingSystem = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<RequiresEyeProtectionComponent, ToolUseAttemptEvent>(OnUseAttempt);
|
||||
SubscribeLocalEvent<RequiresEyeProtectionComponent, WelderToggledEvent>(OnWelderToggled);
|
||||
|
||||
SubscribeLocalEvent<EyeProtectionComponent, GotEquippedEvent>(OnEquipped);
|
||||
SubscribeLocalEvent<EyeProtectionComponent, GotUnequippedEvent>(OnUnequipped);
|
||||
SubscribeLocalEvent<EyeProtectionComponent, GetEyeProtectionEvent>(OnGetProtection);
|
||||
SubscribeLocalEvent<EyeProtectionComponent, InventoryRelayedEvent<GetEyeProtectionEvent>>(OnGetRelayedProtection);
|
||||
}
|
||||
|
||||
private void OnGetRelayedProtection(EntityUid uid, EyeProtectionComponent component,
|
||||
InventoryRelayedEvent<GetEyeProtectionEvent> args)
|
||||
{
|
||||
OnGetProtection(uid, component, args.Args);
|
||||
}
|
||||
|
||||
private void OnGetProtection(EntityUid uid, EyeProtectionComponent component, GetEyeProtectionEvent args)
|
||||
{
|
||||
args.Protection += component.ProtectionTime;
|
||||
}
|
||||
|
||||
private void OnUseAttempt(EntityUid uid, RequiresEyeProtectionComponent component, ToolUseAttemptEvent args)
|
||||
@@ -28,51 +38,26 @@ namespace Content.Server.Eye.Blinding.EyeProtection
|
||||
if (!component.Toggled)
|
||||
return;
|
||||
|
||||
if (!HasComp<StatusEffectsComponent>(args.User) || !TryComp<BlindableComponent>(args.User, out var blindable))
|
||||
if (!TryComp<BlindableComponent>(args.User, out var blindable) || blindable.IsBlind)
|
||||
return;
|
||||
|
||||
if (blindable.Sources > 0)
|
||||
var ev = new GetEyeProtectionEvent();
|
||||
RaiseLocalEvent(args.User, ev);
|
||||
|
||||
var time = (float) (component.StatusEffectTime- ev.Protection).TotalSeconds;
|
||||
if (time <= 0)
|
||||
return;
|
||||
|
||||
var statusTime = (float) component.StatusEffectTime.TotalSeconds - blindable.BlindResistance;
|
||||
|
||||
if (statusTime <= 0)
|
||||
return;
|
||||
|
||||
var statusTimeSpan = TimeSpan.FromSeconds(statusTime * (blindable.EyeDamage + 1));
|
||||
// Add permanent eye damage if they had zero protection, also scale their temporary blindness by how much they already accumulated.
|
||||
if (_statusEffectsSystem.TryAddStatusEffect(args.User, SharedBlindingSystem.BlindingStatusEffect, statusTimeSpan, false, "TemporaryBlindness") && blindable.BlindResistance <= 0)
|
||||
_blindingSystem.AdjustEyeDamage(args.User, 1, blindable);
|
||||
// Add permanent eye damage if they had zero protection, also somewhat scale their temporary blindness by
|
||||
// how much damage they already accumulated.
|
||||
_blindingSystem.AdjustEyeDamage(args.User, 1, blindable);
|
||||
var statusTimeSpan = TimeSpan.FromSeconds(time * MathF.Sqrt(blindable.EyeDamage));
|
||||
_statusEffectsSystem.TryAddStatusEffect(args.User, TemporaryBlindnessSystem.BlindingStatusEffect,
|
||||
statusTimeSpan, false, TemporaryBlindnessSystem.BlindingStatusEffect);
|
||||
}
|
||||
private void OnWelderToggled(EntityUid uid, RequiresEyeProtectionComponent component, WelderToggledEvent args)
|
||||
{
|
||||
component.Toggled = args.WelderOn;
|
||||
}
|
||||
|
||||
private void OnEquipped(EntityUid uid, EyeProtectionComponent component, GotEquippedEvent args)
|
||||
{
|
||||
if (!TryComp<ClothingComponent>(uid, out var clothing) || clothing.Slots == SlotFlags.PREVENTEQUIP)
|
||||
return;
|
||||
|
||||
if (!clothing.Slots.HasFlag(args.SlotFlags))
|
||||
return;
|
||||
|
||||
component.IsActive = true;
|
||||
if (!TryComp<BlindableComponent>(args.Equipee, out var blindComp))
|
||||
return;
|
||||
|
||||
blindComp.BlindResistance += (float) component.ProtectionTime.TotalSeconds;
|
||||
}
|
||||
|
||||
private void OnUnequipped(EntityUid uid, EyeProtectionComponent component, GotUnequippedEvent args)
|
||||
{
|
||||
if (!component.IsActive)
|
||||
return;
|
||||
component.IsActive = false;
|
||||
if (!TryComp<BlindableComponent>(args.Equipee, out var blindComp))
|
||||
return;
|
||||
|
||||
blindComp.BlindResistance -= (float) component.ProtectionTime.TotalSeconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user