using Content.Shared.Emp; using Content.Shared.Power.Components; 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. /// A positive value will add charge, a negative value will remove charge. /// /// The actually changed amount. public virtual float ChangeCharge(Entity ent, float amount) { return 0f; } /// /// Removes the given amount of charge from the battery. /// /// The actually changed amount. public virtual float UseCharge(Entity ent, float amount) { return 0f; } /// /// If sufficient charge is available on the battery, use it. Otherwise, don't. /// Always returns false on the client. /// /// If the full amount was able to be removed. public virtual bool TryUseCharge(Entity ent, float amount) { return false; } /// /// Sets the battery's charge. /// public virtual void SetCharge(Entity ent, float value) { } /// /// Sets the battery's maximum charge. /// 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. /// public virtual void TrySetChargeCooldown(Entity ent) { } /// /// Puts the entity's self recharge on cooldown for the specified time. /// public virtual void SetChargeCooldown(Entity ent, TimeSpan cooldown) { } }