From ab755aac223aaf80edfc1a12feead78ab6e9c85c Mon Sep 17 00:00:00 2001 From: sladecraven Date: Wed, 10 Aug 2022 14:41:40 +0200 Subject: [PATCH] Better roll with advantage --- modules/crucible-roll-dialog.js | 7 ++--- modules/crucible-utility.js | 45 ++++++++++++++++++++++++++---- system.json | 4 +-- templates/chat-generic-result.html | 26 +++++++++++------ 4 files changed, 62 insertions(+), 20 deletions(-) diff --git a/modules/crucible-roll-dialog.js b/modules/crucible-roll-dialog.js index 975852f..8c26219 100644 --- a/modules/crucible-roll-dialog.js +++ b/modules/crucible-roll-dialog.js @@ -67,12 +67,9 @@ export class CrucibleRollDialog extends Dialog { html.find('#rollAdvantage').change((event) => { this.rollData.rollAdvantage = event.currentTarget.value }) - /*html.find('#featDieName').change((event) => { - this.rollData.featDieName = event.currentTarget.value + html.find('#useshield').change((event) => { + this.rollData.useShield = event.currentTarget.checked }) - html.find('#featDieSL').change((event) => { - this.rollData.featDieSL = event.currentTarget.value - })*/ } } \ No newline at end of file diff --git a/modules/crucible-utility.js b/modules/crucible-utility.js index a2a9710..0f389a2 100644 --- a/modules/crucible-utility.js +++ b/modules/crucible-utility.js @@ -244,6 +244,19 @@ export class CrucibleUtility { } } + /* -------------------------------------------- */ + getSuccessResult(sum){ + ui.notifications.warn("Not implemented up to now !") + } + + /* -------------------------------------------- */ + static async processAttackDefense( rollData) { + if ( rollData.attackRollData) { + let sumSuccess = rollData.attackRollData.nbSuccess - rollData.nbSuccess + this.getSuccessResult(sumSuccess) + } + } + /* -------------------------------------------- */ static async onSocketMesssage(msg) { console.log("SOCKET MESSAGE", msg.name) @@ -328,9 +341,6 @@ export class CrucibleUtility { if (rollData.save) { startFormula = String(rollData.save.value) + "d6cs>=5" } - if (rollData.shield) { - startFormula = "1" + String(rollData.shield.data.shielddie) + "cs>=5" - } diceFormula = startFormula // skill => 2 @@ -401,6 +411,13 @@ export class CrucibleUtility { diceFormula += `- 0d8cs>=5` } + // shield => 14 + if (rollData.useShield && rollData.shield) { + diceFormula += "+ 1" + String(rollData.shield.data.shielddie) + "cs>=5" + } else { + diceFormula += " + 0d6cs>=5" + } + // Performs roll console.log("Roll formula", diceFormula) let myRoll = rollData.roll @@ -408,13 +425,27 @@ export class CrucibleUtility { myRoll = new Roll(diceFormula).roll({ async: false }) await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode")) } + rollData.rollOrder = 0 rollData.roll = myRoll rollData.nbSuccess = myRoll.total if (rollData.rollAdvantage != "none") { + + rollData.rollOrder = 1 + this.createChatWithRollMode(rollData.alias, { + content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-generic-result.html`, rollData) + }) + + rollData.rollOrder = 2 let myRoll2 = new Roll(diceFormula).roll({ async: false }) - await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode")) + await this.showDiceSoNice(myRoll2, game.settings.get("core", "rollMode")) + rollData.roll = myRoll2 // Tmp switch to display the proper results + this.createChatWithRollMode(rollData.alias, { + content: await renderTemplate(`systems/fvtt-crucible-rpg/templates/chat-generic-result.html`, rollData) + }) + rollData.roll = myRoll // Revert the tmp switch if (rollData.rollAdvantage == "roll-advantage") { if (myRoll2.total > rollData.nbSuccess) { + hasChanged = true rollData.roll = myRoll2 rollData.nbSuccess = myRoll2.total } @@ -424,7 +455,10 @@ export class CrucibleUtility { rollData.nbSuccess = myRoll2.total } } + rollData.rollOrder = 3 } + + rollData.isFirstRollAdvantage = false // Manage exp if (rollData.skill && rollData.skill.data.level > 0) { let nbSkillSuccess = rollData.roll.terms[2].total @@ -444,7 +478,8 @@ export class CrucibleUtility { // Message response this.displayDefenseMessage(rollData) - // And save the roll + // Manage defense result + this.processAttackDefense(rollData) } /* -------------------------------------------- */ diff --git a/system.json b/system.json index 67e608f..8aa7b89 100644 --- a/system.json +++ b/system.json @@ -221,8 +221,8 @@ "templateVersion": 14, "title": "Crucible RPG", "manifest": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg/raw/master/system.json", - "download": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg/archive/fvtt-crucible-rpg-v0.1.25.zip", + "download": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg/archive/fvtt-crucible-rpg-v0.1.26.zip", "url": "https://www.uberwald.me/gitea/public/fvtt-crucible-rpg", - "version": "0.1.25", + "version": "0.1.26", "background" : "./images/ui/crucible_welcome_page.webp" } diff --git a/templates/chat-generic-result.html b/templates/chat-generic-result.html index 2f38209..46f77cd 100644 --- a/templates/chat-generic-result.html +++ b/templates/chat-generic-result.html @@ -18,16 +18,18 @@