Removed use of reflection inside RemoveChristmasItemsFromBotInventory
Replaced more strings with mongoIds
This commit is contained in:
@@ -221,8 +221,8 @@ public class BotInventoryGenerator(
|
||||
var pmcProfile = profileHelper.GetPmcProfile(sessionId);
|
||||
var botEquipmentRole = botGeneratorHelper.GetBotEquipmentRole(botRole);
|
||||
|
||||
// Iterate over all equipment slots of bot, do it in specifc order to reduce conflicts
|
||||
// e.g. ArmorVest should be generated after TactivalVest
|
||||
// Iterate over all equipment slots of bot, do it in specific order to reduce conflicts
|
||||
// e.g. ArmorVest should be generated after TacticalVest
|
||||
// or FACE_COVER before HEADWEAR
|
||||
foreach (var (equipmentSlot, value) in templateInventory.Equipment)
|
||||
{
|
||||
@@ -409,14 +409,14 @@ public class BotInventoryGenerator(
|
||||
/// <param name="templateInventory"></param>
|
||||
/// <param name="isPmc">is bot a PMC</param>
|
||||
/// <returns></returns>
|
||||
protected Dictionary<string, double>? GetPocketPoolByGameEdition(
|
||||
protected Dictionary<MongoId, double>? GetPocketPoolByGameEdition(
|
||||
string chosenGameVersion,
|
||||
BotTypeInventory templateInventory,
|
||||
bool isPmc
|
||||
)
|
||||
{
|
||||
return chosenGameVersion == GameEditions.UNHEARD && isPmc
|
||||
? new Dictionary<string, double> { [ItemTpl.POCKETS_1X4_TUE] = 1 }
|
||||
? new Dictionary<MongoId, double> { [ItemTpl.POCKETS_1X4_TUE] = 1 }
|
||||
: templateInventory.Equipment.GetValueOrDefault(EquipmentSlots.Pockets);
|
||||
}
|
||||
|
||||
@@ -426,7 +426,7 @@ public class BotInventoryGenerator(
|
||||
/// <param name="templateEquipment">Equipment to filter TacticalVest of</param>
|
||||
/// <param name="botRole">Role of bot vests are being filtered for</param>
|
||||
public void FilterRigsToThoseWithProtection(
|
||||
Dictionary<EquipmentSlots, Dictionary<string, double>> templateEquipment,
|
||||
Dictionary<EquipmentSlots, Dictionary<MongoId, double>> templateEquipment,
|
||||
string botRole
|
||||
)
|
||||
{
|
||||
@@ -456,7 +456,7 @@ public class BotInventoryGenerator(
|
||||
/// <param name="botRole">Role of bot vests are being filtered for</param>
|
||||
/// <param name="allowEmptyResult">Should the function return all rigs when 0 unarmored are found</param>
|
||||
public void FilterRigsToThoseWithoutProtection(
|
||||
Dictionary<EquipmentSlots, Dictionary<string, double>> templateEquipment,
|
||||
Dictionary<EquipmentSlots, Dictionary<MongoId, double>> templateEquipment,
|
||||
string botRole,
|
||||
bool allowEmptyResult = true
|
||||
)
|
||||
|
||||
@@ -446,7 +446,7 @@ public record BotTypeInventory
|
||||
public Dictionary<string, object>? ExtensionData { get; set; }
|
||||
|
||||
[JsonPropertyName("equipment")]
|
||||
public Dictionary<EquipmentSlots, Dictionary<string, double>>? Equipment { get; set; }
|
||||
public Dictionary<EquipmentSlots, Dictionary<MongoId, double>>? Equipment { get; set; }
|
||||
|
||||
public GlobalAmmo? Ammo { get; set; }
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using SPTarkov.Server.Core.Models.Common;
|
||||
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
|
||||
using SPTarkov.Server.Core.Models.Enums;
|
||||
using SPTarkov.Server.Core.Models.Spt.Config;
|
||||
@@ -20,7 +21,7 @@ public record GenerateEquipmentProperties
|
||||
/// Equipment pool for root slot being generated
|
||||
/// </summary>
|
||||
[JsonPropertyName("rootEquipmentPool")]
|
||||
public Dictionary<string, double>? RootEquipmentPool { get; set; }
|
||||
public Dictionary<MongoId, double>? RootEquipmentPool { get; set; }
|
||||
|
||||
[JsonPropertyName("modPool")]
|
||||
public GlobalMods? ModPool { get; set; }
|
||||
|
||||
@@ -267,8 +267,7 @@ public class BotEquipmentFilterService(
|
||||
}
|
||||
|
||||
// Filter equipment slot items to just items in whitelist
|
||||
baseBotNode.BotInventory.Equipment[equipmentSlotKey.Key] =
|
||||
new Dictionary<string, double>();
|
||||
baseBotNode.BotInventory.Equipment[equipmentSlotKey.Key] = [];
|
||||
foreach (var dict in botEquipment)
|
||||
{
|
||||
if (whitelistEquipmentForSlot.Contains(dict.Key))
|
||||
@@ -384,7 +383,7 @@ public class BotEquipmentFilterService(
|
||||
/// <param name="botItemPool">Bot item dictionary to adjust</param>
|
||||
protected void AdjustWeighting(
|
||||
AdjustmentDetails? weightingAdjustments,
|
||||
Dictionary<EquipmentSlots, Dictionary<string, double>> botItemPool,
|
||||
Dictionary<EquipmentSlots, Dictionary<MongoId, double>> botItemPool,
|
||||
bool showEditWarnings = true
|
||||
)
|
||||
{
|
||||
|
||||
@@ -363,9 +363,10 @@ public class SeasonalEventService(
|
||||
var christmasItems = GetChristmasEventItems();
|
||||
|
||||
// Remove christmas related equipment
|
||||
botInventory.Equipment ??= new Dictionary<EquipmentSlots, Dictionary<MongoId, double>>();
|
||||
foreach (var equipmentSlotKey in _equipmentSlotsToFilter)
|
||||
{
|
||||
if (botInventory.Equipment[equipmentSlotKey] is null)
|
||||
if (!botInventory.Equipment.TryGetValue(equipmentSlotKey, out var equipment))
|
||||
{
|
||||
logger.Warning(
|
||||
serverLocalisationService.GetText(
|
||||
@@ -373,39 +374,32 @@ public class SeasonalEventService(
|
||||
new { equipmentSlot = equipmentSlotKey, botRole }
|
||||
)
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
var equipment = botInventory.Equipment[equipmentSlotKey];
|
||||
botInventory.Equipment[equipmentSlotKey] = equipment
|
||||
.Where(i => !_christmasEventItems.Contains(i.Key))
|
||||
.ToDictionary();
|
||||
}
|
||||
|
||||
// Remove christmas related loot from loot containers
|
||||
var props = botInventory.Items.GetType().GetProperties();
|
||||
foreach (var lootContainerKey in _lootContainersToFilter)
|
||||
var containersToCheck = new List<Dictionary<MongoId, double>>
|
||||
{
|
||||
var propInfo = props.FirstOrDefault(p =>
|
||||
string.Equals(
|
||||
p.Name.ToLowerInvariant(),
|
||||
lootContainerKey.ToLowerInvariant(),
|
||||
StringComparison.OrdinalIgnoreCase
|
||||
)
|
||||
);
|
||||
var prop = (Dictionary<MongoId, double>?)propInfo.GetValue(botInventory.Items);
|
||||
botInventory.Items.Backpack,
|
||||
botInventory.Items.Pockets,
|
||||
botInventory.Items.SecuredContainer,
|
||||
botInventory.Items.TacticalVest,
|
||||
botInventory.Items.SpecialLoot,
|
||||
};
|
||||
|
||||
if (prop is null)
|
||||
foreach (var container in containersToCheck)
|
||||
{
|
||||
// Find all Christmas items in container
|
||||
var keysToRemove = container.Keys.Where(key => christmasItems.Contains(key)).ToList();
|
||||
foreach (var key in keysToRemove)
|
||||
{
|
||||
logger.Warning(
|
||||
serverLocalisationService.GetText(
|
||||
"seasonal-missing_loot_container_slot_on_bot",
|
||||
new { lootContainer = lootContainerKey, botRole }
|
||||
)
|
||||
);
|
||||
container.Remove(key);
|
||||
}
|
||||
|
||||
var newProp = prop.Where(tpl => !christmasItems.Contains(tpl.Key)).ToDictionary();
|
||||
propInfo.SetValue(botInventory.Items, newProp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,7 +407,7 @@ public class SeasonalEventService(
|
||||
/// Make adjusted to server code based on the name of the event passed in
|
||||
/// </summary>
|
||||
/// <param name="globalConfig">globals.json</param>
|
||||
/// <param name="event">Name of the event to enable. e.g. Christmas</param>
|
||||
/// <param name="eventType">Name of the event to enable. e.g. Christmas</param>
|
||||
private void UpdateGlobalEvents(Config globalConfig, SeasonalEvent eventType)
|
||||
{
|
||||
logger.Success(serverLocalisationService.GetText("season-event_is_active", eventType.Type));
|
||||
|
||||
Reference in New Issue
Block a user