forked from new-frontiers-14/frontier-station-14
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from Corvax-Frontier/DespawnCrate
Inflation trade crates
- Loading branch information
Showing
5 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
Content.Server/Corvax/Inflation/InflationCargoCrateComponent.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,7 @@ | ||
[RegisterComponent] | ||
[AutoGenerateComponentState] | ||
public sealed partial class InflationCargoCrateComponent : Component | ||
{ | ||
[DataField("isInflated"), ViewVariables(VVAccess.ReadWrite)] | ||
public bool IsInflated = false; | ||
} |
69 changes: 69 additions & 0 deletions
69
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,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; | ||
} | ||
} | ||
} |
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
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
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