string to mongoId + Various small refactors
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -1146,12 +1146,10 @@ public class ItemHelper(
|
||||
/// <returns>bool Match found</returns>
|
||||
public bool DoesItemOrParentsIdMatch(MongoId tpl, List<MongoId> 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(
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to be checked</param>
|
||||
@@ -1359,7 +1357,7 @@ public class ItemHelper(
|
||||
/// </summary>
|
||||
/// <param name="item">Db item template to look up Cartridge filter values from</param>
|
||||
/// <returns>Valid caliber for cartridge</returns>
|
||||
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))
|
||||
|
||||
@@ -137,7 +137,7 @@ public record Upd
|
||||
/// SPT specific property, not made by BSG
|
||||
/// </summary>
|
||||
[JsonPropertyName("sptPresetId")]
|
||||
public string? SptPresetId { get; set; }
|
||||
public MongoId? SptPresetId { get; set; }
|
||||
|
||||
public UpdFaceShield? FaceShield { get; set; }
|
||||
|
||||
|
||||
@@ -106,10 +106,10 @@ public record HideoutStashItem
|
||||
public Dictionary<string, object>? 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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ public class PmcChatResponseService(
|
||||
ConfigServer configServer
|
||||
)
|
||||
{
|
||||
protected GiftsConfig _giftConfig = configServer.GetConfig<GiftsConfig>();
|
||||
protected readonly PmcChatResponse _pmcResponsesConfig =
|
||||
configServer.GetConfig<PmcChatResponse>();
|
||||
|
||||
@@ -76,11 +75,6 @@ public class PmcChatResponseService(
|
||||
/// <param name="killer"> The bot who killed the player </param>
|
||||
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(
|
||||
/// <returns> Localised location name </returns>
|
||||
protected string GetLocationName(string locationKey)
|
||||
{
|
||||
return localeService.GetLocaleDb()[locationKey] ?? locationKey;
|
||||
return localeService.GetLocaleDb().GetValueOrDefault(locationKey, locationKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -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<SptProfile>(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<AbstractProfileMigration> SortMigrations()
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user