From 242e51b746c97761237e82062e7e89286aa2cba3 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 25 Jan 2025 21:43:59 +0000 Subject: [PATCH] Improved typing --- .../Generators/BotEquipmentModGenerator.cs | 30 +++++++++---------- Libraries/Core/Models/Spt/Config/BotConfig.cs | 4 ++- Libraries/SptAssets/Assets/configs/bot.json | 25 +++++++++++----- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/Libraries/Core/Generators/BotEquipmentModGenerator.cs b/Libraries/Core/Generators/BotEquipmentModGenerator.cs index fc6a45fc..01675e69 100644 --- a/Libraries/Core/Generators/BotEquipmentModGenerator.cs +++ b/Libraries/Core/Generators/BotEquipmentModGenerator.cs @@ -240,7 +240,7 @@ public class BotEquipmentModGenerator( } // Get the front/back/side weights based on bots level - var plateSlotWeights = settings.BotEquipmentConfig?.ArmorPlateWeighting?.FirstOrDefault( + var plateSlotWeights = settings.BotEquipmentConfig?.ArmorPlateWeighting.FirstOrDefault( (armorWeight) => settings.BotData.Level >= armorWeight.LevelRange.Min && settings.BotData.Level <= armorWeight.LevelRange.Max @@ -256,7 +256,7 @@ public class BotEquipmentModGenerator( } // Get the specific plate slot weights (front/back/side) - var plateWeights = plateSlotWeights[modSlot]; + var plateWeights = plateSlotWeights.Values[modSlot]; if (plateWeights is null) { // No weights, return original array of plate tpls @@ -270,15 +270,15 @@ public class BotEquipmentModGenerator( var chosenArmorPlateLevel = _weightedRandomHelper.GetWeightedValue(plateWeights); // Convert the array of ids into database items - var platesFromDb = existingPlateTplPool.Select((plateTpl) => _itemHelper.GetItem(plateTpl)[1]); + var platesFromDb = existingPlateTplPool.Select((plateTpl) => _itemHelper.GetItem(plateTpl).Value); // Filter plates to the chosen level based on its armorClass property - var platesOfDesiredLevel = platesFromDb.Filter((item) => item._props.armorClass == chosenArmorPlateLevel); - if (platesOfDesiredLevel.length > 0) + var platesOfDesiredLevel = platesFromDb.Where((item) => item.Properties.ArmorClass == chosenArmorPlateLevel); + if (platesOfDesiredLevel.Count() > 0) { // Plates found result.Result = Result.SUCCESS; - result.PlateModTemplates = platesOfDesiredLevel.map((item) => item._id); + result.PlateModTemplates = platesOfDesiredLevel.Select((item) => item.Id); return result; } @@ -286,26 +286,26 @@ public class BotEquipmentModGenerator( // no plates found that fit requirements, lets get creative // Get lowest and highest plate classes available for this armor - const minMaxArmorPlateClass = this.getMinMaxArmorPlateClass(platesFromDb); + var minMaxArmorPlateClass = GetMinMaxArmorPlateClass(platesFromDb); // Increment plate class level in attempt to get useable plate - let findCompatiblePlateAttempts = 0; - const maxAttempts = 3; - for (let i = 0; i < maxAttempts; i++) + var findCompatiblePlateAttempts = 0; + var maxAttempts = 3; + for (var i = 0; i < maxAttempts; i++) { - chosenArmorPlateLevel = (Number.parseInt(chosenArmorPlateLevel) + 1).toString(); + chosenArmorPlateLevel = (int.Parse(chosenArmorPlateLevel)) + 1).ToString(); // New chosen plate class is higher than max, then set to min and check if valid - if (Number(chosenArmorPlateLevel) > minMaxArmorPlateClass.max) + if (chosenArmorPlateLevel > minMaxArmorPlateClass.max) { chosenArmorPlateLevel = minMaxArmorPlateClass.min.toString(); } findCompatiblePlateAttempts++; - platesOfDesiredLevel = platesFromDb.filter((item) => item._props.armorClass == = chosenArmorPlateLevel); + platesOfDesiredLevel = platesFromDb.Where((item) => item.Properties.ArmorClass == chosenArmorPlateLevel); // Valid plates found, exit - if (platesOfDesiredLevel.length > 0) + if (platesOfDesiredLevel.Count() > 0) { break; } @@ -313,7 +313,7 @@ public class BotEquipmentModGenerator( // No valid plate class found in 3 tries, attempt default plates if (findCompatiblePlateAttempts >= maxAttempts) { - this.logger.debug( + _logger.Debug( $"Plate filter too restrictive for armor: ${{ armorItem._name}} ${{ armorItem._id}}, unable to find plates of level: ${{ chosenArmorPlateLevel}}, using items default plate" ); diff --git a/Libraries/Core/Models/Spt/Config/BotConfig.cs b/Libraries/Core/Models/Spt/Config/BotConfig.cs index 6e66a316..a3726a7e 100644 --- a/Libraries/Core/Models/Spt/Config/BotConfig.cs +++ b/Libraries/Core/Models/Spt/Config/BotConfig.cs @@ -524,10 +524,12 @@ public record AdjustmentDetails public Dictionary> Edit { get; set; } } -public class ArmorPlateWeights : Dictionary +public class ArmorPlateWeights { [JsonPropertyName("levelRange")] public MinMax LevelRange { get; set; } + + public Dictionary> Values { get; set; } } public record RandomisedResourceDetails diff --git a/Libraries/SptAssets/Assets/configs/bot.json b/Libraries/SptAssets/Assets/configs/bot.json index 72ae77e3..f021e3b5 100644 --- a/Libraries/SptAssets/Assets/configs/bot.json +++ b/Libraries/SptAssets/Assets/configs/bot.json @@ -345,7 +345,6 @@ "minLimitPercent": 15 } } - } }, "lootItemResourceRandomization": { "assault": { @@ -2324,7 +2323,8 @@ "min": 1, "max": 10 }, - "front_plate": { + "values": { + "front_plate": { "2": 25, "3": 20, "4": 5, @@ -2359,6 +2359,7 @@ "5": 1, "6": 1 } + } }, { "levelRange": { @@ -2406,7 +2407,8 @@ "min": 15, "max": 24 }, - "front_plate": { + "values": { + "front_plate": { "2": 10, "3": 15, "4": 24, @@ -2441,13 +2443,15 @@ "5": 5, "6": 4 } + } }, { "levelRange": { "min": 25, "max": 35 }, - "front_plate": { + "values": { + "front_plate": { "2": 2, "3": 10, "4": 35, @@ -2482,13 +2486,16 @@ "5": 15, "6": 5 } + } + }, { "levelRange": { "min": 36, "max": 55 }, - "front_plate": { + "values": { + "front_plate": { "2": 0, "3": 4, "4": 32, @@ -2522,14 +2529,16 @@ "4": 32, "5": 50, "6": 20 - } + }} + }, { "levelRange": { "min": 56, "max": 90 }, - "front_plate": { + "values": { + "front_plate": { "2": 0, "3": 0, "4": 10, @@ -2564,6 +2573,8 @@ "5": 40, "6": 50 } + } + } ], "whitelist": [