Converted RemapRootItemId into extension method
This commit is contained in:
@@ -1236,7 +1236,7 @@ public class HideoutController(
|
||||
// Ensure preset has unique ids and is cloned so we don't alter the preset data stored in memory
|
||||
var presetAndModsClone = _cloner.Clone(defaultPreset.Items).ReplaceIDs().ToList();
|
||||
|
||||
_itemHelper.RemapRootItemId(presetAndModsClone);
|
||||
presetAndModsClone.RemapRootItemId();
|
||||
|
||||
// Store preset items in array
|
||||
return [presetAndModsClone];
|
||||
|
||||
@@ -413,5 +413,40 @@ namespace SPTarkov.Server.Core.Extensions
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a root items _id property value to be unique
|
||||
/// </summary>
|
||||
/// <param name="itemWithChildren">Item to update root items _id property</param>
|
||||
/// <param name="newId">Optional: new id to use</param>
|
||||
/// <returns>New root id</returns>
|
||||
public static string RemapRootItemId(
|
||||
this List<Item> itemWithChildren,
|
||||
MongoId? newId = null
|
||||
)
|
||||
{
|
||||
newId ??= new MongoId();
|
||||
|
||||
var rootItemExistingId = itemWithChildren.FirstOrDefault().Id;
|
||||
|
||||
foreach (var item in itemWithChildren)
|
||||
{
|
||||
// Root, update id
|
||||
if (item.Id.Equals(rootItemExistingId))
|
||||
{
|
||||
item.Id = newId.Value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Child with parent of root, update
|
||||
if (item.ParentId == rootItemExistingId)
|
||||
{
|
||||
item.ParentId = newId.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return newId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class FenceBaseAssortGenerator(
|
||||
}
|
||||
|
||||
// Ensure IDs are unique
|
||||
itemHelper.RemapRootItemId(itemWithChildrenToAdd);
|
||||
itemWithChildrenToAdd.RemapRootItemId();
|
||||
if (itemWithChildrenToAdd.Count > 1)
|
||||
{
|
||||
itemHelper.ReparentItemAndChildren(itemWithChildrenToAdd[0], itemWithChildrenToAdd);
|
||||
|
||||
@@ -1281,7 +1281,7 @@ public class LocationLootGenerator(
|
||||
if (defaultPreset is not null)
|
||||
{
|
||||
var presetAndModsClone = _cloner.Clone(defaultPreset.Items).ReplaceIDs().ToList();
|
||||
_itemHelper.RemapRootItemId(presetAndModsClone);
|
||||
presetAndModsClone.RemapRootItemId();
|
||||
|
||||
// Use original items parentId otherwise item doesn't get added to container correctly
|
||||
presetAndModsClone.FirstOrDefault().ParentId = rootItem.ParentId;
|
||||
|
||||
@@ -500,7 +500,7 @@ public class LootGenerator(
|
||||
}
|
||||
|
||||
var presetAndModsClone = _cloner.Clone(chosenPreset.Items).ReplaceIDs().ToList();
|
||||
_itemHelper.RemapRootItemId(presetAndModsClone);
|
||||
presetAndModsClone.RemapRootItemId();
|
||||
|
||||
_itemHelper.SetFoundInRaid(presetAndModsClone);
|
||||
|
||||
@@ -568,7 +568,7 @@ public class LootGenerator(
|
||||
|
||||
// Clean up Ids to ensure they're all unique and prevent collisions
|
||||
var presetAndModsClone = _cloner.Clone(chosenWeaponPreset.Items).ReplaceIDs().ToList();
|
||||
_itemHelper.RemapRootItemId(presetAndModsClone);
|
||||
presetAndModsClone.RemapRootItemId();
|
||||
|
||||
// Add preset to return object
|
||||
itemsToReturn.Add(presetAndModsClone);
|
||||
@@ -767,7 +767,7 @@ public class LootGenerator(
|
||||
// Ensure preset has unique ids and is cloned so we don't alter the preset data stored in memory
|
||||
var presetAndMods = preset.Items.ReplaceIDs().ToList();
|
||||
|
||||
_itemHelper.RemapRootItemId(presetAndMods);
|
||||
presetAndMods.RemapRootItemId();
|
||||
itemsToReturn.Add(presetAndMods);
|
||||
|
||||
continue;
|
||||
|
||||
@@ -67,7 +67,7 @@ public class RagfairAssortGenerator(
|
||||
{
|
||||
// Update Ids and clone
|
||||
var presetAndModsClone = cloner.Clone(preset.Items).ReplaceIDs().ToList();
|
||||
itemHelper.RemapRootItemId(presetAndModsClone);
|
||||
presetAndModsClone.RemapRootItemId();
|
||||
|
||||
// Add presets base item tpl to the processed list so its skipped later on when processing items
|
||||
processedArmorItems.Add(preset.Items[0].Template);
|
||||
|
||||
@@ -405,7 +405,7 @@ public class ScavCaseRewardGenerator(
|
||||
|
||||
// Ensure preset has unique ids and is cloned so we don't alter the preset data stored in memory
|
||||
var presetAndMods = _cloner.Clone(preset.Items).ReplaceIDs().ToList();
|
||||
_itemHelper.RemapRootItemId(presetAndMods);
|
||||
presetAndMods.RemapRootItemId();
|
||||
|
||||
resultItem = presetAndMods;
|
||||
}
|
||||
|
||||
@@ -1916,39 +1916,6 @@ public class ItemHelper(
|
||||
return itemWithChildren;
|
||||
}
|
||||
|
||||
// Update a root items _id property value to be unique
|
||||
// Item to update root items _id property
|
||||
// Optional: new id to use
|
||||
// Returns New root id
|
||||
|
||||
public string RemapRootItemId(List<Item> itemWithChildren, MongoId? newId = null)
|
||||
{
|
||||
newId ??= new MongoId();
|
||||
|
||||
var rootItemExistingId = itemWithChildren[0].Id;
|
||||
|
||||
foreach (var item in itemWithChildren)
|
||||
{
|
||||
// Root, update id
|
||||
if (item.Id.Equals(rootItemExistingId))
|
||||
{
|
||||
item.Id = newId.Value;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Child with parent of root, update
|
||||
if (
|
||||
string.Equals(item.ParentId, rootItemExistingId, StringComparison.OrdinalIgnoreCase)
|
||||
)
|
||||
{
|
||||
item.ParentId = newId;
|
||||
}
|
||||
}
|
||||
|
||||
return newId;
|
||||
}
|
||||
|
||||
// Add a blank upd object to passed in item if it does not exist already
|
||||
// item to add upd to
|
||||
// text to write to log when upd object was not found
|
||||
|
||||
@@ -384,7 +384,7 @@ public class RewardHelper(
|
||||
{
|
||||
// Found preset, use mods to hydrate reward item
|
||||
var presetAndMods = _cloner.Clone(defaultPreset.Items).ReplaceIDs().ToList();
|
||||
var newRootId = _itemHelper.RemapRootItemId(presetAndMods);
|
||||
var newRootId = presetAndMods.RemapRootItemId();
|
||||
|
||||
reward.Items = presetAndMods;
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ public class TradeHelper(
|
||||
offerClone.FirstOrDefault().Upd.StackObjectsCount = itemCountToSend;
|
||||
|
||||
// Prevent any collisions
|
||||
_itemHelper.RemapRootItemId(offerClone);
|
||||
offerClone.RemapRootItemId();
|
||||
if (offerClone.Count > 1)
|
||||
{
|
||||
_itemHelper.ReparentItemAndChildren(offerClone.FirstOrDefault(), offerClone);
|
||||
|
||||
@@ -400,7 +400,7 @@ public class CircleOfCultistService(
|
||||
|
||||
// Ensure preset has unique ids and is cloned so we don't alter the preset data stored in memory
|
||||
var presetAndMods = defaultPreset.Items.ReplaceIDs().ToList();
|
||||
_itemHelper.RemapRootItemId(presetAndMods);
|
||||
presetAndMods.RemapRootItemId();
|
||||
|
||||
// Set item as FiR
|
||||
_itemHelper.SetFoundInRaid(presetAndMods);
|
||||
@@ -495,7 +495,7 @@ public class CircleOfCultistService(
|
||||
|
||||
// Ensure preset has unique ids and is cloned so we don't alter the preset data stored in memory
|
||||
var presetAndMods = defaultPreset.Items.ReplaceIDs().ToList();
|
||||
_itemHelper.RemapRootItemId(presetAndMods);
|
||||
presetAndMods.RemapRootItemId();
|
||||
|
||||
// Set item as FiR
|
||||
_itemHelper.SetFoundInRaid(presetAndMods);
|
||||
@@ -546,18 +546,18 @@ public class CircleOfCultistService(
|
||||
/// <param name="sessionId">sessionId</param>
|
||||
/// <param name="sacrificedItems">Items sacrificed</param>
|
||||
/// <returns>Direct reward items to send to player</returns>
|
||||
protected DirectRewardSettings CheckForDirectReward(
|
||||
protected DirectRewardSettings? CheckForDirectReward(
|
||||
string sessionId,
|
||||
List<Item> sacrificedItems,
|
||||
Dictionary<string, DirectRewardSettings> directRewardsCache
|
||||
)
|
||||
{
|
||||
// Get sacrificed tpls
|
||||
IEnumerable<MongoId> sacrificedItemTpls = sacrificedItems
|
||||
var sacrificedItemTpls = sacrificedItems
|
||||
.Select(item => item.Template)
|
||||
.Where(item => item != null);
|
||||
// Create md5 key of the items player sacrificed so we can compare against the direct reward cache
|
||||
string sacrificedItemsKey = CreateSacrificeCacheKey(sacrificedItemTpls);
|
||||
var sacrificedItemsKey = CreateSacrificeCacheKey(sacrificedItemTpls);
|
||||
|
||||
var matchingDirectReward = directRewardsCache.GetValueOrDefault(sacrificedItemsKey);
|
||||
if (matchingDirectReward is null)
|
||||
|
||||
@@ -862,7 +862,7 @@ public class FenceService(
|
||||
.Clone(desiredAssortItemAndChildrenClone)
|
||||
.ReplaceIDs()
|
||||
.ToList();
|
||||
itemHelper.RemapRootItemId(desiredAssortItemAndChildrenClone);
|
||||
desiredAssortItemAndChildrenClone.RemapRootItemId();
|
||||
|
||||
var rootItemBeingAdded = desiredAssortItemAndChildrenClone[0];
|
||||
|
||||
@@ -1153,7 +1153,7 @@ public class FenceService(
|
||||
presetWithChildrenClone[0],
|
||||
presetWithChildrenClone
|
||||
);
|
||||
itemHelper.RemapRootItemId(presetWithChildrenClone);
|
||||
presetWithChildrenClone.RemapRootItemId();
|
||||
|
||||
// Remapping IDs causes parentId to be altered, fix
|
||||
presetWithChildrenClone[0].ParentId = "hideout";
|
||||
@@ -1222,7 +1222,7 @@ public class FenceService(
|
||||
|
||||
// MUST randomise Ids as its possible to add the same base fence assort twice = duplicate IDs = dead client
|
||||
itemHelper.ReparentItemAndChildren(presetWithChildrenClone[0], presetWithChildrenClone);
|
||||
itemHelper.RemapRootItemId(presetWithChildrenClone);
|
||||
presetWithChildrenClone.RemapRootItemId();
|
||||
|
||||
// Remapping IDs causes parentId to be altered
|
||||
presetWithChildrenClone[0].ParentId = "hideout";
|
||||
|
||||
@@ -24,7 +24,6 @@ public class InsuranceService(
|
||||
TimeUtil _timeUtil,
|
||||
SaveServer _saveServer,
|
||||
TraderHelper _traderHelper,
|
||||
ProfileHelper _profileHelper,
|
||||
ServerLocalisationService _serverLocalisationService,
|
||||
MailSendService _mailSendService,
|
||||
ConfigServer _configServer
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using SPTarkov.Common.Extensions;
|
||||
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.Tables;
|
||||
@@ -345,7 +346,7 @@ public class RagfairOfferService(
|
||||
itemAndChildrenClone.FirstOrDefault(),
|
||||
itemAndChildrenClone
|
||||
);
|
||||
itemHelper.RemapRootItemId(reparentedItemAndChildren);
|
||||
reparentedItemAndChildren.RemapRootItemId();
|
||||
|
||||
result.AddRange(reparentedItemAndChildren);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ public class RagfairTaxService(
|
||||
DatabaseService _databaseService,
|
||||
RagfairPriceService _ragfairPriceService,
|
||||
ItemHelper _itemHelper,
|
||||
ProfileHelper _profileHelper,
|
||||
ICloner _cloner
|
||||
)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user