telescreen and television require vision + Move eye to shared (#30260)
* telescreen and television require vision * Move Content.Server.Eye to Shared * fix popups * Filthy
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
namespace Content.Server.Eye.Blinding
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed partial class ActivatableUIRequiresVisionComponent : Component
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
using Content.Shared.Eye.Blinding;
|
||||
using Content.Shared.UserInterface;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Eye.Blinding.Components;
|
||||
using Content.Shared.Eye.Blinding.Systems;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Collections;
|
||||
|
||||
namespace Content.Server.Eye.Blinding;
|
||||
|
||||
public sealed class ActivatableUIRequiresVisionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ActivatableUIRequiresVisionComponent, ActivatableUIOpenAttemptEvent>(OnOpenAttempt);
|
||||
SubscribeLocalEvent<BlindableComponent, BlindnessChangedEvent>(OnBlindnessChanged);
|
||||
}
|
||||
|
||||
private void OnOpenAttempt(EntityUid uid, ActivatableUIRequiresVisionComponent component, ActivatableUIOpenAttemptEvent args)
|
||||
{
|
||||
if (args.Cancelled)
|
||||
return;
|
||||
|
||||
if (TryComp<BlindableComponent>(args.User, out var blindable) && blindable.IsBlind)
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("blindness-fail-attempt"), args.User, Shared.Popups.PopupType.MediumCaution);
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBlindnessChanged(EntityUid uid, BlindableComponent component, ref BlindnessChangedEvent args)
|
||||
{
|
||||
if (!args.Blind)
|
||||
return;
|
||||
|
||||
var toClose = new ValueList<(EntityUid Entity, Enum Key)>();
|
||||
|
||||
foreach (var bui in _userInterfaceSystem.GetActorUis(uid))
|
||||
{
|
||||
if (HasComp<ActivatableUIRequiresVisionComponent>(bui.Entity))
|
||||
{
|
||||
toClose.Add(bui);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var bui in toClose)
|
||||
{
|
||||
_userInterfaceSystem.CloseUi(bui.Entity, bui.Key, uid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
using Content.Shared.StatusEffect;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Eye.Blinding.Components;
|
||||
using Content.Shared.Eye.Blinding.Systems;
|
||||
using Content.Shared.Tools.Components;
|
||||
using Content.Shared.Item.ItemToggle.Components;
|
||||
|
||||
namespace Content.Server.Eye.Blinding.EyeProtection
|
||||
{
|
||||
public sealed class EyeProtectionSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly StatusEffectsSystem _statusEffectsSystem = default!;
|
||||
[Dependency] private readonly BlindableSystem _blindingSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<RequiresEyeProtectionComponent, ToolUseAttemptEvent>(OnUseAttempt);
|
||||
SubscribeLocalEvent<RequiresEyeProtectionComponent, ItemToggledEvent>(OnWelderToggled);
|
||||
|
||||
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)
|
||||
{
|
||||
if (!component.Toggled)
|
||||
return;
|
||||
|
||||
if (!TryComp<BlindableComponent>(args.User, out var blindable) || blindable.IsBlind)
|
||||
return;
|
||||
|
||||
var ev = new GetEyeProtectionEvent();
|
||||
RaiseLocalEvent(args.User, ev);
|
||||
|
||||
var time = (float) (component.StatusEffectTime - ev.Protection).TotalSeconds;
|
||||
if (time <= 0)
|
||||
return;
|
||||
|
||||
// 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, blindable), 1);
|
||||
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, ItemToggledEvent args)
|
||||
{
|
||||
component.Toggled = args.Activated;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user