Skip to content

Commit

Permalink
Xddd
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornado-Technology committed Dec 9, 2024
1 parent a4ac15c commit c70c9d3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<BluespaceHarvesterCategoryInfo> Categories = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed class BluespaceHarvesterSystem : EntitySystem
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSound = default!;

public List<BluespaceHarvesterTap> Taps =
private readonly List<BluespaceHarvesterTap> _taps =
[
new BluespaceHarvesterTap { Level = 0, Visual = BluespaceHarvesterVisuals.Tap0 },
new BluespaceHarvesterTap { Level = 1, Visual = BluespaceHarvesterVisuals.Tap1 },
Expand All @@ -37,16 +37,41 @@ public sealed class BluespaceHarvesterSystem : EntitySystem
private float _updateTimer;
private const float UpdateTime = 1.0f;

private EntityQuery<BluespaceHarvesterComponent> _harvesterQuery;

public override void Initialize()
{
base.Initialize();

_harvesterQuery = GetEntityQuery<BluespaceHarvesterComponent>();

SubscribeLocalEvent<BluespaceHarvesterComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<BluespaceHarvesterComponent, ComponentRemove>(OnRemove);

SubscribeLocalEvent<BluespaceHarvesterComponent, PowerConsumerReceivedChanged>(ReceivedChanged);
SubscribeLocalEvent<BluespaceHarvesterComponent, BluespaceHarvesterTargetLevelMessage>(OnTargetLevel);
SubscribeLocalEvent<BluespaceHarvesterComponent, BluespaceHarvesterBuyMessage>(OnBuy);
SubscribeLocalEvent<BluespaceHarvesterComponent, DestructionEventArgs>(OnDestruction);
}

private void OnStartup(Entity<BluespaceHarvesterComponent> ent, ref ComponentStartup args)
{
var query = EntityQueryEnumerator<BluespaceHarvesterComponent>();
while (query.MoveNext(out _, out var harvester))
{
harvester.Harvesters++;
}
}

private void OnRemove(Entity<BluespaceHarvesterComponent> ent, ref ComponentRemove args)
{
var query = EntityQueryEnumerator<BluespaceHarvesterComponent>();
while (query.MoveNext(out _, out var harvester))
{
harvester.Harvesters--;
}
}

private void ReceivedChanged(Entity<BluespaceHarvesterComponent> ent, ref PowerConsumerReceivedChanged args)
{
ent.Comp.ReceivedPower = args.ReceivedPower;
Expand All @@ -67,27 +92,14 @@ public override void Update(float frameTime)
var query = EntityQueryEnumerator<BluespaceHarvesterComponent, PowerConsumerComponent>();
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;

// 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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;

Expand All @@ -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;
}

Expand Down

0 comments on commit c70c9d3

Please sign in to comment.