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

58 lines
1.8 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>();
while (query.MoveNext(out var uid, out var active, out var comp, out var gasTankComp))
{
2023-07-23 16:00:59 +10:00
if (_timing.CurTime < active.TargetTime)
continue;
var gasTank = (uid, gasTankComp);
active.TargetTime = _timing.CurTime + TimeSpan.FromSeconds(active.EffectCooldown);
var usedAir = _gasTank.RemoveAir(gasTank, comp.MoleUsage);
if (usedAir == null)
continue;
var usedEnoughAir =
MathHelper.CloseTo(usedAir.TotalMoles, comp.MoleUsage, comp.MoleUsage/100);
if (!usedEnoughAir)
{
2023-07-23 16:00:59 +10:00
toDisable.Add((uid, comp));
}
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);
}
}
}