shrink logic for same result :p
This commit is contained in:
@@ -45,61 +45,30 @@ export class RollL5r5e extends Roll {
|
||||
if (this._rolled) {
|
||||
throw new Error("This Roll object has already been rolled.");
|
||||
}
|
||||
if (this.terms.length < 1) {
|
||||
throw new Error("This Roll object need dice to be rolled.");
|
||||
}
|
||||
|
||||
console.log("RollL5r5e.evaluate.in", this); // TODO tmp
|
||||
|
||||
// Split L5R dices / regulars for non inners
|
||||
let l5rDices = this.terms.filter((term) => term instanceof L5rBaseDie);
|
||||
this.terms = this.terms.filter((t) => !(t instanceof L5rBaseDie));
|
||||
// Clean terms (trim symbols)
|
||||
this.terms = this._identifyTerms(this.constructor.cleanFormula(this.terms));
|
||||
|
||||
// Roll regular dices / inner dices
|
||||
// Roll dices and inner dices
|
||||
this._total = 0;
|
||||
if (this.terms.length > 0) {
|
||||
// clean terms (trim symbols)
|
||||
this.terms = this._identifyTerms(this.constructor.cleanFormula(this.terms));
|
||||
|
||||
// Roll
|
||||
super.evaluate({ minimize, maximize });
|
||||
}
|
||||
// Roll
|
||||
super.evaluate({ minimize, maximize });
|
||||
|
||||
// Check inner L5R rolls
|
||||
this._dice.forEach((term) => {
|
||||
if (term instanceof L5rBaseDie) {
|
||||
// Add results to total
|
||||
["success", "explosive", "opportunity", "strife"].forEach((props) => {
|
||||
this.l5r5e.summary[props] += parseInt(term.l5r5e[props]);
|
||||
});
|
||||
}
|
||||
});
|
||||
// Current terms - L5R Summary
|
||||
this.terms.forEach((term) => this._l5rSummary(term));
|
||||
|
||||
// Roll non inner L5R dices
|
||||
if (l5rDices.length > 0) {
|
||||
l5rDices.forEach((term) => {
|
||||
// Roll
|
||||
term.evaluate({ minimize, maximize });
|
||||
|
||||
// Total
|
||||
["success", "explosive", "opportunity", "strife"].forEach((props) => {
|
||||
this.l5r5e.summary[props] += parseInt(term.l5r5e[props]);
|
||||
});
|
||||
|
||||
// re-inject L5R dices
|
||||
this.terms.push("+");
|
||||
this.terms.push(term);
|
||||
});
|
||||
|
||||
// Clean
|
||||
if (this.terms[0] === "+") {
|
||||
this.terms.shift();
|
||||
}
|
||||
|
||||
// TODO Others advantage/disadvantage
|
||||
}
|
||||
// Check inner L5R rolls - L5R Summary
|
||||
this._dice.forEach((term) => this._l5rSummary(term));
|
||||
|
||||
// Store final outputs
|
||||
this._rolled = true;
|
||||
this.l5r5e.dicesTypes.std = this.dice.some((term) => term instanceof DiceTerm && !(term instanceof L5rBaseDie));
|
||||
this.l5r5e.dicesTypes.std = this.dice.some((term) => term instanceof DiceTerm && !(term instanceof L5rBaseDie)); // ignore math symbols
|
||||
this.l5r5e.dicesTypes.l5r = this.dice.some((term) => term instanceof L5rBaseDie);
|
||||
|
||||
console.log("RollL5r5e.evaluate.out", this); // TODO tmp
|
||||
@@ -107,6 +76,21 @@ export class RollL5r5e extends Roll {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Summarise the total of success, strife... for L5R dices for the current roll
|
||||
*
|
||||
* @param term
|
||||
* @private
|
||||
*/
|
||||
_l5rSummary(term) {
|
||||
if (term instanceof L5rBaseDie) {
|
||||
["success", "explosive", "opportunity", "strife"].forEach((props) => {
|
||||
this.l5r5e.summary[props] += parseInt(term.l5r5e[props]);
|
||||
});
|
||||
// TODO Others advantage/disadvantage
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the total result of the Roll expression if it has been evaluated, otherwise null
|
||||
* @override
|
||||
@@ -133,7 +117,7 @@ export class RollL5r5e extends Roll {
|
||||
["success", "explosive", "opportunity", "strife"]
|
||||
.map((props) => (summary[props] > 0 ? props + ": " + summary[props] : null))
|
||||
.filter((c) => !!c)
|
||||
.join(", ");
|
||||
.join(" | ");
|
||||
}
|
||||
|
||||
return total;
|
||||
@@ -180,6 +164,7 @@ export class RollL5r5e extends Roll {
|
||||
const chatData = {
|
||||
parts: parts,
|
||||
l5r5e: this.l5r5e,
|
||||
displaySummary: contexte?.from !== "render",
|
||||
};
|
||||
|
||||
return renderTemplate(this.constructor.TOOLTIP_TEMPLATE, { chatData });
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
{{/each}}
|
||||
|
||||
{{#if chatData.l5r5e.dicesTypes.l5r}}
|
||||
{{#if chatData.displaySummary}}
|
||||
{{#chatData.l5r5e.summary}}
|
||||
<ul>
|
||||
<li>Successes: {{this.success}}</li>
|
||||
@@ -40,4 +41,5 @@
|
||||
</ul>
|
||||
{{/chatData.l5r5e.summary}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user