This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
forked from new-frontiers-14/frontier-station-14
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
Content.Server/Corvax/Inflation/InflationCargoCrateSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |