rejuvenate support for eye damage (#12164)
This commit is contained in:
@@ -11,13 +11,14 @@ namespace Content.Server.Chemistry.ReagentEffects
|
||||
public sealed class ChemHealEyeDamage : ReagentEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// Add or remove eye damage?
|
||||
[DataField("add")]
|
||||
public bool Add = false;
|
||||
/// How much eye damage to remove.
|
||||
/// </summary>
|
||||
[DataField("amount")]
|
||||
public int Amount = -1;
|
||||
|
||||
public override void Effect(ReagentEffectArgs args)
|
||||
{
|
||||
EntitySystem.Get<SharedBlindingSystem>().AdjustEyeDamage(args.SolutionEntity, Add);
|
||||
args.EntityManager.EntitySysManager.GetEntitySystem<SharedBlindingSystem>().AdjustEyeDamage(args.SolutionEntity, Amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,13 +27,13 @@ namespace Content.Server.Eye.Blinding.EyeProtection
|
||||
if (!component.Toggled)
|
||||
return;
|
||||
|
||||
if (!TryComp<StatusEffectsComponent>(args.User, out var status) || !TryComp<BlindableComponent>(args.User, out var blindable))
|
||||
if (!HasComp<StatusEffectsComponent>(args.User) || !TryComp<BlindableComponent>(args.User, out var blindable))
|
||||
return;
|
||||
|
||||
if (blindable.Sources > 0)
|
||||
return;
|
||||
|
||||
float statusTime = (float) component.StatusEffectTime.TotalSeconds - blindable.BlindResistance;
|
||||
var statusTime = (float) component.StatusEffectTime.TotalSeconds - blindable.BlindResistance;
|
||||
|
||||
if (statusTime <= 0)
|
||||
return;
|
||||
@@ -41,7 +41,7 @@ namespace Content.Server.Eye.Blinding.EyeProtection
|
||||
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, true, blindable);
|
||||
_blindingSystem.AdjustEyeDamage(args.User, 1, blindable);
|
||||
}
|
||||
private void OnWelderToggled(EntityUid uid, RequiresEyeProtectionComponent component, WelderToggledEvent args)
|
||||
{
|
||||
|
||||
@@ -19,15 +19,15 @@ namespace Content.Server.Bed.Sleep
|
||||
private void OnInit(EntityUid uid, SleepingComponent component, ComponentInit args)
|
||||
{
|
||||
var ev = new SleepStateChangedEvent(true);
|
||||
RaiseLocalEvent(uid, ev, false);
|
||||
_blindingSystem.AdjustBlindSources(uid, true);
|
||||
RaiseLocalEvent(uid, ev);
|
||||
_blindingSystem.AdjustBlindSources(uid, 1);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, SleepingComponent component, ComponentShutdown args)
|
||||
{
|
||||
var ev = new SleepStateChangedEvent(false);
|
||||
RaiseLocalEvent(uid, ev, false);
|
||||
_blindingSystem.AdjustBlindSources(uid, false);
|
||||
RaiseLocalEvent(uid, ev);
|
||||
_blindingSystem.AdjustBlindSources(uid, -1);
|
||||
}
|
||||
|
||||
private void OnSpeakAttempt(EntityUid uid, SleepingComponent component, SpeakAttemptEvent args)
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace Content.Shared.Eye.Blinding
|
||||
|
||||
/// <summary>
|
||||
/// Whether eye damage has accumulated enough to blind them.
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool EyeTooDamaged = false;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Clothing.Components;
|
||||
using Content.Shared.Inventory.Events;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Rejuvenate;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using JetBrains.Annotations;
|
||||
@@ -23,6 +24,8 @@ namespace Content.Shared.Eye.Blinding
|
||||
|
||||
SubscribeLocalEvent<TemporaryBlindnessComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<TemporaryBlindnessComponent, ComponentShutdown>(OnShutdown);
|
||||
|
||||
SubscribeLocalEvent<BlindableComponent, RejuvenateEvent>(OnRejuvenate);
|
||||
}
|
||||
|
||||
private void OnEquipped(EntityUid uid, BlindfoldComponent component, GotEquippedEvent args)
|
||||
@@ -36,7 +39,7 @@ namespace Content.Shared.Eye.Blinding
|
||||
component.IsActive = true;
|
||||
if (!TryComp<BlindableComponent>(args.Equipee, out var blindComp))
|
||||
return;
|
||||
AdjustBlindSources(args.Equipee, true, blindComp);
|
||||
AdjustBlindSources(args.Equipee, 1, blindComp);
|
||||
}
|
||||
|
||||
private void OnUnequipped(EntityUid uid, BlindfoldComponent component, GotUnequippedEvent args)
|
||||
@@ -46,7 +49,7 @@ namespace Content.Shared.Eye.Blinding
|
||||
component.IsActive = false;
|
||||
if (!TryComp<BlindableComponent>(args.Equipee, out var blindComp))
|
||||
return;
|
||||
AdjustBlindSources(args.Equipee, false, blindComp);
|
||||
AdjustBlindSources(args.Equipee, -1, blindComp);
|
||||
}
|
||||
|
||||
private void OnGlassesEquipped(EntityUid uid, VisionCorrectionComponent component, GotEquippedEvent args)
|
||||
@@ -81,52 +84,45 @@ namespace Content.Shared.Eye.Blinding
|
||||
|
||||
private void OnInit(EntityUid uid, TemporaryBlindnessComponent component, ComponentInit args)
|
||||
{
|
||||
AdjustBlindSources(uid, true);
|
||||
AdjustBlindSources(uid, 1);
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, TemporaryBlindnessComponent component, ComponentShutdown args)
|
||||
{
|
||||
AdjustBlindSources(uid, false);
|
||||
AdjustBlindSources(uid, -1);
|
||||
}
|
||||
|
||||
private void OnRejuvenate(EntityUid uid, BlindableComponent component, RejuvenateEvent args)
|
||||
{
|
||||
AdjustEyeDamage(uid, -component.EyeDamage, component);
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public void AdjustBlindSources(EntityUid uid, bool Add, BlindableComponent? blindable = null)
|
||||
public void AdjustBlindSources(EntityUid uid, int amount, BlindableComponent? blindable = null)
|
||||
{
|
||||
if (!Resolve(uid, ref blindable, false))
|
||||
return;
|
||||
|
||||
if (Add)
|
||||
{
|
||||
blindable.Sources++;
|
||||
} else
|
||||
{
|
||||
blindable.Sources--;
|
||||
}
|
||||
|
||||
blindable.Sources += amount;
|
||||
blindable.Sources = Math.Max(blindable.Sources, 0);
|
||||
|
||||
Dirty(blindable);
|
||||
}
|
||||
|
||||
public void AdjustEyeDamage(EntityUid uid, bool add, BlindableComponent? blindable = null)
|
||||
public void AdjustEyeDamage(EntityUid uid, int amount, BlindableComponent? blindable = null)
|
||||
{
|
||||
if (!Resolve(uid, ref blindable, false))
|
||||
return;
|
||||
|
||||
if (add)
|
||||
{
|
||||
blindable.EyeDamage++;
|
||||
} else
|
||||
{
|
||||
blindable.EyeDamage--;
|
||||
}
|
||||
blindable.EyeDamage += amount;
|
||||
|
||||
if (blindable.EyeDamage > 0)
|
||||
{
|
||||
var blurry = EnsureComp<BlurryVisionComponent>(uid);
|
||||
blurry.Magnitude = (9 - blindable.EyeDamage);
|
||||
blurry.Dirty();
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
RemComp<BlurryVisionComponent>(uid);
|
||||
}
|
||||
@@ -134,12 +130,12 @@ namespace Content.Shared.Eye.Blinding
|
||||
if (!blindable.EyeTooDamaged && blindable.EyeDamage >= 8)
|
||||
{
|
||||
blindable.EyeTooDamaged = true;
|
||||
AdjustBlindSources(uid, true, blindable);
|
||||
AdjustBlindSources(uid, 1, blindable);
|
||||
}
|
||||
if (blindable.EyeTooDamaged && blindable.EyeDamage < 8)
|
||||
{
|
||||
blindable.EyeTooDamaged = false;
|
||||
AdjustBlindSources(uid, false, blindable);
|
||||
AdjustBlindSources(uid, -1, blindable);
|
||||
}
|
||||
|
||||
blindable.EyeDamage = Math.Clamp(blindable.EyeDamage, 0, 8);
|
||||
|
||||
@@ -31,11 +31,11 @@ public sealed class PermanentBlindnessSystem : EntitySystem
|
||||
|
||||
private void OnShutdown(EntityUid uid, PermanentBlindnessComponent component, ComponentShutdown args)
|
||||
{
|
||||
_blinding.AdjustBlindSources(uid, false);
|
||||
_blinding.AdjustBlindSources(uid, -1);
|
||||
}
|
||||
|
||||
private void OnStartup(EntityUid uid, PermanentBlindnessComponent component, ComponentStartup args)
|
||||
{
|
||||
_blinding.AdjustBlindSources(uid, true);
|
||||
_blinding.AdjustBlindSources(uid, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user