Skip to content

Commit

Permalink
Better brt compatbility
Browse files Browse the repository at this point in the history
  • Loading branch information
p4535992 committed Apr 9, 2024
1 parent 645dcd6 commit da2d2b8
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/helpers/pile-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -2141,4 +2158,4 @@ async function getItem(itemToGet) {
}
}
return item;
}
}

0 comments on commit da2d2b8

Please sign in to comment.