Wires patches (#8385)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user