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