Dice/critical checks/tests

This commit is contained in:
Chris Ryan 2026-01-03 11:28:09 +10:00
parent 3a7fd0eb8b
commit 658eb1bb2d
2 changed files with 23 additions and 2 deletions

View file

@ -26,6 +26,7 @@ export default class DualityRoll extends D20Roll {
} }
get dHope() { get dHope() {
console.log("dHope", this.dice, this.terms);
// if ( !(this.terms[0] instanceof foundry.dice.terms.Die) ) return; // if ( !(this.terms[0] instanceof foundry.dice.terms.Die) ) return;
if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice(); if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice();
return this.dice[0]; return this.dice[0];
@ -33,12 +34,14 @@ export default class DualityRoll extends D20Roll {
} }
set dHope(faces) { set dHope(faces) {
console.log("set dHope", this.dice, this.terms);
if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice(); if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice();
this.terms[0].faces = this.getFaces(faces); this.dice[0].faces = this.getFaces(faces);
// this.#hopeDice = `d${face}`; // this.#hopeDice = `d${face}`;
} }
get dFear() { get dFear() {
console.log("dFear", this.dice, this.terms);
// if ( !(this.terms[1] instanceof foundry.dice.terms.Die) ) return; // if ( !(this.terms[1] instanceof foundry.dice.terms.Die) ) return;
if (!(this.dice[1] instanceof foundry.dice.terms.Die)) this.createBaseDice(); if (!(this.dice[1] instanceof foundry.dice.terms.Die)) this.createBaseDice();
return this.dice[1]; return this.dice[1];
@ -46,6 +49,7 @@ export default class DualityRoll extends D20Roll {
} }
set dFear(faces) { set dFear(faces) {
console.log("set dFear", this.dice, this.terms);
if (!(this.dice[1] instanceof foundry.dice.terms.Die)) this.createBaseDice(); if (!(this.dice[1] instanceof foundry.dice.terms.Die)) this.createBaseDice();
this.dice[1].faces = this.getFaces(faces); this.dice[1].faces = this.getFaces(faces);
// this.#fearDice = `d${face}`; // this.#fearDice = `d${face}`;
@ -130,12 +134,22 @@ export default class DualityRoll extends D20Roll {
/** @inheritDoc */ /** @inheritDoc */
static fromData(data) { static fromData(data) {
console.log("fromData", data);
data.terms[0].class = foundry.dice.terms.Die.name; data.terms[0].class = foundry.dice.terms.Die.name;
data.terms[2].class = foundry.dice.terms.Die.name; data.terms[2].class = foundry.dice.terms.Die.name;
return super.fromData(data); return super.fromData(data);
} }
createBaseDice() { createBaseDice() {
if (this.guaranteedCritical) {
console.log("gc - createBaseDice");
this.terms[0] = new foundry.dice.terms.Die({ faces: 1, number: 1 });
this.terms[1] = new foundry.dice.terms.OperatorTerm({ operator: '+' });
this.terms[2] = new foundry.dice.terms.Die({ faces: 1, number: 1 });
this.terms = [this.terms[0], this.terms[1], this.terms[2]];
return;
}
if (this.dice[0] instanceof foundry.dice.terms.Die && this.dice[1] instanceof foundry.dice.terms.Die) { if (this.dice[0] instanceof foundry.dice.terms.Die && this.dice[1] instanceof foundry.dice.terms.Die) {
this.terms = [this.terms[0], this.terms[1], this.terms[2]]; this.terms = [this.terms[0], this.terms[1], this.terms[2]];
return; return;
@ -145,6 +159,13 @@ export default class DualityRoll extends D20Roll {
this.terms[2] = new foundry.dice.terms.Die({ faces: 12 }); this.terms[2] = new foundry.dice.terms.Die({ faces: 12 });
} }
configureModifiers() {
console.log("this.guaranteedCritical", this.guaranteedCritical);
if (!this.guaranteedCritical) {
super.configureModifiers();
}
}
applyAdvantage() { applyAdvantage() {
if (this.hasAdvantage || this.hasDisadvantage) { if (this.hasAdvantage || this.hasDisadvantage) {
const dieFaces = this.advantageFaces, const dieFaces = this.advantageFaces,

View file

@ -26,7 +26,7 @@ export default class FateRoll extends D20Roll {
set dHope(faces) { set dHope(faces) {
if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice(); if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice();
this.terms[0].faces = this.getFaces(faces); this.dice[0].faces = this.getFaces(faces);
// this.#hopeDice = `d${face}`; // this.#hopeDice = `d${face}`;
} }