Fixed Server serializing difficulty values incorrectly
This commit is contained in:
@@ -69,55 +69,6 @@ public class BotHelper(ISptLogger<BotHelper> logger, DatabaseService databaseSer
|
||||
return botRole.StartsWith("infected", StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a bot to the FRIENDLY_BOT_TYPES list
|
||||
/// </summary>
|
||||
/// <param name="difficultySettings">bot settings to alter</param>
|
||||
/// <param name="typeToAdd">bot type to add to friendly list</param>
|
||||
public void AddBotToFriendlyList(DifficultyCategories difficultySettings, string typeToAdd)
|
||||
{
|
||||
const string friendlyBotTypesKey = "FRIENDLY_BOT_TYPES";
|
||||
|
||||
// Null guard
|
||||
if (!difficultySettings.Mind.ContainsKey(friendlyBotTypesKey))
|
||||
{
|
||||
difficultySettings.Mind[friendlyBotTypesKey] = new List<string>();
|
||||
}
|
||||
|
||||
((List<string>)difficultySettings.Mind[friendlyBotTypesKey]).Add(typeToAdd);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a bot to the REVENGE_BOT_TYPES list
|
||||
/// </summary>
|
||||
/// <param name="difficultySettings">bot settings to alter</param>
|
||||
/// <param name="typesToAdd">bot type to add to revenge list</param>
|
||||
public void AddBotToRevengeList(DifficultyCategories difficultySettings, string[] typesToAdd)
|
||||
{
|
||||
const string revengePropKey = "REVENGE_BOT_TYPES";
|
||||
|
||||
// Nothing to add
|
||||
if (typesToAdd.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Null guard
|
||||
if (!difficultySettings.Mind.ContainsKey(revengePropKey))
|
||||
{
|
||||
difficultySettings.Mind[revengePropKey] = new List<string>();
|
||||
}
|
||||
|
||||
var revengeArray = (List<string>)difficultySettings.Mind[revengePropKey];
|
||||
foreach (var botTypeToAdd in typesToAdd)
|
||||
{
|
||||
if (!revengeArray.Contains(botTypeToAdd))
|
||||
{
|
||||
revengeArray.Add(botTypeToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get randomization settings for bot from config/bot.json
|
||||
/// </summary>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Models.Enums;
|
||||
@@ -240,33 +241,33 @@ public double? ModPistol_Grip { get; set; }
|
||||
|
||||
public record DifficultyCategories
|
||||
{
|
||||
public Dictionary<string, object>? Aiming { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Aiming { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Boss { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Boss { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Change { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Change { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Core { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Core { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Cover { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Cover { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Grenade { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Grenade { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Hearing { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Hearing { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Lay { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Lay { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Look { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Look { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Mind { get; set; } // TODO: string | number | boolean | string[]
|
||||
public Dictionary<string, JsonElement>? Mind { get; set; } // TODO: string | number | boolean | string[]
|
||||
|
||||
public Dictionary<string, object>? Move { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Move { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Patrol { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Patrol { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Scattering { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Scattering { get; set; } // TODO: string | number | boolean
|
||||
|
||||
public Dictionary<string, object>? Shoot { get; set; } // TODO: string | number | boolean
|
||||
public Dictionary<string, JsonElement>? Shoot { get; set; } // TODO: string | number | boolean
|
||||
}
|
||||
|
||||
public record Experience
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Frozen;
|
||||
using System.Text.Json;
|
||||
using SPTarkov.Common.Extensions;
|
||||
using SPTarkov.DI.Annotations;
|
||||
using SPTarkov.Server.Core.Extensions;
|
||||
@@ -920,13 +921,31 @@ public class SeasonalEventService(
|
||||
protected void AddLootItemsToGifterDropItemsList()
|
||||
{
|
||||
var gifterBot = databaseService.GetBots().Types["gifter"];
|
||||
var itemsCSV = string.Join(",", gifterBot.BotInventory.Items.Backpack.Keys);
|
||||
string[] difficulties = ["easy", "normal", "hard", "impossible"];
|
||||
|
||||
foreach (var difficulty in difficulties)
|
||||
{
|
||||
gifterBot.BotDifficulty[difficulty].Patrol.TryAdd("ITEMS_TO_DROP", "");
|
||||
gifterBot.BotDifficulty[difficulty].Patrol["ITEMS_TO_DROP"] = itemsCSV;
|
||||
var gifterPatrolValues = gifterBot.BotDifficulty[difficulty].Patrol;
|
||||
|
||||
// Read existing value from property
|
||||
var existingItems = Enumerable.Empty<string>();
|
||||
if (gifterPatrolValues.TryGetValue("ITEMS_TO_DROP", out var jsonElement) && jsonElement.ValueKind == JsonValueKind.String)
|
||||
{
|
||||
var existingCsv = jsonElement.GetString();
|
||||
if (!string.IsNullOrWhiteSpace(existingCsv))
|
||||
{
|
||||
existingItems = existingCsv.Split(',');
|
||||
}
|
||||
}
|
||||
|
||||
// Merge existing and new tpls we want
|
||||
var combinedItems = new HashSet<string>(existingItems);
|
||||
combinedItems.UnionWith(gifterBot.BotInventory.Items.Backpack.Keys.Select(x => x.ToString()));
|
||||
|
||||
// Turn set into a comma separated list ready for insertion
|
||||
var finalItemsCsv = string.Join(",", combinedItems);
|
||||
|
||||
gifterPatrolValues["ITEMS_TO_DROP"] = JsonDocument.Parse($"\"{finalItemsCsv}\"").RootElement.Clone();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user