Fixes power wire action electrocution (#8520)

This commit is contained in:
Flipp Syder
2022-07-24 21:53:30 -07:00
committed by GitHub
parent 151ed21a95
commit fab5aed3b8
5 changed files with 111 additions and 46 deletions

View File

@@ -231,6 +231,7 @@ public sealed class WiresSystem : EntitySystem
false,
color,
letter,
position,
action);
}
@@ -557,14 +558,23 @@ public sealed class WiresSystem : EntitySystem
var statusData = entry.Action.GetStatusLightData(entry);
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(
new WiresBoundUserInterfaceState(
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.SerialNumber,
wires.WireSeed));
@@ -630,6 +640,12 @@ public sealed class WiresSystem : EntitySystem
return;
}
if (wire.IsCut)
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-cannot-cut-cut-wire"), Filter.Entities(user));
return;
}
break;
case WiresAction.Mend:
if (!_toolSystem.HasQuality(toolEntity, "Cutting", tool))
@@ -638,6 +654,12 @@ public sealed class WiresSystem : EntitySystem
return;
}
if (!wire.IsCut)
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-cannot-mend-uncut-wire"), Filter.Entities(user));
return;
}
break;
case WiresAction.Pulse:
if (!_toolSystem.HasQuality(toolEntity, "Pulsing", tool))
@@ -646,9 +668,17 @@ public sealed class WiresSystem : EntitySystem
return;
}
if (wire.IsCut)
{
_popupSystem.PopupCursor(Loc.GetString("wires-component-ui-on-receive-message-cannot-pulse-cut-wire"), Filter.Entities(user));
return;
}
break;
}
wires.WiresQueue.Add(id);
if (_toolTime > 0f)
{
var args = new DoAfterEventArgs(user, _toolTime, default, used)
@@ -672,8 +702,6 @@ public sealed class WiresSystem : EntitySystem
};
_doAfter.DoAfter(args);
wires.WiresQueue.Add(id);
}
else
{
@@ -688,6 +716,9 @@ public sealed class WiresSystem : EntitySystem
if (!Resolve(used, ref wires))
return;
if (!wires.WiresQueue.Contains(id))
return;
if (!Resolve(toolEntity, ref tool))
{
wires.WiresQueue.Remove(id);
@@ -711,6 +742,12 @@ public sealed class WiresSystem : EntitySystem
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);
if (wire.Action.Cut(user, wire))
{
@@ -726,6 +763,12 @@ public sealed class WiresSystem : EntitySystem
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);
if (wire.Action.Mend(user, wire))
{
@@ -754,6 +797,7 @@ public sealed class WiresSystem : EntitySystem
break;
}
wire.Action.Update(wire);
wires.WiresQueue.Remove(id);
}
@@ -888,6 +932,12 @@ public sealed class Wire
[ViewVariables]
public int Id { get; set; }
/// <summary>
/// The original position of this wire in the prototype.
/// </summary>
[ViewVariables]
public int OriginalPosition { get; set; }
/// <summary>
/// The color of the wire.
/// </summary>
@@ -903,11 +953,12 @@ public sealed class Wire
// The action that this wire performs upon activation.
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;
IsCut = isCut;
Color = color;
OriginalPosition = position;
Letter = letter;
Action = action;
}