Add Reroll and Swap visualisation in chatlog

This commit is contained in:
Vlyan
2021-02-04 10:04:45 +01:00
parent 78568ded55
commit 84b160b50d
6 changed files with 69 additions and 28 deletions

View File

@@ -91,6 +91,9 @@ export class L5rBaseDie extends DiceTerm {
["success", "explosive", "opportunity", "strife"].forEach((props) => {
this.l5r5e[props] += parseInt(face[props]);
});
if (face.explosive) {
term.exploded = true;
}
});
}

View File

@@ -507,12 +507,23 @@ export class RollnKeepDialog extends FormApplication {
*/
async _rebuildRoll() {
// Get all kept dices + new (choice null)
const diceList = this.object.dicesList.reduce((acc, step) => {
step.forEach((die) => {
const diceList = this.object.dicesList.reduce((acc, step, stepIdx) => {
step.forEach((die, idx) => {
if (!!die && [RollnKeepDialog.CHOICES.keep, RollnKeepDialog.CHOICES.nothing].includes(die.choice)) {
if (!acc[die.type]) {
acc[die.type] = [];
}
// Check previous dice, to add html classes in chat
if (stepIdx > 0 && this.object.dicesList[stepIdx - 1][idx]) {
switch (this.object.dicesList[stepIdx - 1][idx].choice) {
case RollnKeepDialog.CHOICES.reroll:
die.class = "rerolled";
break;
case RollnKeepDialog.CHOICES.swap:
die.class = "swapped";
break;
}
}
acc[die.type].push(die);
}
});
@@ -535,6 +546,11 @@ export class RollnKeepDialog extends FormApplication {
term.results.map((res) => {
const die = diceList[term.constructor.name].shift();
res.result = die.face;
// add class to term result
if (die.class) {
res[die.class] = true;
}
return res;
});
term.l5rSummary();

View File

@@ -104,10 +104,13 @@ export class RollL5r5e extends Roll {
); // ignore math symbols
this.l5r5e.dicesTypes.l5r = this.dice.some((term) => term instanceof game.l5r5e.L5rBaseDie);
summary.totalBonus = Math.max(0, summary.totalSuccess - this.l5r5e.difficulty);
this.l5r5e.keepLimit = this.dice.reduce(
(acc, term) => (term instanceof game.l5r5e.RingDie ? acc + term.number : acc),
0
);
if (!this.l5r5e.keepLimit) {
this.l5r5e.keepLimit = this.dice.reduce(
(acc, term) => (term instanceof game.l5r5e.RingDie ? acc + term.number : acc),
0
);
}
}
/**
@@ -183,8 +186,9 @@ export class RollL5r5e extends Roll {
classes: [
cls.name.toLowerCase(),
"d" + term.faces,
!isL5rDie && r.rerolled ? "rerolled" : null,
!isL5rDie && r.exploded ? "exploded" : null,
isL5rDie && r.swapped ? "swapped" : null,
r.rerolled ? "rerolled" : null,
r.exploded ? "exploded" : null,
!isL5rDie && r.discarded ? "discarded" : null,
!isL5rDie && r.result === 1 ? "min" : null,
!isL5rDie && r.result === term.faces ? "max" : null,
@@ -240,12 +244,20 @@ export class RollL5r5e extends Roll {
? {}
: {
...this.l5r5e,
dices: this.dice.map((d) => {
dices: this.dice.map((term) => {
const isL5rDie = term instanceof game.l5r5e.L5rBaseDie;
return {
diceTypeL5r: d instanceof game.l5r5e.L5rBaseDie,
rolls: d.results.map((r) => {
diceTypeL5r: isL5rDie,
rolls: term.results.map((r) => {
return {
result: d.constructor.getResultLabel(r.result),
result: term.constructor.getResultLabel(r.result),
classes: [
isL5rDie && r.swapped ? "swapped" : null,
r.rerolled ? "rerolled" : null,
r.exploded ? "exploded" : null,
]
.filter((c) => !!c)
.join(" "),
};
}),
};