Rename method to GetItemWithChildren
This commit is contained in:
@@ -410,7 +410,7 @@ public class InsuranceController(
|
||||
if (parentAttachmentsMap.ContainsKey(insuredItem.Id))
|
||||
{
|
||||
// This call will also return the parent item itself, queueing it for deletion as well.
|
||||
var itemAndChildren = insured.Items.FindAndReturnChildrenAsItems(
|
||||
var itemAndChildren = insured.Items.GetItemWithChildren(
|
||||
insuredItem.Id
|
||||
);
|
||||
foreach (var item in itemAndChildren)
|
||||
|
||||
@@ -299,7 +299,7 @@ public class ProfileController(
|
||||
foreach (var rootItems in hideoutRootItems)
|
||||
{
|
||||
// Check each root items for children and add
|
||||
var itemWithChildren = profileToViewPmc.Inventory.Items.FindAndReturnChildrenAsItems(
|
||||
var itemWithChildren = profileToViewPmc.Inventory.Items.GetItemWithChildren(
|
||||
rootItems.Id
|
||||
);
|
||||
itemsToReturn.AddRange(itemWithChildren);
|
||||
|
||||
@@ -312,9 +312,7 @@ public class QuestController(
|
||||
else
|
||||
{
|
||||
// Remove item with children
|
||||
var toRemove = pmcData.Inventory.Items.FindAndReturnChildrenByItems(
|
||||
itemHandover.Id
|
||||
);
|
||||
var toRemove = pmcData.Inventory.Items.GetItemWithChildrenTpls(itemHandover.Id);
|
||||
var index = pmcData.Inventory.Items.Count;
|
||||
|
||||
// Important: don't tell the client to remove the attachments, it will handle it
|
||||
@@ -335,7 +333,7 @@ public class QuestController(
|
||||
// element `location` properties of the parent so they are sequential, while retaining order
|
||||
if (removedItem.Location?.GetType() == typeof(int))
|
||||
{
|
||||
var childItems = pmcData.Inventory.Items.FindAndReturnChildrenAsItems(
|
||||
var childItems = pmcData.Inventory.Items.GetItemWithChildren(
|
||||
removedItem.ParentId
|
||||
);
|
||||
childItems.RemoveAt(0); // Remove the parent
|
||||
|
||||
@@ -591,7 +591,7 @@ public class RagfairController(
|
||||
|
||||
// multi-offers are all the same item,
|
||||
// Get first item and its children and use as template
|
||||
var inventoryItems = pmcData.Inventory.Items.FindAndReturnChildrenAsItems(
|
||||
var inventoryItems = pmcData.Inventory.Items.GetItemWithChildren(
|
||||
firstOfferItemId // Choose first item as they're all the same item
|
||||
);
|
||||
|
||||
@@ -707,7 +707,7 @@ public class RagfairController(
|
||||
|
||||
// multi-offers are all the same item,
|
||||
// Get first item and its children and use as template
|
||||
var firstInventoryItemAndChildren = pmcData.Inventory.Items.FindAndReturnChildrenAsItems(
|
||||
var firstInventoryItemAndChildren = pmcData.Inventory.Items.GetItemWithChildren(
|
||||
offerRequest.Items.FirstOrDefault()
|
||||
);
|
||||
|
||||
@@ -1090,7 +1090,7 @@ public class RagfairController(
|
||||
|
||||
rootItem.FixItemStackCount();
|
||||
|
||||
itemsToReturn.Add(pmcData.Inventory.Items.FindAndReturnChildrenAsItems(itemId));
|
||||
itemsToReturn.Add(pmcData.Inventory.Items.GetItemWithChildren(itemId));
|
||||
}
|
||||
|
||||
if (itemsToReturn.Count == 0)
|
||||
|
||||
@@ -341,7 +341,7 @@ public class TradeController(
|
||||
TraderBase traderDetails
|
||||
)
|
||||
{
|
||||
var itemWithChildren = items.FindAndReturnChildrenAsItems(parentItemId);
|
||||
var itemWithChildren = items.GetItemWithChildren(parentItemId);
|
||||
|
||||
var totalPrice = 0;
|
||||
foreach (var itemToSell in itemWithChildren)
|
||||
|
||||
@@ -199,7 +199,7 @@ namespace SPTarkov.Server.Core.Extensions
|
||||
/// <param name="items">List of items (item + possible children)</param>
|
||||
/// <param name="baseItemId">Parent item's id</param>
|
||||
/// <returns>list of child item ids</returns>
|
||||
public static List<MongoId> FindAndReturnChildrenByItems(
|
||||
public static List<MongoId> GetItemWithChildrenTpls(
|
||||
this IEnumerable<Item> items,
|
||||
MongoId baseItemId
|
||||
)
|
||||
@@ -210,7 +210,7 @@ namespace SPTarkov.Server.Core.Extensions
|
||||
{
|
||||
if (childItem.ParentId == baseItemId.ToString())
|
||||
{
|
||||
list.AddRange(FindAndReturnChildrenByItems(items, childItem.Id));
|
||||
list.AddRange(GetItemWithChildrenTpls(items, childItem.Id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,16 +267,16 @@ namespace SPTarkov.Server.Core.Extensions
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A variant of FindAndReturnChildren where the output is list of item objects instead of their ids.
|
||||
/// Get an item with its attachments (children)
|
||||
/// </summary>
|
||||
/// <param name="items">List of items (item + possible children)</param>
|
||||
/// <param name="baseItemId">Parent item's id</param>
|
||||
/// <param name="modsOnly">OPTIONAL - Include only mod items, exclude items stored inside root item</param>
|
||||
/// <param name="excludeStoredItems">OPTIONAL - Include only mod items, exclude items stored inside root item</param>
|
||||
/// <returns>list of Item objects</returns>
|
||||
public static List<Item> FindAndReturnChildrenAsItems(
|
||||
public static List<Item> GetItemWithChildren(
|
||||
this IEnumerable<Item> items,
|
||||
MongoId baseItemId,
|
||||
bool modsOnly = false
|
||||
bool excludeStoredItems = false
|
||||
)
|
||||
{
|
||||
// Use dictionary to make key lookup faster, convert to list before being returned
|
||||
@@ -308,13 +308,13 @@ namespace SPTarkov.Server.Core.Extensions
|
||||
}
|
||||
|
||||
// Is stored in parent and disallowed
|
||||
if (modsOnly && item.Location is not null)
|
||||
if (excludeStoredItems && item.Location is not null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Item may have children, check
|
||||
foreach (var subItem in FindAndReturnChildrenAsItems(itemList, item.Id))
|
||||
foreach (var subItem in GetItemWithChildren(itemList, item.Id))
|
||||
{
|
||||
result.Add(subItem.Id, subItem);
|
||||
}
|
||||
@@ -375,7 +375,7 @@ namespace SPTarkov.Server.Core.Extensions
|
||||
return [];
|
||||
}
|
||||
|
||||
var itemsInSecureContainer = items.FindAndReturnChildrenByItems(secureContainer.Id);
|
||||
var itemsInSecureContainer = items.GetItemWithChildrenTpls(secureContainer.Id);
|
||||
|
||||
// Return all items returned and exclude the secure container item itself
|
||||
return itemsInSecureContainer.Where(x => x != secureContainer.Id).ToList();
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace SPTarkov.Server.Core.Extensions
|
||||
assort.LoyalLevelItems.Remove(itemId);
|
||||
|
||||
// The item being removed may have children linked to it, find and remove them too
|
||||
var idsToRemove = assort.Items.FindAndReturnChildrenByItems(itemId);
|
||||
var idsToRemove = assort.Items.GetItemWithChildrenTpls(itemId);
|
||||
assort.Items.RemoveAll(item => idsToRemove.Contains(item.Id));
|
||||
|
||||
return assort;
|
||||
|
||||
@@ -1170,7 +1170,7 @@ public class LocationLootGenerator(
|
||||
{
|
||||
// Also used by armors to get child mods
|
||||
// Get item + children and add into array we return
|
||||
var itemWithChildren = lootItems.FindAndReturnChildrenAsItems(chosenItem.Id);
|
||||
var itemWithChildren = lootItems.GetItemWithChildren(chosenItem.Id);
|
||||
|
||||
// Ensure all IDs are unique
|
||||
itemWithChildren = _cloner.Clone(itemWithChildren).ReplaceIDs().ToList();
|
||||
|
||||
@@ -735,7 +735,7 @@ public class BotGeneratorHelper(
|
||||
// Check item in container for children, store for later insertion into `containerItemsToCheck`
|
||||
// (used later when figuring out how much space weapon takes up)
|
||||
List<Item> itemsToFilter = [.. itemsWithoutLocation, rootItem];
|
||||
var itemWithChildItems = itemsToFilter.FindAndReturnChildrenAsItems(rootItem.Id);
|
||||
var itemWithChildItems = itemsToFilter.GetItemWithChildren(rootItem.Id);
|
||||
|
||||
// Item had children, replace existing data with item + its children
|
||||
result.AddRange(itemWithChildItems);
|
||||
|
||||
@@ -80,12 +80,12 @@ public class InRaidHelper(
|
||||
);
|
||||
|
||||
// Get all items that have a parent of `serverProfile.Inventory.equipment` (All items player had on them at end of raid)
|
||||
var postRaidInventoryItems = postRaidProfile.Inventory.Items.FindAndReturnChildrenAsItems(
|
||||
var postRaidInventoryItems = postRaidProfile.Inventory.Items.GetItemWithChildren(
|
||||
postRaidProfile.Inventory.Equipment.Value
|
||||
);
|
||||
|
||||
// Get all items that have a parent of `serverProfile.Inventory.questRaidItems` (Quest items player had on them at end of raid)
|
||||
var postRaidQuestItems = postRaidProfile.Inventory.Items.FindAndReturnChildrenAsItems(
|
||||
var postRaidQuestItems = postRaidProfile.Inventory.Items.GetItemWithChildren(
|
||||
postRaidProfile.Inventory.QuestRaidItems.Value
|
||||
);
|
||||
|
||||
|
||||
@@ -492,7 +492,7 @@ public class InventoryHelper(
|
||||
}
|
||||
|
||||
// Get children of item, they get deleted too
|
||||
var itemAndChildrenToRemove = profile.Inventory.Items.FindAndReturnChildrenAsItems(itemId);
|
||||
var itemAndChildrenToRemove = profile.Inventory.Items.GetItemWithChildren(itemId);
|
||||
if (!itemAndChildrenToRemove.Any())
|
||||
{
|
||||
if (logger.IsLogEnabled(LogLevel.Debug))
|
||||
@@ -569,7 +569,7 @@ public class InventoryHelper(
|
||||
if (messageWithReward is not null)
|
||||
{
|
||||
// Find item + any possible children and remove them from mails items array
|
||||
var itemWithChildren = messageWithReward.Items.Data.FindAndReturnChildrenAsItems(
|
||||
var itemWithChildren = messageWithReward.Items.Data.GetItemWithChildren(
|
||||
removeRequest.Item
|
||||
);
|
||||
foreach (var itemToDelete in itemWithChildren)
|
||||
@@ -626,7 +626,7 @@ public class InventoryHelper(
|
||||
}
|
||||
|
||||
// Goal is to keep removing items until we can remove part of an items stack
|
||||
var itemsToReduce = pmcData.Inventory.Items.FindAndReturnChildrenAsItems(itemId);
|
||||
var itemsToReduce = pmcData.Inventory.Items.GetItemWithChildren(itemId);
|
||||
var remainingCount = countToRemove;
|
||||
foreach (var itemToReduce in itemsToReduce)
|
||||
{
|
||||
@@ -1139,7 +1139,7 @@ public class InventoryHelper(
|
||||
HandleCartridgeMove(sourceItems, request);
|
||||
|
||||
// Get all children item has, they need to move with item
|
||||
var idsToMove = sourceItems.FindAndReturnChildrenByItems(request.Item.Value);
|
||||
var idsToMove = sourceItems.GetItemWithChildrenTpls(request.Item.Value);
|
||||
foreach (var itemId in idsToMove)
|
||||
{
|
||||
var itemToMove = sourceItems.FirstOrDefault(item => item.Id == itemId);
|
||||
|
||||
@@ -1313,7 +1313,7 @@ public class ItemHelper(
|
||||
var forcedLeft = 0;
|
||||
var forcedRight = 0;
|
||||
|
||||
var children = items.FindAndReturnChildrenAsItems(rootItemId);
|
||||
var children = items.GetItemWithChildren(rootItemId);
|
||||
foreach (var child in children)
|
||||
{
|
||||
var itemTemplate = GetItem(child.Template).Value;
|
||||
|
||||
@@ -373,9 +373,7 @@ public class ProfileHelper(
|
||||
if (secureContainer is not null)
|
||||
{
|
||||
// Find and remove container + children
|
||||
var childItemsInSecureContainer = items.FindAndReturnChildrenByItems(
|
||||
secureContainer.Id
|
||||
);
|
||||
var childItemsInSecureContainer = items.GetItemWithChildrenTpls(secureContainer.Id);
|
||||
|
||||
// Remove child items + secure container
|
||||
profile.Inventory.Items = items
|
||||
@@ -646,7 +644,7 @@ public class ProfileHelper(
|
||||
foreach (var itemId in profile.Inventory?.FavoriteItems ?? [])
|
||||
{
|
||||
// When viewing another users profile, the client expects a full item with children, so get that
|
||||
var itemAndChildren = profile.Inventory.Items.FindAndReturnChildrenAsItems(itemId);
|
||||
var itemAndChildren = profile.Inventory.Items.GetItemWithChildren(itemId);
|
||||
if (itemAndChildren?.Count > 0)
|
||||
{
|
||||
// To get the client to actually see the items, we set the main item's parent to null, so it's treated as a root item
|
||||
|
||||
@@ -154,7 +154,7 @@ public class TradeHelper(
|
||||
return;
|
||||
}
|
||||
|
||||
offerItems = fenceItems.FindAndReturnChildrenAsItems(buyRequestData.ItemId);
|
||||
offerItems = fenceItems.GetItemWithChildren(buyRequestData.ItemId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -222,7 +222,7 @@ public class TradeHelper(
|
||||
.Items;
|
||||
|
||||
// Get item + children for purchase
|
||||
var relevantItems = traderItems.FindAndReturnChildrenAsItems(buyRequestData.ItemId);
|
||||
var relevantItems = traderItems.GetItemWithChildren(buyRequestData.ItemId);
|
||||
if (relevantItems.Count == 0)
|
||||
{
|
||||
logger.Error(
|
||||
|
||||
@@ -188,7 +188,7 @@ public record WalletLootSettings
|
||||
/// What wallets will have money in them
|
||||
/// </summary>
|
||||
[JsonPropertyName("walletTplPool")]
|
||||
public required List<string> WalletTplPool { get; set; }
|
||||
public required List<MongoId> WalletTplPool { get; set; }
|
||||
}
|
||||
|
||||
public record EquipmentFilters
|
||||
|
||||
@@ -333,7 +333,7 @@ public class CircleOfCultistService(
|
||||
List<Item> sacrificedItems = [];
|
||||
foreach (var rootItem in inventoryRootItemsInCultistGrid)
|
||||
{
|
||||
var rootItemWithChildren = pmcData.Inventory.Items.FindAndReturnChildrenAsItems(
|
||||
var rootItemWithChildren = pmcData.Inventory.Items.GetItemWithChildren(
|
||||
rootItem.Id
|
||||
);
|
||||
sacrificedItems.AddRange(rootItemWithChildren);
|
||||
|
||||
@@ -146,7 +146,7 @@ public class FenceService(
|
||||
{
|
||||
// HUGE THANKS TO LACYWAY AND LEAVES FOR PROVIDING THIS SOLUTION FOR SPT TO IMPLEMENT!!
|
||||
// Copy the item and its children
|
||||
var clonedItems = _cloner.Clone(items.FindAndReturnChildrenAsItems(mainItem.Id));
|
||||
var clonedItems = _cloner.Clone(items.GetItemWithChildren(mainItem.Id));
|
||||
// I BLAME LACY FOR THIS ISSUE, I SPENT HOURS FIXING IT /s
|
||||
// i think on node the one with hideout usually came first
|
||||
var root = clonedItems.FirstOrDefault(x => x.SlotId == "hideout");
|
||||
@@ -422,7 +422,7 @@ public class FenceService(
|
||||
// Check if same type of item exists + its on list of item types to always stack
|
||||
if (existingRootItem != null && ItemInPreventDupeCategoryList(newRootItem.Template))
|
||||
{
|
||||
var existingFullItemTree = existingFenceAssorts.Items.FindAndReturnChildrenAsItems(
|
||||
var existingFullItemTree = existingFenceAssorts.Items.GetItemWithChildren(
|
||||
existingRootItem.Id
|
||||
);
|
||||
if (
|
||||
@@ -578,7 +578,7 @@ public class FenceService(
|
||||
}
|
||||
|
||||
// Remove item + child mods (if any)
|
||||
var itemWithChildren = assort.Items.FindAndReturnChildrenAsItems(rootItemToAdjust.Id);
|
||||
var itemWithChildren = assort.Items.GetItemWithChildren(rootItemToAdjust.Id);
|
||||
foreach (var itemToDelete in itemWithChildren)
|
||||
// Delete item from assort items array
|
||||
{
|
||||
@@ -857,7 +857,7 @@ public class FenceService(
|
||||
// MUST randomise Ids as its possible to add the same base fence assort twice = duplicate IDs = dead client
|
||||
var desiredAssortItemAndChildrenClone = _cloner
|
||||
.Clone(
|
||||
childItemsAndSingleRoot.FindAndReturnChildrenAsItems(chosenBaseAssortRoot.Id)
|
||||
childItemsAndSingleRoot.GetItemWithChildren(chosenBaseAssortRoot.Id)
|
||||
)
|
||||
.ReplaceIDs()
|
||||
.ToList();
|
||||
@@ -1112,7 +1112,7 @@ public class FenceService(
|
||||
var rootItemDb = itemHelper.GetItem(randomPresetRoot.Template).Value;
|
||||
|
||||
var presetWithChildrenClone = _cloner.Clone(
|
||||
baseFenceAssort.Items.FindAndReturnChildrenAsItems(randomPresetRoot.Id)
|
||||
baseFenceAssort.Items.GetItemWithChildren(randomPresetRoot.Id)
|
||||
);
|
||||
|
||||
RandomiseItemUpdProperties(rootItemDb, presetWithChildrenClone[0]);
|
||||
@@ -1192,7 +1192,7 @@ public class FenceService(
|
||||
var rootItemDb = itemHelper.GetItem(randomPresetRoot.Template).Value;
|
||||
|
||||
var presetWithChildrenClone = _cloner.Clone(
|
||||
baseFenceAssort.Items.FindAndReturnChildrenAsItems(randomPresetRoot.Id)
|
||||
baseFenceAssort.Items.GetItemWithChildren(randomPresetRoot.Id)
|
||||
);
|
||||
|
||||
// Need to add mods to armors so they don't show as red in the trade screen
|
||||
@@ -1488,7 +1488,7 @@ public class FenceService(
|
||||
}
|
||||
|
||||
// Remove item and its sub-items to prevent orphans
|
||||
toDelete.UnionWith(itemAndMods.FindAndReturnChildrenByItems(itemMod.Id));
|
||||
toDelete.UnionWith(itemAndMods.GetItemWithChildrenTpls(itemMod.Id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1790,7 +1790,7 @@ public class FenceService(
|
||||
protected void DeleteOffer(MongoId assortId, List<Item> assorts)
|
||||
{
|
||||
// Assort could have child items, remove those too
|
||||
var itemWithChildrenToRemove = assorts.FindAndReturnChildrenAsItems(assortId);
|
||||
var itemWithChildrenToRemove = assorts.GetItemWithChildren(assortId);
|
||||
foreach (var itemToRemove in itemWithChildrenToRemove)
|
||||
{
|
||||
var indexToRemove = assorts.FindIndex(item => item.Id == itemToRemove.Id);
|
||||
|
||||
@@ -164,7 +164,7 @@ public class RagfairTaxService(
|
||||
if (isRootItem)
|
||||
{
|
||||
// Since we get a flat list of all child items, we only want to recurse from parent item
|
||||
var itemChildren = pmcData.Inventory.Items.FindAndReturnChildrenAsItems(item.Id);
|
||||
var itemChildren = pmcData.Inventory.Items.GetItemWithChildren(item.Id);
|
||||
if (itemChildren.Count > 1)
|
||||
{
|
||||
var itemChildrenClone = cloner.Clone(itemChildren); // Clone is expensive, only run if necessary
|
||||
|
||||
@@ -12,7 +12,7 @@ public class ItemTests
|
||||
public void Initialize() { }
|
||||
|
||||
[Test]
|
||||
public void FindAndReturnChildrenAsItems_one_child_mods_only()
|
||||
public void GetItemWithChildren_one_child_mods_only()
|
||||
{
|
||||
var testData = new List<Item>();
|
||||
var rootItem = new Item
|
||||
@@ -29,13 +29,13 @@ public class ItemTests
|
||||
testData.Add(rootItem);
|
||||
testData.Add(childItem);
|
||||
|
||||
var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true);
|
||||
var result = testData.GetItemWithChildren(rootItem.Id, true);
|
||||
|
||||
Assert.AreEqual(result[1].Id, childItem.Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindAndReturnChildrenAsItems_mods_only_one_inventory_item()
|
||||
public void GetItemWithChildren_mods_only_one_inventory_item()
|
||||
{
|
||||
var testData = new List<Item>();
|
||||
var rootItem = new Item
|
||||
@@ -60,14 +60,14 @@ public class ItemTests
|
||||
testData.Add(childItem);
|
||||
testData.Add(childItem2);
|
||||
|
||||
var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true);
|
||||
var result = testData.GetItemWithChildren(rootItem.Id, true);
|
||||
|
||||
Assert.AreEqual(result[1].Id, childItem2.Id);
|
||||
Assert.AreEqual(result.Count, 2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindAndReturnChildrenAsItems_mods_and_inventory_item()
|
||||
public void GetItemWithChildren_mods_and_inventory_item()
|
||||
{
|
||||
var testData = new List<Item>();
|
||||
var rootItem = new Item
|
||||
@@ -92,14 +92,14 @@ public class ItemTests
|
||||
testData.Add(childItem);
|
||||
testData.Add(childItem2);
|
||||
|
||||
var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, false);
|
||||
var result = testData.GetItemWithChildren(rootItem.Id, false);
|
||||
|
||||
Assert.AreEqual(result[1].Id, childItem.Id);
|
||||
Assert.AreEqual(result.Count, 3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindAndReturnChildrenAsItems_mod_with_child()
|
||||
public void GetItemWithChildren_mod_with_child()
|
||||
{
|
||||
var testData = new List<Item>();
|
||||
var rootItem = new Item
|
||||
@@ -123,14 +123,14 @@ public class ItemTests
|
||||
testData.Add(childItem);
|
||||
testData.Add(childOfChild);
|
||||
|
||||
var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true);
|
||||
var result = testData.GetItemWithChildren(rootItem.Id, true);
|
||||
|
||||
Assert.AreEqual(result[1].Id, childItem.Id);
|
||||
Assert.AreEqual(result.Count, 3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FindAndReturnChildrenAsItems_no_matching_children()
|
||||
public void GetItemWithChildren_no_matching_children()
|
||||
{
|
||||
var testData = new List<Item>();
|
||||
var rootItem = new Item
|
||||
@@ -154,7 +154,7 @@ public class ItemTests
|
||||
testData.Add(childItem);
|
||||
testData.Add(childOfChild);
|
||||
|
||||
var result = testData.FindAndReturnChildrenAsItems(rootItem.Id, true);
|
||||
var result = testData.GetItemWithChildren(rootItem.Id, true);
|
||||
|
||||
Assert.AreEqual(result[0].Id, rootItem.Id);
|
||||
Assert.AreEqual(result.Count, 1);
|
||||
|
||||
Reference in New Issue
Block a user