Replaced various instances of dictionaries and hashsets with their frozen counterparts

This commit is contained in:
Chomp
2025-03-09 17:12:07 +00:00
parent 3c83018513
commit df8ffa2b16
12 changed files with 37 additions and 25 deletions
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
@@ -40,10 +41,10 @@ public class BotEquipmentModGenerator(
)
{
protected BotConfig _botConfig = _configServer.GetConfig<BotConfig>();
protected static readonly HashSet<string> _modSightIds = ["mod_sight_front", "mod_sight_rear"];
protected static readonly FrozenSet<string> _modSightIds = ["mod_sight_front", "mod_sight_rear"];
// Slots that hold scopes
protected static readonly HashSet<string> _scopeIds =
protected static readonly FrozenSet<string> _scopeIds =
[
"mod_scope",
"mod_mount",
@@ -55,13 +56,13 @@ public class BotEquipmentModGenerator(
];
// Slots that hold muzzles
protected static readonly HashSet<string> _muzzleIds = ["mod_muzzle", "mod_muzzle_000", "mod_muzzle_001"];
protected static readonly FrozenSet<string> _muzzleIds = ["mod_muzzle", "mod_muzzle_000", "mod_muzzle_001"];
// Slots a weapon can store its stock in
protected static readonly HashSet<string> _stockSlots = ["mod_stock", "mod_stock_000", "mod_stock_001", "mod_stock_akms"];
protected static readonly FrozenSet<string> _stockSlots = ["mod_stock", "mod_stock_000", "mod_stock_001", "mod_stock_akms"];
// Slots that hold cartridges
protected static readonly HashSet<string> _cartridgeHolderSlots =
protected static readonly FrozenSet<string> _cartridgeHolderSlots =
[
"mod_magazine",
"patron_in_weapon",
@@ -1487,7 +1488,7 @@ public class BotEquipmentModGenerator(
/// e.g. mod_magazine / patron_in_weapon_000
/// </summary>
/// <returns>string array</returns>
public HashSet<string> GetAmmoContainers()
public FrozenSet<string> GetAmmoContainers()
{
return _cartridgeHolderSlots;
}
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using SPTarkov.Server.Core.Context;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
@@ -39,7 +40,7 @@ public class BotInventoryGenerator(
private readonly BotConfig _botConfig = _configServer.GetConfig<BotConfig>();
// Slots handled individually inside `GenerateAndAddEquipmentToBot`
private static readonly HashSet<EquipmentSlots> _excludedEquipmentSlots =
private static readonly FrozenSet<EquipmentSlots> _excludedEquipmentSlots =
[
EquipmentSlots.Pockets,
EquipmentSlots.FirstPrimaryWeapon,
@@ -10,6 +10,7 @@ using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using SPTarkov.Common.Annotations;
using LogLevel = SPTarkov.Server.Core.Models.Spt.Logging.LogLevel;
using System.Collections.Frozen;
namespace SPTarkov.Server.Core.Helpers;
@@ -30,7 +31,7 @@ public class BotGeneratorHelper(
protected PmcConfig _pmcConfig = _configServer.GetConfig<PmcConfig>();
// Equipment slot ids that do not conflict with other slots
protected static readonly HashSet<string> _slotsWithNoCompatIssues = ["Scabbard", "Backpack", "SecureContainer", "Holster", "ArmBand"];
protected static readonly FrozenSet<string> _slotsWithNoCompatIssues = ["Scabbard", "Backpack", "SecureContainer", "Holster", "ArmBand"];
/// <summary>
/// Adds properties to an item
@@ -5,6 +5,7 @@ using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using SPTarkov.Common.Annotations;
using System.Collections.Frozen;
namespace SPTarkov.Server.Core.Helpers;
@@ -18,7 +19,7 @@ public class BotHelper(
{
protected BotConfig _botConfig = _configServer.GetConfig<BotConfig>();
protected PmcConfig _pmcConfig = _configServer.GetConfig<PmcConfig>();
protected static readonly HashSet<string?> _pmcTypeIds = ["usec", "bear", "pmc", "pmcbear", "pmcusec"];
protected static readonly FrozenSet<string> _pmcTypeIds = ["usec", "bear", "pmc", "pmcbear", "pmcusec"];
protected Dictionary<string, List<string>> _pmcNameCache = new();
/// <summary>
@@ -5,6 +5,7 @@ using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using SPTarkov.Common.Annotations;
using System.Collections.Frozen;
namespace SPTarkov.Server.Core.Helpers;
@@ -20,7 +21,7 @@ public class BotWeaponGeneratorHelper(
LocalisationService _localisationService
)
{
private static readonly HashSet<string> _magCheck = ["CylinderMagazine", "SpringDrivenCylinder"];
private static readonly FrozenSet<string> _magCheck = ["CylinderMagazine", "SpringDrivenCylinder"];
/// <summary>
/// Get a randomized number of bullets for a specific magazine
@@ -9,6 +9,7 @@ using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using SPTarkov.Server.Core.Utils.Cloners;
using SPTarkov.Common.Annotations;
using System.Collections.Frozen;
namespace SPTarkov.Server.Core.Helpers.Dialogue.Commando.SptCommands.GiveCommand;
@@ -29,7 +30,7 @@ public class GiveSptCommand(
private static readonly Regex _commandRegex = new(@"^spt give (((([a-z]{2,5}) )?""(.+)""|\w+) )?([0-9]+)$");
// Exception for flares
protected static readonly HashSet<string> _excludedPresetItems =
protected static readonly FrozenSet<string> _excludedPresetItems =
[
ItemTpl.FLARE_RSP30_REACTIVE_SIGNAL_CARTRIDGE_RED,
ItemTpl.FLARE_RSP30_REACTIVE_SIGNAL_CARTRIDGE_GREEN,
@@ -4,6 +4,7 @@ using SPTarkov.Server.Core.Models.Eft.Profile;
using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using SPTarkov.Common.Annotations;
using System.Collections.Frozen;
namespace SPTarkov.Server.Core.Helpers.Dialogue.SPTFriend.Commands;
@@ -12,7 +13,7 @@ public class HelloMessageHandler(
MailSendService _mailSendService,
RandomUtil _randomUtil) : IChatMessageHandler
{
protected static readonly HashSet<string> _listOfGreetings = ["hello", "hi", "sup", "yo", "hey", "bonjour"];
protected static readonly FrozenSet<string> _listOfGreetings = ["hello", "hi", "sup", "yo", "hey", "bonjour"];
public int GetPriority()
@@ -16,6 +16,7 @@ using SPTarkov.Server.Core.Utils.Cloners;
using SPTarkov.Common.Annotations;
using SPTarkov.Common.Extensions;
using LogLevel = SPTarkov.Server.Core.Models.Spt.Logging.LogLevel;
using System.Collections.Frozen;
namespace SPTarkov.Server.Core.Helpers;
@@ -36,7 +37,7 @@ public class InventoryHelper(
)
{
protected InventoryConfig _inventoryConfig = _configServer.GetConfig<InventoryConfig>();
private static readonly HashSet<string> _variableSizeItemTypes = [BaseClasses.WEAPON, BaseClasses.FUNCTIONAL_MOD];
private static readonly FrozenSet<string> _variableSizeItemTypes = [BaseClasses.WEAPON, BaseClasses.FUNCTIONAL_MOD];
/// <summary>
/// Add multiple items to player stash (assuming they all fit)
@@ -9,6 +9,7 @@ using SPTarkov.Server.Core.Utils.Cloners;
using SPTarkov.Server.Core.Utils.Collections;
using SPTarkov.Common.Annotations;
using LogLevel = SPTarkov.Server.Core.Models.Spt.Logging.LogLevel;
using System.Collections.Frozen;
namespace SPTarkov.Server.Core.Helpers;
@@ -27,7 +28,7 @@ public class ItemHelper(
ICloner _cloner
)
{
protected static readonly HashSet<string> _defaultInvalidBaseTypes =
protected static readonly FrozenSet<string> _defaultInvalidBaseTypes =
[
BaseClasses.LOOT_CONTAINER,
BaseClasses.MOB_CONTAINER,
@@ -38,7 +39,7 @@ public class ItemHelper(
BaseClasses.POCKETS
];
protected static readonly HashSet<string> _slotsAsStrings =
protected static readonly FrozenSet<string> _slotsAsStrings =
[
EquipmentSlots.Headwear.ToString(),
EquipmentSlots.Earpiece.ToString(),
@@ -56,7 +57,7 @@ public class ItemHelper(
EquipmentSlots.Scabbard.ToString()
];
protected static readonly HashSet<string> _dogTagTpls =
protected static readonly FrozenSet<string> _dogTagTpls =
[
ItemTpl.BARTER_DOGTAG_BEAR,
ItemTpl.BARTER_DOGTAG_BEAR_EOD,
@@ -70,7 +71,7 @@ public class ItemHelper(
ItemTpl.BARTER_DOGTAG_USEC_PRESTIGE_2
];
protected static readonly HashSet<string> _softInsertIds =
protected static readonly FrozenSet<string> _softInsertIds =
[
"groin",
"groin_back",
@@ -88,7 +89,7 @@ public class ItemHelper(
"helmet_ears"
];
protected static readonly HashSet<string> _removablePlateSlotIds =
protected static readonly FrozenSet<string> _removablePlateSlotIds =
[
"front_plate",
"back_plate",
@@ -451,7 +452,7 @@ public class ItemHelper(
// Get all soft insert slot ids
// @returns A List of soft insert ids (e.g. soft_armor_back, helmet_top)
public HashSet<string> GetSoftInsertSlotIds()
public FrozenSet<string> GetSoftInsertSlotIds()
{
return _softInsertIds;
}
@@ -1980,7 +1981,7 @@ public class ItemHelper(
// Get a list of slot names that hold removable plates
// Returns Array of slot ids (e.g. front_plate)
public HashSet<string> GetRemovablePlateSlotIds()
public FrozenSet<string> GetRemovablePlateSlotIds()
{
return _removablePlateSlotIds;
}
@@ -10,6 +10,7 @@ using SPTarkov.Server.Core.Utils;
using SPTarkov.Server.Core.Utils.Cloners;
using SPTarkov.Common.Annotations;
using LogLevel = SPTarkov.Server.Core.Models.Spt.Logging.LogLevel;
using System.Collections.Frozen;
namespace SPTarkov.Server.Core.Helpers;
@@ -27,7 +28,7 @@ public class ProfileHelper(
ConfigServer _configServer
)
{
protected static readonly HashSet<string> gameEditionsWithFreeRefresh = ["edge_of_darkness", "unheard_edition"];
protected static readonly FrozenSet<string> gameEditionsWithFreeRefresh = ["edge_of_darkness", "unheard_edition"];
protected InventoryConfig _inventoryConfig = _configServer.GetConfig<InventoryConfig>();
/// <summary>
@@ -12,6 +12,7 @@ using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using SPTarkov.Common.Annotations;
using SPTarkov.Common.Extensions;
using System.Collections.Frozen;
namespace SPTarkov.Server.Core.Helpers;
@@ -43,7 +44,7 @@ public class RagfairOfferHelper(
protected BotConfig _botConfig = _configServer.GetConfig<BotConfig>();
protected RagfairConfig _ragfairConfig = _configServer.GetConfig<RagfairConfig>();
protected static readonly HashSet<string> _currencies = ["all", "RUB", "USD", "EUR"];
protected static readonly FrozenSet<string> _currencies = ["all", "RUB", "USD", "EUR"];
/// <summary>
/// Passthrough to ragfairOfferService.getOffers(), get flea offers a player should see
@@ -1,3 +1,4 @@
using System.Collections.Frozen;
using System.Text.Json.Serialization;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
@@ -7,7 +8,7 @@ public record Locations
{
// sometimes we get the key or value given so save changing logic in each place
// have it key both
private static readonly Dictionary<string, string> _locationMappings = new()
private readonly FrozenDictionary<string, string> _locationMappings = new Dictionary<string, string>
{
// EFT
{ "factory4_day", "Factory4Day" },
@@ -48,7 +49,7 @@ public record Locations
{ "Woods", "Woods" },
{ "Sandbox", "Sandbox" },
{ "SandboxHigh", "SandboxHigh" }
};
}.ToFrozenDictionary();
private Dictionary<string, Eft.Common.Location>? _locationDictionaryCache;
@@ -209,7 +210,7 @@ public record Locations
/// <returns></returns>
public string GetMappedKey(string key)
{
return _locationMappings.TryGetValue(key, out var value) ? value : key;
return _locationMappings.GetValueOrDefault(key, key);
}
private void HydrateDictionary()