Skip to content

Commit

Permalink
Merge pull request #247 from winks-vtt/fix-v11-rolls
Browse files Browse the repository at this point in the history
Fix rolls in V11 of Foundry
  • Loading branch information
AlexOkafor authored Jul 3, 2023
2 parents 7d02d61 + 2eb57a6 commit eb62811
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ module/foundry.js
foundry.js
foundry_07.js

# foundry
packs/ship-sheet-instructions/

# OS
.DS_Store
.DS_Store
.gitignore

29 changes: 17 additions & 12 deletions module/coriolis-roll.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export async function coriolisRoll(chatOptions, rollData) {
await roll.evaluate({ async: false });
await showDiceSoNice(roll, chatOptions.rollMode);
const result = evaluateCoriolisRoll(rollData, roll);
await showChatMessage(chatOptions, result);
await showChatMessage(chatOptions, result, roll);
}

/**
Expand Down Expand Up @@ -227,7 +227,7 @@ export async function coriolisPushRoll(chatMessage, origRollData, origRoll) {

await showDiceSoNice(origRoll, chatMessage.rollMode);
const result = evaluateCoriolisRoll(origRollData, origRoll);
await updateChatMessage(chatMessage, result, bonus);
await updateChatMessage(chatMessage, result, bonus, origRoll);
if (origRollData.actorType === "npc") {
await spendDarknessPoints(1);
} else {
Expand Down Expand Up @@ -295,7 +295,6 @@ export function evaluateCoriolisRoll(rollData, roll) {
criticalSuccess: successes >= 3,
failure: isDesparation ? successes < 2 : successes === 0,
rollData: rollData,
roll: roll,
pushed: rollData.pushed,
};

Expand Down Expand Up @@ -326,10 +325,10 @@ function getTotalDice(rollData) {
return 0;
}

async function showChatMessage(chatMsgOptions, resultData) {
async function showChatMessage(chatMsgOptions, resultData, roll) {
let tooltip = await renderTemplate(
"systems/yzecoriolis/templates/sidebar/dice-results.html",
getTooltipData(resultData)
getTooltipData(resultData, roll)
);
let chatData = {
title: getRollTitle(resultData.rollData),
Expand Down Expand Up @@ -366,7 +365,7 @@ async function showChatMessage(chatMsgOptions, resultData) {
else if (chatMsgOptions.rollMode === "selfroll")
chatMsgOptions["whisper"] = [game.user];

chatMsgOptions.roll = resultData.roll;
chatMsgOptions.roll = roll;
const html = await renderTemplate(chatMsgOptions.template, chatData);
chatMsgOptions["content"] = html;
const msg = await ChatMessage.create(chatMsgOptions, false);
Expand All @@ -375,10 +374,15 @@ async function showChatMessage(chatMsgOptions, resultData) {
return msg;
}

async function updateChatMessage(chatMessage, resultData, prayerBonus) {
async function updateChatMessage(
chatMessage,
resultData,
prayerBonus,
origRoll
) {
let tooltip = await renderTemplate(
"systems/yzecoriolis/templates/sidebar/dice-results.html",
getTooltipData(resultData)
getTooltipData(resultData, origRoll)
);
let chatData = {
title: getRollTitle(resultData.rollData),
Expand Down Expand Up @@ -434,13 +438,13 @@ function getRollIconKey(rollData) {
return icon ? CONFIG.YZECORIOLIS.icons[icon] : "";
}

function getTooltipData(results) {
function getTooltipData(results, roll) {
const rollData = {
formula: results.roll.formula,
formula: roll.formula,
total: results.successes,
};
// Prepare dice parts
rollData["parts"] = results.roll.dice.map((d) => {
rollData["parts"] = roll.dice.map((d) => {
let maxRoll = CONFIG.YZECORIOLIS.maxRoll;
// Generate tooltip data
return {
Expand Down Expand Up @@ -553,7 +557,8 @@ export async function coriolisChatListeners(html) {
messageId = button.parents(".message").attr("data-message-id"),
message = game.messages.get(messageId);
let results = message.getFlag("yzecoriolis", "results");
coriolisPushRoll(message, results.rollData, message.roll);
let originalRoll = message.rolls[0]; // TODO: handle this in a safer manner.
coriolisPushRoll(message, results.rollData, originalRoll);
});
}
/**
Expand Down
4 changes: 2 additions & 2 deletions system.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "yzecoriolis",
"title": "Coriolis",
"description": "Coriolis System for Foundry VTT.",
"version": "3.3.1",
"version": "3.4.0",
"compatibility": {
"minimum": "10",
"verified": "10"
"verified": "11"
},
"templateVersion": 2,
"authors": [
Expand Down

0 comments on commit eb62811

Please sign in to comment.