Files
tbd-station-14/Content.Server/Movement/Systems/JetpackSystem.cs
rolfero 1151ca42e5 changing accumulators to timespan targets (#12407)
* changing accumulators to timespan targets

* Update Content.Server/Abilities/Mime/MimePowersSystem.cs

Co-authored-by: 0x6273 <0x40@keemail.me>

* Update MimePowersSystem.cs

* serializing timespans and adding pausetime where applicable

* remove nullable

Co-authored-by: CommieFlowers <rasmus.cedergren@hotmail.com>
Co-authored-by: 0x6273 <0x40@keemail.me>
2022-11-08 13:59:34 -06:00

50 lines
1.6 KiB
C#

using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Systems;
using Robust.Shared.Collections;
using Robust.Shared.Timing;
namespace Content.Server.Movement.Systems;
public sealed class JetpackSystem : SharedJetpackSystem
{
[Dependency] private readonly GasTankSystem _gasTank = default!;
[Dependency] private readonly IGameTiming _timing = default!;
private const float UpdateCooldown = 0.5f;
protected override bool CanEnable(JetpackComponent component)
{
return base.CanEnable(component) && TryComp<GasTankComponent>(component.Owner, out var gasTank) && !(gasTank.Air.TotalMoles < component.MoleUsage);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
var toDisable = new ValueList<JetpackComponent>();
foreach (var (active, comp, gasTank) in EntityQuery<ActiveJetpackComponent, JetpackComponent, GasTankComponent>())
{
if (_timing.CurTime < active.TargetTime) continue;
active.TargetTime = _timing.CurTime + TimeSpan.FromSeconds(active.EffectCooldown);
var air = _gasTank.RemoveAir(gasTank, comp.MoleUsage);
if (air == null || !MathHelper.CloseTo(air.TotalMoles, comp.MoleUsage, 0.001f))
{
toDisable.Add(comp);
continue;
}
_gasTank.UpdateUserInterface(gasTank);
}
foreach (var comp in toDisable)
{
SetEnabled(comp, false);
}
}
}