Files
OldThink/Content.Shared/Wires/SharedWiresSystem.cs

136 lines
4.8 KiB
C#
Raw Permalink Normal View History

using Content.Shared.Administration.Logs;
using Content.Shared.Database;
2023-03-24 03:09:45 +03:00
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Tools.Systems;
using Robust.Shared.Audio.Systems;
2023-03-24 03:09:45 +03:00
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!;
2023-03-24 03:09:45 +03:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WiresPanelComponent, WirePanelDoAfterEvent>(OnPanelDoAfter);
SubscribeLocalEvent<WiresPanelComponent, InteractUsingEvent>(OnInteractUsing);
2023-03-24 03:09:45 +03:00
SubscribeLocalEvent<WiresPanelComponent, ExaminedEvent>(OnExamine);
}
private void OnPanelDoAfter(EntityUid uid, WiresPanelComponent panel, WirePanelDoAfterEvent args)
{
if (args.Cancelled)
return;
if (!TogglePanel(uid, panel, !panel.Open, args.User))
return;
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);
args.Handled = true;
}
private void OnInteractUsing(Entity<WiresPanelComponent> ent, ref InteractUsingEvent args)
{
if (!Tool.HasQuality(args.Used, ent.Comp.OpeningTool))
return;
if (!CanTogglePanel(ent, args.User))
return;
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;
}
2023-03-24 03:09:45 +03:00
private void OnExamine(EntityUid uid, WiresPanelComponent component, ExaminedEvent args)
{
using (args.PushGroup(nameof(WiresPanelComponent)))
2023-03-24 03:09:45 +03:00
{
if (!component.Open)
Hacking protections for airlocks (#18894) * Adds the ability to better protect to the internal wiring of airlocks - Achieved by opening the maintenance panel, adding either steel or plasteel to the airlock, then welding the plate in place - To access the wiring, the plating must be cut with a welder and then pried out with a crowbar * Code revisions - Cleaned up the code - Cutting the security grille can now shock you - Atmospherics and Security dept airlocks start with a medium level of protection (a welded steel plate) - Command dept airlocks start with a high level of protection (a welded plasteel plate and electrified security grille) * Code revision - Accounted for a potentially null string * Update Content.Server/Construction/Completions/AttemptElectrocute.cs Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> * Update ChangeWiresPanelSecurityLevel.cs Adjusted scope * Update Content.Shared/Wires/SharedWiresSystem.cs Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> * Update Content.Shared/Wires/SharedWiresSystem.cs Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> * Update ChangeWiresPanelSecurityLevel.cs Removed get / setter and added [ValidatePrototypeId] attribute * Update ChangeWiresPanelSecurityLevel.cs Set security level to "Level0" as the default * Update airlock.yml Removed 'super max' level of security * Update WiresPanelSecurityLevelPrototype.cs * Update WiresSystem.cs Added check for WiresAccessible to OnInteractUsing * Update AttemptElectrocute.cs File scoped namespace * Update ChangeWiresPanelSecurityLevel.cs File scoped namespace * Update AirlockSystem.cs File scoped namespace * Update SharedWiresSystem.cs Removed boiler plate 'OnGetState' and 'OnHandleState' * Update WiresPanelComponent.cs Implemented AutoGenerateComponentState * Removed unnecessary usage references * use TryCloseAll when wires not accessible * minor changes to AttemmptElectrocute * lets try all 7 levels * fix indent in airlock graph * fix indent 2 --------- Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> Co-authored-by: Slava0135 <super.novalskiy_0135@inbox.ru>
2023-08-10 03:33:03 -05:00
{
if (!string.IsNullOrEmpty(component.ExamineTextClosed))
args.PushMarkup(Loc.GetString(component.ExamineTextClosed));
}
else
{
if (!string.IsNullOrEmpty(component.ExamineTextOpen))
args.PushMarkup(Loc.GetString(component.ExamineTextOpen));
if (TryComp<WiresPanelSecurityComponent>(uid, out var wiresPanelSecurity) &&
wiresPanelSecurity.Examine != null)
{
args.PushMarkup(Loc.GetString(wiresPanelSecurity.Examine));
}
Hacking protections for airlocks (#18894) * Adds the ability to better protect to the internal wiring of airlocks - Achieved by opening the maintenance panel, adding either steel or plasteel to the airlock, then welding the plate in place - To access the wiring, the plating must be cut with a welder and then pried out with a crowbar * Code revisions - Cleaned up the code - Cutting the security grille can now shock you - Atmospherics and Security dept airlocks start with a medium level of protection (a welded steel plate) - Command dept airlocks start with a high level of protection (a welded plasteel plate and electrified security grille) * Code revision - Accounted for a potentially null string * Update Content.Server/Construction/Completions/AttemptElectrocute.cs Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> * Update ChangeWiresPanelSecurityLevel.cs Adjusted scope * Update Content.Shared/Wires/SharedWiresSystem.cs Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> * Update Content.Shared/Wires/SharedWiresSystem.cs Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> * Update ChangeWiresPanelSecurityLevel.cs Removed get / setter and added [ValidatePrototypeId] attribute * Update ChangeWiresPanelSecurityLevel.cs Set security level to "Level0" as the default * Update airlock.yml Removed 'super max' level of security * Update WiresPanelSecurityLevelPrototype.cs * Update WiresSystem.cs Added check for WiresAccessible to OnInteractUsing * Update AttemptElectrocute.cs File scoped namespace * Update ChangeWiresPanelSecurityLevel.cs File scoped namespace * Update AirlockSystem.cs File scoped namespace * Update SharedWiresSystem.cs Removed boiler plate 'OnGetState' and 'OnHandleState' * Update WiresPanelComponent.cs Implemented AutoGenerateComponentState * Removed unnecessary usage references * use TryCloseAll when wires not accessible * minor changes to AttemmptElectrocute * lets try all 7 levels * fix indent in airlock graph * fix indent 2 --------- Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> Co-authored-by: Slava0135 <super.novalskiy_0135@inbox.ru>
2023-08-10 03:33:03 -05:00
}
}
2023-03-24 03:09:45 +03:00
}
public void ChangePanelVisibility(EntityUid uid, WiresPanelComponent component, bool visible)
{
component.Visible = visible;
UpdateAppearance(uid, component);
Dirty(uid, component);
}
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 bool TogglePanel(EntityUid uid, WiresPanelComponent component, bool open, EntityUid? user = null)
{
if (!CanTogglePanel((uid, component), user))
return false;
component.Open = open;
UpdateAppearance(uid, component);
Dirty(uid, component);
var ev = new PanelChangedEvent(component.Open);
RaiseLocalEvent(uid, ref ev);
return true;
}
public bool CanTogglePanel(Entity<WiresPanelComponent> ent, EntityUid? user)
{
var attempt = new AttemptChangePanelEvent(ent.Comp.Open, user);
RaiseLocalEvent(ent, ref attempt);
return !attempt.Cancelled;
}
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;
}
Hacking protections for airlocks (#18894) * Adds the ability to better protect to the internal wiring of airlocks - Achieved by opening the maintenance panel, adding either steel or plasteel to the airlock, then welding the plate in place - To access the wiring, the plating must be cut with a welder and then pried out with a crowbar * Code revisions - Cleaned up the code - Cutting the security grille can now shock you - Atmospherics and Security dept airlocks start with a medium level of protection (a welded steel plate) - Command dept airlocks start with a high level of protection (a welded plasteel plate and electrified security grille) * Code revision - Accounted for a potentially null string * Update Content.Server/Construction/Completions/AttemptElectrocute.cs Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> * Update ChangeWiresPanelSecurityLevel.cs Adjusted scope * Update Content.Shared/Wires/SharedWiresSystem.cs Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> * Update Content.Shared/Wires/SharedWiresSystem.cs Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> * Update ChangeWiresPanelSecurityLevel.cs Removed get / setter and added [ValidatePrototypeId] attribute * Update ChangeWiresPanelSecurityLevel.cs Set security level to "Level0" as the default * Update airlock.yml Removed 'super max' level of security * Update WiresPanelSecurityLevelPrototype.cs * Update WiresSystem.cs Added check for WiresAccessible to OnInteractUsing * Update AttemptElectrocute.cs File scoped namespace * Update ChangeWiresPanelSecurityLevel.cs File scoped namespace * Update AirlockSystem.cs File scoped namespace * Update SharedWiresSystem.cs Removed boiler plate 'OnGetState' and 'OnHandleState' * Update WiresPanelComponent.cs Implemented AutoGenerateComponentState * Removed unnecessary usage references * use TryCloseAll when wires not accessible * minor changes to AttemmptElectrocute * lets try all 7 levels * fix indent in airlock graph * fix indent 2 --------- Co-authored-by: Slava0135 <40753025+Slava0135@users.noreply.github.com> Co-authored-by: Slava0135 <super.novalskiy_0135@inbox.ru>
2023-08-10 03:33:03 -05:00
}