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
|
public sealed class ChemHealEyeDamage : ReagentEffect
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add or remove eye damage?
|
/// How much eye damage to remove.
|
||||||
[DataField("add")]
|
/// </summary>
|
||||||
public bool Add = false;
|
[DataField("amount")]
|
||||||
|
public int Amount = -1;
|
||||||
|
|
||||||
public override void Effect(ReagentEffectArgs args)
|
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)
|
if (!component.Toggled)
|
||||||
return;
|
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;
|
return;
|
||||||
|
|
||||||
if (blindable.Sources > 0)
|
if (blindable.Sources > 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float statusTime = (float) component.StatusEffectTime.TotalSeconds - blindable.BlindResistance;
|
var statusTime = (float) component.StatusEffectTime.TotalSeconds - blindable.BlindResistance;
|
||||||
|
|
||||||
if (statusTime <= 0)
|
if (statusTime <= 0)
|
||||||
return;
|
return;
|
||||||
@@ -41,7 +41,7 @@ namespace Content.Server.Eye.Blinding.EyeProtection
|
|||||||
var statusTimeSpan = TimeSpan.FromSeconds(statusTime * (blindable.EyeDamage + 1));
|
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.
|
// 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)
|
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)
|
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)
|
private void OnInit(EntityUid uid, SleepingComponent component, ComponentInit args)
|
||||||
{
|
{
|
||||||
var ev = new SleepStateChangedEvent(true);
|
var ev = new SleepStateChangedEvent(true);
|
||||||
RaiseLocalEvent(uid, ev, false);
|
RaiseLocalEvent(uid, ev);
|
||||||
_blindingSystem.AdjustBlindSources(uid, true);
|
_blindingSystem.AdjustBlindSources(uid, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnShutdown(EntityUid uid, SleepingComponent component, ComponentShutdown args)
|
private void OnShutdown(EntityUid uid, SleepingComponent component, ComponentShutdown args)
|
||||||
{
|
{
|
||||||
var ev = new SleepStateChangedEvent(false);
|
var ev = new SleepStateChangedEvent(false);
|
||||||
RaiseLocalEvent(uid, ev, false);
|
RaiseLocalEvent(uid, ev);
|
||||||
_blindingSystem.AdjustBlindSources(uid, false);
|
_blindingSystem.AdjustBlindSources(uid, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnSpeakAttempt(EntityUid uid, SleepingComponent component, SpeakAttemptEvent args)
|
private void OnSpeakAttempt(EntityUid uid, SleepingComponent component, SpeakAttemptEvent args)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace Content.Shared.Eye.Blinding
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether eye damage has accumulated enough to blind them.
|
/// Whether eye damage has accumulated enough to blind them.
|
||||||
/// <summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public bool EyeTooDamaged = false;
|
public bool EyeTooDamaged = false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Content.Shared.Clothing.Components;
|
using Content.Shared.Clothing.Components;
|
||||||
using Content.Shared.Inventory.Events;
|
using Content.Shared.Inventory.Events;
|
||||||
using Content.Shared.Inventory;
|
using Content.Shared.Inventory;
|
||||||
|
using Content.Shared.Rejuvenate;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
@@ -23,6 +24,8 @@ namespace Content.Shared.Eye.Blinding
|
|||||||
|
|
||||||
SubscribeLocalEvent<TemporaryBlindnessComponent, ComponentInit>(OnInit);
|
SubscribeLocalEvent<TemporaryBlindnessComponent, ComponentInit>(OnInit);
|
||||||
SubscribeLocalEvent<TemporaryBlindnessComponent, ComponentShutdown>(OnShutdown);
|
SubscribeLocalEvent<TemporaryBlindnessComponent, ComponentShutdown>(OnShutdown);
|
||||||
|
|
||||||
|
SubscribeLocalEvent<BlindableComponent, RejuvenateEvent>(OnRejuvenate);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEquipped(EntityUid uid, BlindfoldComponent component, GotEquippedEvent args)
|
private void OnEquipped(EntityUid uid, BlindfoldComponent component, GotEquippedEvent args)
|
||||||
@@ -36,7 +39,7 @@ namespace Content.Shared.Eye.Blinding
|
|||||||
component.IsActive = true;
|
component.IsActive = true;
|
||||||
if (!TryComp<BlindableComponent>(args.Equipee, out var blindComp))
|
if (!TryComp<BlindableComponent>(args.Equipee, out var blindComp))
|
||||||
return;
|
return;
|
||||||
AdjustBlindSources(args.Equipee, true, blindComp);
|
AdjustBlindSources(args.Equipee, 1, blindComp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnUnequipped(EntityUid uid, BlindfoldComponent component, GotUnequippedEvent args)
|
private void OnUnequipped(EntityUid uid, BlindfoldComponent component, GotUnequippedEvent args)
|
||||||
@@ -46,7 +49,7 @@ namespace Content.Shared.Eye.Blinding
|
|||||||
component.IsActive = false;
|
component.IsActive = false;
|
||||||
if (!TryComp<BlindableComponent>(args.Equipee, out var blindComp))
|
if (!TryComp<BlindableComponent>(args.Equipee, out var blindComp))
|
||||||
return;
|
return;
|
||||||
AdjustBlindSources(args.Equipee, false, blindComp);
|
AdjustBlindSources(args.Equipee, -1, blindComp);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGlassesEquipped(EntityUid uid, VisionCorrectionComponent component, GotEquippedEvent args)
|
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)
|
private void OnInit(EntityUid uid, TemporaryBlindnessComponent component, ComponentInit args)
|
||||||
{
|
{
|
||||||
AdjustBlindSources(uid, true);
|
AdjustBlindSources(uid, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnShutdown(EntityUid uid, TemporaryBlindnessComponent component, ComponentShutdown args)
|
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]
|
[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))
|
if (!Resolve(uid, ref blindable, false))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Add)
|
blindable.Sources += amount;
|
||||||
{
|
|
||||||
blindable.Sources++;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
blindable.Sources--;
|
|
||||||
}
|
|
||||||
|
|
||||||
blindable.Sources = Math.Max(blindable.Sources, 0);
|
blindable.Sources = Math.Max(blindable.Sources, 0);
|
||||||
|
|
||||||
Dirty(blindable);
|
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))
|
if (!Resolve(uid, ref blindable, false))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (add)
|
blindable.EyeDamage += amount;
|
||||||
{
|
|
||||||
blindable.EyeDamage++;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
blindable.EyeDamage--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (blindable.EyeDamage > 0)
|
if (blindable.EyeDamage > 0)
|
||||||
{
|
{
|
||||||
var blurry = EnsureComp<BlurryVisionComponent>(uid);
|
var blurry = EnsureComp<BlurryVisionComponent>(uid);
|
||||||
blurry.Magnitude = (9 - blindable.EyeDamage);
|
blurry.Magnitude = (9 - blindable.EyeDamage);
|
||||||
blurry.Dirty();
|
blurry.Dirty();
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
RemComp<BlurryVisionComponent>(uid);
|
RemComp<BlurryVisionComponent>(uid);
|
||||||
}
|
}
|
||||||
@@ -134,12 +130,12 @@ namespace Content.Shared.Eye.Blinding
|
|||||||
if (!blindable.EyeTooDamaged && blindable.EyeDamage >= 8)
|
if (!blindable.EyeTooDamaged && blindable.EyeDamage >= 8)
|
||||||
{
|
{
|
||||||
blindable.EyeTooDamaged = true;
|
blindable.EyeTooDamaged = true;
|
||||||
AdjustBlindSources(uid, true, blindable);
|
AdjustBlindSources(uid, 1, blindable);
|
||||||
}
|
}
|
||||||
if (blindable.EyeTooDamaged && blindable.EyeDamage < 8)
|
if (blindable.EyeTooDamaged && blindable.EyeDamage < 8)
|
||||||
{
|
{
|
||||||
blindable.EyeTooDamaged = false;
|
blindable.EyeTooDamaged = false;
|
||||||
AdjustBlindSources(uid, false, blindable);
|
AdjustBlindSources(uid, -1, blindable);
|
||||||
}
|
}
|
||||||
|
|
||||||
blindable.EyeDamage = Math.Clamp(blindable.EyeDamage, 0, 8);
|
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)
|
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)
|
private void OnStartup(EntityUid uid, PermanentBlindnessComponent component, ComponentStartup args)
|
||||||
{
|
{
|
||||||
_blinding.AdjustBlindSources(uid, true);
|
_blinding.AdjustBlindSources(uid, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user