From c0f0ce8b1be40050ddaac1e45f59c5f179e72b26 Mon Sep 17 00:00:00 2001 From: Dmitriy <108795395+Sh1ntra@users.noreply.github.com> Date: Tue, 7 May 2024 05:47:26 +0300 Subject: [PATCH] Create InflationCargoCrateSystem.cs --- .../Inflation/InflationCargoCrateSystem.cs | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Content.Server/Corvax/Inflation/InflationCargoCrateSystem.cs diff --git a/Content.Server/Corvax/Inflation/InflationCargoCrateSystem.cs b/Content.Server/Corvax/Inflation/InflationCargoCrateSystem.cs new file mode 100644 index 00000000000..f4b8596ed98 --- /dev/null +++ b/Content.Server/Corvax/Inflation/InflationCargoCrateSystem.cs @@ -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(); + + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var inflationCargoCrateComponent)) + { + var xformQuery = GetEntityQuery(); + 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(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; + } + } +}