Added MongoId type to various places

This commit is contained in:
Chomp
2025-07-02 19:07:58 +01:00
parent 2beebaed12
commit 86295b68fb
19 changed files with 59 additions and 66 deletions
@@ -1,6 +1,7 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Game;
using SPTarkov.Server.Core.Models.Eft.Profile;
@@ -82,12 +83,12 @@ public class GameController(
return;
}
fullProfile.CharacterData!.PmcData!.WishList ??= new DictionaryOrList<string, int>(
new Dictionary<string, int>(),
fullProfile.CharacterData!.PmcData!.WishList ??= new DictionaryOrList<MongoId, int>(
new Dictionary<MongoId, int>(),
[]
);
fullProfile.CharacterData.ScavData!.WishList ??= new DictionaryOrList<string, int>(
new Dictionary<string, int>(),
fullProfile.CharacterData.ScavData!.WishList ??= new DictionaryOrList<MongoId, int>(
new Dictionary<MongoId, int>(),
[]
);
@@ -1771,7 +1771,7 @@ public class HideoutController(
foreach (var poseKvP in request.Poses)
{
// Nullguard
pmcData.Hideout.MannequinPoses ??= new Dictionary<string, string>();
pmcData.Hideout.MannequinPoses ??= new Dictionary<string, MongoId>();
pmcData.Hideout.MannequinPoses[poseKvP.Key] = poseKvP.Value;
}
@@ -113,12 +113,12 @@ public class PlayerScavGenerator(
scavData.Quests = existingScavDataClone.Quests ?? [];
scavData.TaskConditionCounters =
existingScavDataClone.TaskConditionCounters
?? new Dictionary<string, TaskConditionCounter>();
?? new Dictionary<MongoId, TaskConditionCounter>();
scavData.Notes = existingScavDataClone.Notes ?? new Notes { DataNotes = new List<Note>() };
scavData.WishList =
existingScavDataClone.WishList
?? new DictionaryOrList<string, int>(new Dictionary<string, int>(), new List<int>());
scavData.Encyclopedia = pmcDataClone.Encyclopedia ?? new Dictionary<string, bool>();
?? new DictionaryOrList<MongoId, int>(new Dictionary<MongoId, int>(), []);
scavData.Encyclopedia = pmcDataClone.Encyclopedia ?? new Dictionary<MongoId, bool>();
// Add additional items to player scav as loot
AddAdditionalLootToPlayerScavContainers(
@@ -1,19 +1,18 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Models.Spt.Config;
using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using SPTarkov.Server.Core.Utils.Cloners;
namespace SPTarkov.Server.Core.Generators;
[Injectable]
public class RagfairAssortGenerator(
HashUtil hashUtil,
ItemHelper itemHelper,
PresetHelper presetHelper,
SeasonalEventService seasonalEventService,
@@ -133,16 +132,16 @@ public class RagfairAssortGenerator(
/// <param name="tplId"> tplid to add to item </param>
/// <param name="id"> id to add to item </param>
/// <returns> Hydrated Item object </returns>
protected Item CreateRagfairAssortRootItem(string tplId, string? id = null)
protected Item CreateRagfairAssortRootItem(string tplId, MongoId? id = null)
{
if (string.IsNullOrEmpty(id))
{
id = hashUtil.Generate();
id = new MongoId();
}
return new Item
{
Id = id,
Id = id.Value,
Template = tplId,
ParentId = "hideout",
SlotId = "hideout",
@@ -2,6 +2,7 @@ using System.Diagnostics;
using SPTarkov.Common.Extensions;
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Eft.Ragfair;
using SPTarkov.Server.Core.Models.Enums;
@@ -467,7 +468,7 @@ public class RagfairOfferGenerator(
clonedAssort[0].SlotId = null;
CreateSingleOfferForItem(
hashUtil.Generate(),
new MongoId(),
clonedAssort,
isPreset,
itemToSellDetails.Value,
@@ -6,7 +6,6 @@ using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Models.Spt.Config;
using SPTarkov.Server.Core.Models.Spt.Repeatable;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using SPTarkov.Server.Core.Utils.Json;
@@ -21,23 +20,20 @@ public class CompletionQuestGenerator(
DatabaseService databaseService,
SeasonalEventService seasonalEventService,
ServerLocalisationService localisationService,
ConfigServer configServer,
RandomUtil randomUtil,
MathUtil mathUtil,
HashUtil hashUtil,
ItemHelper itemHelper
) : IRepeatableQuestGenerator
{
protected const int MaxRandomNumberAttempts = 6;
protected QuestConfig QuestConfig = configServer.GetConfig<QuestConfig>();
/// <summary>
/// Generates a valid Completion quest
/// </summary>
/// <param name="sessionId">session Id to generate the quest for</param>
/// <param name="pmcLevel">player's level for requested items and reward generation</param>
/// <param name="traderId">trader from which the quest will be provided</param>
/// <param name="questTypePool"></param>
/// <param name="repeatableConfig">
/// The configuration for the repeatably kind (daily, weekly) as configured in QuestConfig
/// for the requested quest
@@ -424,7 +420,7 @@ public class CompletionQuestGenerator(
return new QuestCondition
{
Id = hashUtil.Generate(),
Id = new MongoId(),
Index = 0,
ParentId = "",
DynamicLocale = true,
@@ -21,7 +21,6 @@ namespace SPTarkov.Server.Core.Generators.RepeatableQuestGeneration;
public class EliminationQuestGenerator(
ISptLogger<EliminationQuestGenerator> logger,
RandomUtil randomUtil,
HashUtil hashUtil,
MathUtil mathUtil,
RepeatableQuestHelper repeatableQuestHelper,
ItemHelper itemHelper,
@@ -277,7 +276,7 @@ public class EliminationQuestGenerator(
}
var availableForFinishCondition = quest.Conditions.AvailableForFinish![0];
availableForFinishCondition.Counter!.Id = hashUtil.Generate();
availableForFinishCondition.Counter!.Id = new MongoId();
availableForFinishCondition.Counter.Conditions = [];
// Only add specific location condition if specific map selected
@@ -299,7 +298,7 @@ public class EliminationQuestGenerator(
)
);
availableForFinishCondition.Value = desiredKillCount;
availableForFinishCondition.Id = hashUtil.Generate();
availableForFinishCondition.Id = new MongoId();
// Get the quest location, default to any if none exist
quest.Location = repeatableQuestHelper.GetQuestLocationByMapId(locationKey) ?? "any";
@@ -744,7 +743,7 @@ public class EliminationQuestGenerator(
{
return new QuestConditionCounterCondition
{
Id = hashUtil.Generate(),
Id = new MongoId(),
DynamicLocale = true,
Target = new ListOrT<string>(location, null),
ConditionType = "Location",
@@ -770,7 +769,7 @@ public class EliminationQuestGenerator(
{
var killConditionProps = new QuestConditionCounterCondition
{
Id = hashUtil.Generate(),
Id = new MongoId(),
DynamicLocale = true,
Target = new ListOrT<string>(null, target), // e,g, "AnyPmc"
Value = 1,
@@ -7,7 +7,6 @@ using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Models.Spt.Config;
using SPTarkov.Server.Core.Models.Spt.Repeatable;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using SPTarkov.Server.Core.Utils.Json;
@@ -21,10 +20,8 @@ public class ExplorationQuestGenerator(
RepeatableQuestRewardGenerator repeatableQuestRewardGenerator,
DatabaseService databaseService,
ServerLocalisationService localisationService,
ConfigServer configServer,
RandomUtil randomUtil,
MathUtil mathUtil,
HashUtil hashUtil
MathUtil mathUtil
) : IRepeatableQuestGenerator
{
protected record LocationInfo(
@@ -34,8 +31,6 @@ public class ExplorationQuestGenerator(
int NumOfExtractsRequired
);
protected QuestConfig QuestConfig = configServer.GetConfig<QuestConfig>();
/// <summary>
/// Generates a valid Exploration quest
/// </summary>
@@ -254,7 +249,7 @@ public class ExplorationQuestGenerator(
var exitStatusCondition = new QuestConditionCounterCondition
{
Id = hashUtil.Generate(),
Id = new MongoId(),
DynamicLocale = true,
Status = ["Survived"],
ConditionType = "ExitStatus",
@@ -262,20 +257,20 @@ public class ExplorationQuestGenerator(
var locationCondition = new QuestConditionCounterCondition
{
Id = hashUtil.Generate(),
Id = new MongoId(),
DynamicLocale = true,
Target = new ListOrT<string>(locationInfo.LocationTarget, null),
ConditionType = "Location",
};
quest.Conditions.AvailableForFinish![0].Counter!.Id = hashUtil.Generate();
quest.Conditions.AvailableForFinish![0].Counter!.Id = new MongoId();
quest.Conditions.AvailableForFinish![0].Counter!.Conditions =
[
exitStatusCondition,
locationCondition,
];
quest.Conditions.AvailableForFinish[0].Value = locationInfo.NumOfExtractsRequired;
quest.Conditions.AvailableForFinish[0].Id = hashUtil.Generate();
quest.Conditions.AvailableForFinish[0].Id = new MongoId();
quest.Location = location;
@@ -357,7 +352,7 @@ public class ExplorationQuestGenerator(
{
return new QuestConditionCounterCondition
{
Id = hashUtil.Generate(),
Id = new MongoId(),
DynamicLocale = true,
ExitName = exit.Name,
ConditionType = "ExitName",
@@ -20,7 +20,6 @@ namespace SPTarkov.Server.Core.Generators.RepeatableQuestGeneration;
public class RepeatableQuestRewardGenerator(
ISptLogger<RepeatableQuestRewardGenerator> logger,
RandomUtil randomUtil,
HashUtil hashUtil,
MathUtil mathUtil,
DatabaseService databaseService,
ItemHelper itemHelper,
@@ -95,7 +94,7 @@ public class RepeatableQuestRewardGenerator(
rewards.Success.Add(
new Reward
{
Id = hashUtil.Generate(),
Id = new MongoId(),
Unknown = false,
GameMode = [],
AvailableInGameEditions = [],
@@ -193,7 +192,7 @@ public class RepeatableQuestRewardGenerator(
{
Reward reward = new()
{
Id = hashUtil.Generate(),
Id = new MongoId(),
Unknown = false,
GameMode = [],
AvailableInGameEditions = [],
@@ -219,7 +218,7 @@ public class RepeatableQuestRewardGenerator(
var targetSkill = randomUtil.GetArrayValue(eliminationConfig.PossibleSkillRewards);
Reward reward = new()
{
Id = hashUtil.Generate(),
Id = new MongoId(),
Unknown = false,
GameMode = [],
AvailableInGameEditions = [],
@@ -664,10 +663,10 @@ public class RepeatableQuestRewardGenerator(
bool foundInRaid = true
)
{
var id = hashUtil.Generate();
var id = new MongoId();
var questRewardItem = new Reward
{
Id = hashUtil.Generate(),
Id = new MongoId(),
Unknown = false,
GameMode = [],
AvailableInGameEditions = [],
@@ -713,10 +712,10 @@ public class RepeatableQuestRewardGenerator(
bool foundInRaid = true
)
{
var id = hashUtil.Generate();
var id = new MongoId();
var questRewardItem = new Reward
{
Id = hashUtil.Generate(),
Id = new MongoId(),
Unknown = false,
GameMode = [],
AvailableInGameEditions = [],
@@ -6,7 +6,6 @@ using SPTarkov.Server.Core.Models.Spt.Config;
using SPTarkov.Server.Core.Models.Utils;
using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using SPTarkov.Server.Core.Utils.Cloners;
namespace SPTarkov.Server.Core.Helpers;
@@ -16,7 +15,6 @@ public class RepeatableQuestHelper(
ISptLogger<RepeatableQuestHelper> logger,
DatabaseService databaseService,
ServerLocalisationService serverLocalisationService,
HashUtil hashUtil,
ICloner cloner,
ConfigServer configServer
)
@@ -88,7 +86,7 @@ public class RepeatableQuestHelper(
return null;
}
quest.Id = hashUtil.Generate();
quest.Id = new MongoId();
quest.TraderId = traderId;
return quest;
@@ -202,7 +200,7 @@ public class RepeatableQuestHelper(
return null;
}
questData.QuestStatus.Id = hashUtil.Generate();
questData.QuestStatus.Id = new MongoId();
questData.QuestStatus.Uid = sessionId; // Needs to match user id
questData.QuestStatus.QId = questData.Id; // Needs to match quest id
@@ -14,7 +14,7 @@ public record BotBase
public Dictionary<string, object>? ExtensionData { get; set; }
[JsonPropertyName("_id")]
public string? Id { get; set; }
public MongoId? Id { get; set; }
[JsonPropertyName("aid")]
[JsonConverter(typeof(StringToNumberFactoryConverter))]
@@ -28,7 +28,7 @@ public record BotBase
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
[JsonPropertyName("savage")]
public string? Savage { get; set; }
public MongoId? Savage { get; set; }
[JsonPropertyName("karmaValue")]
public double? KarmaValue { get; set; }
@@ -53,10 +53,10 @@ public record BotBase
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
[JsonPropertyName("Encyclopedia")]
public Dictionary<string, bool>? Encyclopedia { get; set; }
public Dictionary<MongoId, bool>? Encyclopedia { get; set; }
[JsonPropertyName("TaskConditionCounters")]
public Dictionary<string, TaskConditionCounter>? TaskConditionCounters { get; set; }
public Dictionary<MongoId, TaskConditionCounter>? TaskConditionCounters { get; set; }
[JsonPropertyName("InsuredItems")]
public List<InsuredItem>? InsuredItems { get; set; }
@@ -82,7 +82,7 @@ public record BotBase
/// </summary>
[JsonPropertyName("Achievements")]
[JsonConverter(typeof(ArrayToObjectFactoryConverter))]
public Dictionary<string, long>? Achievements { get; set; }
public Dictionary<MongoId, long>? Achievements { get; set; }
[JsonPropertyName("RepeatableQuests")]
public List<PmcDataRepeatableQuest>? RepeatableQuests { get; set; }
@@ -105,7 +105,7 @@ public record BotBase
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
[JsonPropertyName("WishList")]
[JsonConverter(typeof(ArrayToObjectFactoryConverter))]
public DictionaryOrList<string, int>? WishList { get; set; }
public DictionaryOrList<MongoId, int>? WishList { get; set; }
[JsonPropertyName("moneyTransferLimitData")]
public MoneyTransferLimits? MoneyTransferLimitData { get; set; }
@@ -826,7 +826,7 @@ public record Hideout
/// </summary>
public string? Seed { get; set; }
public Dictionary<string, string>? MannequinPoses { get; set; }
public Dictionary<string, MongoId>? MannequinPoses { get; set; }
[JsonPropertyName("sptUpdateLastRunTimestamp")]
public long? SptUpdateLastRunTimestamp { get; set; }
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Utils.Json.Converters;
@@ -72,7 +73,7 @@ public record TraderService
public Dictionary<string, ServiceItemCostDetails>? ServiceItemCost { get; set; }
[JsonPropertyName("UniqueItems")]
public List<string>? UniqueItems { get; set; }
public List<MongoId>? UniqueItems { get; set; }
}
public record ServiceRequirements
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Utils.Json;
using SPTarkov.Server.Core.Utils.Json.Converters;
@@ -189,7 +190,7 @@ public record QuestCondition
public Dictionary<string, object>? ExtensionData { get; set; }
[JsonPropertyName("id")]
public required string Id { get; set; }
public required MongoId Id { get; set; }
[JsonPropertyName("index")]
public int? Index { get; set; }
@@ -226,13 +226,13 @@ public record TraderRepair
public bool? Availability { get; set; }
[JsonPropertyName("currency")]
public MongoId Currency { get; set; }
public string Currency { get; set; }
[JsonPropertyName("currency_coefficient")]
public double? CurrencyCoefficient { get; set; }
[JsonPropertyName("excluded_category")]
public List<string>? ExcludedCategory { get; set; }
public List<MongoId>? ExcludedCategory { get; set; }
/// <summary>
/// Doesn't exist in client object
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Inventory;
namespace SPTarkov.Server.Core.Models.Eft.Hideout;
@@ -9,7 +10,7 @@ public record HideoutCustomizationSetMannequinPoseRequest : InventoryBaseActionR
public Dictionary<string, object>? ExtensionData { get; set; }
[JsonPropertyName("poses")]
public Dictionary<string, string>? Poses { get; set; }
public Dictionary<string, MongoId>? Poses { get; set; }
[JsonPropertyName("timestamp")]
public double? Timestamp { get; set; }
@@ -10,7 +10,7 @@ public record GetOtherProfileResponse
public Dictionary<string, object>? ExtensionData { get; set; }
[JsonPropertyName("id")]
public string? Id { get; set; }
public MongoId? Id { get; set; }
[JsonPropertyName("aid")]
public int? Aid { get; set; }
@@ -28,7 +28,7 @@ public record GetOtherProfileResponse
public OtherProfileEquipment? Equipment { get; set; }
[JsonPropertyName("achievements")]
public Dictionary<string, long>? Achievements { get; set; }
public Dictionary<MongoId, long>? Achievements { get; set; }
[JsonPropertyName("favoriteItems")]
public List<Item>? FavoriteItems { get; set; }
@@ -3,6 +3,7 @@ using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Generators;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Eft.ItemEvent;
@@ -67,7 +68,7 @@ public class CreateProfileService(
pmcData.RepeatableQuests = [];
pmcData.CarExtractCounts = new Dictionary<string, int>();
pmcData.CoopExtractCounts = new Dictionary<string, int>();
pmcData.Achievements = new Dictionary<string, long>();
pmcData.Achievements = new Dictionary<MongoId, long>();
// Process handling if the account has been forced to wipe
// BSG keeps both the achievements, prestige level and the total in-game time in a wipe
@@ -253,7 +254,7 @@ public class CreateProfileService(
protected void UpdateInventoryEquipmentId(PmcData pmcData)
{
var oldEquipmentId = pmcData.Inventory.Equipment;
pmcData.Inventory.Equipment = _hashUtil.Generate();
pmcData.Inventory.Equipment = new MongoId();
foreach (var item in pmcData.Inventory.Items)
{
@@ -1320,7 +1320,7 @@ public class LocationLifecycleService
/// <param name="postRaidAchievements"> All profile achievements at the end of a raid </param>
protected void ProcessAchievementRewards(
SptProfile fullProfile,
Dictionary<string, long>? postRaidAchievements
Dictionary<MongoId, long>? postRaidAchievements
)
{
var sessionId = fullProfile.ProfileInfo.ProfileId;
@@ -1,6 +1,7 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Common;
using SPTarkov.Server.Core.Models.Eft.Common.Tables;
using SPTarkov.Server.Core.Models.Eft.Inventory;
@@ -272,7 +273,7 @@ public class PaymentService(
// Create single currency item with all currency on it
var rootCurrencyReward = new Item
{
Id = _hashUtil.Generate(),
Id = new MongoId(),
Template = currencyTpl,
Upd = new Upd { StackObjectsCount = Math.Round(calcAmount) },
};