diff --git a/Core/Generators/PlayerScavGenerator.cs b/Core/Generators/PlayerScavGenerator.cs index 9675b90e..ad0235ef 100644 --- a/Core/Generators/PlayerScavGenerator.cs +++ b/Core/Generators/PlayerScavGenerator.cs @@ -251,43 +251,44 @@ public class PlayerScavGenerator protected void AdjustBotTemplateWithKarmaSpecificSettings(KarmaLevel karmaSettings, BotType baseBotNode) { // Adjust equipment chance values - foreach (var equipment in karmaSettings.Modifiers.Equipment) - { - if (equipment.Value == 0) - continue; + foreach (var equipmentKvP in karmaSettings.Modifiers.Equipment) { - var prop = typeof(EquipmentChances).GetProperties().FirstOrDefault(p => p.Name == equipment.Key); - var value = (int)prop.GetValue(baseBotNode.BotChances.EquipmentChances); - var newValue = (int)value + karmaSettings.Modifiers.Equipment[equipment.Key]; - prop.SetValue(baseBotNode.BotChances.EquipmentChances, newValue); + // Adjustment value zero, nothing to do + if (equipmentKvP.Value == 0) + { + continue; + } + + // Try add new key with value + if (!baseBotNode.BotChances.EquipmentChances.TryAdd(equipmentKvP.Key, equipmentKvP.Value)) + { + // Unable to add new, update existing + baseBotNode.BotChances.EquipmentChances[equipmentKvP.Key] += equipmentKvP.Value; + } } // Adjust mod chance values - foreach (var mod in karmaSettings.Modifiers.Mod) + foreach (var modKvP in karmaSettings.Modifiers.Mod) { - if (mod.Value == 0) + // Adjustment value zero, nothing to do + if (modKvP.Value == 0) continue; - baseBotNode.BotChances.WeaponModsChances[mod.Key] += karmaSettings.Modifiers.Mod[mod.Key]; + baseBotNode.BotChances.WeaponModsChances[modKvP.Key] += karmaSettings.Modifiers.Mod[modKvP.Key]; } // Adjust item spawn quantity values - var props = karmaSettings.ItemLimits.GetType().GetProperties(); - var botGenProps = baseBotNode.BotGeneration.Items.GetType().GetProperties(); - foreach (var prop in props) + foreach (var itemLimitKvP in karmaSettings.ItemLimits) { - botGenProps.FirstOrDefault(p => p.Name == prop.Name).SetValue(baseBotNode.BotGeneration.Items, prop.GetValue(karmaSettings.ItemLimits)); + baseBotNode.BotGeneration.Items[itemLimitKvP.Key] = itemLimitKvP.Value; } - // Blacklist equipment - props = baseBotNode.BotInventory.Equipment.GetType().GetProperties(); - foreach (var equipment in karmaSettings.EquipmentBlacklist) - { - var blacklistedItemTpls = equipment.Value; - foreach (var itemToRemove in blacklistedItemTpls) + // Blacklist equipment, keyed by equipment slot + foreach (var equipmentBlacklistKvP in karmaSettings.EquipmentBlacklist) { + baseBotNode.BotInventory.Equipment.TryGetValue(equipmentBlacklistKvP.Key, out var equipmentDict); + foreach (var itemToRemove in equipmentBlacklistKvP.Value) { - var dict = (Dictionary?)props.FirstOrDefault(p => p.Name == equipment.Key).GetValue(baseBotNode.BotInventory.Equipment); - dict.Remove(itemToRemove); + equipmentDict.Remove(itemToRemove); } } } diff --git a/Core/Helpers/BotHelper.cs b/Core/Helpers/BotHelper.cs index e4f689ec..60cc7871 100644 --- a/Core/Helpers/BotHelper.cs +++ b/Core/Helpers/BotHelper.cs @@ -1,13 +1,25 @@ -using Core.Annotations; +using Core.Annotations; using Core.Models.Common; using Core.Models.Eft.Common.Tables; using Core.Models.Spt.Config; +using Core.Services; +using ILogger = Core.Models.Utils.ILogger; namespace Core.Helpers; [Injectable] public class BotHelper { + private readonly ILogger _logger; + private readonly DatabaseService _databaseService; + + public BotHelper( + ILogger logger, + DatabaseService databaseService) + { + _logger = logger; + _databaseService = databaseService; + } /// /// Get a template object for the specified botRole from bots.types db /// @@ -15,7 +27,14 @@ public class BotHelper /// BotType object public BotType GetBotTemplate(string role) { - throw new NotImplementedException(); + if (!_databaseService.GetBots().Types.TryGetValue(role.ToLower(), out var bot)) + { + _logger.Error($"Unable to get bot of type: {role} from DB"); + + return null; + } + + return bot; } /// diff --git a/Core/Models/Eft/Common/Tables/BotType.cs b/Core/Models/Eft/Common/Tables/BotType.cs index d9ade1be..83268791 100644 --- a/Core/Models/Eft/Common/Tables/BotType.cs +++ b/Core/Models/Eft/Common/Tables/BotType.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using System.Collections.Generic; +using System.Text.Json.Serialization; using Core.Models.Common; using Core.Utils.Json.Converters; @@ -61,7 +62,7 @@ public class Appearance public class Chances { [JsonPropertyName("equipment")] - public EquipmentChances? EquipmentChances { get; set; } + public Dictionary? EquipmentChances { get; set; } [JsonPropertyName("weaponMods")] public Dictionary? WeaponModsChances { get; set; } @@ -73,50 +74,6 @@ public class Chances public Dictionary? Mods { get; set; } } -public class EquipmentChances -{ - [JsonPropertyName("ArmBand")] - public int? ArmBand { get; set; } - - [JsonPropertyName("ArmorVest")] - public int? ArmorVest { get; set; } - - [JsonPropertyName("Backpack")] - public int? Backpack { get; set; } - - [JsonPropertyName("Earpiece")] - public int? Earpiece { get; set; } - - [JsonPropertyName("Eyewear")] - public int? Eyewear { get; set; } - - [JsonPropertyName("FaceCover")] - public int? FaceCover { get; set; } - - [JsonPropertyName("FirstPrimaryWeapon")] - public int? FirstPrimaryWeapon { get; set; } - - [JsonPropertyName("Headwear")] - public int? Headwear { get; set; } - - [JsonPropertyName("Holster")] - public int? Holster { get; set; } - - [JsonPropertyName("Pockets")] - public int? Pockets { get; set; } - - [JsonPropertyName("Scabbard")] - public int? Scabbard { get; set; } - - [JsonPropertyName("SecondPrimaryWeapon")] - public int? SecondPrimaryWeapon { get; set; } - - [JsonPropertyName("SecuredContainer")] - public int? SecuredContainer { get; set; } - - [JsonPropertyName("TacticalVest")] - public int? TacticalVest { get; set; } -} /* class removed in favor of Dictionary used to be used in: Chances.WeaponModsChances @@ -339,46 +296,7 @@ public class Experience public class Generation { [JsonPropertyName("items")] - public GenerationWeightingItems? Items { get; set; } -} - -public class GenerationWeightingItems -{ - [JsonPropertyName("grenades")] - public GenerationData? Grenades { get; set; } - - [JsonPropertyName("healing")] - public GenerationData? Healing { get; set; } - - [JsonPropertyName("drugs")] - public GenerationData? Drugs { get; set; } - - [JsonPropertyName("food")] - public GenerationData? Food { get; set; } - - [JsonPropertyName("drink")] - public GenerationData? Drink { get; set; } - - [JsonPropertyName("currency")] - public GenerationData? Currency { get; set; } - - [JsonPropertyName("stims")] - public GenerationData? Stims { get; set; } - - [JsonPropertyName("backpackLoot")] - public GenerationData? BackpackLoot { get; set; } - - [JsonPropertyName("pocketLoot")] - public GenerationData? PocketLoot { get; set; } - - [JsonPropertyName("vestLoot")] - public GenerationData? VestLoot { get; set; } - - [JsonPropertyName("magazines")] - public GenerationData? Magazines { get; set; } - - [JsonPropertyName("specialItems")] - public GenerationData? SpecialItems { get; set; } + public Dictionary? Items { get; set; } } public class GenerationData @@ -415,7 +333,7 @@ public class BodyPart public class BotTypeInventory { [JsonPropertyName("equipment")] - public Equipment? Equipment { get; set; } + public Dictionary>? Equipment { get; set; } public GlobalAmmo? Ammo { get; set; } @@ -451,4 +369,4 @@ public class ItemPools public Dictionary? SecuredContainer { get; set; } public Dictionary? SpecialLoot { get; set; } public Dictionary? TacticalVest { get; set; } -} \ No newline at end of file +} diff --git a/Core/Models/Spt/Config/PlayerScavConfig.cs b/Core/Models/Spt/Config/PlayerScavConfig.cs index 370e1329..7df449a9 100644 --- a/Core/Models/Spt/Config/PlayerScavConfig.cs +++ b/Core/Models/Spt/Config/PlayerScavConfig.cs @@ -1,4 +1,4 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; using Core.Models.Eft.Common.Tables; namespace Core.Models.Spt.Config; @@ -21,7 +21,7 @@ public class KarmaLevel public Modifiers Modifiers { get; set; } [JsonPropertyName("itemLimits")] - public ItemLimits ItemLimits { get; set; } + public Dictionary ItemLimits { get; set; } [JsonPropertyName("equipmentBlacklist")] public Dictionary EquipmentBlacklist { get; set; } diff --git a/Core/Services/BotEquipmentFilterService.cs b/Core/Services/BotEquipmentFilterService.cs index e088a562..1c8ea8a0 100644 --- a/Core/Services/BotEquipmentFilterService.cs +++ b/Core/Services/BotEquipmentFilterService.cs @@ -1,4 +1,4 @@ -using Core.Annotations; +using Core.Annotations; using Core.Models.Eft.Common.Tables; using Core.Models.Spt.Bots; using Core.Models.Spt.Config; @@ -31,7 +31,7 @@ public class BotEquipmentFilterService /// data to update protected void AdjustChances( Dictionary equipmentChanges, - EquipmentChances baseValues) + object baseValues) { throw new NotImplementedException(); }