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

@@ -0,0 +1,23 @@
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Eye.Blinding;
using JetBrains.Annotations;
namespace Content.Server.Chemistry.ReagentEffects
{
/// <summary>
/// Heal eye damage (or deal)
/// </summary>
[UsedImplicitly]
public sealed class ChemHealEyeDamage : ReagentEffect
{
/// <summary>
/// Add or remove eye damage?
[DataField("add")]
public bool Add = false;
public override void Effect(ReagentEffectArgs args)
{
EntitySystem.Get<SharedBlindingSystem>().AdjustEyeDamage(args.SolutionEntity, Add);
}
}
}

View File

@@ -16,10 +16,14 @@ namespace Content.Server.Examine
private static readonly FormattedMessage _entityNotFoundMessage;
private static readonly FormattedMessage _entityOutOfRangeMessage;
static ExamineSystem()
{
_entityNotFoundMessage = new FormattedMessage();
_entityNotFoundMessage.AddText(Loc.GetString("examine-system-entity-does-not-exist"));
_entityOutOfRangeMessage = new FormattedMessage();
_entityOutOfRangeMessage.AddText(Loc.GetString("examine-system-cant-see-entity"));
}
public override void Initialize()
@@ -54,14 +58,20 @@ namespace Content.Server.Examine
var channel = player.ConnectedClient;
if (session.AttachedEntity is not {Valid: true} playerEnt
|| !EntityManager.EntityExists(request.EntityUid)
|| !CanExamine(playerEnt, request.EntityUid))
|| !EntityManager.EntityExists(request.EntityUid))
{
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
request.EntityUid, _entityNotFoundMessage), channel);
return;
}
if (!CanExamine(playerEnt, request.EntityUid))
{
RaiseNetworkEvent(new ExamineSystemMessages.ExamineInfoResponseMessage(
request.EntityUid, _entityOutOfRangeMessage, knowTarget: false), channel);
return;
}
SortedSet<Verb>? verbs = null;
if (request.GetVerbs)
verbs = _verbSystem.GetLocalVerbs(request.EntityUid, playerEnt, typeof(ExamineVerb));

View File

@@ -0,0 +1,77 @@
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;
namespace Content.Server.Eye.Blinding.EyeProtection
{
public sealed class EyeProtectionSystem : EntitySystem
{
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
[Dependency] private readonly SharedBlindingSystem _blindingSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RequiresEyeProtectionComponent, ToolUseAttemptEvent>(OnUseAttempt);
SubscribeLocalEvent<RequiresEyeProtectionComponent, WelderToggledEvent>(OnWelderToggled);
SubscribeLocalEvent<EyeProtectionComponent, GotEquippedEvent>(OnEquipped);
SubscribeLocalEvent<EyeProtectionComponent, GotUnequippedEvent>(OnUnequipped);
}
private void OnUseAttempt(EntityUid uid, RequiresEyeProtectionComponent component, ToolUseAttemptEvent args)
{
if (!component.Toggled)
return;
if (!TryComp<StatusEffectsComponent>(args.User, out var status) || !TryComp<BlindableComponent>(args.User, out var blindable))
return;
if (blindable.Sources > 0)
return;
float 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, true, blindable);
}
private void OnWelderToggled(EntityUid uid, RequiresEyeProtectionComponent component, WelderToggledEvent args)
{
component.Toggled = args.WelderOn;
}
private void OnEquipped(EntityUid uid, EyeProtectionComponent component, GotEquippedEvent args)
{
if (!TryComp<SharedClothingComponent>(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;
}
}
}

View File

@@ -104,6 +104,9 @@ namespace Content.Server.Tools
welder.Lit = true;
var ev = new WelderToggledEvent(true);
RaiseLocalEvent(welder.Owner, ev, false);
if(item != null)
_itemSystem.SetHeldPrefix(uid, "on", item);
@@ -140,6 +143,9 @@ namespace Content.Server.Tools
welder.Lit = false;
var ev = new WelderToggledEvent(false);
RaiseLocalEvent(welder.Owner, ev, false);
// TODO: Make all this use visualizers.
if (item != null)
_itemSystem.SetHeldPrefix(uid, "off", item);
@@ -332,4 +338,14 @@ namespace Content.Server.Tools
_welderTimer -= WelderUpdateTimer;
}
}
public sealed class WelderToggledEvent : EntityEventArgs
{
public bool WelderOn;
public WelderToggledEvent(bool welderOn)
{
WelderOn = welderOn;
}
}
}