Implemented GetAllStaticPrices

This commit is contained in:
Chomp
2025-01-18 16:26:51 +00:00
parent 5f488fb4cd
commit a59f2a598c
2 changed files with 35 additions and 8 deletions
@@ -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<string, int>? Static { get; set; }
[JsonPropertyName("staticPrices")]
public Dictionary<string, double>? StaticPrices { get; set; }
[JsonPropertyName("dynamic")]
public Dictionary<string, int>? Dynamic { get; set; }
[JsonPropertyName("dynamicPrices")]
public Dictionary<string, double>? DynamicPrices { get; set; }
}
+30 -3
View File
@@ -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<RagfairPriceService> _logger;
private readonly HandbookHelper _handbookHelper;
private readonly DatabaseService _databaseService;
protected RagfairServerPrices _prices = new RagfairServerPrices{ StaticPrices = new Dictionary<string, double>(), DynamicPrices = new Dictionary<string, double>() };
public RagfairPriceService(
ISptLogger<RagfairPriceService> logger,
HandbookHelper handbookHelper,
DatabaseService databaseService)
{
_logger = logger;
_handbookHelper = handbookHelper;
_databaseService = databaseService;
}
/// <summary>
/// Generate static (handbook) and dynamic (prices.json) flea prices, store inside class as dictionaries
/// </summary>
@@ -26,7 +47,10 @@ public class RagfairPriceService
/// </summary>
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));
}
}
/// <summary>
@@ -90,7 +114,10 @@ public class RagfairPriceService
public Dictionary<string, double> GetAllStaticPrices()
{
throw new NotImplementedException();
// Refresh the cache so we include any newly added custom items
RefreshStaticPrices();
return _prices.StaticPrices;
}
/// <summary>