Skip to content

Commit

Permalink
IT'S FINALLY REAL
Browse files Browse the repository at this point in the history
  • Loading branch information
MilonPL committed Nov 4, 2024
1 parent 599d0c9 commit d05fd6d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,39 @@ public sealed partial class StationStockMarketComponent : Component
DisplayName = "Nanotrasen [NT]",
CurrentPrice = 100f,
BasePrice = 100f,
PriceHistory = [100f, 100f, 100f, 100f, 100f], // look somewhere else
PriceHistory = [],
},
["Gorlex"] = new StockCompanyStruct
{
Name = "Gorlex",
DisplayName = "Gorlex [GRX]",
CurrentPrice = 75f,
BasePrice = 75f,
PriceHistory = [75f, 75f, 75f, 75f, 75f],
PriceHistory = [],
},
["Interdyne"] = new StockCompanyStruct
{
Name = "Interdyne",
DisplayName = "Interdyne Pharmaceuticals [INTP]",
CurrentPrice = 300f,
BasePrice = 300f,
PriceHistory = [],
},
["FishInc"] = new StockCompanyStruct
{
Name = "FishInc",
DisplayName = "Fish Inc. [FIN]",
CurrentPrice = 25f,
BasePrice = 25f,
PriceHistory = [25f, 25f, 25f, 25f, 25f],
PriceHistory = [],
},
["Donk"] = new StockCompanyStruct
{
Name = "Donk",
DisplayName = "Donk Co. [DONK]",
CurrentPrice = 90f,
BasePrice = 90f,
PriceHistory = [90f, 90f, 90f, 90f, 90f],
},
};

Expand All @@ -51,7 +67,7 @@ public sealed partial class StationStockMarketComponent : Component
/// The interval at which the stock market updates
/// </summary>
[DataField]
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(10); // 5 minutes
public TimeSpan UpdateInterval = TimeSpan.FromSeconds(600); // 10 minutes

/// <summary>
/// The <see cref="IGameTiming.CurTime"/> timespan of next update.
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/DeltaV/Cargo/StocksCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async void Execute(IConsoleShell shell, string argStr, string[] args)
DisplayName = displayName,
CurrentPrice = basePrice,
BasePrice = basePrice,
PriceHistory = [basePrice, basePrice, basePrice, basePrice, basePrice],
PriceHistory = [],
};

var stockMarket = _entitySystemManager.GetEntitySystem<StockMarketSystem>();
Expand Down
18 changes: 17 additions & 1 deletion Content.Server/DeltaV/Cargo/Systems/StockMarketSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ public override void Initialize()
_sawmill = _log.GetSawmill("admin.stock_market");

SubscribeLocalEvent<StockTradingCartridgeComponent, CartridgeMessageEvent>(OnStockTradingMessage);
SubscribeLocalEvent<StationStockMarketComponent, ComponentInit>(OnInit);
}

private static void OnInit(Entity<StationStockMarketComponent> ent, ref ComponentInit args)
{
foreach (var company in ent.Comp.Companies.Values)
{
UpdatePriceHistory(company);
}
}

public override void Update(float frameTime)
Expand Down Expand Up @@ -369,11 +378,18 @@ public bool TryAddCompany(EntityUid station,

private static void UpdatePriceHistory(StockCompanyStruct company)
{
// Make sure it has at least 5 entries
while (company.PriceHistory.Count < 5)
{
company.PriceHistory.Add(company.BasePrice);
}


// Store previous price in history
company.PriceHistory.Add(company.CurrentPrice);

if (company.PriceHistory.Count > 5) // Keep last 5 prices
company.PriceHistory.RemoveAt(0);
company.PriceHistory.RemoveAt(1); // Always keep the base price
}

private StockChangeType DetermineChangeType(StationStockMarketComponent stockMarket)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@
- type: entity
parent: BaseItem
id: StockTradingCartridge
name: stock trading cartridge
name: StockTrading cartridge
description: A cartridge that tracks the intergalactic stock market.
components:
- type: Sprite
sprite: DeltaV/Objects/Devices/cartridge.rsi
state: cart-mail
state: cart-stonk
- type: Icon
sprite: DeltaV/Objects/Devices/cartridge.rsi
state: cart-mail
Expand Down
8 changes: 7 additions & 1 deletion Resources/Prototypes/Entities/Objects/Devices/pda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@
- NotekeeperCartridge
- NewsReaderCartridge
- MailMetricsCartridge # DeltaV - MailMetrics courier tracker
- StockTradingCartridge # DeltaV - StockTrading for the LO
- StockTradingCartridge # DeltaV - StockTrading

- type: entity
parent: BasePDA
Expand All @@ -413,6 +413,12 @@
borderColor: "#e39751"
- type: Icon
state: pda-cargo
- type: CartridgeLoader # DeltaV
preinstalled:
- CrewManifestCartridge
- NotekeeperCartridge
- NewsReaderCartridge
- StockTradingCartridge # DeltaV - StockTrading

- type: entity
parent: BasePDA
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
},
{
"name": "cart-psi"
},
{
"name": "cart-stonk"
}
]
}

0 comments on commit d05fd6d

Please sign in to comment.