mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
Fix duality roll (#436)
* allow /dr and [[/dr]] to be rolled without selection * fix weird ternary * Fixed so trait modifier comes along correctly --------- Co-authored-by: psitacus <walther.johnson@ucalgary.ca> Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
parent
ff7927896a
commit
f55698af02
4 changed files with 23 additions and 13 deletions
|
|
@ -202,7 +202,7 @@ Hooks.on('chatMessage', (_, message) => {
|
||||||
: undefined;
|
: undefined;
|
||||||
const difficulty = rollCommand.difficulty;
|
const difficulty = rollCommand.difficulty;
|
||||||
|
|
||||||
const target = getCommandTarget();
|
const target = getCommandTarget({ allowNull: true });
|
||||||
const title = traitValue
|
const title = traitValue
|
||||||
? game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
|
? game.i18n.format('DAGGERHEART.UI.Chat.dualityRoll.abilityCheckTitle', {
|
||||||
ability: game.i18n.localize(SYSTEM.ACTOR.abilities[traitValue].label)
|
ability: game.i18n.localize(SYSTEM.ACTOR.abilities[traitValue].label)
|
||||||
|
|
|
||||||
|
|
@ -91,9 +91,10 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
|
||||||
context.roll = this.roll;
|
context.roll = this.roll;
|
||||||
context.rollType = this.roll?.constructor.name;
|
context.rollType = this.roll?.constructor.name;
|
||||||
context.rallyDie = this.roll.rallyChoices;
|
context.rallyDie = this.roll.rallyChoices;
|
||||||
context.experiences = Object.keys(this.config.data.experiences).map(id => ({
|
const experiences = this.config.data?.experiences || {};
|
||||||
|
context.experiences = Object.keys(experiences).map(id => ({
|
||||||
id,
|
id,
|
||||||
...this.config.data.experiences[id]
|
...experiences[id]
|
||||||
}));
|
}));
|
||||||
context.selectedExperiences = this.config.experiences;
|
context.selectedExperiences = this.config.experiences;
|
||||||
context.advantage = this.config.roll?.advantage;
|
context.advantage = this.config.roll?.advantage;
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ function getDualityMessage(roll) {
|
||||||
export const renderDualityButton = async event => {
|
export const renderDualityButton = async event => {
|
||||||
const button = event.currentTarget,
|
const button = event.currentTarget,
|
||||||
traitValue = button.dataset.trait?.toLowerCase(),
|
traitValue = button.dataset.trait?.toLowerCase(),
|
||||||
target = getCommandTarget(),
|
target = getCommandTarget({ allowNull: true }),
|
||||||
difficulty = button.dataset.difficulty,
|
difficulty = button.dataset.difficulty,
|
||||||
advantage = button.dataset.advantage ? Number(button.dataset.advantage) : undefined;
|
advantage = button.dataset.advantage ? Number(button.dataset.advantage) : undefined;
|
||||||
|
|
||||||
|
|
@ -80,13 +80,11 @@ export const enrichedDualityRoll = async (
|
||||||
{ traitValue, target, difficulty, title, label, actionType, advantage },
|
{ traitValue, target, difficulty, title, label, actionType, advantage },
|
||||||
event
|
event
|
||||||
) => {
|
) => {
|
||||||
if (!target) return;
|
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
event: event ?? {},
|
event: event ?? {},
|
||||||
title: title,
|
title: title,
|
||||||
roll: {
|
roll: {
|
||||||
modifier: traitValue ? target.system.traits[traitValue].value : null,
|
trait: traitValue && target ? traitValue : null,
|
||||||
label: label,
|
label: label,
|
||||||
difficulty: difficulty,
|
difficulty: difficulty,
|
||||||
advantage,
|
advantage,
|
||||||
|
|
@ -96,5 +94,13 @@ export const enrichedDualityRoll = async (
|
||||||
template: 'systems/daggerheart/templates/ui/chat/duality-roll.hbs'
|
template: 'systems/daggerheart/templates/ui/chat/duality-roll.hbs'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await target.diceRoll(config);
|
|
||||||
|
if (target) {
|
||||||
|
await target.diceRoll(config);
|
||||||
|
} else {
|
||||||
|
// For no target, call DualityRoll directly with basic data
|
||||||
|
config.data = { experiences: {}, traits: {} };
|
||||||
|
config.source = { actor: null };
|
||||||
|
await CONFIG.Dice.daggerheart.DualityRoll.build(config);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -31,21 +31,24 @@ export function rollCommandToJSON(text) {
|
||||||
return Object.keys(result).length > 0 ? result : null;
|
return Object.keys(result).length > 0 ? result : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getCommandTarget = () => {
|
export const getCommandTarget = (options = {}) => {
|
||||||
|
const { allowNull = false } = options;
|
||||||
let target = game.canvas.tokens.controlled.length > 0 ? game.canvas.tokens.controlled[0].actor : null;
|
let target = game.canvas.tokens.controlled.length > 0 ? game.canvas.tokens.controlled[0].actor : null;
|
||||||
if (!game.user.isGM) {
|
if (!game.user.isGM) {
|
||||||
target = game.user.character;
|
target = game.user.character;
|
||||||
if (!target) {
|
if (!target && !allowNull) {
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noAssignedPlayerCharacter'));
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noAssignedPlayerCharacter'));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!target) {
|
if (!target && !allowNull) {
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noSelectedToken'));
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noSelectedToken'));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (target.type !== 'character') {
|
if (target && target.type !== 'character') {
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.onlyUseableByPC'));
|
if (!allowNull) {
|
||||||
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.onlyUseableByPC'));
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue