Eye damage (#10262)

This commit is contained in:
Rane
2022-08-14 01:59:14 -04:00
committed by GitHub
parent ef924faae7
commit 572a4f7fb3
39 changed files with 653 additions and 20 deletions

View File

@@ -12,6 +12,24 @@ namespace Content.Shared.Eye.Blinding
[DataField("sources")]
public int Sources = 0;
/// <summary>
/// How many seconds will be subtracted from each attempt to add blindness to us?
/// </summary>
[DataField("blindResistance")]
public float BlindResistance = 0;
/// <summary>
/// Replace with actual eye damage after bobby I guess
/// </summary>
[ViewVariables]
public int EyeDamage = 0;
/// <summary>
/// Whether eye damage has accumulated enough to blind them.
/// <summary>
[ViewVariables]
public bool EyeTooDamaged = false;
/// <description>
/// Used to ensure that this doesn't break with sandbox or admin tools.
/// This is not "enabled/disabled".

View File

@@ -0,0 +1,14 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Eye.Blinding
{
[RegisterComponent]
[NetworkedComponent]
public sealed class BlurryVisionComponent : Component
{
[DataField("mangitude")]
public float Magnitude = 1f;
public bool Active => Magnitude < 10f;
}
}

View File

@@ -0,0 +1,18 @@
namespace Content.Shared.Eye.Blinding.EyeProtection
{
/// <summary>
/// For welding masks, sunglasses, etc.
/// </summary>
[RegisterComponent]
public sealed class EyeProtectionComponent : Component
{
/// <summary>
/// How many seconds to subtract from the status effect. If it's greater than the source
/// of blindness, do not blind.
/// </summary>
[DataField("protectionTime")]
public TimeSpan ProtectionTime = TimeSpan.FromSeconds(10);
public bool IsActive = false;
}
}

View File

@@ -0,0 +1,21 @@
namespace Content.Shared.Eye.Blinding.EyeProtection
{
/// <summary>
/// For tools like welders that will damage your eyes when you use them.
/// </summary>
[RegisterComponent]
public sealed class RequiresEyeProtectionComponent : Component
{
/// <summary>
/// How long to apply temporary blindness to the user.
/// </summary>
[DataField("statusEffectTime")]
public TimeSpan StatusEffectTime = TimeSpan.FromSeconds(10);
/// <summary>
/// You probably want to turn this on in yaml if it's something always on and not a welder.
/// </summary>
[DataField("toggled")]
public bool Toggled = false;
}
}

View File

@@ -1,18 +1,28 @@
using Content.Shared.Clothing.Components;
using Content.Shared.Inventory.Events;
using Content.Shared.Inventory;
using Content.Shared.Item;
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
using JetBrains.Annotations;
namespace Content.Shared.Eye.Blinding
{
public sealed class SharedBlindingSystem : EntitySystem
{
public const string BlindingStatusEffect = "TemporaryBlindness";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BlindfoldComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<BlindfoldComponent, GotUnequippedEvent>(OnUnequipped);
SubscribeLocalEvent<VisionCorrectionComponent, GotEquippedEvent>(OnGlassesEquipped);
SubscribeLocalEvent<VisionCorrectionComponent, GotUnequippedEvent>(OnGlassesUnequipped);
SubscribeLocalEvent<BlurryVisionComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<TemporaryBlindnessComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<TemporaryBlindnessComponent, ComponentShutdown>(OnShutdown);
}
private void OnEquipped(EntityUid uid, BlindfoldComponent component, GotEquippedEvent args)
@@ -39,6 +49,46 @@ namespace Content.Shared.Eye.Blinding
AdjustBlindSources(args.Equipee, false, blindComp);
}
private void OnGlassesEquipped(EntityUid uid, VisionCorrectionComponent component, GotEquippedEvent args)
{
if (!TryComp<SharedClothingComponent>(uid, out var clothing) || clothing.Slots == SlotFlags.PREVENTEQUIP) // we live in a society
return;
// Is the clothing in its actual slot?
if (!clothing.Slots.HasFlag(args.SlotFlags))
return;
if (!TryComp<BlurryVisionComponent>(args.Equipee, out var blur))
return;
component.IsActive = true;
blur.Magnitude += component.VisionBonus;
blur.Dirty();
}
private void OnGlassesUnequipped(EntityUid uid, VisionCorrectionComponent component, GotUnequippedEvent args)
{
if (!component.IsActive || !TryComp<BlurryVisionComponent>(args.Equipee, out var blur))
return;
component.IsActive = false;
blur.Magnitude -= component.VisionBonus;
blur.Dirty();
}
private void OnGetState(EntityUid uid, BlurryVisionComponent component, ref ComponentGetState args)
{
args.State = new BlurryVisionComponentState(component.Magnitude);
}
private void OnInit(EntityUid uid, TemporaryBlindnessComponent component, ComponentInit args)
{
AdjustBlindSources(uid, true);
}
private void OnShutdown(EntityUid uid, TemporaryBlindnessComponent component, ComponentShutdown args)
{
AdjustBlindSources(uid, false);
}
[PublicAPI]
public void AdjustBlindSources(EntityUid uid, bool Add, BlindableComponent? blindable = null)
{
@@ -52,6 +102,56 @@ namespace Content.Shared.Eye.Blinding
{
blindable.Sources--;
}
blindable.Sources = Math.Max(blindable.Sources, 0);
}
public void AdjustEyeDamage(EntityUid uid, bool add, BlindableComponent? blindable = null)
{
if (!Resolve(uid, ref blindable, false))
return;
if (add)
{
blindable.EyeDamage++;
} else
{
blindable.EyeDamage--;
}
if (blindable.EyeDamage > 0)
{
var blurry = EnsureComp<BlurryVisionComponent>(uid);
blurry.Magnitude = (9 - blindable.EyeDamage);
blurry.Dirty();
} else
{
RemComp<BlurryVisionComponent>(uid);
}
if (!blindable.EyeTooDamaged && blindable.EyeDamage >= 8)
{
blindable.EyeTooDamaged = true;
AdjustBlindSources(uid, true, blindable);
}
if (blindable.EyeTooDamaged && blindable.EyeDamage < 8)
{
blindable.EyeTooDamaged = false;
AdjustBlindSources(uid, false, blindable);
}
blindable.EyeDamage = Math.Clamp(blindable.EyeDamage, 0, 8);
}
}
// I have no idea why blurry vision needs this but blindness doesn't
[Serializable, NetSerializable]
public sealed class BlurryVisionComponentState : ComponentState
{
public float Magnitude;
public BlurryVisionComponentState(float magnitude)
{
Magnitude = magnitude;
}
}
}

View File

@@ -0,0 +1,11 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Eye.Blinding
{
/// <summary>
/// Blind status effect.
/// </summary>
[NetworkedComponent, RegisterComponent]
public sealed class TemporaryBlindnessComponent : Component
{}
}

View File

@@ -0,0 +1,15 @@
using Robust.Shared.GameStates;
namespace Content.Shared.Eye.Blinding
{
[RegisterComponent]
[NetworkedComponent]
public sealed class VisionCorrectionComponent : Component
{
[ViewVariables]
public bool IsActive = false;
[DataField("visionBonus")]
public float VisionBonus = 3f;
}
}