Files
OldThink/Content.Server/Movement/Systems/JetpackSystem.cs

52 lines
1.7 KiB
C#
Raw Normal View History

using Content.Server.Atmos.Components;
2022-07-25 14:42:25 +10:00
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
{
2022-07-25 14:42:25 +10:00
[Dependency] private readonly GasTankSystem _gasTank = default!;
[Dependency] private readonly IGameTiming _timing = default!;
2022-07-25 14:42:25 +10:00
2023-07-23 16:00:59 +10:00
protected override bool CanEnable(EntityUid uid, JetpackComponent component)
{
2023-07-23 16:00:59 +10:00
return base.CanEnable(uid, component) &&
TryComp<GasTankComponent>(uid, out var gasTank) &&
!(gasTank.Air.TotalMoles < component.MoleUsage);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
2023-07-23 16:00:59 +10:00
var toDisable = new ValueList<(EntityUid Uid, JetpackComponent Component)>();
var query = EntityQueryEnumerator<ActiveJetpackComponent, JetpackComponent, GasTankComponent>();
2023-07-23 16:00:59 +10:00
while (query.MoveNext(out var uid, out var active, out var comp, out var gasTank))
{
2023-07-23 16:00:59 +10:00
if (_timing.CurTime < active.TargetTime)
continue;
active.TargetTime = _timing.CurTime + TimeSpan.FromSeconds(active.EffectCooldown);
2022-07-25 14:42:25 +10:00
var air = _gasTank.RemoveAir(gasTank, comp.MoleUsage);
if (air == null || !MathHelper.CloseTo(air.TotalMoles, comp.MoleUsage, 0.001f))
{
2023-07-23 16:00:59 +10:00
toDisable.Add((uid, comp));
continue;
}
2022-07-25 14:42:25 +10:00
_gasTank.UpdateUserInterface(gasTank);
}
2023-07-23 16:00:59 +10:00
foreach (var (uid, comp) in toDisable)
{
2023-07-23 16:00:59 +10:00
SetEnabled(uid, comp, false);
}
}
}