Fix treasure tables
parent
e1d9c59889
commit
1d9b5a35d5
|
@ -494,7 +494,7 @@
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
background: url("/systems/acks/assets/treasure.png") no-repeat center;
|
background: url("/systems/acks/assets/treasure.png") no-repeat center;
|
||||||
background-size: cover;
|
background-size: cover;
|
||||||
padding: 5px 8px;
|
padding: 16px 8px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
filter: grayscale(1) opacity(0.5);
|
filter: grayscale(1) opacity(0.5);
|
||||||
}
|
}
|
||||||
|
@ -636,7 +636,6 @@
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
.acks.chat-card .card-content .treasure-list .treasure div {
|
.acks.chat-card .card-content .treasure-list .treasure div {
|
||||||
text-indent: 10px;
|
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,52 +25,54 @@ export const augmentTable = (table, html, data) => {
|
||||||
html.find(".sheet-footer .roll").replaceWith(roll);
|
html.find(".sheet-footer .roll").replaceWith(roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
html.find(".roll-treasure").click((ev) => {
|
html.find(".roll-treasure").click(async (event) => {
|
||||||
rollTreasure(table.object, { event: ev });
|
await rollTreasure(table.object, { event: event });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function drawTreasure(table, data) {
|
async function drawTreasure(table, data) {
|
||||||
const percent = (chance) => {
|
|
||||||
const roll = new Roll("1d100").roll();
|
|
||||||
return roll.total <= chance;
|
|
||||||
};
|
|
||||||
data.treasure = {};
|
data.treasure = {};
|
||||||
if (table.getFlag('acks', 'treasure')) {
|
if (table.getFlag('acks', 'treasure')) {
|
||||||
table.results.forEach((r) => {
|
for (const result of table.results) {
|
||||||
if (percent(r.weight)) {
|
const roll = new Roll("1d100");
|
||||||
const text = table._getResultChatText(r);
|
await roll.evaluate({async: true});
|
||||||
data.treasure[r._id] = ({
|
|
||||||
img: r.img,
|
if (roll.total <= result.data.weight) {
|
||||||
|
const text = result.getChatText();
|
||||||
|
data.treasure[result.id] = ({
|
||||||
|
img: result.img,
|
||||||
text: TextEditor.enrichHTML(text),
|
text: TextEditor.enrichHTML(text),
|
||||||
});
|
});
|
||||||
if ((r.type === CONST.TABLE_RESULT_TYPES.ENTITY) && (r.collection === "RollTable")) {
|
|
||||||
const embeddedTable = game.tables.get(r.resultId);
|
if ((result.data.type === CONST.TABLE_RESULT_TYPES.DOCUMENT)
|
||||||
drawTreasure(embeddedTable, data.treasure[r._id]);
|
&& (result.collection === "RollTable")) {
|
||||||
|
const embeddedTable = game.tables.get(result.resultId);
|
||||||
|
drawTreasure(embeddedTable, data.treasure[result.id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} else {
|
} else {
|
||||||
const results = table.roll().results;
|
const results = await table.roll().results;
|
||||||
results.forEach((s) => {
|
results.forEach((result) => {
|
||||||
const text = TextEditor.enrichHTML(table._getResultChatText(s));
|
const text = TextEditor.enrichHTML(result.getChatText());
|
||||||
data.treasure[s._id] = {img: s.img, text: text};
|
data.treasure[result.id] = {img: result.img, text: text};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function rollTreasure(table, options = {}) {
|
async function rollTreasure(table, options = {}) {
|
||||||
// Draw treasure
|
// Draw treasure
|
||||||
const data = drawTreasure(table, {});
|
const data = await drawTreasure(table, {});
|
||||||
let templateData = {
|
let templateData = {
|
||||||
treasure: data.treasure,
|
treasure: data.treasure,
|
||||||
table: table,
|
table: table,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Animation
|
// Animation
|
||||||
if (options.event) {
|
if (options.event) {
|
||||||
let results = $(event.currentTarget.parentElement)
|
let results = $(options.event.currentTarget.parentElement)
|
||||||
.prev()
|
.prev()
|
||||||
.find(".table-result");
|
.find(".table-result");
|
||||||
results.each((_, item) => {
|
results.each((_, item) => {
|
||||||
|
@ -83,7 +85,7 @@ async function rollTreasure(table, options = {}) {
|
||||||
|
|
||||||
let html = await renderTemplate(
|
let html = await renderTemplate(
|
||||||
"systems/acks/templates/chat/roll-treasure.html",
|
"systems/acks/templates/chat/roll-treasure.html",
|
||||||
templateData
|
templateData,
|
||||||
);
|
);
|
||||||
|
|
||||||
let chatData = {
|
let chatData = {
|
||||||
|
@ -93,7 +95,7 @@ async function rollTreasure(table, options = {}) {
|
||||||
|
|
||||||
let rollMode = game.settings.get("core", "rollMode");
|
let rollMode = game.settings.get("core", "rollMode");
|
||||||
if (["gmroll", "blindroll"].includes(rollMode)) chatData["whisper"] = ChatMessage.getWhisperRecipients("GM");
|
if (["gmroll", "blindroll"].includes(rollMode)) chatData["whisper"] = ChatMessage.getWhisperRecipients("GM");
|
||||||
if (rollMode === "selfroll") chatData["whisper"] = [game.user._id];
|
if (rollMode === "selfroll") chatData["whisper"] = [game.user.id];
|
||||||
if (rollMode === "blindroll") chatData["blind"] = true;
|
if (rollMode === "blindroll") chatData["blind"] = true;
|
||||||
|
|
||||||
ChatMessage.create(chatData);
|
ChatMessage.create(chatData);
|
||||||
|
|
Loading…
Reference in New Issue