diff --git a/Content.Server/_CorvaxNext/BluespaceHarvester/BluespaceHarvesterComponent.cs b/Content.Server/_CorvaxNext/BluespaceHarvester/BluespaceHarvesterComponent.cs index aad9b1a3c4a..b065b4f060d 100644 --- a/Content.Server/_CorvaxNext/BluespaceHarvester/BluespaceHarvesterComponent.cs +++ b/Content.Server/_CorvaxNext/BluespaceHarvester/BluespaceHarvesterComponent.cs @@ -109,6 +109,9 @@ public sealed partial class BluespaceHarvesterComponent : Component [DataField, ViewVariables(VVAccess.ReadWrite)] public float EmaggedRiftChance = 0.03f; + [ViewVariables(VVAccess.ReadWrite)] + public int Harvesters; + [DataField] public List Categories = new() { diff --git a/Content.Server/_CorvaxNext/BluespaceHarvester/BluespaceHarvesterSystem.cs b/Content.Server/_CorvaxNext/BluespaceHarvester/BluespaceHarvesterSystem.cs index a86f9f9b488..d4075356253 100644 --- a/Content.Server/_CorvaxNext/BluespaceHarvester/BluespaceHarvesterSystem.cs +++ b/Content.Server/_CorvaxNext/BluespaceHarvester/BluespaceHarvesterSystem.cs @@ -24,7 +24,7 @@ public sealed class BluespaceHarvesterSystem : EntitySystem [Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedAmbientSoundSystem _ambientSound = default!; - public List Taps = + private readonly List _taps = [ new BluespaceHarvesterTap { Level = 0, Visual = BluespaceHarvesterVisuals.Tap0 }, new BluespaceHarvesterTap { Level = 1, Visual = BluespaceHarvesterVisuals.Tap1 }, @@ -37,16 +37,41 @@ public sealed class BluespaceHarvesterSystem : EntitySystem private float _updateTimer; private const float UpdateTime = 1.0f; + private EntityQuery _harvesterQuery; + public override void Initialize() { base.Initialize(); + _harvesterQuery = GetEntityQuery(); + + SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnRemove); + SubscribeLocalEvent(ReceivedChanged); SubscribeLocalEvent(OnTargetLevel); SubscribeLocalEvent(OnBuy); SubscribeLocalEvent(OnDestruction); } + private void OnStartup(Entity ent, ref ComponentStartup args) + { + var query = EntityQueryEnumerator(); + while (query.MoveNext(out _, out var harvester)) + { + harvester.Harvesters++; + } + } + + private void OnRemove(Entity ent, ref ComponentRemove args) + { + var query = EntityQueryEnumerator(); + while (query.MoveNext(out _, out var harvester)) + { + harvester.Harvesters--; + } + } + private void ReceivedChanged(Entity ent, ref PowerConsumerReceivedChanged args) { ent.Comp.ReceivedPower = args.ReceivedPower; @@ -67,8 +92,6 @@ public override void Update(float frameTime) var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var harvester, out var consumer)) { - var ent = (uid, harvester); - // We start only after manual switching on. if (harvester is { Reseted: false, CurrentLevel: 0 }) harvester.Reseted = true; @@ -76,18 +99,7 @@ public override void Update(float frameTime) // The HV wires cannot transmit a lot of electricity so quickly, // which is why it will not start. // So this is simply using the amount of free electricity in the network. - if (harvester.ResetTime == TimeSpan.Zero) - { - if (harvester.ReceivedPower < harvester.DrawRate && harvester.CurrentLevel != 0) - harvester.ResetTime = _timing.CurTime; - } - else - { - if (harvester.ReceivedPower >= harvester.DrawRate) - harvester.ResetTime = TimeSpan.Zero; - } - - if (harvester.ResetTime <= _timing.CurTime && harvester.ResetTime != TimeSpan.Zero) + if (harvester.ReceivedPower < harvester.DrawRate && harvester.CurrentLevel != 0) { // If there is insufficient production, // it will reset itself (turn off) and you will need to start it again, @@ -171,7 +183,7 @@ private void UpdateAppearance(EntityUid uid, BluespaceHarvesterComponent? harves var level = harvester.CurrentLevel; BluespaceHarvesterTap? max = null; - foreach (var tap in Taps) + foreach (var tap in _taps) { if (tap.Level > level) continue; @@ -279,7 +291,7 @@ private int GetPointGeneration(EntityUid uid, BluespaceHarvesterComponent? harve if (!Resolve(uid, ref harvester)) return 0; - return harvester.CurrentLevel * 4 * (Emagged(uid) ? 2 : 1) + (harvester.ResetTime == TimeSpan.Zero ? 1 : 0); + return harvester.CurrentLevel * 4 * (Emagged(uid) ? 2 : 1) * (harvester.ResetTime == TimeSpan.Zero ? 1 : 0); } private int GetDangerPointGeneration(EntityUid uid, BluespaceHarvesterComponent? harvester = null) @@ -288,7 +300,6 @@ private int GetDangerPointGeneration(EntityUid uid, BluespaceHarvesterComponent? return 0; var stable = GetStableLevel(uid, harvester); - if (harvester.CurrentLevel < stable && harvester.CurrentLevel != 0) return -1; @@ -311,6 +322,9 @@ private int GetStableLevel(EntityUid uid, BluespaceHarvesterComponent? harvester if (!Resolve(uid, ref harvester)) return 0; + if (harvester.Harvesters > 1) + return 0; + return Emagged(uid) ? harvester.EmaggedStableLevel : harvester.StableLevel; }