diff --git a/Content.Server/AME/AntimatterEngineSystem.cs b/Content.Server/AME/AntimatterEngineSystem.cs index 1aa203aa76..bb7413c59a 100644 --- a/Content.Server/AME/AntimatterEngineSystem.cs +++ b/Content.Server/AME/AntimatterEngineSystem.cs @@ -47,7 +47,7 @@ namespace Content.Server.AME } } - private static void OnAMEPowerChange(EntityUid uid, AMEControllerComponent component, PowerChangedEvent args) + private static void OnAMEPowerChange(EntityUid uid, AMEControllerComponent component, ref PowerChangedEvent args) { component.UpdateUserInterface(); } diff --git a/Content.Server/Advertise/AdvertiseSystem.cs b/Content.Server/Advertise/AdvertiseSystem.cs index f07765b687..5bbf2fc559 100644 --- a/Content.Server/Advertise/AdvertiseSystem.cs +++ b/Content.Server/Advertise/AdvertiseSystem.cs @@ -34,7 +34,7 @@ namespace Content.Server.Advertise RefreshTimer(uid, true, advertise); } - private void OnPowerChanged(EntityUid uid, AdvertiseComponent advertise, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, AdvertiseComponent advertise, ref PowerChangedEvent args) { SetEnabled(uid, args.Powered, advertise); } diff --git a/Content.Server/Arcade/ArcadeSystem.BlockGame.cs b/Content.Server/Arcade/ArcadeSystem.BlockGame.cs index 6c8370ee5f..72f416df69 100644 --- a/Content.Server/Arcade/ArcadeSystem.BlockGame.cs +++ b/Content.Server/Arcade/ArcadeSystem.BlockGame.cs @@ -10,7 +10,7 @@ public sealed partial class ArcadeSystem SubscribeLocalEvent(OnBlockPowerChanged); } - private static void OnBlockPowerChanged(EntityUid uid, BlockGameArcadeComponent component, PowerChangedEvent args) + private static void OnBlockPowerChanged(EntityUid uid, BlockGameArcadeComponent component, ref PowerChangedEvent args) { component.OnPowerStateChanged(args); } diff --git a/Content.Server/Arcade/ArcadeSystem.SpaceVillain.cs b/Content.Server/Arcade/ArcadeSystem.SpaceVillain.cs index 7b99165cdb..a223d24655 100644 --- a/Content.Server/Arcade/ArcadeSystem.SpaceVillain.cs +++ b/Content.Server/Arcade/ArcadeSystem.SpaceVillain.cs @@ -10,7 +10,7 @@ public sealed partial class ArcadeSystem SubscribeLocalEvent(OnSVillainPower); } - private void OnSVillainPower(EntityUid uid, SpaceVillainArcadeComponent component, PowerChangedEvent args) + private void OnSVillainPower(EntityUid uid, SpaceVillainArcadeComponent component, ref PowerChangedEvent args) { component.OnPowerStateChanged(args); } diff --git a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs index 4c18165e43..85ba99ec9a 100644 --- a/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AirAlarmSystem.cs @@ -195,7 +195,7 @@ public sealed class AirAlarmSystem : EntitySystem UpdateUI(uid, component); } - private void OnPowerChanged(EntityUid uid, AirAlarmComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, AirAlarmComponent component, ref PowerChangedEvent args) { if (args.Powered) { diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs b/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs index ae04a88aec..38d492cf75 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosAlarmableSystem.cs @@ -56,7 +56,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem false); } - private void OnPowerChange(EntityUid uid, AtmosAlarmableComponent component, PowerChangedEvent args) + private void OnPowerChange(EntityUid uid, AtmosAlarmableComponent component, ref PowerChangedEvent args) { if (!args.Powered) { diff --git a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs index 24dafa8481..a37c930eee 100644 --- a/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs +++ b/Content.Server/Atmos/Monitor/Systems/AtmosMonitoringSystem.cs @@ -142,7 +142,7 @@ public sealed class AtmosMonitorSystem : EntitySystem } } - private void OnPowerChangedEvent(EntityUid uid, AtmosMonitorComponent component, PowerChangedEvent args) + private void OnPowerChangedEvent(EntityUid uid, AtmosMonitorComponent component, ref PowerChangedEvent args) { if (TryComp(uid, out var atmosDeviceComponent)) { diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs index e2203aae4f..5cbf5727a1 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentPumpSystem.cs @@ -173,7 +173,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems UpdateState(uid, component); } - private void OnPowerChanged(EntityUid uid, GasVentPumpComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, GasVentPumpComponent component, ref PowerChangedEvent args) { component.Enabled = args.Powered; UpdateState(uid, component); diff --git a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs index 9b36d8111d..05d9a1dec3 100644 --- a/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs +++ b/Content.Server/Atmos/Piping/Unary/EntitySystems/GasVentScrubberSystem.cs @@ -138,7 +138,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems UpdateState(uid, component); } - private void OnPowerChanged(EntityUid uid, GasVentScrubberComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, GasVentScrubberComponent component, ref PowerChangedEvent args) { component.Enabled = args.Powered; UpdateState(uid, component); diff --git a/Content.Server/Atmos/Portable/PortableScrubberSystem.cs b/Content.Server/Atmos/Portable/PortableScrubberSystem.cs index ceef3992e4..e4b6c92da7 100644 --- a/Content.Server/Atmos/Portable/PortableScrubberSystem.cs +++ b/Content.Server/Atmos/Portable/PortableScrubberSystem.cs @@ -104,7 +104,7 @@ namespace Content.Server.Atmos.Portable UpdateDrainingAppearance(uid, portableNode.ConnectionsEnabled); } - private void OnPowerChanged(EntityUid uid, PortableScrubberComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, PortableScrubberComponent component, ref PowerChangedEvent args) { UpdateAppearance(uid, component.Full, args.Powered); component.Enabled = args.Powered; diff --git a/Content.Server/Audio/AmbientSoundSystem.cs b/Content.Server/Audio/AmbientSoundSystem.cs index 5a260fe90f..ea3ddf3621 100644 --- a/Content.Server/Audio/AmbientSoundSystem.cs +++ b/Content.Server/Audio/AmbientSoundSystem.cs @@ -13,7 +13,7 @@ namespace Content.Server.Audio SubscribeLocalEvent(HandlePowerSupply); } - private void HandlePowerSupply(EntityUid uid, AmbientOnPoweredComponent component, PowerNetBatterySupplyEvent args) + private void HandlePowerSupply(EntityUid uid, AmbientOnPoweredComponent component, ref PowerNetBatterySupplyEvent args) { if (!EntityManager.TryGetComponent(uid, out var ambientSound)) return; if (ambientSound.Enabled == args.Supply) return; @@ -21,7 +21,7 @@ namespace Content.Server.Audio Dirty(ambientSound); } - private void HandlePowerChange(EntityUid uid, AmbientOnPoweredComponent component, PowerChangedEvent args) + private void HandlePowerChange(EntityUid uid, AmbientOnPoweredComponent component, ref PowerChangedEvent args) { if (!EntityManager.TryGetComponent(uid, out var ambientSound)) return; if (ambientSound.Enabled == args.Powered) return; diff --git a/Content.Server/Bed/BedSystem.cs b/Content.Server/Bed/BedSystem.cs index 5c6ead3d2f..27e3e2a786 100644 --- a/Content.Server/Bed/BedSystem.cs +++ b/Content.Server/Bed/BedSystem.cs @@ -106,7 +106,7 @@ namespace Content.Server.Bed RaiseLocalEvent(args.BuckledEntity, metabolicEvent, false); } - private void OnPowerChanged(EntityUid uid, StasisBedComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, StasisBedComponent component, ref PowerChangedEvent args) { UpdateAppearance(uid, args.Powered); UpdateMetabolisms(uid, component, args.Powered); diff --git a/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs b/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs index ba99b1f4bd..c8dd15077c 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Telepad.cs @@ -109,7 +109,7 @@ public sealed partial class CargoSystem appearance?.SetData(CargoTelepadVisuals.State, CargoTelepadState.Unpowered); } - private void OnTelepadPowerChange(EntityUid uid, CargoTelepadComponent component, PowerChangedEvent args) + private void OnTelepadPowerChange(EntityUid uid, CargoTelepadComponent component, ref PowerChangedEvent args) { SetEnabled(component); } diff --git a/Content.Server/Cloning/CloningConsoleSystem.cs b/Content.Server/Cloning/CloningConsoleSystem.cs index b57b4db96c..43a339087f 100644 --- a/Content.Server/Cloning/CloningConsoleSystem.cs +++ b/Content.Server/Cloning/CloningConsoleSystem.cs @@ -59,7 +59,7 @@ namespace Content.Server.Cloning.Systems UpdateUserInterface(consoleComponent); } - private void OnPowerChanged(EntityUid uid, CloningConsoleComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, CloningConsoleComponent component, ref PowerChangedEvent args) { UpdateUserInterface(component); } diff --git a/Content.Server/Construction/ConstructionSystem.Computer.cs b/Content.Server/Construction/ConstructionSystem.Computer.cs index 693d595931..f536ef8109 100644 --- a/Content.Server/Construction/ConstructionSystem.Computer.cs +++ b/Content.Server/Construction/ConstructionSystem.Computer.cs @@ -31,7 +31,7 @@ public sealed partial class ConstructionSystem CreateComputerBoard(component); } - private void OnCompPowerChange(EntityUid uid, ComputerComponent component, PowerChangedEvent args) + private void OnCompPowerChange(EntityUid uid, ComputerComponent component, ref PowerChangedEvent args) { if (TryComp(uid, out var appearance)) { diff --git a/Content.Server/Disease/DiseaseDiagnosisSystem.cs b/Content.Server/Disease/DiseaseDiagnosisSystem.cs index 879240b733..c749c61156 100644 --- a/Content.Server/Disease/DiseaseDiagnosisSystem.cs +++ b/Content.Server/Disease/DiseaseDiagnosisSystem.cs @@ -303,7 +303,7 @@ namespace Content.Server.Disease /// /// Makes sure the machine is visually off/on. /// - private void OnPowerChanged(EntityUid uid, DiseaseMachineComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, DiseaseMachineComponent component, ref PowerChangedEvent args) { UpdateAppearance(uid, args.Powered, false); } diff --git a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs index 2e16e72ac5..6b8488cb08 100644 --- a/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs +++ b/Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs @@ -319,7 +319,7 @@ namespace Content.Server.Disposal.Unit.EntitySystems RemComp(uid); } - private void HandlePowerChange(EntityUid uid, DisposalUnitComponent component, PowerChangedEvent args) + private void HandlePowerChange(EntityUid uid, DisposalUnitComponent component, ref PowerChangedEvent args) { if (!component.Running) return; diff --git a/Content.Server/Doors/Systems/AirlockSystem.cs b/Content.Server/Doors/Systems/AirlockSystem.cs index b807ebf40d..376c72549d 100644 --- a/Content.Server/Doors/Systems/AirlockSystem.cs +++ b/Content.Server/Doors/Systems/AirlockSystem.cs @@ -30,7 +30,7 @@ namespace Content.Server.Doors.Systems SubscribeLocalEvent(OnDoorPry); } - private void OnPowerChanged(EntityUid uid, AirlockComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, AirlockComponent component, ref PowerChangedEvent args) { if (TryComp(uid, out var appearanceComponent)) { diff --git a/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs b/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs index efc9d0a388..0c8e219c0e 100644 --- a/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs +++ b/Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs @@ -266,7 +266,7 @@ namespace Content.Server.Kitchen.EntitySystems UpdateUserInterfaceState(uid, component); } - private void OnPowerChanged(EntityUid uid, MicrowaveComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, MicrowaveComponent component, ref PowerChangedEvent args) { if (!args.Powered) { diff --git a/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs b/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs index c7c5877e99..e498cdf656 100644 --- a/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs +++ b/Content.Server/Kitchen/EntitySystems/ReagentGrinderSystem.cs @@ -34,7 +34,7 @@ namespace Content.Server.Kitchen.EntitySystems SubscribeLocalEvent(OnComponentInit); SubscribeLocalEvent(OnComponentRemove); - SubscribeLocalEvent((_, component, _) => EnqueueUiUpdate(component)); + SubscribeLocalEvent(OnPowerChange); SubscribeLocalEvent(OnInteractUsing); SubscribeLocalEvent(ExtractableScaling); @@ -43,6 +43,11 @@ namespace Content.Server.Kitchen.EntitySystems SubscribeLocalEvent(OnEntRemoveAttempt); } + private void OnPowerChange(EntityUid uid, ReagentGrinderComponent component, ref PowerChangedEvent args) + { + EnqueueUiUpdate(component); + } + private void OnEntRemoveAttempt(EntityUid uid, ReagentGrinderComponent component, ContainerIsRemovingAttemptEvent args) { if (component.Busy) diff --git a/Content.Server/Lathe/LatheSystem.cs b/Content.Server/Lathe/LatheSystem.cs index 7a9f9d4f3e..bab1165098 100644 --- a/Content.Server/Lathe/LatheSystem.cs +++ b/Content.Server/Lathe/LatheSystem.cs @@ -243,7 +243,7 @@ namespace Content.Server.Lathe _appearance.SetData(uid, LatheVisuals.InsertingColor, color); } - private void OnPowerChanged(EntityUid uid, LatheComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, LatheComponent component, ref PowerChangedEvent args) { if (!args.Powered) { diff --git a/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs b/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs index 6b5c784dca..6da1d8f283 100644 --- a/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs +++ b/Content.Server/Light/EntitySystems/EmergencyLightSystem.cs @@ -34,7 +34,7 @@ namespace Content.Server.Light.EntitySystems SubscribeLocalEvent(OnEmergencyPower); } - private void OnEmergencyPower(EntityUid uid, EmergencyLightComponent component, PowerChangedEvent args) + private void OnEmergencyPower(EntityUid uid, EmergencyLightComponent component, ref PowerChangedEvent args) { UpdateState(component); } diff --git a/Content.Server/Light/EntitySystems/LitOnPoweredSystem.cs b/Content.Server/Light/EntitySystems/LitOnPoweredSystem.cs index ecd5e5aa0b..b3961b15f9 100644 --- a/Content.Server/Light/EntitySystems/LitOnPoweredSystem.cs +++ b/Content.Server/Light/EntitySystems/LitOnPoweredSystem.cs @@ -14,7 +14,7 @@ namespace Content.Server.Light.EntitySystems SubscribeLocalEvent(OnPowerSupply); } - private void OnPowerChanged(EntityUid uid, LitOnPoweredComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, LitOnPoweredComponent component, ref PowerChangedEvent args) { if (EntityManager.TryGetComponent(uid, out var light)) { @@ -22,7 +22,7 @@ namespace Content.Server.Light.EntitySystems } } - private void OnPowerSupply(EntityUid uid, LitOnPoweredComponent component, PowerNetBatterySupplyEvent args) + private void OnPowerSupply(EntityUid uid, LitOnPoweredComponent component, ref PowerNetBatterySupplyEvent args) { if (EntityManager.TryGetComponent(uid, out var light)) { diff --git a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs index 8a76feec2d..0d870e6b45 100644 --- a/Content.Server/Light/EntitySystems/PoweredLightSystem.cs +++ b/Content.Server/Light/EntitySystems/PoweredLightSystem.cs @@ -347,7 +347,7 @@ namespace Content.Server.Light.EntitySystems args.Handled = true; } - private void OnPowerChanged(EntityUid uid, PoweredLightComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, PoweredLightComponent component, ref PowerChangedEvent args) { UpdateLight(uid, component); } diff --git a/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.ControlBox.cs b/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.ControlBox.cs index 91c6d5b4a7..b479b541b0 100644 --- a/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.ControlBox.cs +++ b/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.ControlBox.cs @@ -10,7 +10,7 @@ public sealed partial class ParticleAcceleratorSystem SubscribeLocalEvent(OnControlBoxPowerChange); } - private static void OnControlBoxPowerChange(EntityUid uid, ParticleAcceleratorControlBoxComponent component, PowerChangedEvent args) + private static void OnControlBoxPowerChange(EntityUid uid, ParticleAcceleratorControlBoxComponent component, ref PowerChangedEvent args) { component.OnPowerStateChanged(args); } diff --git a/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.PowerBox.cs b/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.PowerBox.cs index cfb92a4ef6..87d1fa0344 100644 --- a/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.PowerBox.cs +++ b/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.PowerBox.cs @@ -13,7 +13,7 @@ namespace Content.Server.ParticleAccelerator.EntitySystems private static void PowerBoxReceivedChanged( EntityUid uid, ParticleAcceleratorPowerBoxComponent component, - PowerConsumerReceivedChanged args) + ref PowerConsumerReceivedChanged args) { component.Master?.PowerBoxReceivedChanged(args); } diff --git a/Content.Server/Physics/Controllers/ConveyorController.cs b/Content.Server/Physics/Controllers/ConveyorController.cs index 24ac06579d..ee8bd4f410 100644 --- a/Content.Server/Physics/Controllers/ConveyorController.cs +++ b/Content.Server/Physics/Controllers/ConveyorController.cs @@ -87,7 +87,7 @@ namespace Content.Server.Physics.Controllers } } - private void OnPowerChanged(EntityUid uid, ConveyorComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, ConveyorComponent component, ref PowerChangedEvent args) { UpdateAppearance(component); } diff --git a/Content.Server/Power/Components/ApcPowerReceiverComponent.cs b/Content.Server/Power/Components/ApcPowerReceiverComponent.cs index f60e447278..ff919d4a01 100644 --- a/Content.Server/Power/Components/ApcPowerReceiverComponent.cs +++ b/Content.Server/Power/Components/ApcPowerReceiverComponent.cs @@ -71,15 +71,10 @@ namespace Content.Server.Power.Components /// /// Raised whenever an ApcPowerReceiver becomes powered / unpowered. /// - public sealed class PowerChangedEvent : EntityEventArgs + [ByRefEvent] + public readonly record struct PowerChangedEvent(bool Powered, float ReceivingPower) { - public readonly bool Powered; - public readonly float ReceivingPower; - - public PowerChangedEvent(bool powered, float receivingPower) - { - Powered = powered; - ReceivingPower = receivingPower; - } + public readonly bool Powered = Powered; + public readonly float ReceivingPower = ReceivingPower; } } diff --git a/Content.Server/Power/EntitySystems/ActivatableUIRequiresPowerSystem.cs b/Content.Server/Power/EntitySystems/ActivatableUIRequiresPowerSystem.cs index a436c8d517..828789f535 100644 --- a/Content.Server/Power/EntitySystems/ActivatableUIRequiresPowerSystem.cs +++ b/Content.Server/Power/EntitySystems/ActivatableUIRequiresPowerSystem.cs @@ -28,7 +28,7 @@ namespace Content.Server.Power.EntitySystems args.Cancel(); } - private void OnPowerChanged(EntityUid uid, ActivatableUIRequiresPowerComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, ActivatableUIRequiresPowerComponent component, ref PowerChangedEvent args) { if (!args.Powered) _activatableUISystem.CloseAll(uid); diff --git a/Content.Server/Power/EntitySystems/ChargerSystem.cs b/Content.Server/Power/EntitySystems/ChargerSystem.cs index b259d98bb3..3959f25bf7 100644 --- a/Content.Server/Power/EntitySystems/ChargerSystem.cs +++ b/Content.Server/Power/EntitySystems/ChargerSystem.cs @@ -47,7 +47,7 @@ internal sealed class ChargerSystem : EntitySystem _itemSlotsSystem.RemoveItemSlot(uid, component.ChargerSlot); } - private void OnPowerChanged(EntityUid uid, ChargerComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, ChargerComponent component, ref PowerChangedEvent args) { component.UpdateStatus(); } diff --git a/Content.Server/Power/EntitySystems/PowerNetSystem.cs b/Content.Server/Power/EntitySystems/PowerNetSystem.cs index 09c21fc9e4..40cc20f039 100644 --- a/Content.Server/Power/EntitySystems/PowerNetSystem.cs +++ b/Content.Server/Power/EntitySystems/PowerNetSystem.cs @@ -5,6 +5,7 @@ using Content.Server.Power.NodeGroups; using Content.Server.Power.Pow3r; using JetBrains.Annotations; using Content.Shared.Power; +using Robust.Server.GameObjects; namespace Content.Server.Power.EntitySystems { @@ -14,6 +15,8 @@ namespace Content.Server.Power.EntitySystems [UsedImplicitly] public sealed class PowerNetSystem : EntitySystem { + [Dependency] private readonly AppearanceSystem _appearance = default!; + private readonly PowerState _powerState = new(); private readonly HashSet _powerNetReconnectQueue = new(); private readonly HashSet _apcNetReconnectQueue = new(); @@ -247,23 +250,24 @@ namespace Content.Server.Power.EntitySystems continue; apcReceiver.PoweredLastUpdate = powered; + var ev = new PowerChangedEvent(apcReceiver.Powered, apcReceiver.NetworkLoad.ReceivingPower); - RaiseLocalEvent(apcReceiver.Owner, new PowerChangedEvent(apcReceiver.Powered, apcReceiver.NetworkLoad.ReceivingPower), true); + RaiseLocalEvent(apcReceiver.Owner, ref ev); if (appearanceQuery.TryGetComponent(apcReceiver.Owner, out var appearance)) - appearance.SetData(PowerDeviceVisuals.Powered, powered); + _appearance.SetData(appearance.Owner, PowerDeviceVisuals.Powered, powered, appearance); } foreach (var consumer in EntityManager.EntityQuery()) { var newRecv = consumer.NetworkLoad.ReceivingPower; ref var lastRecv = ref consumer.LastReceived; - if (!MathHelper.CloseToPercent(lastRecv, newRecv)) - { - lastRecv = newRecv; - var msg = new PowerConsumerReceivedChanged(newRecv, consumer.DrawRate); - RaiseLocalEvent(consumer.Owner, msg, true); - } + if (MathHelper.CloseToPercent(lastRecv, newRecv)) + continue; + + lastRecv = newRecv; + var msg = new PowerConsumerReceivedChanged(newRecv, consumer.DrawRate); + RaiseLocalEvent(consumer.Owner, ref msg); } foreach (var powerNetBattery in EntityManager.EntityQuery()) @@ -273,11 +277,13 @@ namespace Content.Server.Power.EntitySystems if (lastSupply == 0f && currentSupply != 0f) { - RaiseLocalEvent(powerNetBattery.Owner, new PowerNetBatterySupplyEvent {Supply = true}, true); + var ev = new PowerNetBatterySupplyEvent(true); + RaiseLocalEvent(powerNetBattery.Owner, ref ev); } else if (lastSupply > 0f && currentSupply == 0f) { - RaiseLocalEvent(powerNetBattery.Owner, new PowerNetBatterySupplyEvent {Supply = false}, true); + var ev = new PowerNetBatterySupplyEvent(false); + RaiseLocalEvent(powerNetBattery.Owner, ref ev); } powerNetBattery.LastSupply = currentSupply; @@ -329,9 +335,11 @@ namespace Content.Server.Power.EntitySystems consumer.NetworkLoad.LinkedNetwork = netNode.Id; } + var batteryQuery = GetEntityQuery(); + foreach (var apc in net.Apcs) { - var netBattery = EntityManager.GetComponent(apc.Owner); + var netBattery = batteryQuery.GetComponent(apc.Owner); netNode.BatteriesDischarging.Add(netBattery.NetworkBattery.Id); netBattery.NetworkBattery.LinkedNetworkDischarging = netNode.Id; } @@ -358,16 +366,18 @@ namespace Content.Server.Power.EntitySystems supplier.NetworkSupply.LinkedNetwork = netNode.Id; } + var batteryQuery = GetEntityQuery(); + foreach (var charger in net.Chargers) { - var battery = EntityManager.GetComponent(charger.Owner); + var battery = batteryQuery.GetComponent(charger.Owner); netNode.BatteriesCharging.Add(battery.NetworkBattery.Id); battery.NetworkBattery.LinkedNetworkCharging = netNode.Id; } foreach (var discharger in net.Dischargers) { - var battery = EntityManager.GetComponent(discharger.Owner); + var battery = batteryQuery.GetComponent(discharger.Owner); netNode.BatteriesDischarging.Add(battery.NetworkBattery.Id); battery.NetworkBattery.LinkedNetworkDischarging = netNode.Id; } @@ -378,7 +388,7 @@ namespace Content.Server.Power.EntitySystems /// Raised before power network simulation happens, to synchronize battery state from /// components like into . /// - public struct NetworkBatteryPreSync + public readonly struct NetworkBatteryPreSync { } @@ -386,31 +396,27 @@ namespace Content.Server.Power.EntitySystems /// Raised after power network simulation happens, to synchronize battery charge changes from /// to components like . /// - public struct NetworkBatteryPostSync + public readonly struct NetworkBatteryPostSync { } /// /// Raised when the amount of receiving power on a changes. /// - public sealed class PowerConsumerReceivedChanged : EntityEventArgs + [ByRefEvent] + public readonly record struct PowerConsumerReceivedChanged(float ReceivedPower, float DrawRate) { - public float ReceivedPower { get; } - public float DrawRate { get; } - - public PowerConsumerReceivedChanged(float receivedPower, float drawRate) - { - ReceivedPower = receivedPower; - DrawRate = drawRate; - } + public readonly float ReceivedPower = ReceivedPower; + public readonly float DrawRate = DrawRate; } /// /// Raised whenever a changes from / to 0 CurrentSupply. /// - public sealed class PowerNetBatterySupplyEvent : EntityEventArgs + [ByRefEvent] + public readonly record struct PowerNetBatterySupplyEvent(bool Supply) { - public bool Supply { get; init; } + public readonly bool Supply = Supply; } public struct PowerStatistics diff --git a/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs b/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs index c2b561b82e..467b29c5e1 100644 --- a/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs +++ b/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs @@ -1,11 +1,14 @@ using Content.Server.Power.Components; using Content.Shared.Examine; using Content.Shared.Power; +using Robust.Server.GameObjects; namespace Content.Server.Power.EntitySystems { public sealed class PowerReceiverSystem : EntitySystem { + [Dependency] private readonly AppearanceSystem _appearance = default!; + public override void Initialize() { base.Initialize(); @@ -25,8 +28,9 @@ namespace Content.Server.Power.EntitySystems private void OnExamined(EntityUid uid, ApcPowerReceiverComponent component, ExaminedEvent args) { args.PushMarkup(Loc.GetString("power-receiver-component-on-examine-main", - ("stateText", Loc.GetString( component.Powered ? "power-receiver-component-on-examine-powered" : - "power-receiver-component-on-examine-unpowered")))); + ("stateText", Loc.GetString( component.Powered + ? "power-receiver-component-on-examine-powered" + : "power-receiver-component-on-examine-unpowered")))); } private void OnProviderShutdown(EntityUid uid, ApcPowerProviderComponent component, ComponentShutdown args) @@ -77,11 +81,10 @@ namespace Content.Server.Power.EntitySystems private void ProviderChanged(ApcPowerReceiverComponent receiver) { receiver.NetworkLoad.LinkedNetwork = default; + var ev = new PowerChangedEvent(receiver.Powered, receiver.NetworkLoad.ReceivingPower); - RaiseLocalEvent(receiver.Owner, new PowerChangedEvent(receiver.Powered, receiver.NetworkLoad.ReceivingPower), true); - - if (TryComp(receiver.Owner, out AppearanceComponent? appearance)) - appearance.SetData(PowerDeviceVisuals.Powered, receiver.Powered); + RaiseLocalEvent(receiver.Owner, ref ev); + _appearance.SetData(receiver.Owner, PowerDeviceVisuals.Powered, receiver.Powered); } /// diff --git a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs index 7acaa0e430..e5fb8efa48 100644 --- a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs @@ -145,7 +145,7 @@ namespace Content.Server.Shuttles.Systems UpdateState(component); } - private void OnConsolePowerChange(EntityUid uid, ShuttleConsoleComponent component, PowerChangedEvent args) + private void OnConsolePowerChange(EntityUid uid, ShuttleConsoleComponent component, ref PowerChangedEvent args) { UpdateState(component); } diff --git a/Content.Server/Shuttles/Systems/ThrusterSystem.cs b/Content.Server/Shuttles/Systems/ThrusterSystem.cs index 1c04ed673f..d3a4b1d78d 100644 --- a/Content.Server/Shuttles/Systems/ThrusterSystem.cs +++ b/Content.Server/Shuttles/Systems/ThrusterSystem.cs @@ -223,7 +223,7 @@ namespace Content.Server.Shuttles.Systems DisableThruster(uid, component); } - private void OnPowerChange(EntityUid uid, ThrusterComponent component, PowerChangedEvent args) + private void OnPowerChange(EntityUid uid, ThrusterComponent component, ref PowerChangedEvent args) { if (args.Powered && CanEnable(uid, component)) { diff --git a/Content.Server/Singularity/EntitySystems/EmitterSystem.cs b/Content.Server/Singularity/EntitySystems/EmitterSystem.cs index 15ffa64847..91f68b8346 100644 --- a/Content.Server/Singularity/EntitySystems/EmitterSystem.cs +++ b/Content.Server/Singularity/EntitySystems/EmitterSystem.cs @@ -71,7 +71,7 @@ namespace Content.Server.Singularity.EntitySystems private void ReceivedChanged( EntityUid uid, EmitterComponent component, - PowerConsumerReceivedChanged args) + ref PowerConsumerReceivedChanged args) { if (!component.IsOn) { diff --git a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraMonitorSystem.cs b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraMonitorSystem.cs index a4a02ddf13..87fcce5df3 100644 --- a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraMonitorSystem.cs +++ b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraMonitorSystem.cs @@ -181,7 +181,7 @@ public sealed class SurveillanceCameraMonitorSystem : EntitySystem TrySwitchCameraByAddress(uid, message.Address, component); } - private void OnPowerChanged(EntityUid uid, SurveillanceCameraMonitorComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, SurveillanceCameraMonitorComponent component, ref PowerChangedEvent args) { if (!args.Powered) { diff --git a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraRouterSystem.cs b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraRouterSystem.cs index 1903a3e160..486ce3b752 100644 --- a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraRouterSystem.cs +++ b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraRouterSystem.cs @@ -86,7 +86,7 @@ public sealed class SurveillanceCameraRouterSystem : EntitySystem } } - private void OnPowerChanged(EntityUid uid, SurveillanceCameraRouterComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, SurveillanceCameraRouterComponent component, ref PowerChangedEvent args) { component.MonitorRoutes.Clear(); component.Active = args.Powered; diff --git a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraSystem.cs b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraSystem.cs index 9ebb74dc0d..c2f871526f 100644 --- a/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraSystem.cs +++ b/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraSystem.cs @@ -143,7 +143,7 @@ public sealed class SurveillanceCameraSystem : EntitySystem - private void OnPowerChanged(EntityUid camera, SurveillanceCameraComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid camera, SurveillanceCameraComponent component, ref PowerChangedEvent args) { SetActive(camera, args.Powered, component); } diff --git a/Content.Server/VendingMachines/VendingMachineSystem.cs b/Content.Server/VendingMachines/VendingMachineSystem.cs index ae18a47643..b185ef7926 100644 --- a/Content.Server/VendingMachines/VendingMachineSystem.cs +++ b/Content.Server/VendingMachines/VendingMachineSystem.cs @@ -119,7 +119,7 @@ namespace Content.Server.VendingMachines AuthorizedVend(uid, entity, args.Type, args.ID, component); } - private void OnPowerChanged(EntityUid uid, VendingMachineComponent component, PowerChangedEvent args) + private void OnPowerChanged(EntityUid uid, VendingMachineComponent component, ref PowerChangedEvent args) { TryUpdateVisualState(uid, component); } diff --git a/Content.Server/Wires/WiresSystem.cs b/Content.Server/Wires/WiresSystem.cs index b277f76a2c..98bf10702d 100644 --- a/Content.Server/Wires/WiresSystem.cs +++ b/Content.Server/Wires/WiresSystem.cs @@ -391,7 +391,7 @@ public sealed class WiresSystem : EntitySystem #endregion #region Event Handling - private void OnWiresPowered(EntityUid uid, WiresComponent component, PowerChangedEvent args) + private void OnWiresPowered(EntityUid uid, WiresComponent component, ref PowerChangedEvent args) { UpdateUserInterface(uid); foreach (var wire in component.WiresList)