@@ -1,29 +1,71 @@
|
||||
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)
|
||||
@@ -33,4 +75,34 @@ public abstract class SharedWiresSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user