using Content.Shared.Emp; using Content.Shared.Power.Components; using JetBrains.Annotations; namespace Content.Shared.Power.EntitySystems; public abstract class SharedBatterySystem : EntitySystem { public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnEmpPulse); } private void OnEmpPulse(Entity ent, ref EmpPulseEvent args) { args.Affected = true; UseCharge(ent.AsNullable(), args.EnergyConsumption); // Apply a cooldown to the entity's self recharge if needed to avoid it immediately self recharging after an EMP. TrySetChargeCooldown(ent.Owner); } /// /// Changes the battery's charge by the given amount /// and resets the self-recharge cooldown if it exists. /// A positive value will add charge, a negative value will remove charge. /// /// The actually changed amount. [PublicAPI] public virtual float ChangeCharge(Entity ent, float amount) { return 0f; } /// /// Removes the given amount of charge from the battery /// and resets the self-recharge cooldown if it exists. /// /// The actually changed amount. [PublicAPI] public virtual float UseCharge(Entity ent, float amount) { return 0f; } /// /// If sufficient charge is available on the battery, use it. Otherwise, don't. /// Resets the self-recharge cooldown if it exists. /// Always returns false on the client. /// /// If the full amount was able to be removed. [PublicAPI] public virtual bool TryUseCharge(Entity ent, float amount) { return false; } /// /// Sets the battery's charge. /// [PublicAPI] public virtual void SetCharge(Entity ent, float value) { } /// /// Sets the battery's maximum charge. /// [PublicAPI] public virtual void SetMaxCharge(Entity ent, float value) { } /// /// Checks if the entity has a self recharge and puts it on cooldown if applicable. /// Uses the cooldown time given in the component. /// [PublicAPI] public virtual void TrySetChargeCooldown(Entity ent) { } /// /// Puts the entity's self recharge on cooldown for the specified time. /// [PublicAPI] public virtual void SetChargeCooldown(Entity ent, TimeSpan cooldown) { } }