Wires patches (#8385)

This commit is contained in:
Flipp Syder
2022-05-23 16:00:51 -07:00
committed by GitHub
parent 8cb336b07a
commit 80a68b3867
5 changed files with 74 additions and 52 deletions

View File

@@ -27,7 +27,7 @@ public sealed class PowerWireAction : BaseWireAction
public override StatusLightData? GetStatusLightData(Wire wire) public override StatusLightData? GetStatusLightData(Wire wire)
{ {
StatusLightState lightState = StatusLightState.Off; StatusLightState lightState = StatusLightState.Off;
if (WiresSystem.TryGetData(wire.Owner, PowerWireActionInternalKeys.MainWire, out int main) if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.MainWire, out int main)
&& main != wire.Id) && main != wire.Id)
{ {
return null; return null;
@@ -35,7 +35,8 @@ public sealed class PowerWireAction : BaseWireAction
if (IsPowered(wire.Owner)) if (IsPowered(wire.Owner))
{ {
if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsed) if (!AllWiresMended(wire.Owner)
|| WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsed)
&& pulsed) && pulsed)
{ {
lightState = StatusLightState.BlinkingSlow; lightState = StatusLightState.BlinkingSlow;
@@ -56,11 +57,17 @@ public sealed class PowerWireAction : BaseWireAction
private bool AllWiresCut(EntityUid owner) private bool AllWiresCut(EntityUid owner)
{ {
return WiresSystem.TryGetData(owner, PowerWireActionInternalKeys.CutWires, out int? cut) return WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int? cut)
&& WiresSystem.TryGetData(owner, PowerWireActionInternalKeys.WireCount, out int? count) && WiresSystem.TryGetData(owner, PowerWireActionKey.WireCount, out int? count)
&& count == cut; && count == cut;
} }
private bool AllWiresMended(EntityUid owner)
{
return WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int? cut)
&& cut == 0;
}
// I feel like these two should be within ApcPowerReceiverComponent at this point. // I feel like these two should be within ApcPowerReceiverComponent at this point.
// Getting it from a dictionary is significantly more expensive. // Getting it from a dictionary is significantly more expensive.
private void SetPower(EntityUid owner, bool pulsed) private void SetPower(EntityUid owner, bool pulsed)
@@ -76,8 +83,8 @@ public sealed class PowerWireAction : BaseWireAction
return; return;
} }
if (WiresSystem.TryGetData(owner, PowerWireActionInternalKeys.CutWires, out int? cut) if (WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int? cut)
&& WiresSystem.TryGetData(owner, PowerWireActionInternalKeys.WireCount, out int? count)) && WiresSystem.TryGetData(owner, PowerWireActionKey.WireCount, out int? count))
{ {
if (AllWiresCut(owner)) if (AllWiresCut(owner))
{ {
@@ -98,10 +105,10 @@ public sealed class PowerWireAction : BaseWireAction
private void SetWireCuts(EntityUid owner, bool isCut) private void SetWireCuts(EntityUid owner, bool isCut)
{ {
if (WiresSystem.TryGetData(owner, PowerWireActionInternalKeys.CutWires, out int? cut)) if (WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int? cut))
{ {
cut = isCut ? cut + 1 : cut - 1; cut = isCut ? cut + 1 : cut - 1;
WiresSystem.SetData(owner, PowerWireActionInternalKeys.CutWires, cut); WiresSystem.SetData(owner, PowerWireActionKey.CutWires, cut);
} }
} }
@@ -114,35 +121,38 @@ public sealed class PowerWireAction : BaseWireAction
electrified.Enabled = setting; electrified.Enabled = setting;
} }
/// <returns>false if failed, true otherwise</returns> /// <returns>false if failed, true otherwise, or if the entity cannot be electrified</returns>
private bool TrySetElectrocution(EntityUid user, Wire wire, bool timed = false) private bool TrySetElectrocution(EntityUid user, Wire wire, bool timed = false)
{ {
if (EntityManager.TryGetComponent<ApcPowerReceiverComponent>(wire.Owner, out var power) if (!EntityManager.TryGetComponent<ElectrifiedComponent>(wire.Owner, out var electrified))
&& EntityManager.TryGetComponent<ElectrifiedComponent>(wire.Owner, out var electrified))
{ {
// always set this to true return true;
SetElectrified(wire.Owner, true, electrified); }
// if we were electrified, then return false var allCut = AllWiresCut(wire.Owner);
var electrifiedAttempt = _electrocutionSystem.TryDoElectrifiedAct(wire.Owner, user); // always set this to true
SetElectrified(wire.Owner, true, electrified);
// if this is timed, we set up a doAfter so that the // if we were electrified, then return false
// electrocution continues - unless cancelled var electrifiedAttempt = _electrocutionSystem.TryDoElectrifiedAct(wire.Owner, user);
//
// if the power is disabled however, just don't bother // if this is timed, we set up a doAfter so that the
if (timed && IsPowered(wire.Owner)) // electrocution continues - unless cancelled
{ //
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.ElectrifiedCancel, new TimedWireEvent(AwaitElectrifiedCancel, wire)); // if the power is disabled however, just don't bother
} if (timed && IsPowered(wire.Owner) && !allCut)
else {
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.ElectrifiedCancel, new TimedWireEvent(AwaitElectrifiedCancel, wire));
}
else
{
if (allCut)
{ {
SetElectrified(wire.Owner, false, electrified); SetElectrified(wire.Owner, false, electrified);
} }
return !electrifiedAttempt;
} }
return false; return !electrifiedAttempt;
} }
public override void Initialize() public override void Initialize()
@@ -156,17 +166,17 @@ public sealed class PowerWireAction : BaseWireAction
// in WiresComponent or ApcPowerReceiverComponent. // in WiresComponent or ApcPowerReceiverComponent.
public override bool AddWire(Wire wire, int count) public override bool AddWire(Wire wire, int count)
{ {
if (!WiresSystem.HasData(wire.Owner, PowerWireActionInternalKeys.CutWires)) if (!WiresSystem.HasData(wire.Owner, PowerWireActionKey.CutWires))
{ {
WiresSystem.SetData(wire.Owner, PowerWireActionInternalKeys.CutWires, 0); WiresSystem.SetData(wire.Owner, PowerWireActionKey.CutWires, 0);
} }
if (count == 1) if (count == 1)
{ {
WiresSystem.SetData(wire.Owner, PowerWireActionInternalKeys.MainWire, wire.Id); WiresSystem.SetData(wire.Owner, PowerWireActionKey.MainWire, wire.Id);
} }
WiresSystem.SetData(wire.Owner, PowerWireActionInternalKeys.WireCount, count); WiresSystem.SetData(wire.Owner, PowerWireActionKey.WireCount, count);
return true; return true;
} }
@@ -219,8 +229,6 @@ public sealed class PowerWireAction : BaseWireAction
SetPower(wire.Owner, true); SetPower(wire.Owner, true);
// AwaitPulseCancel(wire.Owner, wire, _doAfterSystem.WaitDoAfter(doAfter));
return true; return true;
} }
@@ -239,8 +247,10 @@ public sealed class PowerWireAction : BaseWireAction
private void AwaitElectrifiedCancel(Wire wire) private void AwaitElectrifiedCancel(Wire wire)
{ {
WiresSystem.SetData(wire.Owner, PowerWireActionKey.Electrified, false); if (AllWiresMended(wire.Owner))
SetElectrified(wire.Owner, false); {
SetElectrified(wire.Owner, false);
}
} }
private void AwaitPulseCancel(Wire wire) private void AwaitPulseCancel(Wire wire)
@@ -248,11 +258,4 @@ public sealed class PowerWireAction : BaseWireAction
WiresSystem.SetData(wire.Owner, PowerWireActionKey.Pulsed, false); WiresSystem.SetData(wire.Owner, PowerWireActionKey.Pulsed, false);
SetPower(wire.Owner, false); SetPower(wire.Owner, false);
} }
private enum PowerWireActionInternalKeys : byte
{
MainWire,
WireCount,
CutWires
}
} }

View File

@@ -240,6 +240,7 @@ public sealed class WiresSystem : EntitySystem
SetOrCreateWireLayout(uid, component); SetOrCreateWireLayout(uid, component);
UpdateUserInterface(uid); UpdateUserInterface(uid);
UpdateAppearance(uid);
} }
#endregion #endregion
@@ -536,7 +537,7 @@ public sealed class WiresSystem : EntitySystem
private void UpdateAppearance(EntityUid uid, AppearanceComponent? appearance = null, WiresComponent? wires = null) private void UpdateAppearance(EntityUid uid, AppearanceComponent? appearance = null, WiresComponent? wires = null)
{ {
if (!Resolve(uid, ref appearance, ref wires)) if (!Resolve(uid, ref appearance, ref wires, false))
return; return;
appearance.SetData(WiresVisuals.MaintenancePanelState, wires.IsPanelOpen && wires.IsPanelVisible); appearance.SetData(WiresVisuals.MaintenancePanelState, wires.IsPanelOpen && wires.IsPanelVisible);
@@ -676,14 +677,22 @@ public sealed class WiresSystem : EntitySystem
private void UpdateWires(EntityUid used, EntityUid user, EntityUid toolEntity, int id, WiresAction action, WiresComponent? wires = null, ToolComponent? tool = null) private void UpdateWires(EntityUid used, EntityUid user, EntityUid toolEntity, int id, WiresAction action, WiresComponent? wires = null, ToolComponent? tool = null)
{ {
if (!Resolve(used, ref wires) if (!Resolve(used, ref wires))
|| !Resolve(toolEntity, ref tool))
return; return;
if (!Resolve(toolEntity, ref tool))
{
wires.WiresQueue.Remove(id);
return;
}
var wire = TryGetWire(used, id, wires); var wire = TryGetWire(used, id, wires);
if (wire == null) if (wire == null)
{
wires.WiresQueue.Remove(id);
return; return;
}
switch (action) switch (action)
{ {
@@ -691,7 +700,7 @@ public sealed class WiresSystem : EntitySystem
if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool)) if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
{ {
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), Filter.Entities(user)); _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), Filter.Entities(user));
return; break;
} }
_toolSystem.PlayToolSound(toolEntity, tool); _toolSystem.PlayToolSound(toolEntity, tool);
@@ -706,7 +715,7 @@ public sealed class WiresSystem : EntitySystem
if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool)) if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
{ {
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), Filter.Entities(user)); _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), Filter.Entities(user));
return; break;
} }
_toolSystem.PlayToolSound(toolEntity, tool); _toolSystem.PlayToolSound(toolEntity, tool);
@@ -721,13 +730,13 @@ public sealed class WiresSystem : EntitySystem
if (!_toolSystem.HasQuality(toolEntity, "Pulsing", tool)) if (!_toolSystem.HasQuality(toolEntity, "Pulsing", tool))
{ {
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), Filter.Entities(user)); _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), Filter.Entities(user));
return; break;
} }
if (wire.IsCut) if (wire.IsCut)
{ {
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-cannot-pulse-cut-wire"), Filter.Entities(user)); _popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-cannot-pulse-cut-wire"), Filter.Entities(user));
return; break;
} }
wire.Action.Pulse(user, wire); wire.Action.Pulse(user, wire);

View File

@@ -18,6 +18,9 @@ namespace Content.Shared.Power
Pulsed, Pulsed,
Electrified, Electrified,
PulseCancel, PulseCancel,
ElectrifiedCancel ElectrifiedCancel,
MainWire,
WireCount,
CutWires
} }
} }

View File

@@ -84,6 +84,9 @@
path: /Audio/Machines/windoor_open.ogg path: /Audio/Machines/windoor_open.ogg
denySound: denySound:
path: /Audio/Machines/airlock_deny.ogg path: /Audio/Machines/airlock_deny.ogg
- type: Electrified
enabled: false
usesApcPower: true
- type: Wires - type: Wires
BoardName: "Windoor Control" BoardName: "Windoor Control"
LayoutId: Windoors LayoutId: Windoors

View File

@@ -21,6 +21,10 @@
parent: Airlock parent: Airlock
id: AirlockArmory id: AirlockArmory
- type: wireLayout
parent: Airlock
id: Windoors
- type: wireLayout - type: wireLayout
id: HighSec id: HighSec
wires: wires: