diff --git a/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs index 0db5efed..2b361eb5 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/BotGenerator.cs @@ -486,9 +486,9 @@ public class BotGenerator( ) { // Choose random values by weight - bot.Customization.Head = weightedRandomHelper.GetWeightedValue(appearance.Head); - bot.Customization.Feet = weightedRandomHelper.GetWeightedValue(appearance.Feet); - bot.Customization.Body = weightedRandomHelper.GetWeightedValue(appearance.Body); + bot.Customization.Head = weightedRandomHelper.GetWeightedValue(appearance.Head); + bot.Customization.Feet = weightedRandomHelper.GetWeightedValue(appearance.Feet); + bot.Customization.Body = weightedRandomHelper.GetWeightedValue(appearance.Body); var bodyGlobalDictDb = databaseService.GetGlobals().Configuration.Customization.Body; var chosenBodyTemplate = databaseService.GetCustomization()[bot.Customization.Body.Value]; @@ -500,7 +500,7 @@ public class BotGenerator( bot.Customization.Hands = chosenBody.Value?.IsNotRandom ?? false ? chosenBody.Value.Hands // Has fixed hands for chosen body, update to match - : weightedRandomHelper.GetWeightedValue(appearance.Hands); // Hands can be random, choose any from weighted dict + : weightedRandomHelper.GetWeightedValue(appearance.Hands); // Hands can be random, choose any from weighted dict } /// diff --git a/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/BotType.cs b/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/BotType.cs index 8e32478a..cbd06fe1 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/BotType.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/BotType.cs @@ -47,18 +47,18 @@ public record Appearance public Dictionary? ExtensionData { get; set; } [JsonPropertyName("body")] - public Dictionary? Body { get; set; } + public Dictionary? Body { get; set; } [JsonPropertyName("feet")] - public Dictionary? Feet { get; set; } + public Dictionary? Feet { get; set; } [JsonPropertyName("hands")] [JsonConverter(typeof(ArrayToObjectFactoryConverter))] - public Dictionary? Hands { get; set; } + public Dictionary? Hands { get; set; } [JsonPropertyName("head")] [JsonConverter(typeof(ArrayToObjectFactoryConverter))] - public Dictionary? Head { get; set; } + public Dictionary? Head { get; set; } [JsonPropertyName("voice")] [JsonConverter(typeof(ArrayToObjectFactoryConverter))] diff --git a/Libraries/SPTarkov.Server.Core/Services/PmcChatResponseService.cs b/Libraries/SPTarkov.Server.Core/Services/PmcChatResponseService.cs index 1a073526..ce06854d 100644 --- a/Libraries/SPTarkov.Server.Core/Services/PmcChatResponseService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/PmcChatResponseService.cs @@ -255,7 +255,7 @@ public class PmcChatResponseService( ? _pmcResponsesConfig.Victim.ResponseTypeWeights : _pmcResponsesConfig.Killer.ResponseTypeWeights; - return weightedRandomHelper.GetWeightedValue(responseWeights); + return weightedRandomHelper.GetWeightedValue(responseWeights); } /// diff --git a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs index a4be9fee..f16ed05a 100644 --- a/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/SeasonalEventService.cs @@ -408,7 +408,7 @@ public class SeasonalEventService( /// /// globals.json /// Name of the event to enable. e.g. Christmas - private void UpdateGlobalEvents(Config globalConfig, SeasonalEvent eventType) + protected void UpdateGlobalEvents(Config globalConfig, SeasonalEvent eventType) { logger.Success(serverLocalisationService.GetText("season-event_is_active", eventType.Type)); _christmasEventActive = false; @@ -465,7 +465,7 @@ public class SeasonalEventService( } } - private void ApplyHalloweenEvent(SeasonalEvent eventType, Config globalConfig) + protected void ApplyHalloweenEvent(SeasonalEvent eventType, Config globalConfig) { _halloweenEventActive = true; @@ -509,7 +509,7 @@ public class SeasonalEventService( AdjustTraderIcons(eventType.Type); } - private void ApplyChristmasEvent(SeasonalEvent eventType, Config globalConfig) + protected void ApplyChristmasEvent(SeasonalEvent eventType, Config globalConfig) { _christmasEventActive = true; @@ -537,7 +537,7 @@ public class SeasonalEventService( } } - private void ApplyNewYearsEvent(SeasonalEvent eventType, Config globalConfig) + protected void ApplyNewYearsEvent(SeasonalEvent eventType, Config globalConfig) { _christmasEventActive = true; @@ -566,7 +566,12 @@ public class SeasonalEventService( } } - private void AdjustBotAppearanceValues(SeasonalEventType season) + /// + /// Adjust the weights for all bots body part appearances, based on data inside + /// seasonalevents.json/botAppearanceChanges + /// + /// Season to apply changes for + protected void AdjustBotAppearanceValues(SeasonalEventType season) { if ( !_seasonalEventConfig.BotAppearanceChanges.TryGetValue( @@ -575,33 +580,49 @@ public class SeasonalEventService( ) ) { + // No changes found for this season return; } foreach (var (botType, botAppearanceAdjustments) in appearanceAdjustments) { - if (!databaseService.GetBots().Types.TryGetValue(botType, out var botDb)) + if (!databaseService.GetBots().Types.TryGetValue(botType, out var bot)) { + // Bot defined in config doesn't exist continue; } - foreach (var (key, weightAdjustments) in botAppearanceAdjustments) + foreach (var (bodyPart, weightAdjustments) in botAppearanceAdjustments) { - var props = botDb.BotAppearance.GetType().GetProperties(); - foreach (var itemKey in weightAdjustments) + // Get the matching bots appearance pool by key + var partPool = bodyPart switch { - var prop = props.FirstOrDefault(x => - string.Equals(x.Name, key, StringComparison.CurrentCultureIgnoreCase) + "body" => bot.BotAppearance.Body, + "feet" => bot.BotAppearance.Feet, + "hands" => bot.BotAppearance.Hands, + "head" => bot.BotAppearance.Head, + _ => null, + }; + + if (partPool is null) + { + logger.Warning( + $"Unable to adjust bot: {botType} body part appearance: {bodyPart}" ); - var propValue = (Dictionary)prop.GetValue(botDb.BotAppearance); - propValue[itemKey.Key] = weightAdjustments[itemKey.Key]; - prop.SetValue(botDb.BotAppearance, propValue); + + continue; + } + + // Apply new weights to values from config + foreach (var (itemId, weighting) in weightAdjustments) + { + partPool[itemId] = weighting; } } } } - private void ReplaceBotHostility( + protected void ReplaceBotHostility( Dictionary> hostilitySettings ) { @@ -695,7 +716,7 @@ public class SeasonalEventService( } } - private void RemoveEntryRequirement(List locationIds) + protected void RemoveEntryRequirement(List locationIds) { foreach (var locationId in locationIds) {