Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Create InflationCargoCrateSystem.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh1ntra authored May 7, 2024
1 parent 6735809 commit c0f0ce8
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Content.Server/Corvax/Inflation/InflationCargoCrateSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Robust.Shared.Timing;
using Robust.Server.Player;
using Content.Server.Chat.Systems;
using Content.Shared._NF.Trade.Components;
using Content.Shared.Cargo.Components;

namespace Content.Server.Corvax.AutoDeleteItems;

public sealed class InflationCargoCrateSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly IEntityManager _entManager = default!;

private TimeSpan? Timer = TimeSpan.FromSeconds(10);
private TimeSpan? NextTimeToCheck = TimeSpan.FromSeconds(5);

StaticPriceComponent? staticPriceComponent = null;

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

public override void Update(float frameTime)
{
base.Update(frameTime);

double modifier = 0;

if (NextTimeToCheck < _gameTiming.CurTime)
{
numberCrates = _entManager.Count<TradeCrateComponent>();

var query = EntityQueryEnumerator<InflationCargoCrateComponent>();
while (query.MoveNext(out var uid, out var inflationCargoCrateComponent))
{
var xformQuery = GetEntityQuery<StaticPriceComponent>();
if (!xformQuery.TryGetComponent(uid, out var xform))
{
return;
}

if (numberCrates == 1)
modifier = 1;
else if (numberCrates >= 2 && numberCrates <= 5)
modifier = 0.5;
else if (numberCrates >= 6 && numberCrates <= 10)
modifier = 0.3;

foreach (var iterator in _entManager.EntityQuery<TradeCrateComponent>(true))
{

if (TryComp(uid, out inflationCargoCrateComponent))
{
if (inflationCargoCrateComponent.IsInflated)
continue;

if (TryComp(uid, out staticPriceComponent))
{
staticPriceComponent.Price *= modifier;
inflationCargoCrateComponent.IsInflated = true;
}

if (iterator.Owner == uid)
continue;
}
}
}
NextTimeToCheck = NextTimeToCheck + Timer;
}
}
}

0 comments on commit c0f0ce8

Please sign in to comment.