This commit is contained in:
WBHarry 2025-07-24 15:46:43 +02:00
parent aeb208e777
commit 72491891ed
7 changed files with 79 additions and 11 deletions

View file

@ -1695,7 +1695,8 @@
"makeDeathMove": "Make a Death Move", "makeDeathMove": "Make a Death Move",
"rangeAndTarget": "Range & Target", "rangeAndTarget": "Range & Target",
"dragApplyEffect": "Drag effect to apply it to an actor", "dragApplyEffect": "Drag effect to apply it to an actor",
"appliedEvenIfSuccessful": "Applied even if save succeeded" "appliedEvenIfSuccessful": "Applied even if save succeeded",
"diceIsRerolled": "The dice has been rerolled (x{times})"
} }
} }
} }

View file

@ -271,6 +271,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
} }
async rerollEvent(event, message) { async rerollEvent(event, message) {
event.stopPropagation();
if (!event.shiftKey) { if (!event.shiftKey) {
const confirmed = await foundry.applications.api.DialogV2.confirm({ const confirmed = await foundry.applications.api.DialogV2.confirm({
window: { window: {

View file

@ -1,4 +1,5 @@
import D20RollDialog from '../applications/dialogs/d20RollDialog.mjs'; import D20RollDialog from '../applications/dialogs/d20RollDialog.mjs';
import { getDiceSoNicePresets } from '../config/generalConfig.mjs';
import DHRoll from './dhRoll.mjs'; import DHRoll from './dhRoll.mjs';
export default class D20Roll extends DHRoll { export default class D20Roll extends DHRoll {
@ -156,6 +157,14 @@ export default class D20Roll extends DHRoll {
dice: roll.dAdvantage?.denomination, dice: roll.dAdvantage?.denomination,
value: roll.dAdvantage?.total value: roll.dAdvantage?.total
}; };
data.dice = data.dice.map(dice => ({
...dice,
results: dice.results.filter(x => !x.rerolled),
rerolled: {
any: dice.results.some(x => x.rerolled),
rerolls: dice.results.filter(x => x.rerolled)
}
}));
data.isCritical = roll.isCritical; data.isCritical = roll.isCritical;
data.extra = roll.dice data.extra = roll.dice
.filter(d => !roll.baseTerms.includes(d)) .filter(d => !roll.baseTerms.includes(d))
@ -173,9 +182,35 @@ export default class D20Roll extends DHRoll {
return (this._formula = this.constructor.getFormula(this.terms)); return (this._formula = this.constructor.getFormula(this.terms));
} }
static async reroll(rollString, _target, message) { static async reroll(rollString, target, message) {
let parsedRoll = game.system.api.dice.D20Roll.fromData(rollString); let parsedRoll = game.system.api.dice.D20Roll.fromData({ ...rollString, evaluated: false });
parsedRoll = await parsedRoll.reroll();
const term = parsedRoll.terms[0];
await term.reroll(`/r1=${term.total}`);
if (game.modules.get('dice-so-nice')?.active) {
const diceSoNiceRoll = {
_evaluated: true,
dice: [
new foundry.dice.terms.Die({
...term,
faces: term._faces,
results: term.results.filter(x => !x.rerolled)
})
],
options: { appearance: {} }
};
const diceSoNicePresets = getDiceSoNicePresets();
const type = target.dataset.type;
if (diceSoNicePresets[type]) {
diceSoNiceRoll.dice[0].options = { appearance: diceSoNicePresets[type] };
}
await game.dice3d.showForRoll(diceSoNiceRoll, game.user, true);
}
await parsedRoll.evaluate();
const newRoll = game.system.api.dice.D20Roll.postEvaluate(parsedRoll, { const newRoll = game.system.api.dice.D20Roll.postEvaluate(parsedRoll, {
targets: message.system.targets, targets: message.system.targets,
roll: { roll: {
@ -184,10 +219,7 @@ export default class D20Roll extends DHRoll {
} }
}); });
if (game.modules.get('dice-so-nice')?.active) { newRoll.extra = newRoll.extra.slice(1);
await game.dice3d.showForRoll(parsedRoll, game.user, true);
}
return { newRoll, parsedRoll }; return { newRoll, parsedRoll };
} }
} }

View file

@ -171,11 +171,19 @@ export default class DualityRoll extends D20Roll {
data.hope = { data.hope = {
dice: roll.dHope.denomination, dice: roll.dHope.denomination,
value: roll.dHope.total value: roll.dHope.total,
rerolled: {
any: roll.dHope.results.some(x => x.rerolled),
rerolls: roll.dHope.results.filter(x => x.rerolled)
}
}; };
data.fear = { data.fear = {
dice: roll.dFear.denomination, dice: roll.dFear.denomination,
value: roll.dFear.total value: roll.dFear.total,
rerolled: {
any: roll.dFear.results.some(x => x.rerolled),
rerolls: roll.dFear.results.filter(x => x.rerolled)
}
}; };
data.rally = { data.rally = {
dice: roll.dRally?.denomination, dice: roll.dRally?.denomination,
@ -236,7 +244,8 @@ export default class DualityRoll extends D20Roll {
source: { actor: message.system.source.actor ?? '' }, source: { actor: message.system.source.actor ?? '' },
targets: message.system.targets, targets: message.system.targets,
roll: newRoll, roll: newRoll,
rerolledRoll: message.system.roll rerolledRoll:
newRoll.result.duality !== message.system.roll.result.duality ? message.system.roll : undefined
}); });
return { newRoll, parsedRoll }; return { newRoll, parsedRoll };
} }

View file

@ -62,6 +62,17 @@
} }
&.rerollable { &.rerollable {
position: relative;
flex: none;
.dice-rerolled {
z-index: 2;
position: absolute;
right: 0;
font-size: 12px;
cursor: help;
}
.reroll-button { .reroll-button {
border: none; border: none;
background: initial; background: initial;
@ -85,12 +96,21 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 2px; gap: 2px;
position: relative;
.dice-title { .dice-title {
color: var(--color-light-1); color: var(--color-light-1);
text-shadow: 0 0 1px black; text-shadow: 0 0 1px black;
} }
.dice-rerolled {
z-index: 2;
position: absolute;
right: -2px;
font-size: 12px;
cursor: help;
}
.dice-inner-container { .dice-inner-container {
display: flex; display: flex;
align-items: center; align-items: center;

View file

@ -13,6 +13,9 @@
</header> </header>
<div class="flexrow"> <div class="flexrow">
<ol class="dice-rolls rerollable"> <ol class="dice-rolls rerollable">
{{#if dice.rerolled.any}}
<i class="fa-solid fa-dice dice-rerolled" title="{{localize "DAGGERHEART.UI.Tooltip.diceIsRerolled" times=dice.rerolled.rerolls.length}}"></i>
{{/if}}
<button type="checkbox" class="reroll-button" data-die-index="0" data-tooltip="{{localize "DAGGERHEART.GENERAL.reroll"}}"> <button type="checkbox" class="reroll-button" data-die-index="0" data-tooltip="{{localize "DAGGERHEART.GENERAL.reroll"}}">
{{#each results as |result index|}} {{#each results as |result index|}}
<li class="roll die {{../dice}}{{#if discarded}} discarded{{/if}} min">{{result.result}}</li> <li class="roll die {{../dice}}{{#if discarded}} discarded{{/if}} min">{{result.result}}</li>

View file

@ -41,6 +41,7 @@
<li class="roll die {{roll.hope.dice}}"> <li class="roll die {{roll.hope.dice}}">
<div class="dice-container"> <div class="dice-container">
<div class="dice-title">{{localize "DAGGERHEART.GENERAL.hope"}}</div> <div class="dice-title">{{localize "DAGGERHEART.GENERAL.hope"}}</div>
{{#if roll.hope.rerolled.any}}<i class="fa-solid fa-dice dice-rerolled" title="{{localize "DAGGERHEART.UI.Tooltip.diceIsRerolled" times=roll.hope.rerolled.rerolls.length}}"></i>{{/if}}
<div class="dice-inner-container hope" data-tooltip="{{localize "DAGGERHEART.GENERAL.rerollThing" thing=(localize "DAGGERHEART.GENERAL.hope")}}"> <div class="dice-inner-container hope" data-tooltip="{{localize "DAGGERHEART.GENERAL.rerollThing" thing=(localize "DAGGERHEART.GENERAL.hope")}}">
<button type="checkbox" class="reroll-button" data-die-index="0" data-type="hope"> <button type="checkbox" class="reroll-button" data-die-index="0" data-type="hope">
<div class="dice-wrapper"> <div class="dice-wrapper">
@ -54,6 +55,7 @@
<li class="roll die {{roll.fear.dice}}"> <li class="roll die {{roll.fear.dice}}">
<div class="dice-container"> <div class="dice-container">
<div class="dice-title">{{localize "DAGGERHEART.GENERAL.fear"}}</div> <div class="dice-title">{{localize "DAGGERHEART.GENERAL.fear"}}</div>
{{#if roll.fear.rerolled.any}}<i class="fa-solid fa-dice dice-rerolled" title="{{localize "DAGGERHEART.UI.Tooltip.diceIsRerolled" times=roll.fear.rerolled.rerolls.length}}"></i>{{/if}}
<div class="dice-inner-container fear" data-tooltip="{{localize "DAGGERHEART.GENERAL.rerollThing" thing=(localize "DAGGERHEART.GENERAL.fear")}}"> <div class="dice-inner-container fear" data-tooltip="{{localize "DAGGERHEART.GENERAL.rerollThing" thing=(localize "DAGGERHEART.GENERAL.fear")}}">
<button type="checkbox" class="reroll-button" data-die-index="2" data-type="fear"> <button type="checkbox" class="reroll-button" data-die-index="2" data-type="fear">
<div class="dice-wrapper"> <div class="dice-wrapper">