diff --git a/Libraries/SPTarkov.Server.Core/Controllers/CustomizationController.cs b/Libraries/SPTarkov.Server.Core/Controllers/CustomizationController.cs index 71bf1447..85bcbfff 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/CustomizationController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/CustomizationController.cs @@ -40,13 +40,11 @@ public class CustomizationController( var clothing = databaseService.GetCustomization(); var suits = databaseService.GetTrader(traderId).Suits; - var matchingSuits = suits?.Where(s => clothing.ContainsKey(s.SuiteId)).ToList(); - matchingSuits = matchingSuits - ?.Where(s => - clothing[s.SuiteId]?.Properties?.Side?.Contains(pmcData?.Info?.Side ?? string.Empty) - ?? false - ) - .ToList(); + var matchingSuits = suits?.Where(s => clothing.ContainsKey(s.SuiteId)); + matchingSuits = matchingSuits?.Where(s => + clothing[s.SuiteId]?.Properties?.Side?.Contains(pmcData?.Info?.Side ?? string.Empty) + ?? false + ); if (matchingSuits == null) { @@ -58,7 +56,7 @@ public class CustomizationController( ); } - return matchingSuits; + return matchingSuits.ToList(); } /// diff --git a/Libraries/SPTarkov.Server.Core/Extensions/FullProfileExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/FullProfileExtensions.cs index 4aec8c59..aa6569bc 100644 --- a/Libraries/SPTarkov.Server.Core/Extensions/FullProfileExtensions.cs +++ b/Libraries/SPTarkov.Server.Core/Extensions/FullProfileExtensions.cs @@ -12,7 +12,10 @@ namespace SPTarkov.Server.Core.Extensions /// /// Profile to add clothing to /// Clothing Ids to add to profile - public static void AddSuitsToProfile(this SptProfile fullProfile, List clothingIds) + public static void AddSuitsToProfile( + this SptProfile fullProfile, + IEnumerable clothingIds + ) { fullProfile.CustomisationUnlocks ??= []; diff --git a/Libraries/SPTarkov.Server.Core/Extensions/ItemExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/ItemExtensions.cs index 26743cb5..ec03e463 100644 --- a/Libraries/SPTarkov.Server.Core/Extensions/ItemExtensions.cs +++ b/Libraries/SPTarkov.Server.Core/Extensions/ItemExtensions.cs @@ -234,7 +234,7 @@ namespace SPTarkov.Server.Core.Extensions /// Gets the identifier for a child using slotId, locationX and locationY. /// /// Item. - /// SlotId OR slotid, locationX, locationY. + /// SlotId OR slotId, locationX, locationY. public static string GetChildId(this Item item) { if (item.Location is null) @@ -365,7 +365,7 @@ namespace SPTarkov.Server.Core.Extensions /// /// Inventory items to look for secure container in /// List of ids - public static List GetSecureContainerItems(this List items) + public static List GetSecureContainerItems(this IEnumerable items) { var secureContainer = items.First(x => x.SlotId == "SecuredContainer"); @@ -417,7 +417,7 @@ namespace SPTarkov.Server.Core.Extensions /// Optional: new id to use /// New root id public static MongoId RemapRootItemId( - this List itemWithChildren, + this IEnumerable itemWithChildren, MongoId? newId = null ) { @@ -450,7 +450,7 @@ namespace SPTarkov.Server.Core.Extensions /// /// Items to hash /// InventoryItemHash - public static InventoryItemHash GetInventoryItemHash(this List inventoryItems) + public static InventoryItemHash GetInventoryItemHash(this IEnumerable inventoryItems) { // Group by parentId + turn value into mongoId as we've filtered out non-mongoId values var byParentId = inventoryItems diff --git a/Libraries/SPTarkov.Server.Core/Extensions/LootContainerSettingsExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/LootContainerSettingsExtensions.cs index a6037e33..4b5c9693 100644 --- a/Libraries/SPTarkov.Server.Core/Extensions/LootContainerSettingsExtensions.cs +++ b/Libraries/SPTarkov.Server.Core/Extensions/LootContainerSettingsExtensions.cs @@ -44,7 +44,7 @@ namespace SPTarkov.Server.Core.Extensions /// rouble amount private static double GetContainerRoubleTotalByLevel( int botLevel, - List containerLootValuesPool + IEnumerable containerLootValuesPool ) { var matchingValue = containerLootValuesPool.FirstOrDefault(minMaxValue => diff --git a/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs index 3fcb7a5e..80e5f40f 100644 --- a/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs +++ b/Libraries/SPTarkov.Server.Core/Extensions/ProfileExtensions.cs @@ -12,7 +12,7 @@ namespace SPTarkov.Server.Core.Extensions /// /// Profile to get quest items from /// List of item objects - public static List GetQuestItemsInProfile(this PmcData profile) + public static IEnumerable GetQuestItemsInProfile(this PmcData profile) { return profile ?.Inventory?.Items.Where(i => i.ParentId == profile.Inventory.QuestRaidItems) diff --git a/Libraries/SPTarkov.Server.Core/Extensions/QuestConditionExtensions.cs b/Libraries/SPTarkov.Server.Core/Extensions/QuestConditionExtensions.cs index 2edfa902..9d2a3a5e 100644 --- a/Libraries/SPTarkov.Server.Core/Extensions/QuestConditionExtensions.cs +++ b/Libraries/SPTarkov.Server.Core/Extensions/QuestConditionExtensions.cs @@ -11,7 +11,7 @@ namespace SPTarkov.Server.Core.Extensions /// OPTIONAL - Additional filter code to run /// public static List GetQuestConditions( - this List questConditions, + this IEnumerable questConditions, Func>? furtherFilter = null ) { @@ -19,7 +19,7 @@ namespace SPTarkov.Server.Core.Extensions } public static List GetLevelConditions( - this List questConditions, + this IEnumerable questConditions, Func>? furtherFilter = null ) { @@ -27,7 +27,7 @@ namespace SPTarkov.Server.Core.Extensions } public static List GetLoyaltyConditions( - this List questConditions, + this IEnumerable questConditions, Func>? furtherFilter = null ) { @@ -35,7 +35,7 @@ namespace SPTarkov.Server.Core.Extensions } public static List GetStandingConditions( - this List questConditions, + this IEnumerable questConditions, Func>? furtherFilter = null ) { @@ -43,7 +43,7 @@ namespace SPTarkov.Server.Core.Extensions } private static List FilterConditions( - List questConditions, + IEnumerable questConditions, string questType, Func>? furtherFilter = null ) diff --git a/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs index e385137b..4103e0a8 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs @@ -631,9 +631,9 @@ public class BotGenerator( /// /// Body parts /// Part with the lowest hp - protected BodyPart? GetLowestHpBodyPart(List bodyParts) + protected BodyPart? GetLowestHpBodyPart(IEnumerable bodyParts) { - if (bodyParts.Count == 0) + if (!bodyParts.Any()) { return null; } diff --git a/Libraries/SPTarkov.Server.Core/Generators/BotInventoryGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/BotInventoryGenerator.cs index a7f4acb7..908b6d99 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/BotInventoryGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/BotInventoryGenerator.cs @@ -732,7 +732,7 @@ public class BotInventoryGenerator( /// /// Chances bot has certain equipment /// What slots bot should have weapons generated for - public List GetDesiredWeaponsForBot(Chances equipmentChances) + public IEnumerable GetDesiredWeaponsForBot(Chances equipmentChances) { var shouldSpawnPrimary = randomUtil.GetChance100( equipmentChances.EquipmentChances["FirstPrimaryWeapon"] diff --git a/Libraries/SPTarkov.Server.Core/Generators/BotLootGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/BotLootGenerator.cs index 5d268182..c9d267c2 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/BotLootGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/BotLootGenerator.cs @@ -667,7 +667,7 @@ public class BotLootGenerator( /// /// Wallet to add loot to /// Generated list of currency stacks with the wallet as their parent - public List> CreateWalletLoot(string walletId) + public List> CreateWalletLoot(MongoId walletId) { List> result = []; diff --git a/Libraries/SPTarkov.Server.Core/Generators/BotWeaponGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/BotWeaponGenerator.cs index 3a62c462..8093ee96 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/BotWeaponGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/BotWeaponGenerator.cs @@ -156,12 +156,13 @@ public class BotWeaponGenerator( // Create with just base weapon item var weaponWithModsArray = ConstructWeaponBaseList( - weaponTpl, - weaponParentId, - slotName, - weaponItemTemplate, - botRole - ); + weaponTpl, + weaponParentId, + slotName, + weaponItemTemplate, + botRole + ) + .ToList(); // Chance to add randomised weapon enhancement if (isPmc && randomUtil.GetChance100(_pmcConfig.WeaponHasEnhancementChancePercent)) @@ -276,7 +277,7 @@ public class BotWeaponGenerator( protected void AddCartridgeToChamber( List weaponWithModsList, MongoId ammoTemplate, - List chamberSlotIds + IEnumerable chamberSlotIds ) { foreach (var slotId in chamberSlotIds) @@ -315,7 +316,7 @@ public class BotWeaponGenerator( /// Database template for weapon /// For durability values /// Base weapon item in a list - protected List ConstructWeaponBaseList( + protected IEnumerable ConstructWeaponBaseList( MongoId weaponTemplate, string weaponParentId, string equipmentSlot, @@ -405,7 +406,7 @@ public class BotWeaponGenerator( /// Weapon + mods /// Role of bot weapon is for /// True if valid - protected bool IsWeaponValid(List weaponItemList, string botRole) + protected bool IsWeaponValid(IEnumerable weaponItemList, string botRole) { foreach (var mod in weaponItemList) { @@ -878,12 +879,12 @@ public class BotWeaponGenerator( } // Magazine, usually - var parentItem = itemHelper.GetItem(magazineTemplate.Parent).Value; + var parentDbItem = itemHelper.GetItem(magazineTemplate.Parent).Value; // Revolver shotgun (MTs-255-12) uses a magazine with chambers, not cartridges ("camora_xxx") // Exchange of the camora ammo is not necessary we could also just check for stackSize > 0 here // and remove the else - if (botWeaponGeneratorHelper.MagazineIsCylinderRelated(parentItem.Name)) + if (botWeaponGeneratorHelper.MagazineIsCylinderRelated(parentDbItem.Name)) { FillCamorasWithAmmo(weaponMods, magazine.Id, cartridgeTemplate); } @@ -904,9 +905,9 @@ public class BotWeaponGenerator( /// Weapon with children. /// Underbarrrel grenade launcher item. /// Grenade ammo template. - protected void FillUbgl(List weaponMods, Item ubglMod, MongoId ubglAmmoTpl) + protected void FillUbgl(IEnumerable weaponMods, Item ubglMod, MongoId ubglAmmoTpl) { - weaponMods.Add( + weaponMods.Append( new Item { Id = new MongoId(), @@ -975,7 +976,11 @@ public class BotWeaponGenerator( /// Weapon mods to find and update camora mod(s) from /// Magazine id to find and add to /// Ammo template id to hydrate with - protected void FillCamorasWithAmmo(List weaponMods, MongoId magazineId, MongoId ammoTpl) + protected void FillCamorasWithAmmo( + IEnumerable weaponMods, + MongoId magazineId, + MongoId ammoTpl + ) { // for CylinderMagazine we exchange the ammo in the "camoras". // This might not be necessary since we already filled the camoras with a random whitelisted and compatible ammo type, diff --git a/Libraries/SPTarkov.Server.Core/Helpers/BotGeneratorHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/BotGeneratorHelper.cs index 375ac726..9a264c77 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/BotGeneratorHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/BotGeneratorHelper.cs @@ -318,7 +318,7 @@ public class BotGeneratorHelper( /// Slot the item will be placed into /// false if no incompatibilities, also has incompatibility reason public ChooseRandomCompatibleModResult IsItemIncompatibleWithCurrentItems( - List itemsEquipped, + IEnumerable itemsEquipped, MongoId tplToCheck, string equipmentSlot ) @@ -335,9 +335,10 @@ public class BotGeneratorHelper( } // TODO: Can probably be optimized to cache itemTemplates as items are added to inventory - var equippedItemsDb = itemsEquipped - .Select(equippedItem => itemHelper.GetItem(equippedItem.Template).Value) - .ToList(); + var equippedItemsDb = itemsEquipped.Select(equippedItem => + itemHelper.GetItem(equippedItem.Template).Value + ); + var (itemIsValid, itemToEquip) = itemHelper.GetItem(tplToCheck); if (!itemIsValid) @@ -380,7 +381,7 @@ public class BotGeneratorHelper( } // Does an equipped item have a property that blocks the desired item - check for prop "BlocksX" .e.g BlocksEarpiece / BlocksFaceCover - var templateItems = equippedItemsDb.ToList(); + var templateItems = equippedItemsDb; var blockingItem = templateItems.FirstOrDefault(item => HasBlockingProperty(item, equipmentSlot) ); @@ -542,7 +543,7 @@ public class BotGeneratorHelper( HashSet equipmentSlots, MongoId rootItemId, MongoId rootItemTplId, - List itemWithChildren, + IEnumerable itemWithChildren, BotBaseInventory inventory, HashSet? containersIdFull = null ) @@ -718,7 +719,7 @@ public class BotGeneratorHelper( /// protected List GetContainerItemsWithChildren( IEnumerable containerRootItems, - List inventoryItems + IEnumerable inventoryItems ) { var result = new List(); @@ -729,7 +730,7 @@ public class BotGeneratorHelper( } // Filter out all items without location prop, (child items) - var itemsWithoutLocation = inventoryItems.Where(item => item.Location is null).ToList(); + var itemsWithoutLocation = inventoryItems.Where(item => item.Location is null); foreach (var rootItem in containerRootItems) { // Check item in container for children, store for later insertion into `containerItemsToCheck` diff --git a/Libraries/SPTarkov.Server.Core/Helpers/InventoryHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/InventoryHelper.cs index 83938713..71cb0eb3 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/InventoryHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/InventoryHelper.cs @@ -172,7 +172,7 @@ public class InventoryHelper( /// /// An item /// Item was found in raid - protected void SetFindInRaidStatusForItem(List itemWithChildren, bool foundInRaid) + protected void SetFindInRaidStatusForItem(IEnumerable itemWithChildren, bool foundInRaid) { foreach (var item in itemWithChildren) { @@ -214,7 +214,10 @@ public class InventoryHelper( /// Player id /// Array of items with children to try and fit /// True all items fit - public bool CanPlaceItemsInInventory(MongoId sessionId, List> itemsWithChildren) + public bool CanPlaceItemsInInventory( + MongoId sessionId, + IEnumerable> itemsWithChildren + ) { var pmcData = profileHelper.GetPmcProfile(sessionId); @@ -238,7 +241,10 @@ public class InventoryHelper( /// Container grid to fit items into /// Items to try and fit into grid /// True all fit - public bool CanPlaceItemsInContainer(int[,] containerFS2D, List> itemsWithChildren) + public bool CanPlaceItemsInContainer( + int[,] containerFS2D, + IEnumerable> itemsWithChildren + ) { return itemsWithChildren.All(itemWithChildren => CanPlaceItemInContainer(containerFS2D, itemWithChildren) @@ -665,7 +671,7 @@ public class InventoryHelper( /// Items id to get size of /// /// [width, height] - public (int, int) GetItemSize(MongoId itemTpl, MongoId itemId, List inventoryItems) + public (int, int) GetItemSize(MongoId itemTpl, MongoId itemId, IEnumerable inventoryItems) { // -> Prepares item Width and height returns [sizeX, sizeY] return GetSizeByInventoryItemHash(itemTpl, itemId, inventoryItems.GetInventoryItemHash()); @@ -859,7 +865,7 @@ public class InventoryHelper( public int[,] GetContainerMap( int containerSizeHorizontalX, int containerSizeVerticalY, - List itemList, + IEnumerable itemList, MongoId containerId ) { @@ -1179,7 +1185,7 @@ public class InventoryHelper( /// True if move was successful public bool MoveItemInternal( PmcData pmcData, - List inventoryItems, + IEnumerable inventoryItems, InventoryMoveRequestData moveRequest, out string errorMessage ) @@ -1193,18 +1199,18 @@ public class InventoryHelper( ); if (matchingInventoryItem is null) { - var noMatchingItemMesage = + var noMatchingItemMessage = $"Unable to move item: {moveRequest.Item}, cannot find in inventory"; - logger.Error(noMatchingItemMesage); + logger.Error(noMatchingItemMessage); - errorMessage = noMatchingItemMesage; + errorMessage = noMatchingItemMessage; return false; } if (logger.IsLogEnabled(LogLevel.Debug)) { logger.Debug( - $"{moveRequest.Action} item: {moveRequest.Item} from slotid: {matchingInventoryItem.SlotId} to container: {moveRequest.To.Container}" + $"{moveRequest.Action} item: {moveRequest.Item} from slotId: {matchingInventoryItem.SlotId} to container: {moveRequest.To.Container}" ); } @@ -1291,7 +1297,7 @@ public class InventoryHelper( /// /// /// - protected void HandleCartridgeMove(List items, InventoryMoveRequestData request) + protected void HandleCartridgeMove(IEnumerable items, InventoryMoveRequestData request) { // Not moving item into a cartridge slot, skip if (request.To.Container != "cartridges") @@ -1326,7 +1332,7 @@ public class InventoryHelper( return _inventoryConfig; } - public void ValidateInventoryUsesMongoIds(List itemsToValidate) + public void ValidateInventoryUsesMongoIds(IEnumerable itemsToValidate) { var errors = itemsToValidate .Where(item => !item.Id.IsValidMongoId()) diff --git a/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs index c8245085..64f73bd4 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs @@ -566,13 +566,13 @@ public class ItemHelper( /// Skip over armor items without durability /// % quality modifier between 0 and 1 public double GetItemQualityModifierForItems( - List itemWithChildren, + IEnumerable itemWithChildren, bool skipArmorItemsWithoutDurability = false ) { - if (IsOfBaseclass(itemWithChildren[0].Template, BaseClasses.WEAPON)) + if (IsOfBaseclass(itemWithChildren.First().Template, BaseClasses.WEAPON)) { - return Math.Round(GetItemQualityModifier(itemWithChildren[0]), 5); + return Math.Round(GetItemQualityModifier(itemWithChildren.First()), 5); } var qualityModifier = 0D; @@ -1712,13 +1712,12 @@ public class ItemHelper( /// /// Item base type wanted /// Array of tpls - public List GetItemTplsOfBaseType(string desiredBaseType) + public IEnumerable GetItemTplsOfBaseType(string desiredBaseType) { return databaseService .GetItems() .Values.Where(item => item.Parent == desiredBaseType) - .Select(item => item.Id) - .ToList(); + .Select(item => item.Id); } /// diff --git a/Libraries/SPTarkov.Server.Core/Services/BotWeaponModLimitService.cs b/Libraries/SPTarkov.Server.Core/Services/BotWeaponModLimitService.cs index 50b63c01..80ce2054 100644 --- a/Libraries/SPTarkov.Server.Core/Services/BotWeaponModLimitService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/BotWeaponModLimitService.cs @@ -68,7 +68,7 @@ public class BotWeaponModLimitService( TemplateItem modTemplate, BotModLimits modLimits, TemplateItem modsParent, - List weapon + IEnumerable weapon ) { // If mod or mods parent is the NcSTAR MPR45 Backup mount, allow it as it looks cool @@ -115,11 +115,11 @@ public class BotWeaponModLimitService( ); } - // Don't allow multple mounts on a weapon (except when mount is on another mount) + // Don't allow multiple mounts on a weapon (except when mount is on another mount) // Fail when: // Over or at scope limit on weapon // Item being added is a mount but the parent item is NOT a mount (Allows red dot sub-mounts on mounts) - // Mount has one slot and its for a mod_scope + // Mount has one slot and it is for a mod_scope if ( modLimits.Scope.Count >= modLimits.ScopeMax && modTemplate.Properties.Slots?.Count == 1 diff --git a/Libraries/SPTarkov.Server.Core/Services/FenceService.cs b/Libraries/SPTarkov.Server.Core/Services/FenceService.cs index 88031874..e6b15920 100644 --- a/Libraries/SPTarkov.Server.Core/Services/FenceService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/FenceService.cs @@ -187,7 +187,7 @@ public class FenceService( /// The item tpl to calculate the fence price for /// The items (with its children) to calculate fence price for /// Price of the item for Fence - public double? GetItemPrice(MongoId itemTpl, List items) + public double? GetItemPrice(MongoId itemTpl, IEnumerable items) { return itemHelper.IsOfBaseclass(itemTpl, BaseClasses.AMMO_BOX) ? GetAmmoBoxPrice(items) * traderConfig.Fence.ItemPriceMult @@ -200,7 +200,7 @@ public class FenceService( /// /// The ammo box (and all its children ammo items) /// The price of the ammo box - protected double? GetAmmoBoxPrice(List items) + protected double? GetAmmoBoxPrice(IEnumerable items) { double? total = 0D; foreach (var item in items) @@ -478,7 +478,7 @@ public class FenceService( /// Base counts assorts should be adjusted to /// GenerationAssortValues object with adjustments needed to reach desired state protected GenerationAssortValues GetItemCountsToGenerate( - List assortItems, + IEnumerable assortItems, GenerationAssortValues generationValues ) { @@ -546,7 +546,7 @@ public class FenceService( /// /// Trader assort to remove item from /// Pool of root items to pick from to remove - protected void RemoveRandomItemFromAssorts(TraderAssort assort, List rootItems) + protected void RemoveRandomItemFromAssorts(TraderAssort assort, IEnumerable rootItems) { // Pick a random root item to remove from Fence var rootItemToAdjust = randomUtil.GetArrayValue(rootItems); @@ -923,7 +923,7 @@ public class FenceService( protected Item? GetMatchingItem( Item rootItemBeingAdded, TemplateItem itemDbDetails, - List> itemsWithChildren + IEnumerable> itemsWithChildren ) { // Get matching root items @@ -967,7 +967,7 @@ public class FenceService( && rootItemBeingAdded.Upd?.MedKit?.HpResource == item.Upd?.MedKit?.HpResource ) // e.g. bandages with multiple use - // Both undefined === both max resoruce left + // Both undefined === both max resource left { return item; } @@ -1243,7 +1243,7 @@ public class FenceService( /// /// Armor item array to add mods into /// Armor items db template - protected void RandomiseArmorModDurability(List armor, TemplateItem itemDbDetails) + protected void RandomiseArmorModDurability(IEnumerable armor, TemplateItem itemDbDetails) { // Armor has no mods, nothing to randomise if (itemDbDetails.Properties.Slots == null) @@ -1251,20 +1251,18 @@ public class FenceService( return; } - // Check for and adjust soft insert durability values - var requiredSlots = itemDbDetails - .Properties.Slots?.Where(slot => slot.Required ?? false) - .ToList(); - if ((requiredSlots?.Count ?? 0) > 1) + var requiredSlots = itemDbDetails.Properties.Slots?.Where(slot => slot.Required ?? false); + if (requiredSlots is not null && requiredSlots.Any()) { + // Has soft inserts, randomise RandomiseArmorSoftInsertDurabilities(requiredSlots, armor); } // Check for and adjust plate durability values - var plateSlots = itemDbDetails - .Properties.Slots?.Where(slot => itemHelper.IsRemovablePlateSlot(slot.Name)) - .ToList(); - if ((plateSlots?.Count ?? 0) > 1) + var plateSlots = itemDbDetails.Properties.Slots?.Where(slot => + itemHelper.IsRemovablePlateSlot(slot.Name) + ); + if (plateSlots is not null && plateSlots.Any()) { RandomiseArmorInsertsDurabilities(plateSlots, armor); } @@ -1276,8 +1274,8 @@ public class FenceService( /// Slots of items to randomise /// Array of armor + inserts to get items from protected void RandomiseArmorSoftInsertDurabilities( - List softInsertSlots, - List armorItemAndMods + IEnumerable softInsertSlots, + IEnumerable armorItemAndMods ) { foreach (var requiredSlot in softInsertSlots) @@ -1308,7 +1306,7 @@ public class FenceService( itemHelper.AddUpdObjectToItem(modItemToAdjust); - // Ensure property isn't null + // Fence assorts can be null, ensure they have defaults modItemToAdjust.Upd.Repairable ??= new UpdRepairable { Durability = modItemDbDetails.Properties.MaxDurability, @@ -1343,8 +1341,8 @@ public class FenceService( /// Slots of items to randomise /// Array of armor + inserts to get items from protected void RandomiseArmorInsertsDurabilities( - List plateSlots, - List armorItemAndMods + IEnumerable plateSlots, + IEnumerable armorItemAndMods ) { foreach (var plateSlot in plateSlots) @@ -1356,8 +1354,6 @@ public class FenceService( continue; } - var armorWithMods = armorItemAndMods; - var modItemDbDetails = itemHelper.GetItem(plateTpl.Value).Value; // Chance to remove plate @@ -1386,14 +1382,14 @@ public class FenceService( ); // Find items mod to apply durability changes to - var modItemToAdjust = armorWithMods.FirstOrDefault(mod => + var modItemToAdjust = armorItemAndMods.FirstOrDefault(mod => string.Equals(mod.SlotId, plateSlot.Name, StringComparison.OrdinalIgnoreCase) ); if (modItemToAdjust == null) { logger.Warning( - $"Unable to randomise armor items {armorWithMods[0].Template} {plateSlot.Name} slot as it cannot be found, skipping" + $"Unable to randomise armor items {armorItemAndMods.First().Template} {plateSlot.Name} slot as it cannot be found, skipping" ); continue; } diff --git a/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs b/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs index 20c4d59a..ae611951 100644 --- a/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs @@ -926,7 +926,7 @@ public class LocationLifecycleService( if (isDead) { - if (lostQuestItems.Count > 0) + if (lostQuestItems.Any()) // MUST occur AFTER quests have post raid quest data has been merged "processPostRaidQuests()" // Player is dead + had quest items, check and fix any broken find item quests { @@ -981,8 +981,8 @@ public class LocationLifecycleService( /// Quest status data from player profile protected void CheckForAndFixPickupQuestsAfterDeath( MongoId sessionId, - List lostQuestItems, - List profileQuests + IEnumerable lostQuestItems, + IEnumerable profileQuests ) { // Exclude completed quests diff --git a/Libraries/SPTarkov.Server.Core/Services/MailSendService.cs b/Libraries/SPTarkov.Server.Core/Services/MailSendService.cs index 513a0174..e78b29b8 100644 --- a/Libraries/SPTarkov.Server.Core/Services/MailSendService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/MailSendService.cs @@ -117,7 +117,7 @@ public class MailSendService( MongoId? trader, MessageType messageType, string messageLocaleId, - List? items, + IEnumerable? items, long? maxStorageTimeSeconds = 172800, SystemData? systemData = null, MessageContentRagfair? ragfair = null @@ -145,9 +145,8 @@ public class MailSendService( Items = [], }; - // add items to message - - if (items?.Count > 0) + // Add items to message + if (items is not null && items.Any()) { details.Items.AddRange(items); details.ItemsMaxStorageLifetimeSeconds =