Make PowerCellDraw not tick dependent, buff anomaly locator power drain (#15719)

This commit is contained in:
Nemanja
2023-04-23 23:35:19 -04:00
committed by GitHub
parent 19b3994d9a
commit 94e26d6c31
3 changed files with 30 additions and 2 deletions

View File

@@ -1,3 +1,5 @@
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.PowerCell; namespace Content.Server.PowerCell;
/// <summary> /// <summary>
@@ -22,4 +24,10 @@ public sealed class PowerCellDrawComponent : Component
/// </summary> /// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("useRate")] [ViewVariables(VVAccess.ReadWrite), DataField("useRate")]
public float UseRate = 0f; public float UseRate = 0f;
/// <summary>
/// When the next automatic power draw will occur
/// </summary>
[DataField("nextUpdate", customTypeSerializer: typeof(TimeOffsetSerializer))]
public TimeSpan NextUpdateTime;
} }

View File

@@ -15,12 +15,14 @@ using Content.Server.UserInterface;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Rejuvenate; using Content.Shared.Rejuvenate;
using Robust.Shared.Timing;
namespace Content.Server.PowerCell; namespace Content.Server.PowerCell;
public sealed class PowerCellSystem : SharedPowerCellSystem public sealed class PowerCellSystem : SharedPowerCellSystem
{ {
[Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ActivatableUISystem _activatable = default!; [Dependency] private readonly ActivatableUISystem _activatable = default!;
[Dependency] private readonly BatterySystem _battery = default!; [Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!; [Dependency] private readonly SolutionContainerSystem _solutionsSystem = default!;
@@ -40,6 +42,9 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
SubscribeLocalEvent<PowerCellComponent, ExaminedEvent>(OnCellExamined); SubscribeLocalEvent<PowerCellComponent, ExaminedEvent>(OnCellExamined);
SubscribeLocalEvent<PowerCellDrawComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<PowerCellDrawComponent, EntityUnpausedEvent>(OnUnpaused);
// funny // funny
SubscribeLocalEvent<PowerCellSlotComponent, BeingMicrowavedEvent>(OnSlotMicrowaved); SubscribeLocalEvent<PowerCellSlotComponent, BeingMicrowavedEvent>(OnSlotMicrowaved);
SubscribeLocalEvent<BatteryComponent, BeingMicrowavedEvent>(OnMicrowaved); SubscribeLocalEvent<BatteryComponent, BeingMicrowavedEvent>(OnMicrowaved);
@@ -55,10 +60,14 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
if (!comp.Enabled) if (!comp.Enabled)
continue; continue;
if (_timing.CurTime < comp.NextUpdateTime)
continue;
comp.NextUpdateTime += TimeSpan.FromSeconds(1);
if (!TryGetBatteryFromSlot(uid, out var batteryEnt, out var battery, slot)) if (!TryGetBatteryFromSlot(uid, out var batteryEnt, out var battery, slot))
continue; continue;
if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate * frameTime, battery)) if (_battery.TryUseCharge(batteryEnt.Value, comp.DrawRate, battery))
continue; continue;
comp.Enabled = false; comp.Enabled = false;
@@ -127,6 +136,17 @@ public sealed class PowerCellSystem : SharedPowerCellSystem
RaiseLocalEvent(uid, ref ev); 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) private void Explode(EntityUid uid, BatteryComponent? battery = null, EntityUid? cause = null)
{ {
if (!Resolve(uid, ref battery)) if (!Resolve(uid, ref battery))

View File

@@ -44,7 +44,7 @@
True: { visible: true } True: { visible: true }
False: { visible: false } False: { visible: false }
- type: PowerCellDraw - type: PowerCellDraw
drawRate: 10 drawRate: 5
useRate: 0 useRate: 0
- type: ProximityBeeper - type: ProximityBeeper
component: Anomaly component: Anomaly