Converted strings into MongoId type

This commit is contained in:
Chomp
2025-07-05 11:03:09 +01:00
parent bec75e6a88
commit 8253215410
37 changed files with 157 additions and 143 deletions
@@ -492,11 +492,11 @@ public class InsuranceController(
);
// Create prob array and add all attachments with rouble price as the weight
var attachmentsProbabilityArray = new ProbabilityObjectArray<string, double?>(_cloner);
var attachmentsProbabilityArray = new ProbabilityObjectArray<MongoId, double?>(_cloner);
foreach (var (itemTpl, price) in weightedAttachmentByPrice)
{
attachmentsProbabilityArray.Add(
new ProbabilityObject<string, double?>(itemTpl, price, null)
new ProbabilityObject<MongoId, double?>(itemTpl, price, null)
);
}
@@ -525,9 +525,9 @@ public class InsuranceController(
/// <param name="attachments"></param>
/// <param name="attachmentPrices"></param>
protected void LogAttachmentsBeingRemoved(
List<string> attachmentIdsToRemove,
List<MongoId> attachmentIdsToRemove,
List<Item> attachments,
Dictionary<string, double> attachmentPrices
Dictionary<MongoId, double> attachmentPrices
)
{
var index = 1;
@@ -550,9 +550,9 @@ public class InsuranceController(
/// </summary>
/// <param name="attachments">Item attachments</param>
/// <returns></returns>
protected Dictionary<string, double> WeightAttachmentsByPrice(List<Item> attachments)
protected Dictionary<MongoId, double> WeightAttachmentsByPrice(List<Item> attachments)
{
var result = new Dictionary<string, double>();
var result = new Dictionary<MongoId, double>();
// Get a dictionary of item tpls + their rouble price
foreach (var attachment in attachments)
@@ -579,7 +579,7 @@ public class InsuranceController(
/// <param name="traderId">Trader the attachment is insured against</param>
/// <returns>Attachment count to remove</returns>
protected double GetAttachmentCountToRemove(
Dictionary<string, double> weightedAttachmentByPrice,
Dictionary<MongoId, double> weightedAttachmentByPrice,
string? traderId
)
{
@@ -599,7 +599,7 @@ public class InventoryController(
/// <param name="request"></param>
/// <param name="sessionId">Session/Player id</param>
/// <returns>Item tpl</returns>
protected string? GetExaminedItemTpl(InventoryExamineRequestData request, string? sessionId)
protected MongoId? GetExaminedItemTpl(InventoryExamineRequestData request, string? sessionId)
{
if (_presetHelper.IsPreset(request.Item))
{
@@ -1,5 +1,6 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Spt.Presets;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Services;
@@ -19,7 +20,7 @@ public class PresetController(
public void Initialize()
{
var presets = _databaseService.GetGlobals().ItemPresets;
var result = new Dictionary<string, PresetCacheDetails>();
var result = new Dictionary<MongoId, PresetCacheDetails>();
foreach (var (presetId, preset) in presets)
{
if (presetId != preset.Id)
@@ -33,9 +34,9 @@ public class PresetController(
// Get root items tpl
var tpl = preset.Items.FirstOrDefault()?.Template;
result.TryAdd(tpl, new PresetCacheDetails { PresetIds = [] });
result.TryAdd(tpl.Value, new PresetCacheDetails { PresetIds = [] });
result.TryGetValue(tpl, out var details);
result.TryGetValue(tpl.Value, out var details);
details.PresetIds.Add(presetId);
if (preset.Encyclopedia is not null)
{
@@ -1326,12 +1326,12 @@ public class RagfairController
/// Get prices for all items on flea
/// </summary>
/// <returns>Dictionary of tpl and item price</returns>
public Dictionary<string, double> GetAllFleaPrices()
public Dictionary<MongoId, double> GetAllFleaPrices()
{
return _ragfairPriceService.GetAllFleaPrices();
}
public Dictionary<string, double> GetStaticPrices()
public Dictionary<MongoId, double> GetStaticPrices()
{
return _ragfairPriceService.GetAllStaticPrices();
}
@@ -186,7 +186,8 @@ public class BotEquipmentModGenerator(
);
switch (plateSlotFilteringOutcome.Result)
{
case Result.UNKNOWN_FAILURE or Result.NO_DEFAULT_FILTER:
case Result.UNKNOWN_FAILURE
or Result.NO_DEFAULT_FILTER:
if (_logger.IsLogEnabled(LogLevel.Debug))
{
_logger.Debug(
@@ -207,7 +208,7 @@ public class BotEquipmentModGenerator(
}
// Choose random mod from pool and check its compatibility
string? modTpl = null;
MongoId? modTpl = null;
var found = false;
var exhaustableModPool = CreateExhaustableArray(modPoolToChooseFrom);
while (exhaustableModPool.HasValues())
@@ -216,7 +217,7 @@ public class BotEquipmentModGenerator(
if (
modTpl is not null
&& !_botGeneratorHelper
.IsItemIncompatibleWithCurrentItems(equipment, modTpl, modSlotName)
.IsItemIncompatibleWithCurrentItems(equipment, modTpl.Value, modSlotName)
.Incompatible.GetValueOrDefault(false)
)
{
@@ -244,7 +245,7 @@ public class BotEquipmentModGenerator(
}
// Get chosen mods db template and check it fits into slot
var modTemplate = _itemHelper.GetItem(modTpl);
var modTemplate = _itemHelper.GetItem(modTpl.Value);
if (
!IsModValidForSlot(
modTemplate,
@@ -855,7 +856,7 @@ public class BotEquipmentModGenerator(
/// <param name="modSlot">Slot to check</param>
/// <param name="tpl"></param>
/// <returns>true if it's a front/rear sight</returns>
public bool ModIsFrontOrRearSight(string modSlot, string tpl)
public bool ModIsFrontOrRearSight(string modSlot, MongoId tpl)
{
// Gas block /w front sight is special case, deem it a 'front sight' too
if (modSlot == "mod_gas_block" && tpl == "5ae30e795acfc408fb139a0b")
@@ -1705,7 +1706,7 @@ public class BotEquipmentModGenerator(
/// <param name="modSlot">Slot to get mod to fill</param>
/// <param name="items">Items to ensure picked mod is compatible with</param>
/// <returns>Item tpl</returns>
public string? GetRandomModTplFromItemDb(
public MongoId? GetRandomModTplFromItemDb(
string fallbackModTpl,
Slot parentSlot,
string modSlot,
@@ -474,7 +474,7 @@ public class BotGenerator(
/// <param name="botInventory">Bot to filter</param>
public void RemoveBlacklistedLootFromBotTemplate(BotTypeInventory botInventory)
{
var containersToProcess = new List<Dictionary<string, double>>
var containersToProcess = new List<Dictionary<MongoId, double>>
{
botInventory.Items.Backpack,
botInventory.Items.Pockets,
@@ -458,7 +458,7 @@ public class BotLootGenerator(
{
// surv12
AddLootFromPool(
new Dictionary<string, double> { { "5d02797c86f774203f38e30a", 1 } },
new Dictionary<MongoId, double> { { "5d02797c86f774203f38e30a", 1 } },
[EquipmentSlots.SecuredContainer],
1,
botInventory,
@@ -470,7 +470,7 @@ public class BotLootGenerator(
// AFAK
AddLootFromPool(
new Dictionary<string, double> { { "60098ad7c2240c0fe85c570a", 1 } },
new Dictionary<MongoId, double> { { "60098ad7c2240c0fe85c570a", 1 } },
[EquipmentSlots.SecuredContainer],
10,
botInventory,
@@ -494,7 +494,7 @@ public class BotLootGenerator(
/// <param name="totalValueLimitRub">Total value of loot allowed in roubles</param>
/// <param name="isPmc">Is bot being generated for a pmc</param>
protected void AddLootFromPool(
Dictionary<string, double> pool,
Dictionary<MongoId, double> pool,
HashSet<EquipmentSlots> equipmentSlots,
double totalItemCount,
BotBaseInventory inventoryToAddItemsTo,
@@ -545,7 +545,7 @@ public class BotWeaponGenerator(
GenerationData ubglMinMax = new()
{
Weights = new Dictionary<double, double> { { 1, 1 }, { 2, 1 } },
Whitelist = new Dictionary<string, double>(),
Whitelist = new Dictionary<MongoId, double>(),
};
// get ammo template from db
@@ -696,7 +696,7 @@ public class LocationLootGenerator(
/// <param name="containerTypeId">Container to get possible loot for</param>
/// <param name="staticLootDist">staticLoot.json</param>
/// <returns>ProbabilityObjectArray of item tpls + probability</returns>
protected ProbabilityObjectArray<string, float?> GetPossibleLootItemsForContainer(
protected ProbabilityObjectArray<MongoId, float?> GetPossibleLootItemsForContainer(
string containerTypeId,
Dictionary<string, StaticLootDetails> staticLootDist
)
@@ -704,7 +704,7 @@ public class LocationLootGenerator(
var seasonalEventActive = _seasonalEventService.SeasonalEventEnabled();
var seasonalItemTplBlacklist = _seasonalEventService.GetInactiveSeasonalEventItems();
var itemDistribution = new ProbabilityObjectArray<string, float?>(_cloner);
var itemDistribution = new ProbabilityObjectArray<MongoId, float?>(_cloner);
var itemContainerDistribution = staticLootDist[containerTypeId]?.ItemDistribution;
if (itemContainerDistribution is null)
@@ -734,7 +734,7 @@ public class LocationLootGenerator(
}
itemDistribution.Add(
new ProbabilityObject<string, float?>(icd.Tpl, icd.RelativeProbability.Value, null)
new ProbabilityObject<MongoId, float?>(icd.Tpl, icd.RelativeProbability.Value, null)
);
}
@@ -25,9 +25,9 @@ public class PMCLootGenerator(
private readonly PmcConfig _pmcConfig = configServer.GetConfig<PmcConfig>();
// Store loot against its type, usec/bear
private readonly Dictionary<string, Dictionary<string, double>>? _backpackLootPool = [];
private readonly Dictionary<string, Dictionary<string, double>>? _pocketLootPool = [];
private readonly Dictionary<string, Dictionary<string, double>>? _vestLootPool = [];
private readonly Dictionary<string, Dictionary<MongoId, double>>? _backpackLootPool = [];
private readonly Dictionary<string, Dictionary<MongoId, double>>? _pocketLootPool = [];
private readonly Dictionary<string, Dictionary<MongoId, double>>? _vestLootPool = [];
protected readonly Lock BackpackLock = new();
protected readonly Lock PocketLock = new();
@@ -38,7 +38,7 @@ public class PMCLootGenerator(
/// </summary>
/// <param name="pmcRole">Role of PMC having loot generated (bear or usec)</param>
/// <returns>Dictionary of string and number</returns>
public Dictionary<string, double> GeneratePMCPocketLootPool(string pmcRole)
public Dictionary<MongoId, double> GeneratePMCPocketLootPool(string pmcRole)
{
lock (PocketLock)
{
@@ -72,7 +72,7 @@ public class PMCLootGenerator(
/// </summary>
/// <param name="pmcRole">Role of PMC having loot generated (bear or usec)</param>
/// <returns>Dictionary item template ids and a weighted chance of being picked</returns>
public Dictionary<string, double> GeneratePMCVestLootPool(string pmcRole)
public Dictionary<MongoId, double> GeneratePMCVestLootPool(string pmcRole)
{
lock (VestLock)
{
@@ -107,7 +107,7 @@ public class PMCLootGenerator(
/// </summary>
/// <param name="pmcRole">Role of PMC having loot generated (bear or usec)</param>
/// <returns>Dictionary of string and number</returns>
public Dictionary<string, double> GeneratePMCBackpackLootPool(string pmcRole)
public Dictionary<MongoId, double> GeneratePMCBackpackLootPool(string pmcRole)
{
lock (BackpackLock)
{
@@ -137,14 +137,14 @@ public class PMCLootGenerator(
/// <param name="itemTplAndParentBlacklist">Item and parent blacklist</param>
/// <param name="genericItemCheck">An optional delegate to validate the TemplateItem object being processed</param>
/// <returns>Dictionary of items and weights inversely tied to the items price</returns>
protected Dictionary<string, double> GenerateLootPool(
protected Dictionary<MongoId, double> GenerateLootPool(
string pmcRole,
HashSet<MongoId> allowedItemTypeWhitelist,
HashSet<MongoId> itemTplAndParentBlacklist,
Func<TemplateItem, bool>? genericItemCheck
)
{
var lootPool = new Dictionary<string, double>();
var lootPool = new Dictionary<MongoId, double>();
var items = databaseService.GetItems();
// Grab price overrides if they exist for the pmcRole passed in
@@ -207,7 +207,7 @@ public class PMCLootGenerator(
/// </summary>
/// <param name="pmcRole">role of PMC to look up</param>
/// <returns>Dictionary of overrides</returns>
protected Dictionary<string, double>? GetPMCPriceOverrides(string pmcRole)
protected Dictionary<MongoId, double>? GetPMCPriceOverrides(string pmcRole)
{
var pmcType = string.Equals(pmcRole, "pmcbear", StringComparison.OrdinalIgnoreCase)
? "bear"
@@ -229,7 +229,10 @@ public class PMCLootGenerator(
/// <param name="tpl">Item tpl to get price of</param>
/// <param name="pmcPriceOverrides"></param>
/// <returns>Rouble price</returns>
protected double GetItemPrice(string tpl, Dictionary<string, double>? pmcPriceOverrides = null)
protected double GetItemPrice(
MongoId tpl,
Dictionary<MongoId, double>? pmcPriceOverrides = null
)
{
if (
pmcPriceOverrides is not null
@@ -132,7 +132,7 @@ public class RagfairAssortGenerator(
/// <param name="tplId"> tplid to add to item </param>
/// <param name="id"> id to add to item </param>
/// <returns> Hydrated Item object </returns>
protected Item CreateRagfairAssortRootItem(string tplId, MongoId? id = null)
protected Item CreateRagfairAssortRootItem(MongoId tplId, MongoId? id = null)
{
if (string.IsNullOrEmpty(id))
{
@@ -786,7 +786,7 @@ public class RagfairOfferGenerator(
/// </summary>
/// <param name="tpl"> Item to look for matching condition object</param>
/// <returns> Condition ID </returns>
protected string? GetDynamicConditionIdForTpl(string tpl)
protected string? GetDynamicConditionIdForTpl(MongoId tpl)
{
// Get keys from condition config dictionary
var configConditions = ragfairConfig.Dynamic.Condition.Keys;
@@ -656,7 +656,7 @@ public class RepeatableQuestRewardGenerator(
/// <param name="foundInRaid"> If generated Item is found in raid, default True </param>
/// <returns> Object of "Reward"-item-type </returns>
protected Reward GeneratePresetReward(
string tpl,
MongoId tpl,
int count,
int index,
List<Item>? preset,
@@ -386,7 +386,7 @@ public class BotGeneratorHelper(
/// <returns>false if no incompatibilities, also has incompatibility reason</returns>
public ChooseRandomCompatibleModResult IsItemIncompatibleWithCurrentItems(
List<Item> itemsEquipped,
string tplToCheck,
MongoId tplToCheck,
string equipmentSlot
)
{
@@ -817,7 +817,7 @@ public class BotGeneratorHelper(
/// <param name="slotGrid">Items sub-grid we want to place item inside</param>
/// <param name="itemTpl">Item tpl being placed</param>
/// <returns>True if allowed</returns>
protected bool ItemAllowedInContainer(Grid? slotGrid, string? itemTpl)
protected bool ItemAllowedInContainer(Grid? slotGrid, MongoId itemTpl)
{
var propFilters = slotGrid?.Props?.Filters;
var excludedFilter = propFilters?.FirstOrDefault()?.ExcludedFilter ?? [];
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Models.Spt.Config;
@@ -88,7 +89,7 @@ public class HandbookHelper(
/// </summary>
/// <param name="tpl">Item tpl to look up price for</param>
/// <returns>price in roubles</returns>
public double GetTemplatePrice(string tpl)
public double GetTemplatePrice(MongoId tpl)
{
if (HandbookPriceCache.Items.ById.TryGetValue(tpl, out var itemPrice))
{
@@ -211,11 +212,11 @@ public class HandbookHelper(
{
public LookupItem()
{
ById = new Dictionary<string, T>();
ById = new Dictionary<MongoId, T>();
ByParent = new Dictionary<string, List<I>>();
}
public Dictionary<string, T> ById { get; set; }
public Dictionary<MongoId, T> ById { get; set; }
public Dictionary<string, List<I>> ByParent { get; set; }
}
@@ -57,7 +57,7 @@ public class ItemHelper(
nameof(EquipmentSlots.Scabbard),
];
protected static readonly FrozenSet<string> _dogTagTpls =
protected static readonly FrozenSet<MongoId> _dogTagTpls =
[
ItemTpl.BARTER_DOGTAG_BEAR,
ItemTpl.BARTER_DOGTAG_BEAR_EOD,
@@ -111,7 +111,7 @@ public class ItemHelper(
/// <param name="itemTpl">Item to look for</param>
/// <param name="slotId">OPTIONAL - slotId of desired item</param>
/// <returns>True if pool contains item</returns>
public bool HasItemWithTpl(IEnumerable<Item> itemPool, string itemTpl, string slotId = "")
public bool HasItemWithTpl(IEnumerable<Item> itemPool, MongoId itemTpl, string slotId = "")
{
// Filter the pool by slotId if provided
var filteredPool = string.IsNullOrEmpty(slotId)
@@ -442,7 +442,7 @@ public class ItemHelper(
/// </summary>
/// <param name="tpl">Item to look price up of</param>
/// <returns>Price in roubles</returns>
public double? GetItemPrice(string tpl)
public double? GetItemPrice(MongoId tpl)
{
var handbookPrice = GetStaticItemPrice(tpl);
if (handbookPrice >= 1)
@@ -459,7 +459,7 @@ public class ItemHelper(
/// </summary>
/// <param name="tpl">Item to look price up of</param>
/// <returns>Price in roubles</returns>
public double GetItemMaxPrice(string tpl)
public double GetItemMaxPrice(MongoId tpl)
{
var staticPrice = GetStaticItemPrice(tpl);
var dynamicPrice = GetDynamicItemPrice(tpl);
@@ -472,7 +472,7 @@ public class ItemHelper(
/// </summary>
/// <param name="tpl">Items tpl id to look up price</param>
/// <returns>Price in roubles (0 if not found)</returns>
public double GetStaticItemPrice(string tpl)
public double GetStaticItemPrice(MongoId tpl)
{
var handbookPrice = _handbookHelper.GetTemplatePrice(tpl);
if (handbookPrice >= 1)
@@ -488,7 +488,7 @@ public class ItemHelper(
/// </summary>
/// <param name="tpl">Items tpl id to look up price</param>
/// <returns>Price in roubles (undefined if not found)</returns>
public double? GetDynamicItemPrice(string tpl)
public double? GetDynamicItemPrice(MongoId tpl)
{
if (_databaseService.GetPrices().TryGetValue(tpl, out var price))
{
@@ -543,7 +543,7 @@ public class ItemHelper(
/// </summary>
/// <param name="itemTpl">Id of the item to check</param>
/// <returns>true if the item is in the database</returns>
public bool IsItemInDb(string itemTpl)
public bool IsItemInDb(MongoId itemTpl)
{
return _databaseService.GetItems().ContainsKey(itemTpl);
}
@@ -748,7 +748,7 @@ public class ItemHelper(
/// </summary>
/// <param name="tpl">Template id to check.</param>
/// <returns>True if it is a dogtag.</returns>
public bool IsDogtag(string tpl)
public bool IsDogtag(MongoId tpl)
{
return _dogTagTpls.Contains(tpl);
}
@@ -758,7 +758,7 @@ public class ItemHelper(
/// </summary>
/// <param name="tpl">Item to check.</param>
/// <returns>True if it can be stacked.</returns>
public bool? IsItemTplStackable(string tpl)
public bool? IsItemTplStackable(MongoId tpl)
{
if (!_databaseService.GetItems().TryGetValue(tpl, out var item))
{
@@ -1178,7 +1178,7 @@ public class ItemHelper(
/// <param name="tpl">Items tpl to check parents of</param>
/// <param name="tplsToCheck">Tpl values to check if parents of item match</param>
/// <returns>bool Match found</returns>
public bool DoesItemOrParentsIdMatch(string tpl, List<string> tplsToCheck)
public bool DoesItemOrParentsIdMatch(MongoId tpl, List<MongoId> tplsToCheck)
{
var itemDetails = GetItem(tpl);
var itemExists = itemDetails.Key;
@@ -2007,7 +2007,7 @@ public class ItemHelper(
// Return all tpls from Money enum
// Returns string tpls
public List<string> GetMoneyTpls()
public List<MongoId> GetMoneyTpls()
{
return [Money.ROUBLES, Money.DOLLARS, Money.EUROS, Money.GP];
}
@@ -2026,7 +2026,7 @@ public class ItemHelper(
);
}
public string? GetItemBaseType(string tpl, bool rootOnly = true)
public string? GetItemBaseType(MongoId tpl, bool rootOnly = true)
{
var result = GetItem(tpl);
if (!result.Key)
@@ -17,9 +17,9 @@ public class PresetHelper(DatabaseService _databaseService, ItemHelper _itemHelp
/// <summary>
/// Preset cache - key = item tpl, value = preset ids
/// </summary>
protected Dictionary<string, PresetCacheDetails> _lookup = new();
protected Dictionary<MongoId, PresetCacheDetails> _lookup = new();
public void HydratePresetStore(Dictionary<string, PresetCacheDetails> input)
public void HydratePresetStore(Dictionary<MongoId, PresetCacheDetails> input)
{
_lookup = input;
}
@@ -113,7 +113,7 @@ public class PresetHelper(DatabaseService _databaseService, ItemHelper _itemHelp
* @param baseClass The BaseClasses enum to check against
* @returns True if the preset is of the given base class, false otherwise
*/
public bool IsPresetBaseClass(string id, string baseClass)
public bool IsPresetBaseClass(string id, MongoId baseClass)
{
return IsPreset(id) && _itemHelper.IsOfBaseclass(GetPreset(id).Encyclopedia, baseClass);
}
@@ -123,7 +123,7 @@ public class PresetHelper(DatabaseService _databaseService, ItemHelper _itemHelp
/// </summary>
/// <param name="templateId">Tpl id to check</param>
/// <returns>True if preset exists for tpl</returns>
public bool HasPreset(string templateId)
public bool HasPreset(MongoId templateId)
{
return _lookup.ContainsKey(templateId);
}
@@ -169,7 +169,7 @@ public class PresetHelper(DatabaseService _databaseService, ItemHelper _itemHelp
/// </summary>
/// <param name="templateId">Items tpl to get preset for</param>
/// <returns>null if no default preset, otherwise Preset</returns>
public Preset? GetDefaultPreset(string templateId)
public Preset? GetDefaultPreset(MongoId templateId)
{
// look in main cache for presets for this tpl
if (!_lookup.TryGetValue(templateId, out var presetDetails))
@@ -202,7 +202,7 @@ public class PresetHelper(DatabaseService _databaseService, ItemHelper _itemHelp
/// </summary>
/// <param name="presetId">Preset id to look up</param>
/// <returns>tpl mongoid</returns>
public string GetBaseItemTpl(string presetId)
public MongoId GetBaseItemTpl(MongoId presetId)
{
if (!_databaseService.GetGlobals().ItemPresets.TryGetValue(presetId, out var preset))
{
@@ -225,7 +225,7 @@ public class PresetHelper(DatabaseService _databaseService, ItemHelper _itemHelp
/// </summary>
/// <param name="tpl">The item template to get the price of</param>
/// <returns>The price of the given item preset, or base item if no preset exists</returns>
public double GetDefaultPresetOrItemPrice(string tpl)
public double GetDefaultPresetOrItemPrice(MongoId tpl)
{
// Get default preset if it exists
var defaultPreset = GetDefaultPreset(tpl);
@@ -1,5 +1,6 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Models.Spt.Config;
@@ -145,7 +146,7 @@ public class RagfairServerHelper(
);
}
public int CalculateDynamicStackCount(string tplId, bool isPreset)
public int CalculateDynamicStackCount(MongoId tplId, bool isPreset)
{
var config = ragfairConfig.Dynamic;
@@ -526,7 +526,7 @@ public class TraderHelper(
/// </summary>
/// <param name="tpl">Item to look up highest price for</param>
/// <returns>highest rouble cost for item</returns>
public double GetHighestTraderPriceRouble(string tpl)
public double GetHighestTraderPriceRouble(MongoId tpl)
{
if (_highestTraderPriceItems is not null)
{
@@ -580,7 +580,7 @@ public class TraderHelper(
/// </summary>
/// <param name="tpl">Item to look up best trader sell-to price</param>
/// <returns>Rouble price</returns>
public double GetHighestSellToTraderPrice(string tpl)
public double GetHighestSellToTraderPrice(MongoId tpl)
{
// Find largest trader price for item
var highestPrice = 1d; // Default price
@@ -1,4 +1,5 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Spt.Helper;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Services;
@@ -111,7 +112,7 @@ public class WeightedRandomHelper(
/// Find the greated common divisor of all weights and use it on the passed in dictionary
/// </summary>
/// <param name="weightedDict">Values to reduce</param>
public void ReduceWeightValues(IDictionary<string, double> weightedDict)
public void ReduceWeightValues(IDictionary<MongoId, double> weightedDict)
{
// No values, nothing to reduce
if (weightedDict.Count == 0)
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Utils.Json;
namespace SPTarkov.Server.Core.Models.Eft.Common;
@@ -147,7 +148,7 @@ public record StaticForced
public string ContainerId { get; set; }
[JsonPropertyName("itemTpl")]
public string ItemTpl { get; set; }
public MongoId ItemTpl { get; set; }
}
public record StaticContainerData
@@ -358,7 +358,7 @@ public record GenerationData
/// </summary>
[JsonPropertyName("whitelist")]
[JsonConverter(typeof(ArrayToObjectFactoryConverter))]
public Dictionary<string, double>? Whitelist { get; set; }
public Dictionary<MongoId, double>? Whitelist { get; set; }
}
public record GenerationWeightingItems
@@ -496,15 +496,15 @@ public record ItemPools
[JsonExtensionData]
public Dictionary<string, object>? ExtensionData { get; set; }
public Dictionary<string, double>? Backpack { get; set; }
public Dictionary<MongoId, double>? Backpack { get; set; }
public Dictionary<string, double>? Pockets { get; set; }
public Dictionary<MongoId, double>? Pockets { get; set; }
public Dictionary<string, double>? SecuredContainer { get; set; }
public Dictionary<MongoId, double>? SecuredContainer { get; set; }
public Dictionary<string, double>? SpecialLoot { get; set; }
public Dictionary<MongoId, double>? SpecialLoot { get; set; }
public Dictionary<string, double>? TacticalVest { get; set; }
public Dictionary<MongoId, double>? TacticalVest { get; set; }
}
public record BotDbSkills
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Utils.Json.Converters;
@@ -14,7 +15,7 @@ public record Reward
public double? Value { get; set; }
[JsonPropertyName("id")]
public string? Id { get; set; }
public MongoId Id { get; set; }
[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter))]
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using SPTarkov.Server.Core.Models.Common;
namespace SPTarkov.Server.Core.Models.Eft.Game;
@@ -11,7 +12,7 @@ public record GetItemPricesResponse
public double? SupplyNextTime { get; set; }
[JsonPropertyName("prices")]
public Dictionary<string, double>? Prices { get; set; }
public Dictionary<MongoId, double>? Prices { get; set; }
[JsonPropertyName("currencyCourses")]
public Dictionary<string, double>? CurrencyCourses { get; set; }
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Utils;
namespace SPTarkov.Server.Core.Models.Eft.Ragfair;
@@ -9,5 +10,5 @@ public record GetMarketPriceRequestData : IRequestData
public Dictionary<string, object>? ExtensionData { get; set; }
[JsonPropertyName("templateId")]
public string? TemplateId { get; set; }
public MongoId TemplateId { get; set; }
}
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using SPTarkov.Server.Core.Models.Common;
namespace SPTarkov.Server.Core.Models.Spt.Bots;
@@ -8,43 +9,43 @@ public record BotLootCache
public Dictionary<string, object>? ExtensionData { get; set; }
[JsonPropertyName("backpackLoot")]
public Dictionary<string, double> BackpackLoot { get; set; } = [];
public Dictionary<MongoId, double> BackpackLoot { get; set; } = [];
[JsonPropertyName("pocketLoot")]
public Dictionary<string, double> PocketLoot { get; set; } = [];
public Dictionary<MongoId, double> PocketLoot { get; set; } = [];
[JsonPropertyName("vestLoot")]
public Dictionary<string, double> VestLoot { get; set; } = [];
public Dictionary<MongoId, double> VestLoot { get; set; } = [];
[JsonPropertyName("secureLoot")]
public Dictionary<string, double> SecureLoot { get; set; } = [];
public Dictionary<MongoId, double> SecureLoot { get; set; } = [];
[JsonPropertyName("combinedPoolLoot")]
public Dictionary<string, double> CombinedPoolLoot { get; set; } = [];
public Dictionary<MongoId, double> CombinedPoolLoot { get; set; } = [];
[JsonPropertyName("specialItems")]
public Dictionary<string, double> SpecialItems { get; set; } = [];
public Dictionary<MongoId, double> SpecialItems { get; set; } = [];
[JsonPropertyName("healingItems")]
public Dictionary<string, double> HealingItems { get; set; } = [];
public Dictionary<MongoId, double> HealingItems { get; set; } = [];
[JsonPropertyName("drugItems")]
public Dictionary<string, double> DrugItems { get; set; } = [];
public Dictionary<MongoId, double> DrugItems { get; set; } = [];
[JsonPropertyName("foodItems")]
public Dictionary<string, double> FoodItems { get; set; } = [];
public Dictionary<MongoId, double> FoodItems { get; set; } = [];
[JsonPropertyName("drinkItems")]
public Dictionary<string, double> DrinkItems { get; set; } = [];
public Dictionary<MongoId, double> DrinkItems { get; set; } = [];
[JsonPropertyName("currencyItems")]
public Dictionary<string, double> CurrencyItems { get; set; } = [];
public Dictionary<MongoId, double> CurrencyItems { get; set; } = [];
[JsonPropertyName("stimItems")]
public Dictionary<string, double> StimItems { get; set; } = [];
public Dictionary<MongoId, double> StimItems { get; set; } = [];
[JsonPropertyName("grenadeItems")]
public Dictionary<string, double> GrenadeItems { get; set; } = [];
public Dictionary<MongoId, double> GrenadeItems { get; set; } = [];
}
public record LootCacheType
@@ -44,7 +44,7 @@ public record Templates
/// Flea prices of items - gathered from online flea market dump
/// </summary>
[JsonPropertyName("prices")]
public Dictionary<string, double>? Prices { get; set; }
public Dictionary<MongoId, double>? Prices { get; set; }
/// <summary>
/// Default equipment loadouts that show on main inventory screen
@@ -135,7 +135,7 @@ public class BotEquipmentModPoolService(
return pool;
}
private bool SetContainsTpl(HashSet<MongoId> itemSet, string tpl)
private bool SetContainsTpl(HashSet<MongoId> itemSet, MongoId tpl)
{
lock (_lockObject)
{
@@ -143,7 +143,7 @@ public class BotEquipmentModPoolService(
}
}
private bool AddTplToSet(HashSet<MongoId> itemSet, string itemToAddTpl)
private bool AddTplToSet(HashSet<MongoId> itemSet, MongoId itemToAddTpl)
{
lock (_lockObject)
{
@@ -48,7 +48,7 @@ public class BotLootCacheService(
/// <param name="itemPriceMinMax">OPTIONAL - item price min and max value filter</param>
/// <remarks>THIS IS NOT A THREAD SAFE METHOD</remarks>
/// <returns>dictionary</returns>
public Dictionary<string, double> GetLootFromCache(
public Dictionary<MongoId, double> GetLootFromCache(
string botRole,
bool isPmc,
string lootType,
@@ -68,7 +68,7 @@ public class BotLootCacheService(
return [];
}
Dictionary<string, double> result;
Dictionary<MongoId, double> result;
switch (lootType)
{
case LootCacheType.Special:
@@ -175,12 +175,12 @@ public class BotLootCacheService(
var lootPool = botJsonTemplate.BotInventory.Items;
// Flatten all individual slot loot pools into one big pool, while filtering out potentially missing templates
Dictionary<string, double> specialLootPool = new();
Dictionary<string, double> backpackLootPool = new();
Dictionary<string, double> pocketLootPool = new();
Dictionary<string, double> vestLootPool = new();
Dictionary<string, double> secureLootPool = new();
Dictionary<string, double> combinedLootPool = new();
Dictionary<MongoId, double> specialLootPool = new();
Dictionary<MongoId, double> backpackLootPool = new();
Dictionary<MongoId, double> pocketLootPool = new();
Dictionary<MongoId, double> vestLootPool = new();
Dictionary<MongoId, double> secureLootPool = new();
Dictionary<MongoId, double> combinedLootPool = new();
if (isPmc)
{
@@ -195,7 +195,7 @@ public class BotLootCacheService(
}
// Backpack/Pockets etc
var poolsToProcess = new Dictionary<string, Dictionary<string, double>>
var poolsToProcess = new Dictionary<string, Dictionary<MongoId, double>>
{
{ "Backpack", lootPool.Backpack },
{ "Pockets", lootPool.Pockets },
@@ -420,7 +420,7 @@ public class BotLootCacheService(
); // lacks width
// Get vest loot (excluding magazines, bullets, grenades, medical and healing/stim items)
var filteredVestItems = new Dictionary<string, double>();
var filteredVestItems = new Dictionary<MongoId, double>();
foreach (var itemKvP in vestLootPool)
{
var itemResult = _itemHelper.GetItem(itemKvP.Key);
@@ -480,12 +480,12 @@ public class BotLootCacheService(
/// <param name="lootPool">Pool to filter</param>
/// <param name="shouldBeSkipped">Delegate to filter pool by</param>
/// <returns></returns>
protected Dictionary<string, double> FilterItemPool(
Dictionary<string, double> lootPool,
protected Dictionary<MongoId, double> FilterItemPool(
Dictionary<MongoId, double> lootPool,
Func<TemplateItem, bool> shouldBeSkipped
)
{
var filteredItems = new Dictionary<string, double>();
var filteredItems = new Dictionary<MongoId, double>();
foreach (var (itemTpl, itemWeight) in lootPool)
{
var (isValidItem, itemTemplate) = _itemHelper.GetItem(itemTpl);
@@ -511,9 +511,9 @@ public class BotLootCacheService(
/// <param name="weights">Weights to return</param>
/// <returns>Dictionary and should pool be hydrated by items in combined loot pool</returns>
protected static (
Dictionary<string, double>,
Dictionary<MongoId, double>,
bool populateFromCombinedPool
) GetGenerationWeights(Dictionary<string, double>? weights)
) GetGenerationWeights(Dictionary<MongoId, double>? weights)
{
var result = weights ?? [];
return (result, !result.Any()); // empty dict = should be populated from combined pool
@@ -526,8 +526,8 @@ public class BotLootCacheService(
/// <param name="poolToAddTo">Dictionary to add item to</param>
/// <param name="poolOfItemsToAdd">Dictionary of items to add</param>
protected void AddItemsToPool(
Dictionary<string, double> poolToAddTo,
Dictionary<string, double> poolOfItemsToAdd
Dictionary<MongoId, double> poolToAddTo,
Dictionary<MongoId, double> poolOfItemsToAdd
)
{
foreach (var (tpl, weight) in poolOfItemsToAdd)
@@ -577,17 +577,17 @@ public class BotLootCacheService(
return props.ThrowType is not null;
}
protected bool IsFood(string tpl)
protected bool IsFood(MongoId tpl)
{
return _itemHelper.IsOfBaseclass(tpl, BaseClasses.FOOD);
}
protected bool IsDrink(string tpl)
protected bool IsDrink(MongoId tpl)
{
return _itemHelper.IsOfBaseclass(tpl, BaseClasses.DRINK);
}
protected bool IsCurrency(string tpl)
protected bool IsCurrency(MongoId tpl)
{
return _itemHelper.IsOfBaseclass(tpl, BaseClasses.MONEY);
}
@@ -280,7 +280,7 @@ public class DatabaseService(
}
/// <returns> assets/database/templates/prices.json </returns>
public Dictionary<string, double> GetPrices()
public Dictionary<MongoId, double> GetPrices()
{
if (_databaseServer.GetTables().Templates?.Prices == null)
{
@@ -1012,7 +1012,7 @@ public class FenceService(
return ItemInPreventDupeCategoryList(itemDbDetails.Id);
}
protected bool ItemInPreventDupeCategoryList(string tpl)
protected bool ItemInPreventDupeCategoryList(MongoId tpl)
{
// Item type in config list
return itemHelper.IsOfBaseclasses(tpl, traderConfig.Fence.PreventDuplicateOffersOfCategory);
@@ -27,7 +27,7 @@ public class ItemFilterService(
/// </summary>
/// <param name="tpl"> Template id</param>
/// <returns> True if blacklisted </returns>
public bool ItemBlacklisted(string tpl)
public bool ItemBlacklisted(MongoId tpl)
{
if (_itemBlacklistCache.Count == 0)
{
@@ -42,7 +42,7 @@ public class ItemFilterService(
/// </summary>
/// <param name="tpl"> Item tpl to check is on blacklist </param>
/// <returns> True when blacklisted </returns>
public bool ItemRewardBlacklisted(string tpl)
public bool ItemRewardBlacklisted(MongoId tpl)
{
return _itemConfig.RewardItemBlacklist.Contains(tpl);
}
@@ -88,7 +88,7 @@ public class ItemFilterService(
/// </summary>
/// <param name="tpl"> template id </param>
/// <returns> True if boss item </returns>
public bool BossItem(string tpl)
public bool BossItem(MongoId tpl)
{
return _itemConfig.BossItems.Contains(tpl);
}
@@ -107,7 +107,7 @@ public class ItemFilterService(
/// </summary>
/// <param name="itemKey"> Template id</param>
/// <returns> True if blacklisted </returns>
public bool IsLootableItemBlacklisted(string itemKey)
public bool IsLootableItemBlacklisted(MongoId itemKey)
{
if (!_lootableItemBlacklistCache.Any())
{
@@ -117,7 +117,7 @@ public class ItemFilterService(
return _lootableItemBlacklistCache.Contains(itemKey);
}
public bool IsItemBlacklisted(string tpl)
public bool IsItemBlacklisted(MongoId tpl)
{
if (!_itemBlacklistCache.Any())
{
@@ -148,7 +148,7 @@ public class ItemFilterService(
/// </summary>
/// <param name="tpl"> Template id</param>
/// <returns> True if boss item </returns>
public bool IsBossItem(string tpl)
public bool IsBossItem(MongoId tpl)
{
return _itemConfig.BossItems.Contains(tpl);
}
@@ -158,7 +158,7 @@ public class ItemFilterService(
/// </summary>
/// <param name="tpl"> Item tpl to check is on blacklist </param>
/// <returns> true when blacklisted </returns>
public bool IsItemRewardBlacklisted(string tpl)
public bool IsItemRewardBlacklisted(MongoId tpl)
{
return _itemConfig.RewardItemBlacklist.Contains(tpl);
}
@@ -42,12 +42,12 @@ public class RagfairOfferService(
return ragfairOfferHolder.GetOffers();
}
public RagfairOffer? GetOfferByOfferId(string offerId)
public RagfairOffer? GetOfferByOfferId(MongoId offerId)
{
return ragfairOfferHolder.GetOfferById(offerId);
}
public List<RagfairOffer>? GetOffersOfType(string templateId)
public List<RagfairOffer>? GetOffersOfType(MongoId templateId)
{
return ragfairOfferHolder.GetOffersByTemplate(templateId);
}
@@ -29,7 +29,7 @@ public class RagfairPriceService(
)
{
private readonly RagfairConfig _ragfairConfig = _configServer.GetConfig<RagfairConfig>();
protected Dictionary<string, double>? _staticPrices;
protected Dictionary<MongoId, double>? _staticPrices;
/// <summary>
/// Generate static (handbook) and dynamic (prices.json) flea prices, store inside class as dictionaries
@@ -50,7 +50,7 @@ public class RagfairPriceService(
/// </summary>
public void RefreshStaticPrices()
{
_staticPrices = new Dictionary<string, double>();
_staticPrices = new Dictionary<MongoId, double>();
foreach (
var item in _databaseService
.GetItems()
@@ -77,9 +77,9 @@ public class RagfairPriceService(
/// </summary>
/// <param name="tplId">Item tpl id to get price for</param>
/// <returns>price in roubles</returns>
public double GetFleaPriceForItem(string tplId)
public double GetFleaPriceForItem(MongoId tplId)
{
// Get dynamic price (templates/prices), if that doesnt exist get price from static array (templates/handbook)
// Get dynamic price (templates/prices), if that doesn't exist get price from static array (templates/handbook)
var itemPrice = _itemHelper.GetDynamicItemPrice(tplId) ?? GetStaticPriceForItem(tplId);
if (itemPrice is null)
{
@@ -122,7 +122,7 @@ public class RagfairPriceService(
/// </summary>
/// <param name="itemTpl"> Item template id to look up </param>
/// <returns> Price in roubles </returns>
public double? GetDynamicPriceForItem(string itemTpl)
public double? GetDynamicPriceForItem(MongoId itemTpl)
{
_databaseService.GetPrices().TryGetValue(itemTpl, out var value);
@@ -134,7 +134,7 @@ public class RagfairPriceService(
/// </summary>
/// <param name="itemTpl">item template id to look up</param>
/// <returns>price in roubles</returns>
public double? GetStaticPriceForItem(string itemTpl)
public double? GetStaticPriceForItem(MongoId itemTpl)
{
return _handbookHelper.GetTemplatePrice(itemTpl);
}
@@ -144,7 +144,7 @@ public class RagfairPriceService(
/// This will refresh the caches prior to building the output
/// </summary>
/// <returns>Dictionary of item tpls and rouble cost</returns>
public Dictionary<string, double> GetAllFleaPrices()
public Dictionary<MongoId, double> GetAllFleaPrices()
{
var dynamicPrices = _databaseService.GetPrices();
// Use dynamic prices first, fill in any gaps with data from static prices (handbook)
@@ -154,7 +154,7 @@ public class RagfairPriceService(
.ToDictionary(x => x.Key, x => x.First().Value);
}
public Dictionary<string, double> GetAllStaticPrices()
public Dictionary<MongoId, double> GetAllStaticPrices()
{
// Refresh the cache so we include any newly added custom items
if (_staticPrices is null)
@@ -251,10 +251,10 @@ public class RagfairPriceService(
/// <param name="isPackOffer"></param>
/// <returns></returns>
public double? GetDynamicItemPrice(
string itemTemplateId,
MongoId itemTemplateId,
string desiredCurrency,
Item item = null,
List<Item> offerItems = null,
Item? item = null,
List<Item>? offerItems = null,
bool? isPackOffer = null
)
{
@@ -1,6 +1,7 @@
using System.Collections.Concurrent;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
namespace SPTarkov.Server.Core.Services;
@@ -13,14 +14,14 @@ public class RagfairRequiredItemsService(
/// <summary>
/// Key = tpl
/// </summary>
protected readonly ConcurrentDictionary<string, HashSet<string>> _requiredItemsCache = new();
protected readonly ConcurrentDictionary<MongoId, HashSet<MongoId>> _requiredItemsCache = new();
/// <summary>
/// Get the offerId of offers that require the supplied tpl
/// </summary>
/// <param name="tpl">Tpl to find offers ids for</param>
/// <returns></returns>
public HashSet<string> GetRequiredOffersById(string tpl)
public HashSet<MongoId> GetRequiredOffersById(MongoId tpl)
{
if (_requiredItemsCache.TryGetValue(tpl, out var offerIds))
{
@@ -392,7 +392,7 @@ public class SeasonalEventService(
StringComparison.OrdinalIgnoreCase
)
);
var prop = (Dictionary<string, double>?)propInfo.GetValue(botInventory.Items);
var prop = (Dictionary<MongoId, double>?)propInfo.GetValue(botInventory.Items);
if (prop is null)
{
@@ -27,17 +27,17 @@ public class RagfairOfferHolder(
/// <summary>
/// Ragfair offer cache, keyed by offer Id
/// </summary>
private readonly ConcurrentDictionary<string, RagfairOffer> _offersById = new();
private readonly ConcurrentDictionary<MongoId, RagfairOffer> _offersById = new();
/// <summary>
/// Offer Ids keyed by tpl
/// </summary>
private readonly ConcurrentDictionary<string, HashSet<string>> _offersByTemplate = new();
private readonly ConcurrentDictionary<MongoId, HashSet<string>> _offersByTemplate = new();
/// <summary>
/// Offer ids keyed by trader Id
/// </summary>
private readonly ConcurrentDictionary<string, HashSet<string>> _offersByTrader = new();
private readonly ConcurrentDictionary<MongoId, HashSet<string>> _offersByTrader = new();
private readonly Lock _expiredOfferIdsLock = new();
private readonly Lock _ragfairOperationLock = new();
@@ -47,7 +47,7 @@ public class RagfairOfferHolder(
/// </summary>
/// <param name="id">Ragfair offer id</param>
/// <returns>RagfairOffer</returns>
public RagfairOffer? GetOfferById(string id)
public RagfairOffer? GetOfferById(MongoId id)
{
return _offersById.GetValueOrDefault(id);
}