diff --git a/Libraries/SPTarkov.Server.Core/Controllers/BuildController.cs b/Libraries/SPTarkov.Server.Core/Controllers/BuildController.cs index 1004faca..af9717ef 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/BuildController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/BuildController.cs @@ -33,15 +33,12 @@ public class BuildController( const string secureContainerSlotId = "SecuredContainer"; var profile = profileHelper.GetFullProfile(sessionID); - if (profile.UserBuildData is null) + profile.UserBuildData ??= new UserBuilds { - profile.UserBuildData = new UserBuilds - { - EquipmentBuilds = [], - WeaponBuilds = [], - MagazineBuilds = [], - }; - } + EquipmentBuilds = [], + WeaponBuilds = [], + MagazineBuilds = [], + }; // Ensure the secure container in the default presets match what the player has equipped var defaultEquipmentPresetsClone = cloner diff --git a/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs b/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs index 83b03cca..1a175713 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/InsuranceController.cs @@ -823,13 +823,14 @@ public class InsuranceController( pmcData.InsuredItems ??= []; foreach (var key in request.Items) { + var inventoryItem = inventoryItemsHash.GetValueOrDefault(key); pmcData.InsuredItems.Add( - new InsuredItem { TId = request.TransactionId, ItemId = inventoryItemsHash[key].Id } + new InsuredItem { TId = request.TransactionId, ItemId = inventoryItem.Id } ); // If Item is Helmet or Body Armour -> Handle insurance of soft inserts - if (itemHelper.ArmorItemHasRemovableOrSoftInsertSlots(inventoryItemsHash[key].Template)) + if (itemHelper.ArmorItemHasRemovableOrSoftInsertSlots(inventoryItem.Template)) { - InsureSoftInserts(inventoryItemsHash[key], pmcData, request); + InsureSoftInserts(inventoryItem, pmcData, request); } } diff --git a/Libraries/SPTarkov.Server.Core/Generators/RagfairOfferGenerator.cs b/Libraries/SPTarkov.Server.Core/Generators/RagfairOfferGenerator.cs index 59d941da..b5f6dfbf 100644 --- a/Libraries/SPTarkov.Server.Core/Generators/RagfairOfferGenerator.cs +++ b/Libraries/SPTarkov.Server.Core/Generators/RagfairOfferGenerator.cs @@ -440,7 +440,9 @@ public class RagfairOfferGenerator( } // Armor presets can hold plates above the allowed flea level, remove if necessary - var isPreset = presetHelper.IsPreset(rootItem.Upd.SptPresetId); + var isPreset = + rootItem?.Upd?.SptPresetId is not null + && presetHelper.IsPreset(rootItem.Upd.SptPresetId.Value); if (!isExpiredOffer && isPreset && ragfairConfig.Dynamic.Blacklist.EnableBsgList) { RemoveBannedPlatesFromPreset( diff --git a/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs index 95441ff9..42503dfe 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/ItemHelper.cs @@ -1146,12 +1146,10 @@ public class ItemHelper( /// bool Match found public bool DoesItemOrParentsIdMatch(MongoId tpl, List tplsToCheck) { - var itemDetails = GetItem(tpl); - var itemExists = itemDetails.Key; - var item = itemDetails.Value; + var (itemExists, item) = GetItem(tpl); // not an item, drop out - if (!itemExists) + if (!itemExists || item == null) { return false; } @@ -1179,7 +1177,7 @@ public class ItemHelper( /// /// Checks to see if the item is *actually* moddable in-raid. Checks include the items existence in the database, the - /// parent items existence in the database, the existence (and value) of the items RaidModdable property, and that + /// parent items existence in the database, the existence (and value) of the items `RaidModdable` property, and that /// the parents slot-required property exists, matches that of the item, and its value. /// /// The item to be checked @@ -1359,7 +1357,7 @@ public class ItemHelper( /// /// Db item template to look up Cartridge filter values from /// Valid caliber for cartridge - public string? GetRandomCompatibleCaliberTemplateId(TemplateItem item) + public MongoId? GetRandomCompatibleCaliberTemplateId(TemplateItem item) { var cartridges = item ?.Properties?.Cartridges?.FirstOrDefault() @@ -1759,7 +1757,7 @@ public class ItemHelper( } } - var itemPool = slot.Props.Filters[0].Filter ?? []; + var itemPool = slot.Props.Filters.FirstOrDefault().Filter ?? []; if (itemPool.Count == 0) { if (logger.IsLogEnabled(LogLevel.Debug)) diff --git a/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/Item.cs b/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/Item.cs index f3dd23cb..392f437b 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/Item.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Eft/Common/Tables/Item.cs @@ -137,7 +137,7 @@ public record Upd /// SPT specific property, not made by BSG /// [JsonPropertyName("sptPresetId")] - public string? SptPresetId { get; set; } + public MongoId? SptPresetId { get; set; } public UpdFaceShield? FaceShield { get; set; } diff --git a/Libraries/SPTarkov.Server.Core/Models/Eft/ItemEvent/ItemEventRouterBase.cs b/Libraries/SPTarkov.Server.Core/Models/Eft/ItemEvent/ItemEventRouterBase.cs index ab595481..32f78b92 100644 --- a/Libraries/SPTarkov.Server.Core/Models/Eft/ItemEvent/ItemEventRouterBase.cs +++ b/Libraries/SPTarkov.Server.Core/Models/Eft/ItemEvent/ItemEventRouterBase.cs @@ -106,10 +106,10 @@ public record HideoutStashItem public Dictionary? ExtensionData { get; set; } [JsonPropertyName("id")] - public string? Id { get; set; } + public MongoId Id { get; set; } [JsonPropertyName("tpl")] - public string? Template { get; set; } + public MongoId? Template { get; set; } } public record WeaponBuildChange diff --git a/Libraries/SPTarkov.Server.Core/Routers/SaveLoad/ProfileSaveLoadRouter.cs b/Libraries/SPTarkov.Server.Core/Routers/SaveLoad/ProfileSaveLoadRouter.cs index af5c2394..8306ba95 100644 --- a/Libraries/SPTarkov.Server.Core/Routers/SaveLoad/ProfileSaveLoadRouter.cs +++ b/Libraries/SPTarkov.Server.Core/Routers/SaveLoad/ProfileSaveLoadRouter.cs @@ -15,14 +15,11 @@ public class ProfileSaveLoadRouter : SaveLoadRouter public override SptProfile HandleLoad(SptProfile profile) { - if (profile.CharacterData == null) + profile.CharacterData ??= new Characters { - profile.CharacterData = new Characters - { - PmcData = new PmcData(), - ScavData = new PmcData(), - }; - } + PmcData = new PmcData(), + ScavData = new PmcData(), + }; return profile; } diff --git a/Libraries/SPTarkov.Server.Core/Services/PmcChatResponseService.cs b/Libraries/SPTarkov.Server.Core/Services/PmcChatResponseService.cs index 895cdd54..20e30949 100644 --- a/Libraries/SPTarkov.Server.Core/Services/PmcChatResponseService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/PmcChatResponseService.cs @@ -26,7 +26,6 @@ public class PmcChatResponseService( ConfigServer configServer ) { - protected GiftsConfig _giftConfig = configServer.GetConfig(); protected readonly PmcChatResponse _pmcResponsesConfig = configServer.GetConfig(); @@ -76,11 +75,6 @@ public class PmcChatResponseService( /// The bot who killed the player public void SendKillerResponse(MongoId sessionId, PmcData pmcData, Aggressor killer) { - if (killer is null) - { - return; - } - if (!randomUtil.GetChance100(_pmcResponsesConfig.Killer.ResponseChancePercent)) { return; @@ -199,7 +193,7 @@ public class PmcChatResponseService( /// Localised location name protected string GetLocationName(string locationKey) { - return localeService.GetLocaleDb()[locationKey] ?? locationKey; + return localeService.GetLocaleDb().GetValueOrDefault(locationKey, locationKey); } /// diff --git a/Libraries/SPTarkov.Server.Core/Services/ProfileMigratorService.cs b/Libraries/SPTarkov.Server.Core/Services/ProfileMigratorService.cs index 34a2be92..4eb9bf69 100644 --- a/Libraries/SPTarkov.Server.Core/Services/ProfileMigratorService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/ProfileMigratorService.cs @@ -20,8 +20,8 @@ namespace SPTarkov.Server.Core.Services public SptProfile HandlePendingMigrations(JsonObject profile) { // On the initial run, begin sorting our migrations - // This will sort it so that any non prerequisite migrations go first - // And then all of the prerequisite ones. + // This will sort it so that any non-prerequisite migrations go first + // And then all the prerequisite ones. if (!_sortedMigrations.Any()) { _sortedMigrations = SortMigrations(); @@ -63,7 +63,7 @@ namespace SPTarkov.Server.Core.Services } } - var SptReadyProfile = + var sptReadyProfile = profile.Deserialize(JsonUtil.JsonSerializerOptionsNoIndent) ?? throw new InvalidOperationException( $"Could not deserialize the profile {profileId}" @@ -71,20 +71,20 @@ namespace SPTarkov.Server.Core.Services foreach (var ranMigration in ranMigrations) { - if (ranMigration.PostMigrate(SptReadyProfile)) + if (ranMigration.PostMigrate(sptReadyProfile)) { logger.Success( $"{profileId} successfully ran profile migration: {ranMigration.MigrationName}" ); - SptReadyProfile.SptData.Migrations.Add( + sptReadyProfile.SptData.Migrations.Add( ranMigration.MigrationName, timeUtil.GetTimeStamp() ); } } - return SptReadyProfile; + return sptReadyProfile; } protected IEnumerable SortMigrations() diff --git a/Libraries/SPTarkov.Server.Core/Services/RagfairPriceService.cs b/Libraries/SPTarkov.Server.Core/Services/RagfairPriceService.cs index f04578e6..24827bc9 100644 --- a/Libraries/SPTarkov.Server.Core/Services/RagfairPriceService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/RagfairPriceService.cs @@ -229,9 +229,9 @@ public class RagfairPriceService( // Check if the item is a weapon preset. if ( item?.Upd?.SptPresetId is not null - && presetHelper.IsPresetBaseClass(item.Upd.SptPresetId, BaseClasses.WEAPON) + && presetHelper.IsPresetBaseClass(item.Upd.SptPresetId.Value, BaseClasses.WEAPON) ) - // This is a weapon preset, which has it's own price calculation that takes into account the mods in the + // This is a weapon preset, which has its own price calculation that takes into account the mods in the // preset. Since we've already calculated the price for the preset entire preset in // `getDynamicItemPrice`, we can skip the rest of the items in the offer. { @@ -281,7 +281,7 @@ public class RagfairPriceService( if ( item?.Upd?.SptPresetId is not null && offerItems is not null - && presetHelper.IsPresetBaseClass(item.Upd.SptPresetId, BaseClasses.WEAPON) + && presetHelper.IsPresetBaseClass(item.Upd.SptPresetId.Value, BaseClasses.WEAPON) ) { price = GetWeaponPresetPrice(item, offerItems, price);