mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 07:59:03 +01:00
Fixed rerolling of duality dice
This commit is contained in:
parent
480d04fee5
commit
dfd10da324
9 changed files with 93 additions and 54 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import { getDiceSoNicePresets } from '../../config/generalConfig.mjs';
|
||||
|
||||
export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLog {
|
||||
constructor(options) {
|
||||
super(options);
|
||||
|
|
@ -313,47 +315,50 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
|||
action.use(event);
|
||||
};
|
||||
|
||||
//Reroll Functionality
|
||||
rerollEvent = async (event, message) => {
|
||||
let DieTerm = foundry.dice.terms.Die;
|
||||
let dicetype = event.target.value;
|
||||
const target = event.target.closest('button[data-die-index]');
|
||||
let originalRoll_parsed = message.rolls.map(roll => JSON.parse(roll))[0];
|
||||
console.log('Parsed Map:', originalRoll_parsed);
|
||||
let originalRoll = Roll.fromData(originalRoll_parsed);
|
||||
let diceIndex;
|
||||
console.log('Dice to reroll is:', dicetype, ', and the message id is:', message._id, originalRoll_parsed);
|
||||
console.log('Original Roll Terms:', originalRoll.terms);
|
||||
switch (dicetype) {
|
||||
case 'hope': {
|
||||
diceIndex = 0; //Hope Die
|
||||
break;
|
||||
let parsedRoll = game.system.api.dice.DualityRoll.fromData({ ...originalRoll_parsed, evaluated: false });
|
||||
const term = parsedRoll.terms[target.dataset.dieIndex];
|
||||
await term.reroll(`/r1=${term.total}`);
|
||||
if (game.modules.get('dice-so-nice')?.active) {
|
||||
const diceSoNiceRoll = {
|
||||
_evaluated: true,
|
||||
dice: [new Die({ ...term, faces: term._faces, results: term.results.filter(x => !x.rerolled) })],
|
||||
options: { appearance: {} }
|
||||
};
|
||||
const diceSoNicePresets = getDiceSoNicePresets();
|
||||
switch (target.dataset.type) {
|
||||
case 'hope':
|
||||
diceSoNiceRoll.dice[0].options = { appearance: diceSoNicePresets.hope };
|
||||
break;
|
||||
case 'fear':
|
||||
diceSoNiceRoll.dice[0].options = { appearance: diceSoNicePresets.fear };
|
||||
break;
|
||||
case 'advantage':
|
||||
diceSoNiceRoll.dice[0].options = { appearance: diceSoNicePresets.advantage };
|
||||
break;
|
||||
case 'disadvantage':
|
||||
diceSoNiceRoll.dice[0].options = { appearance: diceSoNicePresets.disadvantage };
|
||||
break;
|
||||
}
|
||||
case 'fear': {
|
||||
diceIndex = 2; //Fear Die
|
||||
break;
|
||||
|
||||
await game.dice3d.showForRoll(diceSoNiceRoll, game.user, true);
|
||||
}
|
||||
|
||||
await parsedRoll.evaluate();
|
||||
|
||||
const newRoll = game.system.api.dice.DualityRoll.postEvaluate(parsedRoll, {
|
||||
targets: message.system.targets,
|
||||
roll: {
|
||||
advantage: message.system.roll.advantage?.type,
|
||||
difficulty: message.system.roll.difficulty ? Number(message.system.roll.difficulty) : null
|
||||
}
|
||||
default:
|
||||
ui.notifications.warn('Invalid Dice type selected.');
|
||||
break;
|
||||
}
|
||||
let rollClone = originalRoll.clone();
|
||||
let rerolledTerm = originalRoll.terms[diceIndex];
|
||||
console.log('originalRoll:', originalRoll, 'rerolledTerm', rerolledTerm);
|
||||
if (!(rerolledTerm instanceof DieTerm)) {
|
||||
ui.notifications.error('Selected term is not a die.');
|
||||
return;
|
||||
}
|
||||
await rollClone.reroll({ allowStrings: true })[diceIndex];
|
||||
console.log(rollClone);
|
||||
await rollClone.evaluate({ allowStrings: true });
|
||||
console.log(rollClone.result);
|
||||
/*
|
||||
const confirm = await foundry.applications.api.DialogV2.confirm({
|
||||
window: { title: 'Confirm Reroll' },
|
||||
content: `<p>You have rerolled your <strong>${dicetype}</strong> die to <strong>${rollClone.result}</strong>.</p><p>Apply this new roll?</p>`
|
||||
});
|
||||
if (!confirm) return;
|
||||
rollClone.toMessage({flavor: 'Selective reroll applied for ${dicetype}.'});
|
||||
console.log("Updated Roll",rollClone);*/
|
||||
});
|
||||
newRoll.extra = newRoll.extra.slice(2);
|
||||
|
||||
await game.messages.get(message._id).update({
|
||||
'system.roll': newRoll
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ export default class DHAdversaryRoll extends foundry.abstract.TypeDataModel {
|
|||
static defineSchema() {
|
||||
return {
|
||||
title: new fields.StringField(),
|
||||
roll: new fields.DataField(),
|
||||
roll: new fields.ObjectField(),
|
||||
targets: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
id: new fields.StringField({}),
|
||||
|
|
|
|||
|
|
@ -147,7 +147,10 @@ export default class D20Roll extends DHRoll {
|
|||
const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion;
|
||||
target.hit = this.isCritical || roll.total >= difficulty;
|
||||
});
|
||||
} else if (config.roll.difficulty) data.success = roll.isCritical || roll.total >= config.roll.difficulty;
|
||||
} else if (config.roll.difficulty) {
|
||||
data.difficulty = config.roll.difficulty;
|
||||
data.success = roll.isCritical || roll.total >= config.roll.difficulty;
|
||||
}
|
||||
data.advantage = {
|
||||
type: config.roll.advantage,
|
||||
dice: roll.dAdvantage?.denomination,
|
||||
|
|
|
|||
|
|
@ -110,6 +110,13 @@ export default class DualityRoll extends D20Roll {
|
|||
return [...(hooks ?? []), 'Duality'];
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
static fromData(data) {
|
||||
data.terms[0].class = game.system.api.dice.DualityDie.name;
|
||||
data.terms[2].class = game.system.api.dice.DualityDie.name;
|
||||
return super.fromData(data);
|
||||
}
|
||||
|
||||
createBaseDice() {
|
||||
if (
|
||||
this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie &&
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ function getDualityMessage(roll) {
|
|||
>
|
||||
<i class="fa-solid fa-circle-half-stroke"></i>
|
||||
${label}
|
||||
${roll.difficulty || advantageLabel ? `(${[roll.difficulty, game.i18n.localize(`DAGGERHEART.GENERAL.${advantageLabel}.short`)].filter(x => x).join(' ')})` : ''}
|
||||
${roll.difficulty || advantageLabel ? `(${[roll.difficulty, advantageLabel ? game.i18n.localize(`DAGGERHEART.GENERAL.${advantageLabel}.short`) : null].filter(x => x).join(' ')})` : ''}
|
||||
</button>
|
||||
`;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue