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)
{
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)
{
return null;
@@ -35,7 +35,8 @@ public sealed class PowerWireAction : BaseWireAction
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)
{
lightState = StatusLightState.BlinkingSlow;
@@ -56,11 +57,17 @@ public sealed class PowerWireAction : BaseWireAction
private bool AllWiresCut(EntityUid owner)
{
return WiresSystem.TryGetData(owner, PowerWireActionInternalKeys.CutWires, out int? cut)
&& WiresSystem.TryGetData(owner, PowerWireActionInternalKeys.WireCount, out int? count)
return WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int? cut)
&& WiresSystem.TryGetData(owner, PowerWireActionKey.WireCount, out int? count)
&& 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.
// Getting it from a dictionary is significantly more expensive.
private void SetPower(EntityUid owner, bool pulsed)
@@ -76,8 +83,8 @@ public sealed class PowerWireAction : BaseWireAction
return;
}
if (WiresSystem.TryGetData(owner, PowerWireActionInternalKeys.CutWires, out int? cut)
&& WiresSystem.TryGetData(owner, PowerWireActionInternalKeys.WireCount, out int? count))
if (WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int? cut)
&& WiresSystem.TryGetData(owner, PowerWireActionKey.WireCount, out int? count))
{
if (AllWiresCut(owner))
{
@@ -98,10 +105,10 @@ public sealed class PowerWireAction : BaseWireAction
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;
WiresSystem.SetData(owner, PowerWireActionInternalKeys.CutWires, cut);
WiresSystem.SetData(owner, PowerWireActionKey.CutWires, cut);
}
}
@@ -114,35 +121,38 @@ public sealed class PowerWireAction : BaseWireAction
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)
{
if (EntityManager.TryGetComponent<ApcPowerReceiverComponent>(wire.Owner, out var power)
&& EntityManager.TryGetComponent<ElectrifiedComponent>(wire.Owner, out var electrified))
if (!EntityManager.TryGetComponent<ElectrifiedComponent>(wire.Owner, out var electrified))
{
// always set this to true
SetElectrified(wire.Owner, true, electrified);
return true;
}
// if we were electrified, then return false
var electrifiedAttempt = _electrocutionSystem.TryDoElectrifiedAct(wire.Owner, user);
var allCut = AllWiresCut(wire.Owner);
// always set this to true
SetElectrified(wire.Owner, true, electrified);
// if this is timed, we set up a doAfter so that the
// electrocution continues - unless cancelled
//
// if the power is disabled however, just don't bother
if (timed && IsPowered(wire.Owner))
{
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.ElectrifiedCancel, new TimedWireEvent(AwaitElectrifiedCancel, wire));
}
else
// if we were electrified, then return false
var electrifiedAttempt = _electrocutionSystem.TryDoElectrifiedAct(wire.Owner, user);
// if this is timed, we set up a doAfter so that the
// electrocution continues - unless cancelled
//
// if the power is disabled however, just don't bother
if (timed && IsPowered(wire.Owner) && !allCut)
{
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.ElectrifiedCancel, new TimedWireEvent(AwaitElectrifiedCancel, wire));
}
else
{
if (allCut)
{
SetElectrified(wire.Owner, false, electrified);
}
return !electrifiedAttempt;
}
return false;
return !electrifiedAttempt;
}
public override void Initialize()
@@ -156,17 +166,17 @@ public sealed class PowerWireAction : BaseWireAction
// in WiresComponent or ApcPowerReceiverComponent.
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)
{
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;
}
@@ -219,8 +229,6 @@ public sealed class PowerWireAction : BaseWireAction
SetPower(wire.Owner, true);
// AwaitPulseCancel(wire.Owner, wire, _doAfterSystem.WaitDoAfter(doAfter));
return true;
}
@@ -239,8 +247,10 @@ public sealed class PowerWireAction : BaseWireAction
private void AwaitElectrifiedCancel(Wire wire)
{
WiresSystem.SetData(wire.Owner, PowerWireActionKey.Electrified, false);
SetElectrified(wire.Owner, false);
if (AllWiresMended(wire.Owner))
{
SetElectrified(wire.Owner, false);
}
}
private void AwaitPulseCancel(Wire wire)
@@ -248,11 +258,4 @@ public sealed class PowerWireAction : BaseWireAction
WiresSystem.SetData(wire.Owner, PowerWireActionKey.Pulsed, 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);
UpdateUserInterface(uid);
UpdateAppearance(uid);
}
#endregion
@@ -536,7 +537,7 @@ public sealed class WiresSystem : EntitySystem
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;
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)
{
if (!Resolve(used, ref wires)
|| !Resolve(toolEntity, ref tool))
if (!Resolve(used, ref wires))
return;
if (!Resolve(toolEntity, ref tool))
{
wires.WiresQueue.Remove(id);
return;
}
var wire = TryGetWire(used, id, wires);
if (wire == null)
{
wires.WiresQueue.Remove(id);
return;
}
switch (action)
{
@@ -691,7 +700,7 @@ public sealed class WiresSystem : EntitySystem
if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), Filter.Entities(user));
return;
break;
}
_toolSystem.PlayToolSound(toolEntity, tool);
@@ -706,7 +715,7 @@ public sealed class WiresSystem : EntitySystem
if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-wirecutters"), Filter.Entities(user));
return;
break;
}
_toolSystem.PlayToolSound(toolEntity, tool);
@@ -721,13 +730,13 @@ public sealed class WiresSystem : EntitySystem
if (!_toolSystem.HasQuality(toolEntity, "Pulsing", tool))
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-need-multitool"), Filter.Entities(user));
return;
break;
}
if (wire.IsCut)
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-cannot-pulse-cut-wire"), Filter.Entities(user));
return;
break;
}
wire.Action.Pulse(user, wire);

View File

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

View File

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

View File

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