Added system to generate item flea base prices based on handbook value

This commit is contained in:
Chomp
2025-09-16 22:24:35 +01:00
parent 2d172649e1
commit 1ef9ebd88a
3 changed files with 75 additions and 5 deletions
@@ -343,7 +343,16 @@
"newPriceHandbookMultiplier": 11
}
},
"useTraderPriceForOffersIfHigher": true
"useTraderPriceForOffersIfHigher": true,
"generateBaseFleaPrices": {
"useHandbookPrice": true,
"priceMultiplier": 1.5,
"itemTplMultiplierOverride": {
"5780cf7f2459777de4559322": 1.8,
"5c1d0efb86f7744baf2e7b7b": 2.5
},
"preventPriceBeingBelowTraderBuyPrice": true
}
},
"runIntervalSeconds": 8,
"runIntervalValues": {
@@ -227,6 +227,33 @@ public record Dynamic
/// </summary>
[JsonPropertyName("itemPriceOverrideRouble")]
public required Dictionary<MongoId, double> ItemPriceOverrideRouble { get; set; }
[JsonPropertyName("generateBaseFleaPrices")]
public GenerateFleaPrices GenerateBaseFleaPrices { get; set; }
}
public record GenerateFleaPrices
{
/// <summary>
/// Should handbook prices be used (true) as a base or the values already in prices.json (false)
/// </summary>
[JsonPropertyName("useHandbookPrice")]
public bool UseHandbookPrice { get; set; }
/// <summary>
/// Multiplier to apply to handbook price
/// </summary>
[JsonPropertyName("priceMultiplier")]
public double PriceMultiplier { get; set; }
/// <summary>
/// Don't allow prices being added that are below sell to trader price. Prevent ability to buy cheap items on flea and sell to traders for easy rep
/// </summary>
[JsonPropertyName("preventPriceBeingBelowTraderBuyPrice")]
public bool PreventPriceBeingBelowTraderBuyPrice { get; set; }
[JsonPropertyName("itemTplMultiplierOverride")]
public Dictionary<MongoId, double> ItemTplMultiplierOverride { get; set; }
}
public record PriceRanges
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
@@ -24,6 +25,7 @@ public class RagfairPriceService(
PresetHelper presetHelper,
ItemHelper itemHelper,
DatabaseService databaseService,
DatabaseServer databaseServer,
ServerLocalisationService serverLocalisationService,
ConfigServer configServer
)
@@ -37,7 +39,10 @@ public class RagfairPriceService(
public void Load()
{
RefreshStaticPrices();
RefreshDynamicPrices();
if (RagfairConfig.Dynamic.GenerateBaseFleaPrices.UseHandbookPrice)
{
ReplaceFleaBasePrices();
}
}
public string GetRoute()
@@ -62,11 +67,40 @@ public class RagfairPriceService(
}
/// <summary>
/// Copy the prices.json data into our dynamic price dictionary
/// Replace base item price used for flea
/// Use handbook as a base price
/// </summary>
public void RefreshDynamicPrices()
public void ReplaceFleaBasePrices()
{
// TODO: remove as redundant?
var pricePool = databaseServer.GetTables().Templates.Prices;
foreach (var (itemTpl, handbookPrice) in StaticPrices)
{
// Get new price to use
var newBasePrice = handbookPrice * RagfairConfig.Dynamic.GenerateBaseFleaPrices.PriceMultiplier;
if (newBasePrice == 0)
{
continue;
}
// Specific item multiplier may exist, check for it
if (RagfairConfig.Dynamic.GenerateBaseFleaPrices.ItemTplMultiplierOverride.TryGetValue(itemTpl, out var specificItemMultiplier))
{
newBasePrice = handbookPrice * specificItemMultiplier;
}
if (RagfairConfig.Dynamic.GenerateBaseFleaPrices.PreventPriceBeingBelowTraderBuyPrice)
{
// Check if item can be sold to trader for a higher price than what we're going to set
var highestSellToTraderPrice = traderHelper.GetHighestSellToTraderPrice(itemTpl);
if (highestSellToTraderPrice > newBasePrice)
{
// Trader has higher sell price, use that value
newBasePrice = highestSellToTraderPrice;
}
}
pricePool.AddOrUpdate(itemTpl, newBasePrice);
}
}
/// <summary>