Removed reflection from AdjustBotAppearanceValues

More string to MongoId conversions
This commit is contained in:
Chomp
2025-07-14 18:42:42 +01:00
parent 0ec5aeab91
commit 3aa13dd46b
4 changed files with 46 additions and 25 deletions
@@ -486,9 +486,9 @@ public class BotGenerator(
)
{
// Choose random values by weight
bot.Customization.Head = weightedRandomHelper.GetWeightedValue<string>(appearance.Head);
bot.Customization.Feet = weightedRandomHelper.GetWeightedValue<string>(appearance.Feet);
bot.Customization.Body = weightedRandomHelper.GetWeightedValue<string>(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<string>(appearance.Hands); // Hands can be random, choose any from weighted dict
: weightedRandomHelper.GetWeightedValue(appearance.Hands); // Hands can be random, choose any from weighted dict
}
/// <summary>
@@ -47,18 +47,18 @@ public record Appearance
public Dictionary<string, object>? ExtensionData { get; set; }
[JsonPropertyName("body")]
public Dictionary<string, double>? Body { get; set; }
public Dictionary<MongoId, double>? Body { get; set; }
[JsonPropertyName("feet")]
public Dictionary<string, double>? Feet { get; set; }
public Dictionary<MongoId, double>? Feet { get; set; }
[JsonPropertyName("hands")]
[JsonConverter(typeof(ArrayToObjectFactoryConverter))]
public Dictionary<string, double>? Hands { get; set; }
public Dictionary<MongoId, double>? Hands { get; set; }
[JsonPropertyName("head")]
[JsonConverter(typeof(ArrayToObjectFactoryConverter))]
public Dictionary<string, double>? Head { get; set; }
public Dictionary<MongoId, double>? Head { get; set; }
[JsonPropertyName("voice")]
[JsonConverter(typeof(ArrayToObjectFactoryConverter))]
@@ -255,7 +255,7 @@ public class PmcChatResponseService(
? _pmcResponsesConfig.Victim.ResponseTypeWeights
: _pmcResponsesConfig.Killer.ResponseTypeWeights;
return weightedRandomHelper.GetWeightedValue<string>(responseWeights);
return weightedRandomHelper.GetWeightedValue(responseWeights);
}
/// <summary>
@@ -408,7 +408,7 @@ public class SeasonalEventService(
/// </summary>
/// <param name="globalConfig">globals.json</param>
/// <param name="eventType">Name of the event to enable. e.g. Christmas</param>
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)
/// <summary>
/// Adjust the weights for all bots body part appearances, based on data inside
/// seasonalevents.json/botAppearanceChanges
/// </summary>
/// <param name="season">Season to apply changes for</param>
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<string, double>)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<string, List<AdditionalHostilitySettings>> hostilitySettings
)
{
@@ -695,7 +716,7 @@ public class SeasonalEventService(
}
}
private void RemoveEntryRequirement(List<string> locationIds)
protected void RemoveEntryRequirement(List<string> locationIds)
{
foreach (var locationId in locationIds)
{