Fix jetpack warnings (#18227)

This commit is contained in:
metalgearsloth
2023-07-23 16:00:59 +10:00
committed by GitHub
parent c8ef41e732
commit 1de396d566
6 changed files with 83 additions and 71 deletions

View File

@@ -12,38 +12,40 @@ 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)
protected override bool CanEnable(EntityUid uid, JetpackComponent component)
{
return base.CanEnable(component) && TryComp<GasTankComponent>(component.Owner, out var gasTank) && !(gasTank.Air.TotalMoles < component.MoleUsage);
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<JetpackComponent>();
var toDisable = new ValueList<(EntityUid Uid, JetpackComponent Component)>();
var query = EntityQueryEnumerator<ActiveJetpackComponent, JetpackComponent, GasTankComponent>();
foreach (var (active, comp, gasTank) in EntityQuery<ActiveJetpackComponent, JetpackComponent, GasTankComponent>())
while (query.MoveNext(out var uid, out var active, out var comp, out var gasTank))
{
if (_timing.CurTime < active.TargetTime) continue;
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);
toDisable.Add((uid, comp));
continue;
}
_gasTank.UpdateUserInterface(gasTank);
}
foreach (var comp in toDisable)
foreach (var (uid, comp) in toDisable)
{
SetEnabled(comp, false);
SetEnabled(uid, comp, false);
}
}
}