/// <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 <ElectrifiedComponent>(wire.Owner, out var electrified)) { 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) { WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.ElectrifiedCancel, new TimedWireEvent(AwaitElectrifiedCancel, wire)); } else { if (allCut) { SetElectrified(wire.Owner, false, electrified); } } 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 (!activePulse && allCut || AllWiresMended(wire.Owner)) { SetElectrified(wire.Owner, false); } } }
public override StatusLightData?GetStatusLightData(Wire wire) { StatusLightState lightState = StatusLightState.Off; if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.MainWire, out int main) && main != wire.Id) { return(null); } if (IsPowered(wire.Owner)) { if (!AllWiresMended(wire.Owner) || WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsed) && pulsed) { lightState = StatusLightState.BlinkingSlow; } else { lightState = (AllWiresCut(wire.Owner)) ? StatusLightState.Off : StatusLightState.On; } } return(new StatusLightData( _statusColor, lightState, _text)); }
// 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) { if (!EntityManager.TryGetComponent(owner, out ApcPowerReceiverComponent? power)) { return; } if (pulsed) { power.PowerDisabled = true; return; } if (AllWiresCut(owner)) { power.PowerDisabled = true; } else { if (WiresSystem.TryGetData(owner, PowerWireActionKey.Pulsed, out bool isPulsed) && isPulsed) { return; } power.PowerDisabled = false; } }
public override void Update(Wire wire) { if (TimeoutKey != null && !IsPowered(wire.Owner)) { WiresSystem.TryCancelWireAction(wire.Owner, TimeoutKey); } }
public override void Update(Wire wire) { if (!IsPowered(wire.Owner)) { WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); } }
public void WiresSystem_FindManhattanDistanceFromTheCentralPortToTheClosestIntersection(string pathWire1, string pathWire2, int distanceToTheClosesIntersectionPoint) { var wiresSystem = new WiresSystem(); int result = wiresSystem.FindManhattanDistanceFromTheCentralPortToTheClosestIntersection(pathWire1, pathWire2); Assert.AreEqual(result, distanceToTheClosesIntersectionPoint); }
private void SetWireCuts(EntityUid owner, bool isCut) { if (WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int?cut)) { cut = isCut ? cut + 1 : cut - 1; WiresSystem.SetData(owner, PowerWireActionKey.CutWires, cut); } }
public override bool Cut(EntityUid user, Wire wire) { if (EntityManager.TryGetComponent <AirlockComponent>(wire.Owner, out var door)) { WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); door.Safety = false; } return(true); }
public override bool Cut(EntityUid user, Wire wire) { if (EntityManager.TryGetComponent <AirlockComponent>(wire.Owner, out var door)) { WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); door.AutoCloseDelayModifier = 0.01f; } return(true); }
public override bool Cut(EntityUid user, Wire wire) { if (EntityManager.TryGetComponent <AccessReaderComponent>(wire.Owner, out var access)) { WiresSystem.TryCancelWireAction(wire.Owner, PulseTimeoutKey.Key); access.Enabled = false; } return(true); }
public override bool Pulse(EntityUid user, Wire wire) { if (EntityManager.TryGetComponent <AccessReaderComponent>(wire.Owner, out var access)) { access.Enabled = false; WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitPulseCancel, wire)); } return(true); }
public override bool Pulse(EntityUid user, Wire wire) { if (EntityManager.TryGetComponent <AirlockComponent>(wire.Owner, out var door)) { door.Safety = false; WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitSafetyTimerFinish, wire)); } return(true); }
public override bool Pulse(EntityUid user, Wire wire) { ToggleValue(wire.Owner, !GetValue(wire.Owner)); if (TimeoutKey != null) { WiresSystem.StartWireAction(wire.Owner, Delay, TimeoutKey, new TimedWireEvent(AwaitPulseCancel, wire)); } return(true); }
public override bool Cut(EntityUid user, Wire wire) { ToggleValue(wire.Owner, false); if (TimeoutKey != null) { WiresSystem.TryCancelWireAction(wire.Owner, TimeoutKey); } return(true); }
public override bool Pulse(EntityUid user, Wire wire) { if (EntityManager.TryGetComponent <AirlockComponent>(wire.Owner, out var door)) { door.AutoCloseDelayModifier = 0.5f; WiresSystem.StartWireAction(wire.Owner, _timeout, PulseTimeoutKey.Key, new TimedWireEvent(AwaitTimingTimerFinish, wire)); } return(true); }
public override void Update(Wire wire) { if (!IsPowered(wire.Owner)) { if (!WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsed) || !pulsed) { WiresSystem.TryCancelWireAction(wire.Owner, PowerWireActionKey.ElectrifiedCancel); WiresSystem.TryCancelWireAction(wire.Owner, PowerWireActionKey.PulseCancel); } } }
private void SetWireCuts(EntityUid owner, bool isCut) { 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); } }
// This should add a wire into the entity's state, whether it be // in WiresComponent or ApcPowerReceiverComponent. public override bool AddWire(Wire wire, int count) { if (!WiresSystem.HasData(wire.Owner, PowerWireActionKey.CutWires)) { WiresSystem.SetData(wire.Owner, PowerWireActionKey.CutWires, 0); } if (count == 1) { WiresSystem.SetData(wire.Owner, PowerWireActionKey.MainWire, wire.Id); } WiresSystem.SetData(wire.Owner, PowerWireActionKey.WireCount, count); return(true); }
public override bool Mend(EntityUid user, Wire wire) { if (!TrySetElectrocution(user, wire)) { return(false); } // Mending any power wire restores shorts. WiresSystem.TryCancelWireAction(wire.Owner, PowerWireActionKey.PulseCancel); WiresSystem.TryCancelWireAction(wire.Owner, PowerWireActionKey.ElectrifiedCancel); SetWireCuts(wire.Owner, false); SetPower(wire.Owner, false); return(true); }
public override bool Pulse(EntityUid user, Wire wire) { WiresSystem.TryCancelWireAction(wire.Owner, PowerWireActionKey.ElectrifiedCancel); var electrocuted = !TrySetElectrocution(user, wire, true); if (WiresSystem.TryGetData(wire.Owner, PowerWireActionKey.Pulsed, out bool pulsedKey) && pulsedKey) { return(false); } WiresSystem.SetData(wire.Owner, PowerWireActionKey.Pulsed, true); WiresSystem.StartWireAction(wire.Owner, _pulseTimeout, PowerWireActionKey.PulseCancel, new TimedWireEvent(AwaitPulseCancel, wire)); if (electrocuted) { return(false); } SetPower(wire.Owner, true); return(true); }
private bool AllWiresMended(EntityUid owner) { return(WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int?cut) && cut == 0); }
private void AwaitPulseCancel(Wire wire) { WiresSystem.SetData(wire.Owner, PowerWireActionKey.Pulsed, false); SetPower(wire.Owner, false); }
private bool AllWiresCut(EntityUid owner) { return(WiresSystem.TryGetData(owner, PowerWireActionKey.CutWires, out int?cut) && WiresSystem.TryGetData(owner, PowerWireActionKey.WireCount, out int?count) && count == cut); }
// ugly, but IoC doesn't work during deserialization public virtual void Initialize() { EntityManager = IoCManager.Resolve <IEntityManager>(); WiresSystem = EntityManager.EntitySysManager.GetEntitySystem <WiresSystem>(); }