Improved typing

This commit is contained in:
Chomp
2025-01-25 21:43:59 +00:00
parent 8de6a8be94
commit 242e51b746
3 changed files with 36 additions and 23 deletions
@@ -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<string>(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"
);
@@ -524,10 +524,12 @@ public record AdjustmentDetails
public Dictionary<string, Dictionary<string, float>> Edit { get; set; }
}
public class ArmorPlateWeights : Dictionary<string, object>
public class ArmorPlateWeights
{
[JsonPropertyName("levelRange")]
public MinMax LevelRange { get; set; }
public Dictionary<string, Dictionary<string, double>> Values { get; set; }
}
public record RandomisedResourceDetails
+18 -7
View File
@@ -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": [