Fixed more boxing perf issues + removed unnecessary check that reduced perf when generating flea offers

This commit is contained in:
Chomp
2025-07-07 13:07:53 +01:00
parent a5946f9fc5
commit 9470855b50
4 changed files with 7 additions and 12 deletions
@@ -591,18 +591,14 @@ public class TraderHelper(
/// <returns>Rouble price</returns>
public double GetHighestSellToTraderPrice(MongoId tpl)
{
// Find largest trader price for item
var highestPrice = 1d; // Default price
var itemHandbookPrice = handbookHelper.GetTemplatePrice(tpl);
foreach (var trader in traderStore.GetAllTraders())
{
// Get trader and check buy category allows tpl
var traderBase = databaseService.GetTrader(trader.Id).Base;
// Skip traders that don't sell this category of item
if (
traderBase is null
|| !itemHelper.IsOfBaseclasses(tpl, traderBase.ItemsBuy.Category)
)
if (traderBase is null)
{
continue;
}
@@ -613,7 +609,6 @@ public class TraderHelper(
var traderBuyBackPricePercent =
100 - traderBase.LoyaltyLevels.FirstOrDefault().BuyPriceCoefficient;
var itemHandbookPrice = handbookHelper.GetTemplatePrice(tpl);
var priceTraderBuysItemAt = randomUtil.GetPercentOfValue(
traderBuyBackPricePercent ?? 0,
itemHandbookPrice,
@@ -168,7 +168,7 @@ public record Dynamic
/// Settings to control the durability range of item items listed on flea
/// </summary>
[JsonPropertyName("condition")]
public Dictionary<string, Condition> Condition { get; set; }
public Dictionary<MongoId, Condition> Condition { get; set; }
/// <summary>
/// Size stackable items should be listed for in percent of max stack size
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using SPTarkov.Server.Core.Models.Common;
namespace SPTarkov.Server.Core.Models.Spt.Ragfair;
@@ -8,11 +9,11 @@ public record TplWithFleaPrice
public Dictionary<string, object>? ExtensionData { get; set; }
[JsonPropertyName("tpl")]
public string? Tpl { get; set; }
public MongoId Tpl { get; set; }
/// <summary>
/// Roubles
/// </summary>
[JsonPropertyName("price")]
public double? Price { get; set; }
public double Price { get; set; }
}
@@ -350,8 +350,7 @@ public class DatabaseService(
/// <returns> assets/database/traders/ </returns>
public Trader? GetTrader(MongoId traderId)
{
var traders = GetTraders();
if (!traders.TryGetValue(traderId, out var desiredTrader))
if (!databaseServer.GetTables().Traders.TryGetValue(traderId, out var desiredTrader))
{
logger.Error(
serverLocalisationService.GetText("database-no_trader_found_with_id", traderId)