Added aseDie.rerollResult method to specifically reroll a specific result die in a grouping

This commit is contained in:
WBHarry 2026-07-15 14:58:02 +02:00
parent 1274639ba8
commit 221b84726d
7 changed files with 25 additions and 5 deletions

View file

@ -6,6 +6,7 @@ import * as documents from './module/documents/_module.mjs';
import { macros } from './module/_module.mjs'; import { macros } from './module/_module.mjs';
import * as collections from './module/documents/collections/_module.mjs'; import * as collections from './module/documents/collections/_module.mjs';
import * as dice from './module/dice/_module.mjs'; import * as dice from './module/dice/_module.mjs';
import * as die from './module/dice/die/_module.mjs';
import * as fields from './module/data/fields/_module.mjs'; import * as fields from './module/data/fields/_module.mjs';
import RegisterHandlebarsHelpers from './module/helpers/handlebarsHelper.mjs'; import RegisterHandlebarsHelpers from './module/helpers/handlebarsHelper.mjs';
import { enricherConfig, enricherRenderSetup } from './module/enrichers/_module.mjs'; import { enricherConfig, enricherRenderSetup } from './module/enrichers/_module.mjs';
@ -38,6 +39,8 @@ CONFIG.RegionBehavior.dataModels = {
}; };
Object.assign(CONFIG.Dice.termTypes, dice.diceTypes); Object.assign(CONFIG.Dice.termTypes, dice.diceTypes);
CONFIG.Dice.terms.d = die.BaseDie;
CONFIG.Dice.types = [die.BaseDie, CONFIG.Dice.terms.f];
CONFIG.Actor.documentClass = documents.DhpActor; CONFIG.Actor.documentClass = documents.DhpActor;
CONFIG.Actor.dataModels = models.actors.config; CONFIG.Actor.dataModels = models.actors.config;

View file

@ -35,8 +35,7 @@ export class ChatDamageData extends foundry.abstract.DataModel {
async rerollDamageDie(damageType, dice, resultIndex) { async rerollDamageDie(damageType, dice, resultIndex) {
const reroll = this.types[damageType].roll; const reroll = this.types[damageType].roll;
const rerollDice = reroll.dice[dice]; const rerollDice = reroll.dice[dice];
const diceResult = rerollDice.results[resultIndex]; await rerollDice.rerollResult(resultIndex);
await rerollDice.reroll(`/r1=${diceResult.result}`);
await reroll._evaluate(); await reroll._evaluate();
const rerolledResult = rerollDice.results[rerollDice.results.length - 1]; const rerolledResult = rerollDice.results[rerollDice.results.length - 1];

View file

@ -3,6 +3,7 @@ import HopeDie from './hopeDie.mjs';
import FearDie from './fearDie.mjs'; import FearDie from './fearDie.mjs';
import AdvantageDie from './advantageDie.mjs'; import AdvantageDie from './advantageDie.mjs';
import DisadvantageDie from './disadvantageDie.mjs'; import DisadvantageDie from './disadvantageDie.mjs';
export { default as BaseDie } from './baseDie.mjs';
export const diceTypes = { export const diceTypes = {
DualityDie, DualityDie,

View file

@ -1,4 +1,6 @@
export default class AdvantageDie extends foundry.dice.terms.Die { import BaseDie from './baseDie.mjs';
export default class AdvantageDie extends BaseDie {
constructor(options) { constructor(options) {
super(options); super(options);

View file

@ -0,0 +1,12 @@
export default class BaseDie extends foundry.dice.terms.Die {
async rerollResult(resultIndex) {
const result = this.results[resultIndex];
result.rerolled = true;
result.active = false;
await this.roll({ reroll: true });
const rerolledResult = this.results[this.results.length - 1];
this.results.splice(this.results.length - 1, 1);
this.results.splice(resultIndex, 0, rerolledResult);
}
}

View file

@ -1,4 +1,6 @@
export default class DisadvantageDie extends foundry.dice.terms.Die { import BaseDie from './baseDie.mjs';
export default class DisadvantageDie extends BaseDie {
constructor(options) { constructor(options) {
super(options); super(options);

View file

@ -1,6 +1,7 @@
import BaseDie from './baseDie.mjs';
import { updateResourcesForDualityReroll } from '../helpers.mjs'; import { updateResourcesForDualityReroll } from '../helpers.mjs';
export default class DualityDie extends foundry.dice.terms.Die { export default class DualityDie extends BaseDie {
constructor(options) { constructor(options) {
super(options); super(options);