using Content.Shared.Power.Components; using JetBrains.Annotations; namespace Content.Shared.Power.EntitySystems; /// /// Generic system that handles entities with . /// Used for simple machines that only need to switch between "idle" and "working" power states. /// public sealed class PowerStateSystem : EntitySystem { [Dependency] private readonly SharedPowerReceiverSystem _powerReceiverSystem = default!; private EntityQuery _powerStateQuery; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnComponentStartup); _powerStateQuery = GetEntityQuery(); } private void OnComponentStartup(Entity ent, ref ComponentStartup args) { SetWorkingState(ent.Owner, ent.Comp.IsWorking); } /// /// Sets the working state of the entity, adjusting its power draw accordingly. /// /// The entity to set the working state for. /// Whether the entity should be in the working state. [PublicAPI] public void SetWorkingState(Entity ent, bool working) { if (!_powerStateQuery.Resolve(ent, ref ent.Comp)) return; _powerReceiverSystem.SetLoad(ent.Owner, working ? ent.Comp.WorkingPowerDraw : ent.Comp.IdlePowerDraw); ent.Comp.IsWorking = working; } }