Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArturZh committed Aug 10, 2023
2 parents b1bd431 + 4b803af commit d7d3e8f
Show file tree
Hide file tree
Showing 21 changed files with 567 additions and 232 deletions.
25 changes: 16 additions & 9 deletions Content.Server/Construction/Completions/AttemptElectrocute.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
using Content.Server.Electrocution;
using Content.Shared.Construction;

namespace Content.Server.Construction.Completions
namespace Content.Server.Construction.Completions;

[DataDefinition]
public sealed class AttemptElectrocute : IGraphAction
{
[DataDefinition]
public sealed class AttemptElectrocute : IGraphAction
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
{
public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
{
if (userUid == null)
return;
if (userUid == null)
return;

if (!entityManager.TryGetComponent<ElectrifiedComponent>(uid, out var electrified))
return;

var currentValue = electrified.Enabled;
electrified.Enabled = true;

entityManager.EntitySysManager.GetEntitySystem<ElectrocutionSystem>().TryDoElectrifiedAct(uid, userUid.Value, electrified: electrified);

entityManager.EntitySysManager.GetEntitySystem<ElectrocutionSystem>().TryDoElectrifiedAct(uid, userUid.Value);
}
electrified.Enabled = currentValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Content.Server.Wires;
using Content.Shared.Construction;
using Content.Shared.Wires;
using JetBrains.Annotations;

namespace Content.Server.Construction.Completions;

[UsedImplicitly]
[DataDefinition]
public sealed class ChangeWiresPanelSecurityLevel : IGraphAction
{
[DataField("level")]
[ValidatePrototypeId<WiresPanelSecurityLevelPrototype>]
public string WiresPanelSecurityLevelID = "Level0";

public void PerformAction(EntityUid uid, EntityUid? userUid, IEntityManager entityManager)
{
if (WiresPanelSecurityLevelID == null)
return;

if (entityManager.TryGetComponent(uid, out WiresPanelComponent? wiresPanel)
&& entityManager.TrySystem(out WiresSystem? wiresSystem))
{
wiresSystem.SetWiresPanelSecurityData(uid, wiresPanel, WiresPanelSecurityLevelID);
}
}
}
265 changes: 132 additions & 133 deletions Content.Server/Doors/Systems/AirlockSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,181 +10,180 @@
using Robust.Server.GameObjects;
using Content.Shared.Wires;

namespace Content.Server.Doors.Systems
namespace Content.Server.Doors.Systems;

public sealed class AirlockSystem : SharedAirlockSystem
{
public sealed class AirlockSystem : SharedAirlockSystem
{
[Dependency] private readonly WiresSystem _wiresSystem = default!;
[Dependency] private readonly PowerReceiverSystem _power = default!;
[Dependency] private readonly DoorBoltSystem _bolts = default!;
[Dependency] private readonly WiresSystem _wiresSystem = default!;
[Dependency] private readonly PowerReceiverSystem _power = default!;
[Dependency] private readonly DoorBoltSystem _bolts = default!;

public override void Initialize()
{
base.Initialize();
public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<AirlockComponent, ComponentInit>(OnAirlockInit);
SubscribeLocalEvent<AirlockComponent, SignalReceivedEvent>(OnSignalReceived);
SubscribeLocalEvent<AirlockComponent, ComponentInit>(OnAirlockInit);
SubscribeLocalEvent<AirlockComponent, SignalReceivedEvent>(OnSignalReceived);

SubscribeLocalEvent<AirlockComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<AirlockComponent, DoorStateChangedEvent>(OnStateChanged);
SubscribeLocalEvent<AirlockComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened);
SubscribeLocalEvent<AirlockComponent, BeforeDoorDeniedEvent>(OnBeforeDoorDenied);
SubscribeLocalEvent<AirlockComponent, ActivateInWorldEvent>(OnActivate, before: new [] {typeof(DoorSystem)});
SubscribeLocalEvent<AirlockComponent, DoorGetPryTimeModifierEvent>(OnGetPryMod);
SubscribeLocalEvent<AirlockComponent, BeforeDoorPryEvent>(OnDoorPry);
SubscribeLocalEvent<AirlockComponent, PowerChangedEvent>(OnPowerChanged);
SubscribeLocalEvent<AirlockComponent, DoorStateChangedEvent>(OnStateChanged);
SubscribeLocalEvent<AirlockComponent, BeforeDoorOpenedEvent>(OnBeforeDoorOpened);
SubscribeLocalEvent<AirlockComponent, BeforeDoorDeniedEvent>(OnBeforeDoorDenied);
SubscribeLocalEvent<AirlockComponent, ActivateInWorldEvent>(OnActivate, before: new [] {typeof(DoorSystem)});
SubscribeLocalEvent<AirlockComponent, DoorGetPryTimeModifierEvent>(OnGetPryMod);
SubscribeLocalEvent<AirlockComponent, BeforeDoorPryEvent>(OnDoorPry);

}
}

private void OnAirlockInit(EntityUid uid, AirlockComponent component, ComponentInit args)
private void OnAirlockInit(EntityUid uid, AirlockComponent component, ComponentInit args)
{
if (TryComp<ApcPowerReceiverComponent>(uid, out var receiverComponent))
{
if (TryComp<ApcPowerReceiverComponent>(uid, out var receiverComponent))
{
Appearance.SetData(uid, DoorVisuals.Powered, receiverComponent.Powered);
Appearance.SetData(uid, DoorVisuals.ClosedLights, true); // Corvax-Resprite-Airlocks
}
Appearance.SetData(uid, DoorVisuals.Powered, receiverComponent.Powered);
Appearance.SetData(uid, DoorVisuals.ClosedLights, true); // Corvax-Resprite-Airlocks
}
}

private void OnSignalReceived(EntityUid uid, AirlockComponent component, ref SignalReceivedEvent args)
private void OnSignalReceived(EntityUid uid, AirlockComponent component, ref SignalReceivedEvent args)
{
if (args.Port == component.AutoClosePort)
{
if (args.Port == component.AutoClosePort)
{
component.AutoClose = false;
}
component.AutoClose = false;
}
}

private void OnPowerChanged(EntityUid uid, AirlockComponent component, ref PowerChangedEvent args)
private void OnPowerChanged(EntityUid uid, AirlockComponent component, ref PowerChangedEvent args)
{
if (TryComp<AppearanceComponent>(uid, out var appearanceComponent))
{
if (TryComp<AppearanceComponent>(uid, out var appearanceComponent))
{
Appearance.SetData(uid, DoorVisuals.Powered, args.Powered, appearanceComponent);
}
Appearance.SetData(uid, DoorVisuals.Powered, args.Powered, appearanceComponent);
}

if (!TryComp(uid, out DoorComponent? door))
return;
if (!TryComp(uid, out DoorComponent? door))
return;

if (!args.Powered)
{
// stop any scheduled auto-closing
if (door.State == DoorState.Open)
DoorSystem.SetNextStateChange(uid, null);
}
else
{
UpdateAutoClose(uid, door: door);
}
if (!args.Powered)
{
// stop any scheduled auto-closing
if (door.State == DoorState.Open)
DoorSystem.SetNextStateChange(uid, null);
}

private void OnStateChanged(EntityUid uid, AirlockComponent component, DoorStateChangedEvent args)
else
{
// TODO move to shared? having this be server-side, but having client-side door opening/closing & prediction
// 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<WiresPanelComponent>(uid, out var wiresPanel))
{
_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
UpdateAutoClose(uid, component);

// Make sure the airlock auto closes again next time it is opened
if (args.State == DoorState.Closed)
component.AutoClose = true;
UpdateAutoClose(uid, door: door);
}
}

private void OnStateChanged(EntityUid uid, AirlockComponent component, DoorStateChangedEvent args)
{
// TODO move to shared? having this be server-side, but having client-side door opening/closing & prediction
// means that sometimes the panels & bolt lights may be visible despite a door being completely open.

/// <summary>
/// Updates the auto close timer.
/// </summary>
public void UpdateAutoClose(EntityUid uid, AirlockComponent? airlock = null, DoorComponent? door = null)
// Only show the maintenance panel if the airlock is closed
if (TryComp<WiresPanelComponent>(uid, out var wiresPanel))
{
if (!Resolve(uid, ref airlock, ref door))
return;
_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
UpdateAutoClose(uid, component);

if (door.State != DoorState.Open)
return;
// Make sure the airlock auto closes again next time it is opened
if (args.State == DoorState.Closed)
component.AutoClose = true;
}

if (!airlock.AutoClose)
return;
/// <summary>
/// Updates the auto close timer.
/// </summary>
public void UpdateAutoClose(EntityUid uid, AirlockComponent? airlock = null, DoorComponent? door = null)
{
if (!Resolve(uid, ref airlock, ref door))
return;

if (!CanChangeState(uid, airlock))
return;
if (door.State != DoorState.Open)
return;

var autoev = new BeforeDoorAutoCloseEvent();
RaiseLocalEvent(uid, autoev, false);
if (autoev.Cancelled)
return;
if (!airlock.AutoClose)
return;

DoorSystem.SetNextStateChange(uid, airlock.AutoCloseDelay * airlock.AutoCloseDelayModifier);
}
if (!CanChangeState(uid, airlock))
return;

private void OnBeforeDoorOpened(EntityUid uid, AirlockComponent component, BeforeDoorOpenedEvent args)
{
if (!CanChangeState(uid, component))
args.Cancel();
}
var autoev = new BeforeDoorAutoCloseEvent();
RaiseLocalEvent(uid, autoev, false);
if (autoev.Cancelled)
return;

protected override void OnBeforeDoorClosed(EntityUid uid, AirlockComponent component, BeforeDoorClosedEvent args)
{
base.OnBeforeDoorClosed(uid, component, args);
DoorSystem.SetNextStateChange(uid, airlock.AutoCloseDelay * airlock.AutoCloseDelayModifier);
}

if (args.Cancelled)
return;
private void OnBeforeDoorOpened(EntityUid uid, AirlockComponent component, BeforeDoorOpenedEvent args)
{
if (!CanChangeState(uid, component))
args.Cancel();
}

// only block based on bolts / power status when initially closing the door, not when its already
// mid-transition. Particularly relevant for when the door was pried-closed with a crowbar, which bypasses
// the initial power-check.
protected override void OnBeforeDoorClosed(EntityUid uid, AirlockComponent component, BeforeDoorClosedEvent args)
{
base.OnBeforeDoorClosed(uid, component, args);

if (TryComp(uid, out DoorComponent? door)
&& !door.Partial
&& !CanChangeState(uid, component))
{
args.Cancel();
}
}
if (args.Cancelled)
return;

private void OnBeforeDoorDenied(EntityUid uid, AirlockComponent component, BeforeDoorDeniedEvent args)
{
if (!CanChangeState(uid, component))
args.Cancel();
}
// only block based on bolts / power status when initially closing the door, not when its already
// mid-transition. Particularly relevant for when the door was pried-closed with a crowbar, which bypasses
// the initial power-check.

private void OnActivate(EntityUid uid, AirlockComponent component, ActivateInWorldEvent args)
if (TryComp(uid, out DoorComponent? door)
&& !door.Partial
&& !CanChangeState(uid, component))
{
if (TryComp<WiresPanelComponent>(uid, out var panel) && panel.Open &&
TryComp<ActorComponent>(args.User, out var actor))
{
_wiresSystem.OpenUserInterface(uid, actor.PlayerSession);
args.Handled = true;
return;
}

if (component.KeepOpenIfClicked)
{
// Disable auto close
component.AutoClose = false;
}
args.Cancel();
}
}

private void OnGetPryMod(EntityUid uid, AirlockComponent component, DoorGetPryTimeModifierEvent args)
private void OnBeforeDoorDenied(EntityUid uid, AirlockComponent component, BeforeDoorDeniedEvent args)
{
if (!CanChangeState(uid, component))
args.Cancel();
}

private void OnActivate(EntityUid uid, AirlockComponent component, ActivateInWorldEvent args)
{
if (TryComp<WiresPanelComponent>(uid, out var panel) && panel.Open && panel.WiresAccessible
&& TryComp<ActorComponent>(args.User, out var actor))
{
if (_power.IsPowered(uid))
args.PryTimeModifier *= component.PoweredPryModifier;
_wiresSystem.OpenUserInterface(uid, actor.PlayerSession);
args.Handled = true;
return;
}

private void OnDoorPry(EntityUid uid, AirlockComponent component, BeforeDoorPryEvent args)
if (component.KeepOpenIfClicked)
{
if (this.IsPowered(uid, EntityManager))
{
if (HasComp<ToolForcePoweredComponent>(args.Tool))
return;
Popup.PopupEntity(Loc.GetString("airlock-component-cannot-pry-is-powered-message"), uid, args.User);
args.Cancel();
}
// Disable auto close
component.AutoClose = false;
}
}

public bool CanChangeState(EntityUid uid, AirlockComponent component)
private void OnGetPryMod(EntityUid uid, AirlockComponent component, DoorGetPryTimeModifierEvent args)
{
if (_power.IsPowered(uid))
args.PryTimeModifier *= component.PoweredPryModifier;
}

private void OnDoorPry(EntityUid uid, AirlockComponent component, BeforeDoorPryEvent args)
{
if (this.IsPowered(uid, EntityManager))
{
return this.IsPowered(uid, EntityManager) && !_bolts.IsBolted(uid);
if (HasComp<ToolForcePoweredComponent>(args.Tool))
return;
Popup.PopupEntity(Loc.GetString("airlock-component-cannot-pry-is-powered-message"), uid, args.User);
args.Cancel();
}
}

public bool CanChangeState(EntityUid uid, AirlockComponent component)
{
return this.IsPowered(uid, EntityManager) && !_bolts.IsBolted(uid);
}
}
1 change: 0 additions & 1 deletion Content.Server/Electrocution/ElectrocutionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable;
using Content.Shared.Tag;
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Audio;
using Robust.Shared.Map;
Expand Down
Loading

0 comments on commit d7d3e8f

Please sign in to comment.