Skip to content

Commit

Permalink
Merge pull request #557 from p4535992/add_brt_compatiiblity
Browse files Browse the repository at this point in the history
Little fix with Better Rolltables compatibility
  • Loading branch information
Haxxer authored Apr 11, 2024
2 parents 645dcd6 + da2d2b8 commit dbc73e3
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 dbc73e3

Please sign in to comment.