Enhance findAndReturnChildrenAsItems
with the ability to filter out stored child objects
This commit is contained in:
parent
2e6574c917
commit
054aea23e0
@ -403,12 +403,12 @@ export class ItemHelper
|
|||||||
* A variant of findAndReturnChildren where the output is list of item objects instead of their ids.
|
* A variant of findAndReturnChildren where the output is list of item objects instead of their ids.
|
||||||
* @param items Array of items (item + possible children)
|
* @param items Array of items (item + possible children)
|
||||||
* @param baseItemId Parent items id
|
* @param baseItemId Parent items id
|
||||||
|
* @param modsOnly Include only mod items, exclude items stored inside root item
|
||||||
* @returns An array of Item objects
|
* @returns An array of Item objects
|
||||||
*/
|
*/
|
||||||
public findAndReturnChildrenAsItems(items: Item[], baseItemId: string): Item[]
|
public findAndReturnChildrenAsItems(items: Item[], baseItemId: string, modsOnly = false): Item[]
|
||||||
{
|
{
|
||||||
const list: Item[] = [];
|
const list: Item[] = [];
|
||||||
|
|
||||||
for (const childItem of items)
|
for (const childItem of items)
|
||||||
{
|
{
|
||||||
// Include itself
|
// Include itself
|
||||||
@ -418,6 +418,13 @@ export class ItemHelper
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Is stored in parent and disallowed
|
||||||
|
if (modsOnly && childItem.location)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Items parentid matches root item AND returned items doesnt contain current child
|
||||||
if (childItem.parentId === baseItemId && !list.find((item) => childItem._id === item._id))
|
if (childItem.parentId === baseItemId && !list.find((item) => childItem._id === item._id))
|
||||||
{
|
{
|
||||||
list.push(...this.findAndReturnChildrenAsItems(items, childItem._id));
|
list.push(...this.findAndReturnChildrenAsItems(items, childItem._id));
|
||||||
|
@ -265,7 +265,7 @@ export class InsuranceService
|
|||||||
pmcData: pmcData,
|
pmcData: pmcData,
|
||||||
itemsToReturnToPlayer: this.getInsuredItemDetails(
|
itemsToReturnToPlayer: this.getInsuredItemDetails(
|
||||||
pmcData,
|
pmcData,
|
||||||
this.itemHelper.findAndReturnChildrenAsItems(Object.values(preRaidGearHash), preRaidItem._id),
|
this.itemHelper.findAndReturnChildrenAsItems(Object.values(preRaidGearHash), preRaidItem._id, true),
|
||||||
offraidData.insurance,
|
offraidData.insurance,
|
||||||
),
|
),
|
||||||
traderId: insuredItem.tid,
|
traderId: insuredItem.tid,
|
||||||
|
Loading…
Reference in New Issue
Block a user