Telecom server panel check (#14523)

This commit is contained in:
Slava0135
2023-03-24 03:09:45 +03:00
committed by GitHub
parent 8c7e917038
commit d03ca61da1
17 changed files with 226 additions and 138 deletions

View File

@@ -7,7 +7,6 @@ using Content.Server.DeviceNetwork.Systems;
using Content.Server.Popups;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Server.Wires;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.Atmos;
@@ -16,8 +15,8 @@ using Content.Shared.Atmos.Monitor.Components;
using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.DeviceNetwork;
using Content.Shared.Interaction;
using Content.Shared.Wires;
using Robust.Server.GameObjects;
using Robust.Shared.Player;
namespace Content.Server.Atmos.Monitor.Systems;
@@ -227,10 +226,10 @@ public sealed class AirAlarmSystem : EntitySystem
if (!_interactionSystem.InRangeUnobstructed(args.User, args.Target))
return;
if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
if (!TryComp<ActorComponent>(args.User, out var actor))
return;
if (EntityManager.TryGetComponent(uid, out WiresComponent? wire) && wire.IsPanelOpen)
if (TryComp<WiresPanelComponent>(uid, out var panel) && panel.Open)
{
args.Handled = false;
return;
@@ -239,7 +238,9 @@ public sealed class AirAlarmSystem : EntitySystem
if (!this.IsPowered(uid, EntityManager))
return;
_uiSystem.GetUiOrNull(component.Owner, SharedAirAlarmInterfaceKey.Key)?.Open(actor.PlayerSession);
var ui = _uiSystem.GetUiOrNull(uid, SharedAirAlarmInterfaceKey.Key);
if (ui != null)
_uiSystem.OpenUi(ui, actor.PlayerSession);
component.ActivePlayers.Add(actor.PlayerSession.UserId);
AddActiveInterface(uid);
SyncAllDevices(uid);

View File

@@ -1,6 +1,6 @@
using Content.Server.Wires;
using Content.Shared.Construction;
using Content.Shared.Examine;
using Content.Shared.Wires;
using JetBrains.Annotations;
namespace Content.Server.Construction.Conditions
@@ -14,24 +14,23 @@ namespace Content.Server.Construction.Conditions
public bool Condition(EntityUid uid, IEntityManager entityManager)
{
//if it doesn't have a wire panel, then just let it work.
if (!entityManager.TryGetComponent(uid, out WiresComponent? wires))
if (!entityManager.TryGetComponent<WiresPanelComponent>(uid, out var wires))
return true;
return wires.IsPanelOpen == Open;
return wires.Open == Open;
}
public bool DoExamine(ExaminedEvent args)
{
var entity = args.Examined;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out WiresComponent? wires)) return false;
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent<WiresPanelComponent>(entity, out var panel)) return false;
switch (Open)
{
case true when !wires.IsPanelOpen:
case true when !panel.Open:
args.PushMarkup(Loc.GetString("construction-examine-condition-wire-panel-open"));
return true;
case false when wires.IsPanelOpen:
case false when panel.Open:
args.PushMarkup(Loc.GetString("construction-examine-condition-wire-panel-close"));
return true;
}

View File

@@ -3,13 +3,13 @@ using Content.Server.Construction.Components;
using Content.Server.DoAfter;
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems;
using Content.Server.Wires;
using Content.Shared.DoAfter;
using Content.Shared.Construction.Components;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Robust.Shared.Containers;
using Robust.Shared.Utility;
using Content.Shared.Wires;
namespace Content.Server.Construction;
@@ -103,7 +103,7 @@ public sealed class PartExchangerSystem : EntitySystem
if (!HasComp<MachineComponent>(args.Target))
return;
if (TryComp<WiresComponent>(args.Target, out var wires) && !wires.IsPanelOpen)
if (TryComp<WiresPanelComponent>(args.Target, out var panel) && !panel.Open)
{
_popup.PopupEntity(Loc.GetString("construction-step-condition-wire-panel-open"),
args.Target.Value);

View File

@@ -7,6 +7,7 @@ using Content.Shared.Doors.Components;
using Content.Shared.Doors.Systems;
using Content.Shared.Interaction;
using Robust.Server.GameObjects;
using Content.Shared.Wires;
namespace Content.Server.Doors.Systems
{
@@ -71,11 +72,9 @@ namespace Content.Server.Doors.Systems
// means that sometimes the panels & bolt lights may be visible despite a door being completely open.
// Only show the maintenance panel if the airlock is closed
if (TryComp<WiresComponent>(uid, out var wiresComponent))
if (TryComp<WiresPanelComponent>(uid, out var wiresPanel))
{
wiresComponent.IsPanelVisible =
component.OpenPanelVisible
|| args.State != DoorState.Open;
_wiresSystem.ChangePanelVisibility(uid, wiresPanel, component.OpenPanelVisible || args.State != DoorState.Open);
}
// If the door is closed, we should look if the bolt was locked while closing
UpdateBoltLightStatus(uid, component);
@@ -144,8 +143,8 @@ namespace Content.Server.Doors.Systems
private void OnActivate(EntityUid uid, AirlockComponent component, ActivateInWorldEvent args)
{
if (TryComp<WiresComponent>(uid, out var wiresComponent) && wiresComponent.IsPanelOpen &&
EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
if (TryComp<WiresPanelComponent>(uid, out var panel) && panel.Open &&
TryComp<ActorComponent>(args.User, out var actor))
{
_wiresSystem.OpenUserInterface(uid, actor.PlayerSession);
args.Handled = true;

View File

@@ -3,7 +3,6 @@ using Content.Server.Atmos.EntitySystems;
using Content.Server.DoAfter;
using Content.Server.Mech.Components;
using Content.Server.Power.Components;
using Content.Server.Wires;
using Content.Shared.ActionBlocker;
using Content.Shared.Damage;
using Content.Shared.DoAfter;
@@ -15,6 +14,7 @@ using Content.Shared.Mech.EntitySystems;
using Content.Shared.Movement.Events;
using Content.Shared.Tools.Components;
using Content.Shared.Verbs;
using Content.Shared.Wires;
using Robust.Server.Containers;
using Robust.Server.GameObjects;
using Robust.Shared.Map;
@@ -72,7 +72,7 @@ public sealed class MechSystem : SharedMechSystem
}
private void OnInteractUsing(EntityUid uid, MechComponent component, InteractUsingEvent args)
{
if (TryComp<WiresComponent>(uid, out var wires) && !wires.IsPanelOpen)
if (TryComp<WiresPanelComponent>(uid, out var panel) && !panel.Open)
return;
if (component.BatterySlot.ContainedEntity == null && TryComp<BatteryComponent>(args.Used, out var battery))

View File

@@ -1,37 +1,38 @@
using Content.Shared.Popups;
using Content.Server.Power.Components;
using Content.Server.UserInterface;
using Content.Server.Wires;
using JetBrains.Annotations;
using Content.Shared.Wires;
namespace Content.Server.Power.EntitySystems
namespace Content.Server.Power.EntitySystems;
[UsedImplicitly]
internal sealed class ActivatableUIRequiresPowerSystem : EntitySystem
{
[UsedImplicitly]
internal sealed class ActivatableUIRequiresPowerSystem : EntitySystem
[Dependency] private readonly ActivatableUISystem _activatableUI = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
[Dependency] private readonly ActivatableUISystem _activatableUISystem = default!;
public override void Initialize()
{
base.Initialize();
base.Initialize();
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, ActivatableUIOpenAttemptEvent>(OnActivate);
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, PowerChangedEvent>(OnPowerChanged);
}
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, ActivatableUIOpenAttemptEvent>(OnActivate);
SubscribeLocalEvent<ActivatableUIRequiresPowerComponent, PowerChangedEvent>(OnPowerChanged);
}
private void OnActivate(EntityUid uid, ActivatableUIRequiresPowerComponent component, ActivatableUIOpenAttemptEvent args)
{
if (args.Cancelled) return;
if (this.IsPowered(uid, EntityManager)) return;
if (TryComp<WiresComponent>(uid, out var wires) && wires.IsPanelOpen)
return;
args.User.PopupMessageCursor(Loc.GetString("base-computer-ui-component-not-powered", ("machine", uid)));
args.Cancel();
}
private void OnActivate(EntityUid uid, ActivatableUIRequiresPowerComponent component, ActivatableUIOpenAttemptEvent args)
{
if (args.Cancelled) return;
if (this.IsPowered(uid, EntityManager)) return;
if (TryComp<WiresPanelComponent>(uid, out var panel) && panel.Open)
return;
_popup.PopupCursor(Loc.GetString("base-computer-ui-component-not-powered", ("machine", uid)), args.User);
args.Cancel();
}
private void OnPowerChanged(EntityUid uid, ActivatableUIRequiresPowerComponent component, ref PowerChangedEvent args)
{
if (!args.Powered)
_activatableUISystem.CloseAll(uid);
}
private void OnPowerChanged(EntityUid uid, ActivatableUIRequiresPowerComponent component, ref PowerChangedEvent args)
{
if (!args.Powered)
_activatableUI.CloseAll(uid);
}
}

View File

@@ -1,11 +1,11 @@
using System.Linq;
using Content.Server.Cargo.Systems;
using Content.Server.DoAfter;
using Content.Server.Wires;
using Content.Shared.DoAfter;
using Content.Shared.Interaction;
using Content.Shared.Popups;
using Content.Shared.VendingMachines;
using Content.Shared.Wires;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
@@ -35,7 +35,7 @@ namespace Content.Server.VendingMachines.Restock
EntityUid user,
EntityUid target)
{
if (!TryComp<WiresComponent>(target, out var wires) || !wires.IsPanelOpen)
if (!TryComp<WiresPanelComponent>(target, out var panel) || !panel.Open)
{
_popupSystem.PopupCursor(Loc.GetString("vending-machine-restock-needs-panel-open",
("this", uid),

View File

@@ -5,18 +5,6 @@ namespace Content.Server.Wires;
[RegisterComponent]
public sealed class WiresComponent : Component
{
/// <summary>
/// Is the panel open for this entity's wires?
/// </summary>
[ViewVariables]
public bool IsPanelOpen { get; set; }
/// <summary>
/// Should this entity's wires panel be visible at all?
/// </summary>
[ViewVariables]
public bool IsPanelVisible { get; set; } = true;
/// <summary>
/// The name of this entity's internal board.
/// </summary>
@@ -62,13 +50,6 @@ public sealed class WiresComponent : Component
[DataField("alwaysRandomize")]
public bool AlwaysRandomize { get; }
/// <summary>
/// Marks if maintenance panel being open/closed by someone with a screwdriver.
/// Prevents do after spam.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public bool IsScrewing;
/// <summary>
/// Per wire status, keyed by an object.
/// </summary>
@@ -85,10 +66,4 @@ public sealed class WiresComponent : Component
[DataField("pulseSound")]
public SoundSpecifier PulseSound = new SoundPathSpecifier("/Audio/Effects/multitool_pulse.ogg");
[DataField("screwdriverOpenSound")]
public SoundSpecifier ScrewdriverOpenSound = new SoundPathSpecifier("/Audio/Machines/screwdriveropen.ogg");
[DataField("screwdriverCloseSound")]
public SoundSpecifier ScrewdriverCloseSound = new SoundPathSpecifier("/Audio/Machines/screwdriverclose.ogg");
}

View File

@@ -7,7 +7,6 @@ using Content.Server.Hands.Components;
using Content.Server.Power.Components;
using Content.Shared.DoAfter;
using Content.Shared.Database;
using Content.Shared.Examine;
using Content.Shared.GameTicking;
using Content.Shared.Interaction;
using Content.Shared.Popups;
@@ -21,17 +20,17 @@ using Robust.Shared.Random;
namespace Content.Server.Wires;
public sealed class WiresSystem : EntitySystem
public sealed class WiresSystem : SharedWiresSystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly DoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
private IRobustRandom _random = new RobustRandom();
@@ -44,6 +43,8 @@ public sealed class WiresSystem : EntitySystem
#region Initialization
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
// this is a broadcast event
@@ -52,7 +53,6 @@ public sealed class WiresSystem : EntitySystem
SubscribeLocalEvent<WiresComponent, ComponentStartup>(OnWiresStartup);
SubscribeLocalEvent<WiresComponent, WiresActionMessage>(OnWiresActionMessage);
SubscribeLocalEvent<WiresComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<WiresComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<WiresComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<WiresComponent, TimedWireEvent>(OnTimedWire);
SubscribeLocalEvent<WiresComponent, PowerChangedEvent>(OnWiresPowered);
@@ -244,7 +244,6 @@ public sealed class WiresSystem : EntitySystem
SetOrCreateWireLayout(uid, component);
UpdateUserInterface(uid);
UpdateAppearance(uid);
}
#endregion
@@ -456,75 +455,71 @@ public sealed class WiresSystem : EntitySystem
private void OnInteractUsing(EntityUid uid, WiresComponent component, InteractUsingEvent args)
{
if (!EntityManager.TryGetComponent(args.Used, out ToolComponent? tool))
if (!TryComp<ToolComponent>(args.Used, out var tool) || !TryComp<WiresPanelComponent>(uid, out var panel))
return;
if (component.IsPanelOpen &&
if (panel.Open &&
(_toolSystem.HasQuality(args.Used, "Cutting", tool) ||
_toolSystem.HasQuality(args.Used, "Pulsing", tool)))
{
if (EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
{
_uiSystem.GetUiOrNull(uid, WiresUiKey.Key)?.Open(actor.PlayerSession);
var ui = _uiSystem.GetUiOrNull(uid, WiresUiKey.Key);
if (ui != null)
_uiSystem.OpenUi(ui, actor.PlayerSession);
args.Handled = true;
}
}
else if (!component.IsScrewing && _toolSystem.HasQuality(args.Used, "Screwing", tool))
else if (!panel.IsScrewing && _toolSystem.HasQuality(args.Used, "Screwing", tool))
{
var toolEvData = new ToolEventData(new WireToolFinishedEvent(uid, args.User), cancelledEv: new WireToolCanceledEvent(uid));
component.IsScrewing = _toolSystem.UseTool(args.Used, args.User, uid, ScrewTime, new[] { "Screwing" }, toolEvData, toolComponent: tool);
args.Handled = component.IsScrewing;
panel.IsScrewing = _toolSystem.UseTool(args.Used, args.User, uid, ScrewTime, new[] { "Screwing" }, toolEvData, toolComponent: tool);
args.Handled = panel.IsScrewing;
// Log attempt
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} is screwing {ToPrettyString(uid):target}'s {(component.IsPanelOpen ? "open" : "closed")} maintenance panel at {Transform(uid).Coordinates:targetlocation}");
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} is screwing {ToPrettyString(uid):target}'s {(panel.Open ? "open" : "closed")} maintenance panel at {Transform(uid).Coordinates:targetlocation}");
}
}
private void OnToolFinished(WireToolFinishedEvent args)
{
if (!EntityManager.TryGetComponent(args.Target, out WiresComponent? component))
if (!TryComp<WiresPanelComponent>((args.Target), out var panel))
return;
component.IsScrewing = false;
component.IsPanelOpen = !component.IsPanelOpen;
UpdateAppearance(args.Target);
panel.IsScrewing = false;
TogglePanel(args.Target, panel, !panel.Open);
// Log success
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} screwed {ToPrettyString(args.Target):target}'s maintenance panel {(component.IsPanelOpen ? "open" : "closed")}");
_adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} screwed {ToPrettyString(args.Target):target}'s maintenance panel {(panel.Open ? "open" : "closed")}");
if (component.IsPanelOpen)
if (panel.Open)
{
_audio.PlayPvs(component.ScrewdriverOpenSound, args.Target);
_audio.PlayPvs(panel.ScrewdriverOpenSound, args.Target);
}
else
{
_audio.PlayPvs(component.ScrewdriverCloseSound, args.Target);
_audio.PlayPvs(panel.ScrewdriverCloseSound, args.Target);
var ui = _uiSystem.GetUiOrNull(args.Target, WiresUiKey.Key);
if (ui != null)
{
_uiSystem.CloseAll(ui);
}
}
Dirty(panel);
}
private void OnToolCanceled(WireToolCanceledEvent ev)
{
if (!TryComp(ev.Target, out WiresComponent? component))
if (!TryComp<WiresPanelComponent>(ev.Target, out var component))
return;
component.IsScrewing = false;
}
private void OnExamine(EntityUid uid, WiresComponent component, ExaminedEvent args)
{
args.PushMarkup(Loc.GetString(component.IsPanelOpen
? "wires-component-on-examine-panel-open"
: "wires-component-on-examine-panel-closed"));
}
private void OnMapInit(EntityUid uid, WiresComponent component, MapInitEvent args)
{
EnsureComp<WiresPanelComponent>(uid);
if (component.SerialNumber == null)
{
GenerateSerialNumber(uid, component);
@@ -574,14 +569,6 @@ public sealed class WiresSystem : EntitySystem
UpdateUserInterface(uid);
}
private void UpdateAppearance(EntityUid uid, AppearanceComponent? appearance = null, WiresComponent? wires = null)
{
if (!Resolve(uid, ref appearance, ref wires, false))
return;
_appearance.SetData(uid, WiresVisuals.MaintenancePanelState, wires.IsPanelOpen && wires.IsPanelVisible, appearance);
}
private void UpdateUserInterface(EntityUid uid, WiresComponent? wires = null, ServerUserInterfaceComponent? ui = null)
{
if (!Resolve(uid, ref wires, ref ui, false)) // logging this means that we get a bunch of errors
@@ -655,6 +642,26 @@ public sealed class WiresSystem : EntitySystem
}
}
public void ChangePanelVisibility(EntityUid uid, WiresPanelComponent component, bool visible)
{
component.Visible = visible;
UpdateAppearance(uid, component);
Dirty(component);
}
public void TogglePanel(EntityUid uid, WiresPanelComponent component, bool open)
{
component.Open = open;
UpdateAppearance(uid, component);
Dirty(component);
}
private void UpdateAppearance(EntityUid uid, WiresPanelComponent panel)
{
if (TryComp<AppearanceComponent>(uid, out var appearance))
_appearance.SetData(uid, WiresVisuals.MaintenancePanelState, panel.Open && panel.Visible, appearance);
}
private void TryDoWireAction(EntityUid used, EntityUid user, EntityUid toolEntity, int id, WiresAction action, WiresComponent? wires = null, ToolComponent? tool = null)
{
if (!Resolve(used, ref wires)
@@ -720,7 +727,7 @@ public sealed class WiresSystem : EntitySystem
if (_toolTime > 0f)
{
var data = new WireExtraData(action, id);
var args = new DoAfterEventArgs(user, _toolTime, target:used, used:toolEntity)
var args = new DoAfterEventArgs(user, _toolTime, target: used, used: toolEntity)
{
NeedHand = true,
BreakOnStun = true,