mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
[Feature] 460 - Reaction Rolls (#481)
* Added a toggle in D20RollDialog for ReactionRolls * DualityRollEnrichment can now use reaction * Added flavor for DualityRollEnrichment
This commit is contained in:
parent
243630878b
commit
e168e3e7ec
10 changed files with 103 additions and 31 deletions
|
|
@ -7,6 +7,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
this.roll = roll;
|
||||
this.config = config;
|
||||
this.config.experiences = [];
|
||||
this.reactionOverride = config.roll.type === 'reaction';
|
||||
|
||||
if (config.source?.action) {
|
||||
this.item = config.data.parent.items.get(config.source.item) ?? config.data.parent;
|
||||
|
|
@ -30,6 +31,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
actions: {
|
||||
updateIsAdvantage: this.updateIsAdvantage,
|
||||
selectExperience: this.selectExperience,
|
||||
toggleReaction: this.toggleReaction,
|
||||
submitRoll: this.submitRoll
|
||||
},
|
||||
form: {
|
||||
|
|
@ -103,6 +105,9 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
context.isLite = this.config.roll?.lite;
|
||||
context.extraFormula = this.config.extraFormula;
|
||||
context.formula = this.roll.constructFormula(this.config);
|
||||
|
||||
context.showReaction = !context.rollConfig.type && context.rollType === 'DualityRoll';
|
||||
context.reactionOverride = this.reactionOverride;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
|
@ -141,7 +146,19 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
|||
this.render();
|
||||
}
|
||||
|
||||
static toggleReaction() {
|
||||
if (this.config.roll) {
|
||||
this.reactionOverride = !this.reactionOverride;
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
||||
static async submitRoll() {
|
||||
this.config.roll.type = this.reactionOverride
|
||||
? CONFIG.DH.ITEM.actionTypes.reaction.id
|
||||
: this.config.roll.type === CONFIG.DH.ITEM.actionTypes.reaction.id
|
||||
? null
|
||||
: this.config.roll.type;
|
||||
await this.close({ submitted: true });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ export default class DHRoll extends Roll {
|
|||
|
||||
static postEvaluate(roll, config = {}) {
|
||||
return {
|
||||
type: config.roll.type,
|
||||
total: roll.total,
|
||||
formula: roll.formula,
|
||||
dice: roll.dice.map(d => ({
|
||||
|
|
|
|||
|
|
@ -2,22 +2,23 @@ import { abilities } from '../config/actorConfig.mjs';
|
|||
import { getCommandTarget, rollCommandToJSON } from '../helpers/utils.mjs';
|
||||
|
||||
export default function DhDualityRollEnricher(match, _options) {
|
||||
const roll = rollCommandToJSON(match[1]);
|
||||
const roll = rollCommandToJSON(match[1], match[0]);
|
||||
if (!roll) return match[0];
|
||||
|
||||
return getDualityMessage(roll);
|
||||
return getDualityMessage(roll.result, roll.flavor);
|
||||
}
|
||||
|
||||
function getDualityMessage(roll) {
|
||||
const traitLabel =
|
||||
roll.trait && abilities[roll.trait]
|
||||
? game.i18n.format('DAGGERHEART.GENERAL.check', {
|
||||
check: game.i18n.localize(abilities[roll.trait].label)
|
||||
})
|
||||
: null;
|
||||
function getDualityMessage(roll, flavor) {
|
||||
const trait = roll.trait && abilities[roll.trait] ? game.i18n.localize(abilities[roll.trait].label) : null;
|
||||
const label =
|
||||
flavor ??
|
||||
(roll.trait
|
||||
? game.i18n.format('DAGGERHEART.GENERAL.rollWith', { roll: trait })
|
||||
: roll.reaction
|
||||
? game.i18n.localize('DAGGERHEART.GENERAL.reactionRoll')
|
||||
: game.i18n.localize('DAGGERHEART.GENERAL.duality'));
|
||||
|
||||
const label = traitLabel ?? game.i18n.localize('DAGGERHEART.GENERAL.duality');
|
||||
const dataLabel = traitLabel
|
||||
const dataLabel = trait
|
||||
? game.i18n.localize(abilities[roll.trait].label)
|
||||
: game.i18n.localize('DAGGERHEART.GENERAL.duality');
|
||||
|
||||
|
|
@ -38,6 +39,7 @@ function getDualityMessage(roll) {
|
|||
<button class="duality-roll-button"
|
||||
data-title="${label}"
|
||||
data-label="${dataLabel}"
|
||||
data-reaction="${roll.reaction ? 'true' : 'false'}"
|
||||
data-hope="${roll.hope ?? 'd12'}"
|
||||
data-fear="${roll.fear ?? 'd12'}"
|
||||
${advantage ? `data-advantage="${advantage}"` : ''}
|
||||
|
|
@ -46,9 +48,9 @@ function getDualityMessage(roll) {
|
|||
${roll.advantage ? 'data-advantage="true"' : ''}
|
||||
${roll.disadvantage ? 'data-disadvantage="true"' : ''}
|
||||
>
|
||||
<i class="fa-solid fa-circle-half-stroke"></i>
|
||||
${roll.reaction ? '<i class="fa-solid fa-reply"></i>' : '<i class="fa-solid fa-circle-half-stroke"></i>'}
|
||||
${label}
|
||||
${roll.difficulty || advantageLabel ? `(${[roll.difficulty, advantageLabel ? game.i18n.localize(`DAGGERHEART.GENERAL.${advantageLabel}.short`) : null].filter(x => x).join(' ')})` : ''}
|
||||
${!flavor && (roll.difficulty || advantageLabel) ? `(${[roll.difficulty, advantageLabel ? game.i18n.localize(`DAGGERHEART.GENERAL.${advantageLabel}.short`) : null].filter(x => x).join(' ')})` : ''}
|
||||
</button>
|
||||
`;
|
||||
|
||||
|
|
@ -57,6 +59,7 @@ function getDualityMessage(roll) {
|
|||
|
||||
export const renderDualityButton = async event => {
|
||||
const button = event.currentTarget,
|
||||
reaction = button.dataset.reaction === 'true',
|
||||
traitValue = button.dataset.trait?.toLowerCase(),
|
||||
target = getCommandTarget({ allowNull: true }),
|
||||
difficulty = button.dataset.difficulty,
|
||||
|
|
@ -64,12 +67,12 @@ export const renderDualityButton = async event => {
|
|||
|
||||
await enrichedDualityRoll(
|
||||
{
|
||||
reaction,
|
||||
traitValue,
|
||||
target,
|
||||
difficulty,
|
||||
title: button.dataset.title,
|
||||
label: button.dataset.label,
|
||||
actionType: button.dataset.actionType,
|
||||
advantage
|
||||
},
|
||||
event
|
||||
|
|
@ -77,7 +80,7 @@ export const renderDualityButton = async event => {
|
|||
};
|
||||
|
||||
export const enrichedDualityRoll = async (
|
||||
{ traitValue, target, difficulty, title, label, actionType, advantage },
|
||||
{ reaction, traitValue, target, difficulty, title, label, advantage },
|
||||
event
|
||||
) => {
|
||||
const config = {
|
||||
|
|
@ -88,7 +91,7 @@ export const enrichedDualityRoll = async (
|
|||
label: label,
|
||||
difficulty: difficulty,
|
||||
advantage,
|
||||
type: actionType ?? null // Need check,
|
||||
type: reaction ? 'reaction' : null
|
||||
},
|
||||
chatMessage: {
|
||||
template: 'systems/daggerheart/templates/ui/chat/duality-roll.hbs'
|
||||
|
|
|
|||
|
|
@ -7,19 +7,19 @@ export { DhDamageEnricher, DhDualityRollEnricher, DhEffectEnricher, DhTemplateEn
|
|||
|
||||
export const enricherConfig = [
|
||||
{
|
||||
pattern: /^@Damage\[(.*)\]$/g,
|
||||
pattern: /^@Damage\[(.*)\]({.*})?$/g,
|
||||
enricher: DhDamageEnricher
|
||||
},
|
||||
{
|
||||
pattern: /\[\[\/dr\s?(.*?)\]\]/g,
|
||||
pattern: /\[\[\/dr\s?(.*?)\]\]({.*})?/g,
|
||||
enricher: DhDualityRollEnricher
|
||||
},
|
||||
{
|
||||
pattern: /^@Effect\[(.*)\]$/g,
|
||||
pattern: /^@Effect\[(.*)\]({.*})?$/g,
|
||||
enricher: DhEffectEnricher
|
||||
},
|
||||
{
|
||||
pattern: /^@Template\[(.*)\]$/g,
|
||||
pattern: /^@Template\[(.*)\]({.*})?$/g,
|
||||
enricher: DhTemplateEnricher
|
||||
}
|
||||
];
|
||||
|
|
|
|||
|
|
@ -5,9 +5,12 @@ export const capitalize = string => {
|
|||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
};
|
||||
|
||||
export function rollCommandToJSON(text) {
|
||||
export function rollCommandToJSON(text, raw) {
|
||||
if (!text) return {};
|
||||
|
||||
const flavorMatch = raw?.match(/{(.*)}$/);
|
||||
const flavor = flavorMatch ? flavorMatch[1] : null;
|
||||
|
||||
// Match key="quoted string" OR key=unquotedValue
|
||||
const PAIR_RE = /(\w+)=("(?:[^"\\]|\\.)*"|\S+)/g;
|
||||
const result = {};
|
||||
|
|
@ -28,7 +31,7 @@ export function rollCommandToJSON(text) {
|
|||
}
|
||||
result[key] = value;
|
||||
}
|
||||
return Object.keys(result).length > 0 ? result : null;
|
||||
return Object.keys(result).length > 0 ? { result, flavor } : null;
|
||||
}
|
||||
|
||||
export const getCommandTarget = (options = {}) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue