From da2d2b8beb1014f5b67272e2ddddfb3fea013ef6 Mon Sep 17 00:00:00 2001 From: p4535992 Date: Tue, 9 Apr 2024 22:38:59 +0200 Subject: [PATCH] Better brt compatbility --- src/helpers/pile-utilities.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/helpers/pile-utilities.js b/src/helpers/pile-utilities.js index bb50c337..afe58785 100644 --- a/src/helpers/pile-utilities.js +++ b/src/helpers/pile-utilities.js @@ -1964,7 +1964,13 @@ export async function rollTable({ let results = []; if (game.modules.get("better-rolltables")?.active) { - results = (await game.modules.get("better-rolltables").api.roll(table)).itemsData.map(result => ({ + const brtOptions = { + rollsAmount: roll.total, + roll: undefined, + displayChat: displayChat, + recursive: true + } + results = (await game.modules.get("better-rolltables").api.roll(table,brtOptions)).itemsData.map(result => ({ documentCollection: result.documentCollection, documentId: result.documentId, text: result.text || result.name, @@ -2003,8 +2009,13 @@ export async function rollTable({ const items = []; rolledItems.forEach(newItem => { - - const existingItem = items.find((item) => item.documentId === newItem.documentId); + const existingItem = items.find((item) => { + if (item.documentId && newItem.documentId) { + return item.documentId === newItem.documentId; + } else { + return item._id === newItem._id; + } + }); if (existingItem) { existingItem.quantity += Math.max(newItem.quantity, 1); } else { @@ -2096,7 +2107,13 @@ export async function rollMerchantTables({ tableData = false, actor = false } = } tableItems.forEach(newItem => { - const existingItem = items.find((item) => item.documentId === newItem.documentId); + const existingItem = items.find((item) => { + if (item.documentId && newItem.documentId) { + return item.documentId === newItem.documentId; + } else { + return item._id === newItem._id; + } + }); if (existingItem) { existingItem.quantity += Math.max(newItem.quantity, 1); } else { @@ -2141,4 +2158,4 @@ async function getItem(itemToGet) { } } return item; -} +} \ No newline at end of file