-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathJetpackSystem.cs
More file actions
65 lines (51 loc) · 2.03 KB
/
JetpackSystem.cs
File metadata and controls
65 lines (51 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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!;
[Dependency] private readonly EntityManager _entityManager = default!;
public override void Initialize()
{
base.Initialize();
}
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);
}
}
}