From 931a28fbfe2b92e4a98a7d81f737913dd9c215fd Mon Sep 17 00:00:00 2001 From: Vlyan Date: Tue, 2 Feb 2021 09:28:46 +0100 Subject: [PATCH] -RnK dialog auto-open after a roll -Move for some roll props -2 RnK bugfix (TN & Reroll) --- system/scripts/combat.js | 21 ++++++++++++------- system/scripts/dice/dice-picker-dialog.js | 18 +++++++++++----- system/scripts/dice/roll-n-keep-dialog.js | 12 +++++------ system/scripts/dice/roll.js | 14 ++++++------- system/templates/dice/chat-roll.html | 10 +++++---- system/templates/dice/roll-n-keep-dialog.html | 6 +++--- 6 files changed, 48 insertions(+), 33 deletions(-) diff --git a/system/scripts/combat.js b/system/scripts/combat.js index 2d6d11c..730628d 100644 --- a/system/scripts/combat.js +++ b/system/scripts/combat.js @@ -78,6 +78,7 @@ export class CombatL5r5e extends Combat { } let roll; + let rnkMessage; const flavor = game.i18n.localize("l5r5e.chatdices.initiative_roll") + " (" + @@ -87,8 +88,7 @@ export class CombatL5r5e extends Combat { if (messageOptions.rnkRoll instanceof game.l5r5e.RollL5r5e && ids.length === 1) { // Specific RnK roll = messageOptions.rnkRoll; - // Ugly but work... i need the new messageId - combatant.actor.rnkMessage = await roll.toMessage({ flavor }); + rnkMessage = await roll.toMessage({ flavor }); } else { // Regular roll = new game.l5r5e.RollL5r5e(formula); @@ -97,23 +97,28 @@ export class CombatL5r5e extends Combat { roll.l5r5e.stance = data.stance; roll.l5r5e.skillId = skillId; roll.l5r5e.skillCatId = skillCat; - roll.l5r5e.summary.difficulty = + roll.l5r5e.difficulty = messageOptions.difficulty !== undefined ? messageOptions.difficulty : cfg.difficulty; - roll.l5r5e.summary.difficultyHidden = + roll.l5r5e.difficultyHidden = messageOptions.difficultyHidden !== undefined ? messageOptions.difficultyHidden : cfg.difficultyHidden; - roll.l5r5e.summary.voidPointUsed = !!messageOptions.useVoidPoint; + roll.l5r5e.voidPointUsed = !!messageOptions.useVoidPoint; roll.roll(); - roll.toMessage({ flavor }); + rnkMessage = await roll.toMessage({ flavor }); + } + + // Ugly but work... i need the new messageId + if (ids.length === 1) { + combatant.actor.rnkMessage = rnkMessage; } // if the character succeeded on their Initiative check, they add 1 to their base initiative value, // plus an additional amount equal to their bonus successes. const successes = roll.l5r5e.summary.totalSuccess; - if (successes >= roll.l5r5e.summary.difficulty) { - initiative = initiative + 1 + Math.max(successes - roll.l5r5e.summary.difficulty, 0); + if (successes >= roll.l5r5e.difficulty) { + initiative = initiative + 1 + Math.max(successes - roll.l5r5e.difficulty, 0); } } diff --git a/system/scripts/dice/dice-picker-dialog.js b/system/scripts/dice/dice-picker-dialog.js index baa594e..88236db 100644 --- a/system/scripts/dice/dice-picker-dialog.js +++ b/system/scripts/dice/dice-picker-dialog.js @@ -415,9 +415,10 @@ export class DicePickerDialog extends FormApplication { formula.push(`${this.object.skill.value}ds`); } + let message; if (this.object.isInitiativeRoll) { // Initiative roll - this._actor.rollInitiative({ + await this._actor.rollInitiative({ initiativeOptions: { formula: formula.join("+"), // updateTurn: true, @@ -429,6 +430,9 @@ export class DicePickerDialog extends FormApplication { }, }, }); + // Adhesive tape to get the messageId :/ + message = this._actor.rnkMessage; + delete this._actor.rnkMessage; } else { // Regular roll, so let's roll ! const roll = await new game.l5r5e.RollL5r5e(formula.join("+")); @@ -437,12 +441,16 @@ export class DicePickerDialog extends FormApplication { roll.l5r5e.stance = this.object.ring.id; roll.l5r5e.skillId = this.object.skill.id; roll.l5r5e.skillCatId = this.object.skill.cat; - roll.l5r5e.summary.difficulty = this.object.difficulty.value; - roll.l5r5e.summary.difficultyHidden = this.object.difficulty.hidden; - roll.l5r5e.summary.voidPointUsed = this.object.useVoidPoint; + roll.l5r5e.difficulty = this.object.difficulty.value; + roll.l5r5e.difficultyHidden = this.object.difficulty.hidden; + roll.l5r5e.voidPointUsed = this.object.useVoidPoint; await roll.roll(); - await roll.toMessage(); + message = await roll.toMessage(); + } + + if (message) { + new game.l5r5e.RollnKeepDialog(message._id).render(true); } return this.close(); diff --git a/system/scripts/dice/roll-n-keep-dialog.js b/system/scripts/dice/roll-n-keep-dialog.js index 98ab863..b7b86e7 100644 --- a/system/scripts/dice/roll-n-keep-dialog.js +++ b/system/scripts/dice/roll-n-keep-dialog.js @@ -117,7 +117,7 @@ export class RollnKeepDialog extends FormApplication { } // Get the roll - this.roll = game.l5r5e.RollL5r5e.fromData(this.message.roll); + this.roll = game.l5r5e.RollL5r5e.fromData(this.message._roll); // Already history if (Array.isArray(this.roll.l5r5e.history)) { @@ -207,7 +207,7 @@ export class RollnKeepDialog extends FormApplication { // Check only on 1st step if (this.object.currentStep === 0) { const kept = this._getKeepCount(); - this.object.submitDisabled = kept < 1 || kept > this.roll.l5r5e.summary.ringsUsed; + this.object.submitDisabled = kept < 1 || kept > this.roll.l5r5e.ringsUsed; } else if (!this.object.dicesList[this.object.currentStep]) { this.options.editable = false; } @@ -282,7 +282,7 @@ export class RollnKeepDialog extends FormApplication { current.choice = type; // Little time saving : on 1st step, if we reach the max kept dices, discard all dices without a choice - if (this.object.currentStep === 0 && this._getKeepCount() === this.roll.l5r5e.summary.ringsUsed) { + if (this.object.currentStep === 0 && this._getKeepCount() === this.roll.l5r5e.ringsUsed) { this._discardDiceWithoutChoice(); } @@ -445,7 +445,7 @@ export class RollnKeepDialog extends FormApplication { const roll = await new game.l5r5e.RollL5r5e(this._arrayToFormula(newRolls)); roll.l5r5e = { - ...this.message.roll.l5r5e, + ...this.message._roll.l5r5e, summary: roll.l5r5e.summary, }; @@ -480,7 +480,7 @@ export class RollnKeepDialog extends FormApplication { // Get all kept dices + new (choice null) const diceList = this.object.dicesList.reduce((acc, step) => { step.forEach((die) => { - if (!!die && die.choice !== RollnKeepDialog.CHOICES.discard) { + if (!!die && [RollnKeepDialog.CHOICES.keep, RollnKeepDialog.CHOICES.nothing].includes(die.choice)) { if (!acc[die.type]) { acc[die.type] = []; } @@ -493,7 +493,7 @@ export class RollnKeepDialog extends FormApplication { // Re create a new roll const roll = await new game.l5r5e.RollL5r5e(this._arrayToFormula(diceList)); roll.l5r5e = { - ...this.message.roll.l5r5e, + ...this.message._roll.l5r5e, summary: roll.l5r5e.summary, }; diff --git a/system/scripts/dice/roll.js b/system/scripts/dice/roll.js index e072c43..8bcfe18 100644 --- a/system/scripts/dice/roll.js +++ b/system/scripts/dice/roll.js @@ -13,15 +13,16 @@ export class RollL5r5e extends Roll { skillId: "", skillCatId: "", actor: null, + difficulty: 2, + difficultyHidden: false, + voidPointUsed: false, + ringsUsed: null, + isInitiativeRoll: false, dicesTypes: { std: false, l5r: false, }, summary: { - difficulty: 2, - difficultyHidden: false, - voidPointUsed: false, - ringsUsed: null, totalSuccess: 0, totalBonus: 0, success: 0, @@ -30,7 +31,6 @@ export class RollL5r5e extends Roll { strife: 0, }, history: null, - isInitiativeRoll: false, }; // Parse flavor for stance and skillId @@ -103,8 +103,8 @@ export class RollL5r5e extends Roll { (term) => term instanceof DiceTerm && !(term instanceof game.l5r5e.L5rBaseDie) ); // ignore math symbols this.l5r5e.dicesTypes.l5r = this.dice.some((term) => term instanceof game.l5r5e.L5rBaseDie); - summary.totalBonus = Math.max(0, summary.totalSuccess - summary.difficulty); - summary.ringsUsed = this.dice.reduce( + summary.totalBonus = Math.max(0, summary.totalSuccess - this.l5r5e.difficulty); + this.l5r5e.ringsUsed = this.dice.reduce( (acc, term) => (term instanceof game.l5r5e.RingDie ? acc + term.number : acc), 0 ); diff --git a/system/templates/dice/chat-roll.html b/system/templates/dice/chat-roll.html index 9a9607b..94dc5b2 100644 --- a/system/templates/dice/chat-roll.html +++ b/system/templates/dice/chat-roll.html @@ -27,12 +27,12 @@ - {{#if l5r5e.summary.difficultyHidden}} + {{#if l5r5e.difficultyHidden}} {{localize 'l5r5e.chatdices.difficulty_hidden'}} {{else}} - {{localize 'l5r5e.chatdices.difficulty'}} {{l5r5e.summary.difficulty}} + {{localize 'l5r5e.chatdices.difficulty'}} {{l5r5e.difficulty}} {{/if}} - {{#if l5r5e.summary.voidPointUsed}} + {{#if l5r5e.voidPointUsed}}
{{/if}}
@@ -78,13 +78,15 @@ {{!-- Result text --}} + {{^if ../l5r5e.difficultyHidden}}
- {{#ifCond totalSuccess '>=' difficulty}} + {{#ifCond totalSuccess '>=' ../l5r5e.difficulty}} {{localize "l5r5e.chatdices.success_text"}} ({{totalBonus}} {{localize "l5r5e.chatdices.bonus_text"}}) {{else}} {{localize "l5r5e.chatdices.fail_text"}} {{/ifCond}}
+ {{/if}} {{/l5r5e.summary}} {{/if}} diff --git a/system/templates/dice/roll-n-keep-dialog.html b/system/templates/dice/roll-n-keep-dialog.html index be72689..bd58e10 100644 --- a/system/templates/dice/roll-n-keep-dialog.html +++ b/system/templates/dice/roll-n-keep-dialog.html @@ -25,12 +25,12 @@ - {{#if l5r5e.summary.difficultyHidden}} + {{#if l5r5e.difficultyHidden}} {{localize 'l5r5e.chatdices.difficulty_hidden'}} {{else}} - {{localize 'l5r5e.chatdices.difficulty'}} {{l5r5e.summary.difficulty}} + {{localize 'l5r5e.chatdices.difficulty'}} {{l5r5e.difficulty}} {{/if}} - {{#if l5r5e.summary.voidPointUsed}} + {{#if l5r5e.voidPointUsed}}
{{/if}}