using Content.Shared.PowerCell.Components; using JetBrains.Annotations; namespace Content.Shared.PowerCell; public sealed partial class PowerCellSystem { /// /// Enables or disables the power cell draw. /// [PublicAPI] public void SetDrawEnabled(Entity ent, bool enabled) { if (!Resolve(ent, ref ent.Comp, false) || ent.Comp.Enabled == enabled) return; ent.Comp.Enabled = enabled; Dirty(ent, ent.Comp); if (TryGetBatteryFromSlot(ent.Owner, out var battery)) _battery.RefreshChargeRate(battery.Value.AsNullable()); } /// /// Returns whether the entity has a slotted battery and charge. /// /// The device with the power cell slot. /// Show a popup to this user with the relevant details if specified. /// Whether to predict the popup or not. [PublicAPI] public bool HasActivatableCharge(Entity ent, EntityUid? user = null, bool predicted = false) { // Default to true if we don't have the components. if (!Resolve(ent, ref ent.Comp1, ref ent.Comp2, false)) return true; return HasCharge((ent, ent.Comp2), ent.Comp1.UseCharge, user, predicted); } /// /// Tries to use the for this entity. /// /// The device with the power cell slot. /// Show a popup to this user with the relevant details if specified. /// Whether to predict the popup or not. [PublicAPI] public bool TryUseActivatableCharge(Entity ent, EntityUid? user = null, bool predicted = false) { // Default to true if we don't have the components. if (!Resolve(ent, ref ent.Comp1, ref ent.Comp2, false)) return true; if (TryUseCharge((ent, ent.Comp2), ent.Comp1.UseCharge, user, predicted)) return true; return false; } /// /// Whether the power cell has any power at all for the draw rate. /// /// The device with the power cell slot. /// Show a popup to this user with the relevant details if specified. /// Whether to predict the popup or not. [PublicAPI] public bool HasDrawCharge(Entity ent, EntityUid? user = null, bool predicted = false) { // Default to true if we don't have the components. if (!Resolve(ent, ref ent.Comp1, ref ent.Comp2, false)) return true; // 1 second of charge at the required draw rate. return HasCharge((ent, ent.Comp2), ent.Comp1.DrawRate, user, predicted); } }