+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
+
namespace Content.Server.PowerCell;
/// <summary>
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("useRate")]
public float UseRate = 0f;
+
+ /// <summary>
+ /// When the next automatic power draw will occur
+ /// </summary>
+ [DataField("nextUpdate", customTypeSerializer: typeof(TimeOffsetSerializer))]
+ public TimeSpan NextUpdateTime;
}
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Popups;
using Content.Shared.Rejuvenate;
+using Robust.Shared.Timing;
namespace Content.Server.PowerCell;
public sealed class PowerCellSystem : SharedPowerCellSystem
{
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
+ [Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ActivatableUISystem _activatable = default!;
[Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
SubscribeLocalEvent<PowerCellComponent, ExaminedEvent>(OnCellExamined);
+ SubscribeLocalEvent<PowerCellDrawComponent, MapInitEvent>(OnMapInit);
+ SubscribeLocalEvent<PowerCellDrawComponent, EntityUnpausedEvent>(OnUnpaused);
+
// funny
SubscribeLocalEvent<PowerCellSlotComponent, BeingMicrowavedEvent>(OnSlotMicrowaved);
SubscribeLocalEvent<BatteryComponent, BeingMicrowavedEvent>(OnMicrowaved);
if (!comp.Enabled)
continue;
+ if (_timing.CurTime < comp.NextUpdateTime)
+ continue;
+ comp.NextUpdateTime += TimeSpan.FromSeconds(1);
+
if (!TryGetBatteryFromSlot(uid, out var batteryEnt, out var battery, slot))
continue;
- if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate * frameTime, battery))
+ if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate, battery))
continue;
comp.Enabled = false;
RaiseLocalEvent(uid, ref ev);
}
+ private void OnMapInit(EntityUid uid, PowerCellDrawComponent component, MapInitEvent args)
+ {
+ if (component.NextUpdateTime < _timing.CurTime)
+ component.NextUpdateTime = _timing.CurTime;
+ }
+
+ private void OnUnpaused(EntityUid uid, PowerCellDrawComponent component, ref EntityUnpausedEvent args)
+ {
+ component.NextUpdateTime += args.PausedTime;
+ }
+
private void Explode(EntityUid uid, BatteryComponent? battery = null, EntityUid? cause = null)
{
if (!Resolve(uid, ref battery))