mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
[Feature] Roll Difficulty Support (#393)
* Added difficulty support in rollDialog/rollMessage and [[/dr]] * Fixed /dr chat command
This commit is contained in:
parent
42a705a870
commit
3d723e7d8c
7 changed files with 89 additions and 54 deletions
|
|
@ -8,7 +8,7 @@ import { getCommandTarget, rollCommandToJSON } from './module/helpers/utils.mjs'
|
|||
import { NarrativeCountdowns } from './module/applications/ui/countdowns.mjs';
|
||||
import { DualityRollColor } from './module/data/settings/Appearance.mjs';
|
||||
import { DHRoll, DualityRoll, D20Roll, DamageRoll, DualityDie } from './module/dice/_module.mjs';
|
||||
import { renderDualityButton } from './module/enrichers/DualityRollEnricher.mjs';
|
||||
import { enrichedDualityRoll, renderDualityButton } from './module/enrichers/DualityRollEnricher.mjs';
|
||||
import { renderMeasuredTemplate } from './module/enrichers/TemplateEnricher.mjs';
|
||||
import { registerCountdownHooks } from './module/data/countdowns.mjs';
|
||||
import {
|
||||
|
|
@ -188,49 +188,21 @@ Hooks.on('chatMessage', (_, message) => {
|
|||
}
|
||||
|
||||
const traitValue = rollCommand.trait?.toLowerCase();
|
||||
const advantageState = rollCommand.advantage ? true : rollCommand.disadvantage ? false : null;
|
||||
|
||||
// Target not required if an attribute is not used.
|
||||
const target = traitValue ? getCommandTarget() : undefined;
|
||||
if (target || !traitValue) {
|
||||
new Promise(async (resolve, reject) => {
|
||||
const trait = target ? target.system.traits[traitValue] : undefined;
|
||||
if (traitValue && !trait) {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.attributeFaulty'));
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
const advantage = rollCommand.advantage
|
||||
? CONFIG.DH.ACTIONS.advandtageState.advantage.value
|
||||
: rollCommand.disadvantage
|
||||
? CONFIG.DH.ACTIONS.advandtageState.disadvantage.value
|
||||
: undefined;
|
||||
const difficulty = rollCommand.difficulty;
|
||||
|
||||
const target = getCommandTarget();
|
||||
const title = traitValue
|
||||
? game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
|
||||
ability: game.i18n.localize(SYSTEM.ACTOR.abilities[traitValue].label)
|
||||
})
|
||||
: game.i18n.localize('DAGGERHEART.GENERAL.duality');
|
||||
|
||||
const config = {
|
||||
title: title,
|
||||
roll: {
|
||||
trait: traitValue
|
||||
},
|
||||
data: {
|
||||
traits: {
|
||||
[traitValue]: trait
|
||||
}
|
||||
},
|
||||
source: target,
|
||||
hasSave: false,
|
||||
dialog: { configure: false },
|
||||
evaluate: true,
|
||||
advantage: rollCommand.advantage == true,
|
||||
disadvantage: rollCommand.disadvantage == true
|
||||
};
|
||||
|
||||
await CONFIG.Dice.daggerheart['DualityRoll'].build(config);
|
||||
|
||||
resolve();
|
||||
});
|
||||
}
|
||||
|
||||
enrichedDualityRoll({ traitValue, target, difficulty, title, label: 'test', actionType: null, advantage });
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1196,6 +1196,7 @@
|
|||
},
|
||||
"Roll": {
|
||||
"attack": "Attack Roll",
|
||||
"difficulty": "Roll (Difficulty {difficulty})",
|
||||
"primaryWeaponAttack": "Primary Weapon Attack Roll",
|
||||
"secondaryWeaponAttack": "Secondary Weapon Attack Roll",
|
||||
"spellcast": "Spellcast Roll",
|
||||
|
|
@ -1310,6 +1311,7 @@
|
|||
"single": "Experience",
|
||||
"plural": "Experiences"
|
||||
},
|
||||
"failure": "Failure",
|
||||
"fear": "Fear",
|
||||
"features": "Features",
|
||||
"formula": "Formula",
|
||||
|
|
@ -1345,6 +1347,7 @@
|
|||
"scalable": "Scalable",
|
||||
"situationalBonus": "Situational Bonus",
|
||||
"stress": "Stress",
|
||||
"success": "Success",
|
||||
"take": "Take",
|
||||
"Target": {
|
||||
"single": "Target",
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
||||
async renderHTML() {
|
||||
if (this.system.messageTemplate)
|
||||
this.content = await foundry.applications.handlebars.renderTemplate(
|
||||
this.system.messageTemplate,
|
||||
this.system
|
||||
);
|
||||
this.content = await foundry.applications.handlebars.renderTemplate(this.system.messageTemplate, {
|
||||
...this.system,
|
||||
_source: this.system._source
|
||||
});
|
||||
|
||||
/* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */
|
||||
const html = await super.renderHTML();
|
||||
|
|
|
|||
|
|
@ -21,6 +21,18 @@ function getDualityMessage(roll) {
|
|||
? game.i18n.localize(abilities[roll.trait].label)
|
||||
: game.i18n.localize('DAGGERHEART.GENERAL.duality');
|
||||
|
||||
const advantage = roll.advantage
|
||||
? CONFIG.DH.ACTIONS.advandtageState.advantage.value
|
||||
: roll.disadvantage
|
||||
? CONFIG.DH.ACTIONS.advandtageState.disadvantage.value
|
||||
: undefined;
|
||||
const advantageLabel =
|
||||
advantage === CONFIG.DH.ACTIONS.advandtageState.advantage.value
|
||||
? 'Advantage'
|
||||
: advantage === CONFIG.DH.ACTIONS.advandtageState.disadvantage.value
|
||||
? 'Disadvantage'
|
||||
: undefined;
|
||||
|
||||
const dualityElement = document.createElement('span');
|
||||
dualityElement.innerHTML = `
|
||||
<button class="duality-roll-button"
|
||||
|
|
@ -28,12 +40,15 @@ function getDualityMessage(roll) {
|
|||
data-label="${dataLabel}"
|
||||
data-hope="${roll.hope ?? 'd12'}"
|
||||
data-fear="${roll.fear ?? 'd12'}"
|
||||
${advantage ? `data-advantage="${advantage}"` : ''}
|
||||
${roll.difficulty !== undefined ? `data-difficulty="${roll.difficulty}"` : ''}
|
||||
${roll.trait && abilities[roll.trait] ? `data-trait="${roll.trait}"` : ''}
|
||||
${roll.advantage ? 'data-advantage="true"' : ''}
|
||||
${roll.disadvantage ? 'data-disadvantage="true"' : ''}
|
||||
>
|
||||
<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(' ')})` : ''}
|
||||
</button>
|
||||
`;
|
||||
|
||||
|
|
@ -43,16 +58,39 @@ function getDualityMessage(roll) {
|
|||
export const renderDualityButton = async event => {
|
||||
const button = event.currentTarget,
|
||||
traitValue = button.dataset.trait?.toLowerCase(),
|
||||
target = getCommandTarget();
|
||||
target = getCommandTarget(),
|
||||
difficulty = button.dataset.difficulty,
|
||||
advantage = button.dataset.advantage ? Number(button.dataset.advantage) : undefined;
|
||||
|
||||
await enrichedDualityRoll(
|
||||
{
|
||||
traitValue,
|
||||
target,
|
||||
difficulty,
|
||||
title: button.dataset.title,
|
||||
label: button.dataset.label,
|
||||
actionType: button.dataset.actionType,
|
||||
advantage
|
||||
},
|
||||
event
|
||||
);
|
||||
};
|
||||
|
||||
export const enrichedDualityRoll = async (
|
||||
{ traitValue, target, difficulty, title, label, actionType, advantage },
|
||||
event
|
||||
) => {
|
||||
if (!target) return;
|
||||
|
||||
const config = {
|
||||
event: event,
|
||||
title: button.dataset.title,
|
||||
event: event ?? {},
|
||||
title: title,
|
||||
roll: {
|
||||
modifier: traitValue ? target.system.traits[traitValue].value : null,
|
||||
label: button.dataset.label,
|
||||
type: button.dataset.actionType ?? null // Need check
|
||||
label: label,
|
||||
difficulty: difficulty,
|
||||
advantage,
|
||||
type: actionType ?? null // Need check,
|
||||
},
|
||||
chatMessage: {
|
||||
template: 'systems/daggerheart/templates/ui/chat/duality-roll.hbs'
|
||||
|
|
|
|||
|
|
@ -131,13 +131,17 @@
|
|||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
height: 32px;
|
||||
|
||||
.roll-mode-select {
|
||||
width: min-content;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
button {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
font-family: @font-body;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,14 +136,22 @@
|
|||
<input type="text" value="{{extraFormula}}" name="extraFormula" placeholder="{{#if (eq @root.rollType 'DualityRoll')}}Ex: 1d6 + 5{{else}}Situational Bonus{{/if}}">
|
||||
</fieldset>
|
||||
{{/unless}}
|
||||
|
||||
<span class="formula-label"><b>{{localize "DAGGERHEART.GENERAL.formula"}}:</b> {{@root.formula}}</span>
|
||||
|
||||
<div class="roll-dialog-controls">
|
||||
<select class="roll-mode-select" name="selectedRollMode">
|
||||
{{selectOptions rollModes selected=selectedRollMode valueAttr="action" labelAttr="label" localize=true}}
|
||||
</select>
|
||||
<button class="sunmit-btn" data-action="submitRoll"{{#unless canRoll}} disabled{{/unless}}>
|
||||
<i class="fa-solid fa-dice"></i>
|
||||
<span class="label">{{localize "DAGGERHEART.GENERAL.roll"}}</span>
|
||||
<span class="label">
|
||||
{{#if @root.rollConfig.roll.difficulty}}
|
||||
{{localize "DAGGERHEART.GENERAL.Roll.difficulty" difficulty=@root.rollConfig.roll.difficulty}}
|
||||
{{else}}
|
||||
{{localize "DAGGERHEART.GENERAL.roll"}}
|
||||
{{/if}}
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
{{else}}
|
||||
|
|
|
|||
|
|
@ -140,7 +140,17 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="dice-total duality {{#if (eq roll.result.duality 1)}}hope{{else}}{{#if (eq roll.result.duality -1)}}fear{{else}}critical{{/if}}{{/if}}">
|
||||
<div class="dice-total-label">{{roll.result.label}}</div>
|
||||
<div class="dice-total-label">
|
||||
{{#unless (eq _source.roll.success undefined)}}
|
||||
{{#if _source.roll.success}}
|
||||
{{localize "DAGGERHEART.GENERAL.success"}} {{localize "DAGGERHEART.GENERAL.withThing" thing=roll.result.label}}
|
||||
{{else}}
|
||||
{{localize "DAGGERHEART.GENERAL.failure"}} {{localize "DAGGERHEART.GENERAL.withThing" thing=roll.result.label}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{roll.result.label}}
|
||||
{{/unless}}
|
||||
</div>
|
||||
<div class="dice-total-value">
|
||||
{{roll.total}}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue