RnK : fix for swap
This commit is contained in:
@@ -411,7 +411,8 @@ export class RollnKeepDialog extends FormApplication {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _applyChoices() {
|
async _applyChoices() {
|
||||||
const nextStep = this.object.currentStep + 1;
|
let haveSwap = false;
|
||||||
|
let nextStep = this.object.currentStep + 1;
|
||||||
const haveReroll = this._haveChoice(this.object.currentStep, RollnKeepDialog.CHOICES.reroll);
|
const haveReroll = this._haveChoice(this.object.currentStep, RollnKeepDialog.CHOICES.reroll);
|
||||||
|
|
||||||
// Foreach kept dices, apply choices
|
// Foreach kept dices, apply choices
|
||||||
@@ -420,16 +421,17 @@ export class RollnKeepDialog extends FormApplication {
|
|||||||
if (!die) {
|
if (!die) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentRow = this.object.dicesList[this.object.currentStep][idx];
|
||||||
|
|
||||||
switch (die.choice) {
|
switch (die.choice) {
|
||||||
case RollnKeepDialog.CHOICES.keep:
|
case RollnKeepDialog.CHOICES.keep:
|
||||||
if (haveReroll) {
|
if (haveReroll) {
|
||||||
// Reroll line add all kept into a new line
|
// Reroll line add all kept into a new line
|
||||||
this._initializeDicesListStep(nextStep);
|
this._initializeDicesListStep(nextStep);
|
||||||
this.object.dicesList[nextStep][idx] = duplicate(
|
this.object.dicesList[nextStep][idx] = foundry.utils.duplicate(currentRow);
|
||||||
this.object.dicesList[this.object.currentStep][idx]
|
|
||||||
);
|
|
||||||
this.object.dicesList[nextStep][idx].choice = RollnKeepDialog.CHOICES.nothing;
|
this.object.dicesList[nextStep][idx].choice = RollnKeepDialog.CHOICES.nothing;
|
||||||
this.object.dicesList[this.object.currentStep][idx].choice = RollnKeepDialog.CHOICES.discard;
|
currentRow.choice = RollnKeepDialog.CHOICES.discard;
|
||||||
} else if (game.l5r5e[die.type].FACES[die.face].explosive) {
|
} else if (game.l5r5e[die.type].FACES[die.face].explosive) {
|
||||||
// Exploding dice : add a new dice in the next step
|
// Exploding dice : add a new dice in the next step
|
||||||
if (!newRolls[die.type]) {
|
if (!newRolls[die.type]) {
|
||||||
@@ -449,22 +451,36 @@ export class RollnKeepDialog extends FormApplication {
|
|||||||
|
|
||||||
case RollnKeepDialog.CHOICES.swap:
|
case RollnKeepDialog.CHOICES.swap:
|
||||||
// FaceSwap : add a new dice with selected face in next step
|
// FaceSwap : add a new dice with selected face in next step
|
||||||
|
haveSwap = true;
|
||||||
this._initializeDicesListStep(nextStep);
|
this._initializeDicesListStep(nextStep);
|
||||||
this.object.dicesList[nextStep][idx] = {
|
this.object.dicesList[nextStep][idx] = {
|
||||||
type: this.object.dicesList[this.object.currentStep][idx].type,
|
type: currentRow.type,
|
||||||
face: this.object.dicesList[this.object.currentStep][idx].newFace,
|
face: currentRow.newFace,
|
||||||
choice: RollnKeepDialog.CHOICES.keep,
|
choice: RollnKeepDialog.CHOICES.keep,
|
||||||
};
|
};
|
||||||
delete this.object.dicesList[this.object.currentStep][idx].newFace;
|
|
||||||
|
// Swapped to an exploding face : add the roll
|
||||||
|
if (game.l5r5e[currentRow.type].FACES[currentRow.newFace].explosive) {
|
||||||
|
if (!newRolls[currentRow.type]) {
|
||||||
|
newRolls[currentRow.type] = 0;
|
||||||
|
}
|
||||||
|
newRolls[currentRow.type] += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete currentRow.newFace;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// If new rolls, roll and add them
|
// If new rolls, roll and add them
|
||||||
if (Object.keys(newRolls).length > 0) {
|
if (Object.keys(newRolls).length > 0) {
|
||||||
|
if (haveSwap) {
|
||||||
|
nextStep++;
|
||||||
|
}
|
||||||
const newRollsResults = await this._newRoll(newRolls);
|
const newRollsResults = await this._newRoll(newRolls);
|
||||||
this._initializeDicesListStep(nextStep);
|
this._initializeDicesListStep(nextStep);
|
||||||
this.object.dicesList[this.object.currentStep].forEach((die, idx) => {
|
|
||||||
|
const applyNewRolls = (die, idx) => {
|
||||||
if (!die) {
|
if (!die) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -476,7 +492,13 @@ export class RollnKeepDialog extends FormApplication {
|
|||||||
) {
|
) {
|
||||||
this.object.dicesList[nextStep][idx] = newRollsResults[die.type].shift();
|
this.object.dicesList[nextStep][idx] = newRollsResults[die.type].shift();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
this.object.dicesList[this.object.currentStep].forEach(applyNewRolls);
|
||||||
|
if (haveSwap) {
|
||||||
|
this.object.dicesList[nextStep - 1].forEach(applyNewRolls);
|
||||||
|
this.object.currentStep++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user