* Predicted gas pumps I wanted to try out atmos and first thing I found. * a * Atmos device prediction - Canisters - Tanks - Internals AirMixes aren't predicted so nothing on that front but all the UIs should be a lot closer. * Remove details range * Gas tank prediction * Even more sweeping changes * Alerts * rehg * Popup fix * Fix merge conflicts * Fix * Review
59 lines
1.9 KiB
C#
59 lines
1.9 KiB
C#
using Content.Server.Atmos.Components;
|
|
using Content.Server.Atmos.EntitySystems;
|
|
using Content.Shared.Atmos.Components;
|
|
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!;
|
|
|
|
protected override bool CanEnable(EntityUid uid, JetpackComponent component)
|
|
{
|
|
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);
|
|
|
|
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))
|
|
{
|
|
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)
|
|
{
|
|
toDisable.Add((uid, comp));
|
|
}
|
|
|
|
_gasTank.UpdateUserInterface(gasTank);
|
|
}
|
|
|
|
foreach (var (uid, comp) in toDisable)
|
|
{
|
|
SetEnabled(uid, comp, false);
|
|
}
|
|
}
|
|
}
|