Fixes power wire action electrocution (#8520)
This commit is contained in:
@@ -83,30 +83,33 @@ public sealed class PowerWireAction : BaseWireAction
|
||||
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;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (WiresSystem.TryGetData(owner, PowerWireActionKey.Pulsed, out bool isPulsed)
|
||||
&& isPulsed)
|
||||
{
|
||||
power.PowerDisabled = true;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (WiresSystem.TryGetData(owner, PowerWireActionKey.Pulsed, out bool isPulsed)
|
||||
&& isPulsed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
power.PowerDisabled = false;
|
||||
}
|
||||
power.PowerDisabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
WiresSystem.SetData(owner, PowerWireActionKey.CutWires, cut);
|
||||
}
|
||||
@@ -129,30 +132,44 @@ public sealed class PowerWireAction : BaseWireAction
|
||||
return true;
|
||||
}
|
||||
|
||||
var allCut = AllWiresCut(wire.Owner);
|
||||
// always set this to true
|
||||
SetElectrified(wire.Owner, true, electrified);
|
||||
|
||||
// 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)
|
||||
// if we were electrified, then return false
|
||||
return !electrifiedAttempt;
|
||||
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (allCut)
|
||||
if (!activePulse && allCut || AllWiresMended(wire.Owner))
|
||||
{
|
||||
SetElectrified(wire.Owner, false, electrified);
|
||||
SetElectrified(wire.Owner, false);
|
||||
}
|
||||
}
|
||||
|
||||
return !electrifiedAttempt;
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
@@ -213,10 +230,8 @@ public sealed class PowerWireAction : BaseWireAction
|
||||
{
|
||||
WiresSystem.TryCancelWireAction(wire.Owner, PowerWireActionKey.ElectrifiedCancel);
|
||||
|
||||
if (!TrySetElectrocution(user, wire, true))
|
||||
return false;
|
||||
var electrocuted = !TrySetElectrocution(user, wire, true);
|
||||
|
||||
// disrupted power shouldn't re-disrupt
|
||||
if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsedKey)
|
||||
&& pulsedKey)
|
||||
{
|
||||
@@ -224,16 +239,21 @@ public sealed class PowerWireAction : BaseWireAction
|
||||
}
|
||||
|
||||
WiresSystem.SetData(wire.Owner, PowerWireActionKey.Pulsed, true);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public override void Update(Wire wire)
|
||||
{
|
||||
UpdateElectrocution(wire);
|
||||
|
||||
if (!IsPowered(wire.Owner))
|
||||
{
|
||||
if (!WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsed)
|
||||
|
||||
Reference in New Issue
Block a user