Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inflation trade crates #29

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[RegisterComponent]
[AutoGenerateComponentState]
public sealed partial class InflationCargoCrateComponent : Component
{
[DataField("isInflated"), ViewVariables(VVAccess.ReadWrite)]
public bool IsInflated = false;
}
69 changes: 69 additions & 0 deletions Content.Server/Corvax/Inflation/InflationCargoCrateSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Robust.Shared.Timing;
using Content.Server.Chat.Systems;
using Content.Shared._NF.Trade.Components;
using Content.Shared.Cargo.Components;

namespace Content.Server.Corvax.Inflation;

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

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

StaticPriceComponent? staticPriceComponent = null;
public override void Update(float frameTime)
{
base.Update(frameTime);

int numberCrates = 0;

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 && numberCrates <= 19)
modifier = 1;
else if (numberCrates >= 20 && numberCrates <= 39)
modifier = 0.9;
else if (numberCrates >= 40 && numberCrates <= 69)
modifier = 0.85;
else if (numberCrates >= 70)
modifier = 0.82;

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;
}
}
}
4 changes: 2 additions & 2 deletions Resources/Prototypes/_NF/Catalog/Cargo/cargo_trade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
sprite: _NF/Structures/Storage/Crates/tradedark.rsi
state: icon
product: CrateTradeSecureNormalFilled
cost: 1000
cost: 15000
category: cargoproduct-category-name-cargo
group: market

Expand All @@ -14,6 +14,6 @@
sprite: _NF/Structures/Storage/Crates/tradelight.rsi
state: icon
product: CrateTradeSecureHighFilled
cost: 2000
cost: 30000
category: cargoproduct-category-name-cargo
group: market
8 changes: 7 additions & 1 deletion Resources/Prototypes/_NF/Catalog/Fills/Crates/trade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
parent: CrateTradeBaseSecureNormal
name: cargo trading crate
description: Contains goods made in the Frontier sector, ready to be sold on a cargo depot for higher value. MAKE SURE THE CRATE IS INTACT.
components:
- type: InflationCargoCrate
isInflated: false

- type: entity
id: CrateTradeSecureHighFilled
parent: CrateTradeBaseSecureHigh
name: high value cargo trading crate
description: Contains high value goods made in the Frontier sector, ready to be sold on a cargo depot for higher value. MAKE SURE THE CRATE IS INTACT.
components:
- type: InflationCargoCrate
isInflated: false

- type: entity
id: CrateTradeContrabandSecureNormalFilled
Expand All @@ -17,7 +23,7 @@
- type: entity
id: CrateTradeContrabandSecureDonkFilled
parent: CrateTradeContrabandSecureDonk

- type: entity
id: CrateTradeContrabandSecureCyberSunFilled
parent: CrateTradeContrabandSecureCyberSun
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
layer:
- MachineLayer
- type: StaticPrice
price: 1000
price: 15500

- type: entity
parent: CrateTradeBaseSecure
Expand All @@ -75,7 +75,7 @@
layer:
- MachineLayer
- type: StaticPrice
price: 2000
price: 31000

- type: entity
parent: CrateTradeBaseSecure
Expand Down
Loading