Fixes power wire action electrocution (#8520)
This commit is contained in:
@@ -267,16 +267,8 @@ namespace Content.Client.Wires.UI
|
|||||||
|
|
||||||
|
|
||||||
_statusContainer.RemoveAllChildren();
|
_statusContainer.RemoveAllChildren();
|
||||||
var originalStatuses = new List<StatusEntry>(state.Statuses); // TODO: maybe not this way?
|
|
||||||
var shuffledStatuses = new List<StatusEntry>();
|
|
||||||
for (var i = originalStatuses.Count; i > 0; i--)
|
|
||||||
{
|
|
||||||
var index = random.Next(originalStatuses.Count);
|
|
||||||
shuffledStatuses.Add(originalStatuses[index]);
|
|
||||||
originalStatuses.RemoveAt(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var status in shuffledStatuses)
|
foreach (var status in state.Statuses)
|
||||||
{
|
{
|
||||||
if (status.Value is StatusLightData statusLightData)
|
if (status.Value is StatusLightData statusLightData)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public sealed class DoorTimingWireAction : BaseWireAction
|
|||||||
{
|
{
|
||||||
switch (door.AutoCloseDelayModifier)
|
switch (door.AutoCloseDelayModifier)
|
||||||
{
|
{
|
||||||
case 0f:
|
case 0.01f:
|
||||||
lightState = StatusLightState.Off;
|
lightState = StatusLightState.Off;
|
||||||
break;
|
break;
|
||||||
case <= 0.5f:
|
case <= 0.5f:
|
||||||
@@ -50,7 +50,7 @@ public sealed class DoorTimingWireAction : BaseWireAction
|
|||||||
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
if (EntityManager.TryGetComponent<AirlockComponent>(wire.Owner, out var door))
|
||||||
{
|
{
|
||||||
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
|
WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key);
|
||||||
door.AutoCloseDelayModifier = 0f;
|
door.AutoCloseDelayModifier = 0.01f;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -83,9 +83,6 @@ public sealed class PowerWireAction : BaseWireAction
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int? cut)
|
|
||||||
&& WiresSystem.TryGetData(owner, PowerWireActionKey.WireCount, out int? count))
|
|
||||||
{
|
|
||||||
if (AllWiresCut(owner))
|
if (AllWiresCut(owner))
|
||||||
{
|
{
|
||||||
power.PowerDisabled = true;
|
power.PowerDisabled = true;
|
||||||
@@ -101,12 +98,18 @@ public sealed class PowerWireAction : BaseWireAction
|
|||||||
power.PowerDisabled = false;
|
power.PowerDisabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void SetWireCuts(EntityUid owner, bool isCut)
|
private void SetWireCuts(EntityUid owner, bool isCut)
|
||||||
{
|
{
|
||||||
if (WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int? cut))
|
if (WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int? cut)
|
||||||
|
&& WiresSystem.TryGetData(owner, PowerWireActionKey.WireCount, out int? count))
|
||||||
{
|
{
|
||||||
|
if (cut == count && isCut
|
||||||
|
|| cut <= 0 && !isCut)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
cut = isCut ? cut + 1 : cut - 1;
|
cut = isCut ? cut + 1 : cut - 1;
|
||||||
WiresSystem.SetData(owner, PowerWireActionKey.CutWires, cut);
|
WiresSystem.SetData(owner, PowerWireActionKey.CutWires, cut);
|
||||||
}
|
}
|
||||||
@@ -129,30 +132,44 @@ public sealed class PowerWireAction : BaseWireAction
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var allCut = AllWiresCut(wire.Owner);
|
|
||||||
// always set this to true
|
// always set this to true
|
||||||
SetElectrified(wire.Owner, true, electrified);
|
SetElectrified(wire.Owner, true, electrified);
|
||||||
|
|
||||||
// if we were electrified, then return false
|
|
||||||
var electrifiedAttempt = _electrocutionSystem.TryDoElectrifiedAct(wire.Owner, user);
|
var electrifiedAttempt = _electrocutionSystem.TryDoElectrifiedAct(wire.Owner, user);
|
||||||
|
|
||||||
// if this is timed, we set up a doAfter so that the
|
// if we were electrified, then return false
|
||||||
// electrocution continues - unless cancelled
|
return !electrifiedAttempt;
|
||||||
//
|
|
||||||
// if the power is disabled however, just don't bother
|
}
|
||||||
if (timed && IsPowered(wire.Owner) && !allCut)
|
|
||||||
|
private void UpdateElectrocution(Wire wire)
|
||||||
|
{
|
||||||
|
var allCut = AllWiresCut(wire.Owner);
|
||||||
|
|
||||||
|
var activePulse = false;
|
||||||
|
|
||||||
|
if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsed))
|
||||||
|
{
|
||||||
|
activePulse = pulsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if this is actively pulsed,
|
||||||
|
// and there's not already an electrification cancel occurring,
|
||||||
|
// we need to start that timer immediately
|
||||||
|
if (!WiresSystem.HasData(wire.Owner, PowerWireActionKey.ElectrifiedCancel)
|
||||||
|
&& activePulse
|
||||||
|
&& IsPowered(wire.Owner)
|
||||||
|
&& !allCut)
|
||||||
{
|
{
|
||||||
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.ElectrifiedCancel, new TimedWireEvent(AwaitElectrifiedCancel, wire));
|
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.ElectrifiedCancel, new TimedWireEvent(AwaitElectrifiedCancel, wire));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (allCut)
|
if (!activePulse && allCut || AllWiresMended(wire.Owner))
|
||||||
{
|
{
|
||||||
SetElectrified(wire.Owner, false, electrified);
|
SetElectrified(wire.Owner, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return !electrifiedAttempt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
@@ -213,10 +230,8 @@ public sealed class PowerWireAction : BaseWireAction
|
|||||||
{
|
{
|
||||||
WiresSystem.TryCancelWireAction(wire.Owner, PowerWireActionKey.ElectrifiedCancel);
|
WiresSystem.TryCancelWireAction(wire.Owner, PowerWireActionKey.ElectrifiedCancel);
|
||||||
|
|
||||||
if (!TrySetElectrocution(user, wire, true))
|
var electrocuted = !TrySetElectrocution(user, wire, true);
|
||||||
return false;
|
|
||||||
|
|
||||||
// disrupted power shouldn't re-disrupt
|
|
||||||
if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsedKey)
|
if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsedKey)
|
||||||
&& pulsedKey)
|
&& pulsedKey)
|
||||||
{
|
{
|
||||||
@@ -224,16 +239,21 @@ public sealed class PowerWireAction : BaseWireAction
|
|||||||
}
|
}
|
||||||
|
|
||||||
WiresSystem.SetData(wire.Owner, PowerWireActionKey.Pulsed, true);
|
WiresSystem.SetData(wire.Owner, PowerWireActionKey.Pulsed, true);
|
||||||
|
|
||||||
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.PulseCancel, new TimedWireEvent(AwaitPulseCancel, wire));
|
WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.PulseCancel, new TimedWireEvent(AwaitPulseCancel, wire));
|
||||||
|
|
||||||
SetPower(wire.Owner, true);
|
if (electrocuted)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetPower(wire.Owner, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(Wire wire)
|
public override void Update(Wire wire)
|
||||||
{
|
{
|
||||||
|
UpdateElectrocution(wire);
|
||||||
|
|
||||||
if (!IsPowered(wire.Owner))
|
if (!IsPowered(wire.Owner))
|
||||||
{
|
{
|
||||||
if (!WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsed)
|
if (!WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsed)
|
||||||
|
|||||||
@@ -231,6 +231,7 @@ public sealed class WiresSystem : EntitySystem
|
|||||||
false,
|
false,
|
||||||
color,
|
color,
|
||||||
letter,
|
letter,
|
||||||
|
position,
|
||||||
action);
|
action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,14 +558,23 @@ public sealed class WiresSystem : EntitySystem
|
|||||||
var statusData = entry.Action.GetStatusLightData(entry);
|
var statusData = entry.Action.GetStatusLightData(entry);
|
||||||
if (statusData != null && entry.Action.StatusKey != null)
|
if (statusData != null && entry.Action.StatusKey != null)
|
||||||
{
|
{
|
||||||
wires.Statuses[entry.Action.StatusKey] = statusData;
|
wires.Statuses[entry.Action.StatusKey] = (entry.OriginalPosition, statusData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var statuses = new List<(int position, object key, object value)>();
|
||||||
|
foreach (var (key, value) in wires.Statuses)
|
||||||
|
{
|
||||||
|
var valueCast = ((int position, StatusLightData? value)) value;
|
||||||
|
statuses.Add((valueCast.position, key, valueCast.value!));
|
||||||
|
}
|
||||||
|
|
||||||
|
statuses.Sort((a, b) => a.position.CompareTo(b.position));
|
||||||
|
|
||||||
_uiSystem.GetUiOrNull(uid, WiresUiKey.Key)?.SetState(
|
_uiSystem.GetUiOrNull(uid, WiresUiKey.Key)?.SetState(
|
||||||
new WiresBoundUserInterfaceState(
|
new WiresBoundUserInterfaceState(
|
||||||
clientList.ToArray(),
|
clientList.ToArray(),
|
||||||
wires.Statuses.Select(p => new StatusEntry(p.Key, p.Value)).ToArray(),
|
statuses.Select(p => new StatusEntry(p.key, p.value)).ToArray(),
|
||||||
wires.BoardName,
|
wires.BoardName,
|
||||||
wires.SerialNumber,
|
wires.SerialNumber,
|
||||||
wires.WireSeed));
|
wires.WireSeed));
|
||||||
@@ -630,6 +640,12 @@ public sealed class WiresSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wire.IsCut)
|
||||||
|
{
|
||||||
|
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-cannot-cut-cut-wire"), Filter.Entities(user));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case WiresAction.Mend:
|
case WiresAction.Mend:
|
||||||
if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
|
if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
|
||||||
@@ -638,6 +654,12 @@ public sealed class WiresSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!wire.IsCut)
|
||||||
|
{
|
||||||
|
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-cannot-mend-uncut-wire"), Filter.Entities(user));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case WiresAction.Pulse:
|
case WiresAction.Pulse:
|
||||||
if (!_toolSystem.HasQuality(toolEntity, "Pulsing", tool))
|
if (!_toolSystem.HasQuality(toolEntity, "Pulsing", tool))
|
||||||
@@ -646,9 +668,17 @@ public sealed class WiresSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wire.IsCut)
|
||||||
|
{
|
||||||
|
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-cannot-pulse-cut-wire"), Filter.Entities(user));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wires.WiresQueue.Add(id);
|
||||||
|
|
||||||
if (_toolTime > 0f)
|
if (_toolTime > 0f)
|
||||||
{
|
{
|
||||||
var args = new DoAfterEventArgs(user, _toolTime, default, used)
|
var args = new DoAfterEventArgs(user, _toolTime, default, used)
|
||||||
@@ -672,8 +702,6 @@ public sealed class WiresSystem : EntitySystem
|
|||||||
};
|
};
|
||||||
|
|
||||||
_doAfter.DoAfter(args);
|
_doAfter.DoAfter(args);
|
||||||
|
|
||||||
wires.WiresQueue.Add(id);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -688,6 +716,9 @@ public sealed class WiresSystem : EntitySystem
|
|||||||
if (!Resolve(used, ref wires))
|
if (!Resolve(used, ref wires))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!wires.WiresQueue.Contains(id))
|
||||||
|
return;
|
||||||
|
|
||||||
if (!Resolve(toolEntity, ref tool))
|
if (!Resolve(toolEntity, ref tool))
|
||||||
{
|
{
|
||||||
wires.WiresQueue.Remove(id);
|
wires.WiresQueue.Remove(id);
|
||||||
@@ -711,6 +742,12 @@ public sealed class WiresSystem : EntitySystem
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wire.IsCut)
|
||||||
|
{
|
||||||
|
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-cannot-cut-cut-wire"), Filter.Entities(user));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
_toolSystem.PlayToolSound(toolEntity, tool);
|
_toolSystem.PlayToolSound(toolEntity, tool);
|
||||||
if (wire.Action.Cut(user, wire))
|
if (wire.Action.Cut(user, wire))
|
||||||
{
|
{
|
||||||
@@ -726,6 +763,12 @@ public sealed class WiresSystem : EntitySystem
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!wire.IsCut)
|
||||||
|
{
|
||||||
|
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-cannot-mend-uncut-wire"), Filter.Entities(user));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
_toolSystem.PlayToolSound(toolEntity, tool);
|
_toolSystem.PlayToolSound(toolEntity, tool);
|
||||||
if (wire.Action.Mend(user, wire))
|
if (wire.Action.Mend(user, wire))
|
||||||
{
|
{
|
||||||
@@ -754,6 +797,7 @@ public sealed class WiresSystem : EntitySystem
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wire.Action.Update(wire);
|
||||||
wires.WiresQueue.Remove(id);
|
wires.WiresQueue.Remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -888,6 +932,12 @@ public sealed class Wire
|
|||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The original position of this wire in the prototype.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables]
|
||||||
|
public int OriginalPosition { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The color of the wire.
|
/// The color of the wire.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -903,11 +953,12 @@ public sealed class Wire
|
|||||||
// The action that this wire performs upon activation.
|
// The action that this wire performs upon activation.
|
||||||
public IWireAction Action { get; set; }
|
public IWireAction Action { get; set; }
|
||||||
|
|
||||||
public Wire(EntityUid owner, bool isCut, WireColor color, WireLetter letter, IWireAction action)
|
public Wire(EntityUid owner, bool isCut, WireColor color, WireLetter letter, int position, IWireAction action)
|
||||||
{
|
{
|
||||||
Owner = owner;
|
Owner = owner;
|
||||||
IsCut = isCut;
|
IsCut = isCut;
|
||||||
Color = color;
|
Color = color;
|
||||||
|
OriginalPosition = position;
|
||||||
Letter = letter;
|
Letter = letter;
|
||||||
Action = action;
|
Action = action;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ wires-component-ui-on-receive-message-cannot-reach = You can't reach there!
|
|||||||
wires-component-ui-on-receive-message-need-wirecutters = You need to hold a wirecutter in your hand!
|
wires-component-ui-on-receive-message-need-wirecutters = You need to hold a wirecutter in your hand!
|
||||||
wires-component-ui-on-receive-message-need-multitool = You need to hold a multitool in your hand!
|
wires-component-ui-on-receive-message-need-multitool = You need to hold a multitool in your hand!
|
||||||
wires-component-ui-on-receive-message-cannot-pulse-cut-wire = You can't pulse a wire that's been cut!
|
wires-component-ui-on-receive-message-cannot-pulse-cut-wire = You can't pulse a wire that's been cut!
|
||||||
|
wires-component-ui-on-receive-message-cannot-cut-cut-wire = You can't cut a wire that's been cut!
|
||||||
|
wires-component-ui-on-receive-message-cannot-mend-uncut-wire = You can't mend a wire that's been mended!
|
||||||
wires-component-on-examine-panel-open = The [color=lightgray]maintenance panel[/color] is [color=red]open[/color].
|
wires-component-on-examine-panel-open = The [color=lightgray]maintenance panel[/color] is [color=red]open[/color].
|
||||||
wires-component-on-examine-panel-closed = The [color=lightgray]maintenance panel[/color] is [color=darkgreen]closed[/color].
|
wires-component-on-examine-panel-closed = The [color=lightgray]maintenance panel[/color] is [color=darkgreen]closed[/color].
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user