diff --git a/Core/Models/Spt/Ragfair/RagfairServerPrices.cs b/Core/Models/Spt/Ragfair/RagfairServerPrices.cs index ba0ee22d..687b8bb1 100644 --- a/Core/Models/Spt/Ragfair/RagfairServerPrices.cs +++ b/Core/Models/Spt/Ragfair/RagfairServerPrices.cs @@ -1,12 +1,12 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; namespace Core.Models.Spt.Ragfair; public record RagfairServerPrices { - [JsonPropertyName("static")] - public Dictionary? Static { get; set; } + [JsonPropertyName("staticPrices")] + public Dictionary? StaticPrices { get; set; } - [JsonPropertyName("dynamic")] - public Dictionary? Dynamic { get; set; } + [JsonPropertyName("dynamicPrices")] + public Dictionary? DynamicPrices { get; set; } } diff --git a/Core/Services/RagfairPriceService.cs b/Core/Services/RagfairPriceService.cs index 0a0fff03..c151230a 100644 --- a/Core/Services/RagfairPriceService.cs +++ b/Core/Services/RagfairPriceService.cs @@ -1,13 +1,34 @@ -using Core.Annotations; +using Core.Annotations; +using Core.Helpers; using Core.Models.Common; using Core.Models.Eft.Common.Tables; +using Core.Models.Eft.Player; using Core.Models.Spt.Config; +using Core.Models.Spt.Ragfair; +using Core.Models.Utils; namespace Core.Services; [Injectable(InjectionType.Singleton)] public class RagfairPriceService { + private readonly ISptLogger _logger; + private readonly HandbookHelper _handbookHelper; + private readonly DatabaseService _databaseService; + + protected RagfairServerPrices _prices = new RagfairServerPrices{ StaticPrices = new Dictionary(), DynamicPrices = new Dictionary() }; + +public RagfairPriceService( + ISptLogger logger, + HandbookHelper handbookHelper, + DatabaseService databaseService) + { + _logger = logger; + _handbookHelper = handbookHelper; + _databaseService = databaseService; + } + + /// /// Generate static (handbook) and dynamic (prices.json) flea prices, store inside class as dictionaries /// @@ -26,7 +47,10 @@ public class RagfairPriceService /// public void RefreshStaticPrices() { - throw new NotImplementedException(); + foreach (var item in _databaseService.GetItems().Where((x) => x.Value.Type == "Item")) + { + _prices.StaticPrices[item.Key] = Math.Round(_handbookHelper.GetTemplatePrice(item.Key)); + } } /// @@ -90,7 +114,10 @@ public class RagfairPriceService public Dictionary GetAllStaticPrices() { - throw new NotImplementedException(); + // Refresh the cache so we include any newly added custom items + RefreshStaticPrices(); + + return _prices.StaticPrices; } ///