-RnK dialog auto-open after a roll

-Move for some roll props
-2 RnK bugfix (TN & Reroll)
This commit is contained in:
Vlyan
2021-02-02 09:28:46 +01:00
parent 4350506e09
commit 931a28fbfe
6 changed files with 48 additions and 33 deletions

View File

@@ -78,6 +78,7 @@ export class CombatL5r5e extends Combat {
} }
let roll; let roll;
let rnkMessage;
const flavor = const flavor =
game.i18n.localize("l5r5e.chatdices.initiative_roll") + 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) { if (messageOptions.rnkRoll instanceof game.l5r5e.RollL5r5e && ids.length === 1) {
// Specific RnK // Specific RnK
roll = messageOptions.rnkRoll; roll = messageOptions.rnkRoll;
// Ugly but work... i need the new messageId rnkMessage = await roll.toMessage({ flavor });
combatant.actor.rnkMessage = await roll.toMessage({ flavor });
} else { } else {
// Regular // Regular
roll = new game.l5r5e.RollL5r5e(formula); roll = new game.l5r5e.RollL5r5e(formula);
@@ -97,23 +97,28 @@ export class CombatL5r5e extends Combat {
roll.l5r5e.stance = data.stance; roll.l5r5e.stance = data.stance;
roll.l5r5e.skillId = skillId; roll.l5r5e.skillId = skillId;
roll.l5r5e.skillCatId = skillCat; roll.l5r5e.skillCatId = skillCat;
roll.l5r5e.summary.difficulty = roll.l5r5e.difficulty =
messageOptions.difficulty !== undefined ? messageOptions.difficulty : cfg.difficulty; messageOptions.difficulty !== undefined ? messageOptions.difficulty : cfg.difficulty;
roll.l5r5e.summary.difficultyHidden = roll.l5r5e.difficultyHidden =
messageOptions.difficultyHidden !== undefined messageOptions.difficultyHidden !== undefined
? messageOptions.difficultyHidden ? messageOptions.difficultyHidden
: cfg.difficultyHidden; : cfg.difficultyHidden;
roll.l5r5e.summary.voidPointUsed = !!messageOptions.useVoidPoint; roll.l5r5e.voidPointUsed = !!messageOptions.useVoidPoint;
roll.roll(); 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, // 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. // plus an additional amount equal to their bonus successes.
const successes = roll.l5r5e.summary.totalSuccess; const successes = roll.l5r5e.summary.totalSuccess;
if (successes >= roll.l5r5e.summary.difficulty) { if (successes >= roll.l5r5e.difficulty) {
initiative = initiative + 1 + Math.max(successes - roll.l5r5e.summary.difficulty, 0); initiative = initiative + 1 + Math.max(successes - roll.l5r5e.difficulty, 0);
} }
} }

View File

@@ -415,9 +415,10 @@ export class DicePickerDialog extends FormApplication {
formula.push(`${this.object.skill.value}ds`); formula.push(`${this.object.skill.value}ds`);
} }
let message;
if (this.object.isInitiativeRoll) { if (this.object.isInitiativeRoll) {
// Initiative roll // Initiative roll
this._actor.rollInitiative({ await this._actor.rollInitiative({
initiativeOptions: { initiativeOptions: {
formula: formula.join("+"), formula: formula.join("+"),
// updateTurn: true, // 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 { } else {
// Regular roll, so let's roll ! // Regular roll, so let's roll !
const roll = await new game.l5r5e.RollL5r5e(formula.join("+")); 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.stance = this.object.ring.id;
roll.l5r5e.skillId = this.object.skill.id; roll.l5r5e.skillId = this.object.skill.id;
roll.l5r5e.skillCatId = this.object.skill.cat; roll.l5r5e.skillCatId = this.object.skill.cat;
roll.l5r5e.summary.difficulty = this.object.difficulty.value; roll.l5r5e.difficulty = this.object.difficulty.value;
roll.l5r5e.summary.difficultyHidden = this.object.difficulty.hidden; roll.l5r5e.difficultyHidden = this.object.difficulty.hidden;
roll.l5r5e.summary.voidPointUsed = this.object.useVoidPoint; roll.l5r5e.voidPointUsed = this.object.useVoidPoint;
await roll.roll(); await roll.roll();
await roll.toMessage(); message = await roll.toMessage();
}
if (message) {
new game.l5r5e.RollnKeepDialog(message._id).render(true);
} }
return this.close(); return this.close();

View File

@@ -117,7 +117,7 @@ export class RollnKeepDialog extends FormApplication {
} }
// Get the roll // Get the roll
this.roll = game.l5r5e.RollL5r5e.fromData(this.message.roll); this.roll = game.l5r5e.RollL5r5e.fromData(this.message._roll);
// Already history // Already history
if (Array.isArray(this.roll.l5r5e.history)) { if (Array.isArray(this.roll.l5r5e.history)) {
@@ -207,7 +207,7 @@ export class RollnKeepDialog extends FormApplication {
// Check only on 1st step // Check only on 1st step
if (this.object.currentStep === 0) { if (this.object.currentStep === 0) {
const kept = this._getKeepCount(); 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]) { } else if (!this.object.dicesList[this.object.currentStep]) {
this.options.editable = false; this.options.editable = false;
} }
@@ -282,7 +282,7 @@ export class RollnKeepDialog extends FormApplication {
current.choice = type; current.choice = type;
// Little time saving : on 1st step, if we reach the max kept dices, discard all dices without a choice // 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(); this._discardDiceWithoutChoice();
} }
@@ -445,7 +445,7 @@ export class RollnKeepDialog extends FormApplication {
const roll = await new game.l5r5e.RollL5r5e(this._arrayToFormula(newRolls)); const roll = await new game.l5r5e.RollL5r5e(this._arrayToFormula(newRolls));
roll.l5r5e = { roll.l5r5e = {
...this.message.roll.l5r5e, ...this.message._roll.l5r5e,
summary: roll.l5r5e.summary, summary: roll.l5r5e.summary,
}; };
@@ -480,7 +480,7 @@ export class RollnKeepDialog extends FormApplication {
// Get all kept dices + new (choice null) // Get all kept dices + new (choice null)
const diceList = this.object.dicesList.reduce((acc, step) => { const diceList = this.object.dicesList.reduce((acc, step) => {
step.forEach((die) => { 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]) { if (!acc[die.type]) {
acc[die.type] = []; acc[die.type] = [];
} }
@@ -493,7 +493,7 @@ export class RollnKeepDialog extends FormApplication {
// Re create a new roll // Re create a new roll
const roll = await new game.l5r5e.RollL5r5e(this._arrayToFormula(diceList)); const roll = await new game.l5r5e.RollL5r5e(this._arrayToFormula(diceList));
roll.l5r5e = { roll.l5r5e = {
...this.message.roll.l5r5e, ...this.message._roll.l5r5e,
summary: roll.l5r5e.summary, summary: roll.l5r5e.summary,
}; };

View File

@@ -13,15 +13,16 @@ export class RollL5r5e extends Roll {
skillId: "", skillId: "",
skillCatId: "", skillCatId: "",
actor: null, actor: null,
difficulty: 2,
difficultyHidden: false,
voidPointUsed: false,
ringsUsed: null,
isInitiativeRoll: false,
dicesTypes: { dicesTypes: {
std: false, std: false,
l5r: false, l5r: false,
}, },
summary: { summary: {
difficulty: 2,
difficultyHidden: false,
voidPointUsed: false,
ringsUsed: null,
totalSuccess: 0, totalSuccess: 0,
totalBonus: 0, totalBonus: 0,
success: 0, success: 0,
@@ -30,7 +31,6 @@ export class RollL5r5e extends Roll {
strife: 0, strife: 0,
}, },
history: null, history: null,
isInitiativeRoll: false,
}; };
// Parse flavor for stance and skillId // Parse flavor for stance and skillId
@@ -103,8 +103,8 @@ export class RollL5r5e extends Roll {
(term) => term instanceof DiceTerm && !(term instanceof game.l5r5e.L5rBaseDie) (term) => term instanceof DiceTerm && !(term instanceof game.l5r5e.L5rBaseDie)
); // ignore math symbols ); // ignore math symbols
this.l5r5e.dicesTypes.l5r = this.dice.some((term) => term instanceof game.l5r5e.L5rBaseDie); this.l5r5e.dicesTypes.l5r = this.dice.some((term) => term instanceof game.l5r5e.L5rBaseDie);
summary.totalBonus = Math.max(0, summary.totalSuccess - summary.difficulty); summary.totalBonus = Math.max(0, summary.totalSuccess - this.l5r5e.difficulty);
summary.ringsUsed = this.dice.reduce( this.l5r5e.ringsUsed = this.dice.reduce(
(acc, term) => (term instanceof game.l5r5e.RingDie ? acc + term.number : acc), (acc, term) => (term instanceof game.l5r5e.RingDie ? acc + term.number : acc),
0 0
); );

View File

@@ -27,12 +27,12 @@
</span> </span>
<span class="chat-profil-element"> <span class="chat-profil-element">
{{#if l5r5e.summary.difficultyHidden}} {{#if l5r5e.difficultyHidden}}
{{localize 'l5r5e.chatdices.difficulty_hidden'}} {{localize 'l5r5e.chatdices.difficulty_hidden'}}
{{else}} {{else}}
{{localize 'l5r5e.chatdices.difficulty'}} {{l5r5e.summary.difficulty}} {{localize 'l5r5e.chatdices.difficulty'}} {{l5r5e.difficulty}}
{{/if}} {{/if}}
{{#if l5r5e.summary.voidPointUsed}} {{#if l5r5e.voidPointUsed}}
<br><i class="i_void" title="{{localize 'l5r5e.chatdices.void_point_used'}}"></i> <br><i class="i_void" title="{{localize 'l5r5e.chatdices.void_point_used'}}"></i>
{{/if}} {{/if}}
</span> </span>
@@ -78,13 +78,15 @@
</div> </div>
{{!-- Result text --}} {{!-- Result text --}}
{{^if ../l5r5e.difficultyHidden}}
<div> <div>
{{#ifCond totalSuccess '>=' difficulty}} {{#ifCond totalSuccess '>=' ../l5r5e.difficulty}}
{{localize "l5r5e.chatdices.success_text"}} ({{totalBonus}} {{localize "l5r5e.chatdices.bonus_text"}}) {{localize "l5r5e.chatdices.success_text"}} ({{totalBonus}} {{localize "l5r5e.chatdices.bonus_text"}})
{{else}} {{else}}
{{localize "l5r5e.chatdices.fail_text"}} {{localize "l5r5e.chatdices.fail_text"}}
{{/ifCond}} {{/ifCond}}
</div> </div>
{{/if}}
{{/l5r5e.summary}} {{/l5r5e.summary}}
</div> </div>
{{/if}} {{/if}}

View File

@@ -25,12 +25,12 @@
</span> </span>
<span class="chat-profil-element"> <span class="chat-profil-element">
{{#if l5r5e.summary.difficultyHidden}} {{#if l5r5e.difficultyHidden}}
{{localize 'l5r5e.chatdices.difficulty_hidden'}} {{localize 'l5r5e.chatdices.difficulty_hidden'}}
{{else}} {{else}}
{{localize 'l5r5e.chatdices.difficulty'}} {{l5r5e.summary.difficulty}} {{localize 'l5r5e.chatdices.difficulty'}} {{l5r5e.difficulty}}
{{/if}} {{/if}}
{{#if l5r5e.summary.voidPointUsed}} {{#if l5r5e.voidPointUsed}}
<br><i class="i_void" title="{{localize 'l5r5e.chatdices.void_point_used'}}"></i> <br><i class="i_void" title="{{localize 'l5r5e.chatdices.void_point_used'}}"></i>
{{/if}} {{/if}}
</span> </span>