using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
-using Content.Server.Administration.Logs;
using Content.Server.Construction;
using Content.Server.Construction.Components;
using Content.Server.Power.Components;
-using Content.Shared.UserInterface;
-using Content.Shared.Database;
+using Content.Server.UserInterface;
using Content.Shared.DoAfter;
using Content.Shared.GameTicking;
using Content.Shared.Hands.Components;
using Content.Shared.Interaction;
using Content.Shared.Popups;
-using Content.Shared.Tools;
using Content.Shared.Tools.Components;
+using Content.Shared.UserInterface;
using Content.Shared.Wires;
using Robust.Server.GameObjects;
-using Robust.Server.Player;
-using Robust.Shared.Audio;
-using Robust.Shared.Audio.Systems;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
-using SharedToolSystem = Content.Shared.Tools.Systems.SharedToolSystem;
-using Content.Server.UserInterface;
namespace Content.Server.Wires;
public sealed class WiresSystem : SharedWiresSystem
{
[Dependency] private readonly IPrototypeManager _protoMan = default!;
- [Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly ActivatableUISystem _activatableUI = default!;
[Dependency] private readonly SharedDoAfterSystem _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!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ConstructionSystem _construction = default!;
// This is where all the wire layouts are stored.
[ViewVariables] private readonly Dictionary<string, WireLayout> _layouts = new();
- private const float ScrewTime = 1f;
private float _toolTime = 0f;
#region Initialization
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
// this is a broadcast event
- SubscribeLocalEvent<WiresPanelComponent, WirePanelDoAfterEvent>(OnPanelDoAfter);
- SubscribeLocalEvent<WiresComponent, ComponentStartup>(OnWiresStartup);
+ SubscribeLocalEvent<WiresComponent, PanelChangedEvent>(OnPanelChanged);
SubscribeLocalEvent<WiresComponent, WiresActionMessage>(OnWiresActionMessage);
SubscribeLocalEvent<WiresComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<WiresComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<ActivatableUIRequiresPanelComponent, PanelChangedEvent>(OnActivatableUIPanelChanged);
SubscribeLocalEvent<WiresPanelSecurityComponent, WiresPanelSecurityEvent>(SetWiresPanelSecurity);
}
+
private void SetOrCreateWireLayout(EntityUid uid, WiresComponent? wires = null)
{
if (!Resolve(uid, ref wires))
position,
action);
}
-
- private void OnWiresStartup(EntityUid uid, WiresComponent component, ComponentStartup args)
- {
- EnsureComp<WiresPanelComponent>(uid);
- }
#endregion
#region DoAfters
if (args.Handled)
return;
- if (!TryComp<ToolComponent>(args.Used, out var tool) || !TryComp<WiresPanelComponent>(uid, out var panel))
+ if (!TryComp<ToolComponent>(args.Used, out var tool))
return;
- if (panel.Open &&
- (_toolSystem.HasQuality(args.Used, "Cutting", tool) ||
- _toolSystem.HasQuality(args.Used, "Pulsing", tool)))
- {
- if (TryComp<WiresPanelSecurityComponent>(uid, out var wiresPanelSecurity) &&
- !wiresPanelSecurity.WiresAccessible)
- return;
+ if (!IsPanelOpen(uid))
+ return;
+ if (Tool.HasQuality(args.Used, "Cutting", tool) ||
+ Tool.HasQuality(args.Used, "Pulsing", tool))
+ {
if (TryComp(args.User, out ActorComponent? actor))
{
_uiSystem.TryOpen(uid, WiresUiKey.Key, actor.PlayerSession);
args.Handled = true;
}
}
- else if (_toolSystem.UseTool(args.Used, args.User, uid, ScrewTime, "Screwing", new WirePanelDoAfterEvent(), toolComponent: tool))
- {
- _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}");
- args.Handled = true;
- }
}
- private void OnPanelDoAfter(EntityUid uid, WiresPanelComponent panel, WirePanelDoAfterEvent args)
+ private void OnPanelChanged(Entity<WiresComponent> ent, ref PanelChangedEvent args)
{
- if (args.Cancelled)
+ if (args.Open)
return;
-
- TogglePanel(uid, panel, !panel.Open);
- UpdateAppearance(uid, panel);
- _adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} screwed {ToPrettyString(uid):target}'s maintenance panel {(panel.Open ? "open" : "closed")}");
-
- if (panel.Open)
- {
- _audio.PlayPvs(panel.ScrewdriverOpenSound, uid);
- }
- else
- {
- _audio.PlayPvs(panel.ScrewdriverCloseSound, uid);
- _uiSystem.TryCloseAll(uid, WiresUiKey.Key);
- }
+ _uiSystem.TryCloseAll(ent, WiresUiKey.Key);
}
private void OnAttemptOpenActivatableUI(EntityUid uid, ActivatableUIRequiresPanelComponent component, ActivatableUIOpenAttemptEvent args)
Dirty(uid, component);
}
- public void TogglePanel(EntityUid uid, WiresPanelComponent component, bool open)
- {
- component.Open = open;
- UpdateAppearance(uid, component);
- Dirty(uid, component);
-
- var ev = new PanelChangedEvent(component.Open);
- RaiseLocalEvent(uid, ref ev);
- }
-
public void SetWiresPanelSecurity(EntityUid uid, WiresPanelSecurityComponent component, WiresPanelSecurityEvent args)
{
component.Examine = args.Examine;
}
}
- 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 target, EntityUid user, EntityUid toolEntity, int id, WiresAction action, WiresComponent? wires = null, ToolComponent? tool = null)
{
if (!Resolve(target, ref wires)
switch (action)
{
case WiresAction.Cut:
- if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
+ if (!Tool.HasQuality(toolEntity, "Cutting", tool))
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
return;
break;
case WiresAction.Mend:
- if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
+ if (!Tool.HasQuality(toolEntity, "Cutting", tool))
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
return;
break;
case WiresAction.Pulse:
- if (!_toolSystem.HasQuality(toolEntity, "Pulsing", tool))
+ if (!Tool.HasQuality(toolEntity, "Pulsing", tool))
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), user);
return;
switch (action)
{
case WiresAction.Cut:
- if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
+ if (!Tool.HasQuality(toolEntity, "Cutting", tool))
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
break;
break;
}
- _toolSystem.PlayToolSound(toolEntity, tool, user);
+ Tool.PlayToolSound(toolEntity, tool, user);
if (wire.Action == null || wire.Action.Cut(user, wire))
{
wire.IsCut = true;
UpdateUserInterface(used);
break;
case WiresAction.Mend:
- if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
+ if (!Tool.HasQuality(toolEntity, "Cutting", tool))
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), user);
break;
break;
}
- _toolSystem.PlayToolSound(toolEntity, tool, user);
+ Tool.PlayToolSound(toolEntity, tool, user);
if (wire.Action == null || wire.Action.Mend(user, wire))
{
wire.IsCut = false;
UpdateUserInterface(used);
break;
case WiresAction.Pulse:
- if (!_toolSystem.HasQuality(toolEntity, "Pulsing", tool))
+ if (!Tool.HasQuality(toolEntity, "Pulsing", tool))
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), user);
break;
wire.Action?.Pulse(user, wire);
UpdateUserInterface(used);
- _audio.PlayPvs(wires.PulseSound, used);
+ Audio.PlayPvs(wires.PulseSound, used);
break;
}
+using Content.Shared.Administration.Logs;
+using Content.Shared.Database;
using Content.Shared.Examine;
+using Content.Shared.Interaction;
using Content.Shared.Tools.Systems;
-using Robust.Shared.Prototypes;
+using Robust.Shared.Audio.Systems;
namespace Content.Shared.Wires;
public abstract class SharedWiresSystem : EntitySystem
{
+ [Dependency] protected readonly ISharedAdminLogManager AdminLogger = default!;
+ [Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
+ [Dependency] protected readonly SharedAudioSystem Audio = default!;
+ [Dependency] protected readonly SharedToolSystem Tool = default!;
+
public override void Initialize()
{
base.Initialize();
+ SubscribeLocalEvent<WiresPanelComponent, WirePanelDoAfterEvent>(OnPanelDoAfter);
+ SubscribeLocalEvent<WiresPanelComponent, InteractUsingEvent>(OnInteractUsing);
SubscribeLocalEvent<WiresPanelComponent, ExaminedEvent>(OnExamine);
}
+ private void OnPanelDoAfter(EntityUid uid, WiresPanelComponent panel, WirePanelDoAfterEvent args)
+ {
+ if (args.Cancelled)
+ return;
+
+ TogglePanel(uid, panel, !panel.Open);
+ AdminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} screwed {ToPrettyString(uid):target}'s maintenance panel {(panel.Open ? "open" : "closed")}");
+
+ var sound = panel.Open ? panel.ScrewdriverOpenSound : panel.ScrewdriverCloseSound;
+ Audio.PlayPredicted(sound, uid, args.User);
+ }
+
+ private void OnInteractUsing(Entity<WiresPanelComponent> ent, ref InteractUsingEvent args)
+ {
+ if (!Tool.UseTool(
+ args.Used,
+ args.User,
+ ent,
+ (float) ent.Comp.OpenDelay.TotalSeconds,
+ ent.Comp.OpeningTool,
+ new WirePanelDoAfterEvent()))
+ {
+ return;
+ }
+
+ AdminLogger.Add(LogType.Action, LogImpact.Low,
+ $"{ToPrettyString(args.User):user} is screwing {ToPrettyString(ent):target}'s {(ent.Comp.Open ? "open" : "closed")} maintenance panel at {Transform(ent).Coordinates:targetlocation}");
+ args.Handled = true;
+ }
+
private void OnExamine(EntityUid uid, WiresPanelComponent component, ExaminedEvent args)
{
using (args.PushGroup(nameof(WiresPanelComponent)))
{
if (!component.Open)
{
- args.PushMarkup(Loc.GetString("wires-panel-component-on-examine-closed"));
+ if (!string.IsNullOrEmpty(component.ExamineTextClosed))
+ args.PushMarkup(Loc.GetString(component.ExamineTextClosed));
}
else
{
- args.PushMarkup(Loc.GetString("wires-panel-component-on-examine-open"));
+ if (!string.IsNullOrEmpty(component.ExamineTextOpen))
+ args.PushMarkup(Loc.GetString(component.ExamineTextOpen));
if (TryComp<WiresPanelSecurityComponent>(uid, out var wiresPanelSecurity) &&
wiresPanelSecurity.Examine != null)
}
}
}
+
+ protected void UpdateAppearance(EntityUid uid, WiresPanelComponent panel)
+ {
+ if (TryComp<AppearanceComponent>(uid, out var appearance))
+ Appearance.SetData(uid, WiresVisuals.MaintenancePanelState, panel.Open && panel.Visible, appearance);
+ }
+
+ public void TogglePanel(EntityUid uid, WiresPanelComponent component, bool open)
+ {
+ component.Open = open;
+ UpdateAppearance(uid, component);
+ Dirty(uid, component);
+
+ var ev = new PanelChangedEvent(component.Open);
+ RaiseLocalEvent(uid, ref ev);
+ }
+
+ public bool IsPanelOpen(Entity<WiresPanelComponent?> entity)
+ {
+ if (!Resolve(entity, ref entity.Comp, false))
+ return true;
+
+ // Listen, i don't know what the fuck this component does. it's stapled on shit for airlocks
+ // but it looks like an almost direct duplication of WiresPanelComponent except with a shittier API.
+ if (TryComp<WiresPanelSecurityComponent>(entity, out var wiresPanelSecurity) &&
+ !wiresPanelSecurity.WiresAccessible)
+ return false;
+
+ return entity.Comp.Open;
+ }
}