mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-14 20:51:07 +01:00
Fixed so the different chat themes work again
This commit is contained in:
parent
0f3da99f9d
commit
75ee44af52
6 changed files with 83 additions and 68 deletions
|
|
@ -218,28 +218,28 @@ Hooks.on('chatMessage', (_, message) => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const attributeValue = rollCommand.attribute?.toLowerCase();
|
const traitValue = rollCommand.trait?.toLowerCase();
|
||||||
|
|
||||||
// Target not required if an attribute is not used.
|
// Target not required if an attribute is not used.
|
||||||
const target = attributeValue ? getCommandTarget() : undefined;
|
const target = traitValue ? getCommandTarget() : undefined;
|
||||||
if (target || !attributeValue) {
|
if (target || !traitValue) {
|
||||||
new Promise(async (resolve, reject) => {
|
new Promise(async (resolve, reject) => {
|
||||||
const attribute = target ? target.system.attributes[attributeValue] : undefined;
|
const trait = target ? target.system.traits[traitValue] : undefined;
|
||||||
if (attributeValue && !attribute) {
|
if (traitValue && !trait) {
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.Notification.Error.AttributeFaulty'));
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.Notification.Error.AttributeFaulty'));
|
||||||
reject();
|
reject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const title = attributeValue
|
const title = traitValue
|
||||||
? game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', {
|
? game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', {
|
||||||
ability: game.i18n.localize(abilities[attributeValue].label)
|
ability: game.i18n.localize(abilities[traitValue].label)
|
||||||
})
|
})
|
||||||
: game.i18n.localize('DAGGERHEART.General.Duality');
|
: game.i18n.localize('DAGGERHEART.General.Duality');
|
||||||
|
|
||||||
const hopeAndFearRoll = `1${rollCommand.hope ?? 'd12'}+1${rollCommand.fear ?? 'd12'}`;
|
const hopeAndFearRoll = `1${rollCommand.hope ?? 'd12'}+1${rollCommand.fear ?? 'd12'}`;
|
||||||
const advantageRoll = `${rollCommand.advantage && !rollCommand.disadvantage ? '+d6' : rollCommand.disadvantage && !rollCommand.advantage ? '-d6' : ''}`;
|
const advantageRoll = `${rollCommand.advantage && !rollCommand.disadvantage ? '+d6' : rollCommand.disadvantage && !rollCommand.advantage ? '-d6' : ''}`;
|
||||||
const attributeRoll = `${attribute?.data?.value ? `${attribute.data.value > 0 ? `+${attribute.data.value}` : `${attribute.data.value}`}` : ''}`;
|
const attributeRoll = `${trait?.data?.value ? `${trait.data.value > 0 ? `+${trait.data.value}` : `${trait.data.value}`}` : ''}`;
|
||||||
const roll = await Roll.create(`${hopeAndFearRoll}${advantageRoll}${attributeRoll}`).evaluate();
|
const roll = await Roll.create(`${hopeAndFearRoll}${advantageRoll}${attributeRoll}`).evaluate();
|
||||||
|
|
||||||
setDiceSoNiceForDualityRoll(
|
setDiceSoNiceForDualityRoll(
|
||||||
|
|
@ -250,21 +250,21 @@ Hooks.on('chatMessage', (_, message) => {
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
roll,
|
roll,
|
||||||
attribute: attribute
|
trait: trait
|
||||||
? {
|
? {
|
||||||
value: attribute.data.value,
|
value: trait.value,
|
||||||
label: `${game.i18n.localize(abilities[attributeValue].label)} ${attribute.data.value >= 0 ? `+` : ``}${attribute.data.value}`
|
label: `${game.i18n.localize(abilities[traitValue].label)} ${trait.value >= 0 ? `+` : ``}${trait.value}`
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
title
|
title
|
||||||
});
|
});
|
||||||
}).then(async ({ roll, attribute, title }) => {
|
}).then(async ({ roll, trait, title }) => {
|
||||||
const cls = getDocumentClass('ChatMessage');
|
const cls = getDocumentClass('ChatMessage');
|
||||||
const systemData = new DHDualityRoll({
|
const systemData = new DHDualityRoll({
|
||||||
title: title,
|
title: title,
|
||||||
origin: target?.id,
|
origin: target?.id,
|
||||||
roll: roll,
|
roll: roll,
|
||||||
modifiers: attribute ? [attribute] : [],
|
modifiers: trait ? [trait] : [],
|
||||||
hope: { dice: rollCommand.hope ?? 'd12', value: roll.dice[0].total },
|
hope: { dice: rollCommand.hope ?? 'd12', value: roll.dice[0].total },
|
||||||
fear: { dice: rollCommand.fear ?? 'd12', value: roll.dice[1].total },
|
fear: { dice: rollCommand.fear ?? 'd12', value: roll.dice[1].total },
|
||||||
advantage:
|
advantage:
|
||||||
|
|
@ -282,10 +282,7 @@ Hooks.on('chatMessage', (_, message) => {
|
||||||
sound: CONFIG.sounds.dice,
|
sound: CONFIG.sounds.dice,
|
||||||
system: systemData,
|
system: systemData,
|
||||||
user: game.user.id,
|
user: game.user.id,
|
||||||
content: await foundry.applications.handlebars.renderTemplate(
|
content: 'systems/daggerheart/templates/chat/duality-roll.hbs',
|
||||||
'systems/daggerheart/templates/chat/duality-roll.hbs',
|
|
||||||
systemData
|
|
||||||
),
|
|
||||||
rolls: [roll]
|
rolls: [roll]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,15 @@ import DHDualityRoll from '../data/chat-message/dualityRoll.mjs';
|
||||||
|
|
||||||
export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
||||||
async renderHTML() {
|
async renderHTML() {
|
||||||
|
if (
|
||||||
|
this.type === 'dualityRoll' ||
|
||||||
|
this.type === 'adversaryRoll' ||
|
||||||
|
this.type === 'damageRoll' ||
|
||||||
|
this.type === 'abilityUse'
|
||||||
|
) {
|
||||||
|
this.content = await foundry.applications.handlebars.renderTemplate(this.content, this.system);
|
||||||
|
}
|
||||||
|
|
||||||
/* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */
|
/* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */
|
||||||
const html = await super.renderHTML();
|
const html = await super.renderHTML();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -285,12 +285,14 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async rollAttribute(event, button) {
|
static async rollAttribute(event, button) {
|
||||||
|
const abilityLabel = game.i18n.localize(abilities[button.dataset.attribute].label);
|
||||||
const config = {
|
const config = {
|
||||||
event: event,
|
event: event,
|
||||||
title: game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', {
|
title: game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', {
|
||||||
ability: game.i18n.localize(abilities[button.dataset.attribute].label)
|
ability: abilityLabel
|
||||||
}),
|
}),
|
||||||
roll: {
|
roll: {
|
||||||
|
label: abilityLabel,
|
||||||
modifier: button.dataset.value
|
modifier: button.dataset.value
|
||||||
},
|
},
|
||||||
chatMessage: {
|
chatMessage: {
|
||||||
|
|
@ -368,7 +370,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
||||||
|
|
||||||
static async attackRoll(event, button) {
|
static async attackRoll(event, button) {
|
||||||
const weapon = await fromUuid(button.dataset.weapon);
|
const weapon = await fromUuid(button.dataset.weapon);
|
||||||
if(!weapon) return;
|
if (!weapon) return;
|
||||||
weapon.use(event);
|
weapon.use(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { DualityRollColor } from "../settings/Appearance.mjs";
|
import { DualityRollColor } from '../settings/Appearance.mjs';
|
||||||
|
|
||||||
const fields = foundry.data.fields;
|
const fields = foundry.data.fields;
|
||||||
const diceField = () =>
|
const diceField = () =>
|
||||||
|
|
@ -23,8 +23,7 @@ export default class DHDualityRoll extends foundry.abstract.TypeDataModel {
|
||||||
modifiers: new fields.ArrayField(
|
modifiers: new fields.ArrayField(
|
||||||
new fields.SchemaField({
|
new fields.SchemaField({
|
||||||
value: new fields.NumberField({ integer: true }),
|
value: new fields.NumberField({ integer: true }),
|
||||||
label: new fields.StringField({}),
|
label: new fields.StringField({})
|
||||||
title: new fields.StringField({})
|
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
hope: diceField(),
|
hope: diceField(),
|
||||||
|
|
|
||||||
|
|
@ -144,10 +144,10 @@ export default class DhpActor extends Actor {
|
||||||
fearDice = 'd12',
|
fearDice = 'd12',
|
||||||
advantageDice = 'd6',
|
advantageDice = 'd6',
|
||||||
disadvantageDice = 'd6',
|
disadvantageDice = 'd6',
|
||||||
advantage = config.event.altKey ?? config.event.ctrlKey ? false : null,
|
advantage = (config.event.altKey ?? config.event.ctrlKey) ? false : null,
|
||||||
targets,
|
targets,
|
||||||
damage = config.damage,
|
damage = config.damage,
|
||||||
modifiers = this.formatRollModifier(config.roll.modifier),
|
modifiers = this.formatRollModifier(config.roll),
|
||||||
rollConfig,
|
rollConfig,
|
||||||
formula,
|
formula,
|
||||||
hope,
|
hope,
|
||||||
|
|
@ -155,7 +155,13 @@ export default class DhpActor extends Actor {
|
||||||
|
|
||||||
if (!config.event.shiftKey && !config.event.altKey && !config.event.ctrlKey) {
|
if (!config.event.shiftKey && !config.event.altKey && !config.event.ctrlKey) {
|
||||||
const dialogClosed = new Promise((resolve, _) => {
|
const dialogClosed = new Promise((resolve, _) => {
|
||||||
this.type === 'character' ? new RollSelectionDialog(this.system.experiences, this.system.resources.hope.value, resolve).render(true) : new NpcRollSelectionDialog(this.system.experiences, resolve).render(true);
|
this.type === 'character'
|
||||||
|
? new RollSelectionDialog(
|
||||||
|
this.system.experiences,
|
||||||
|
this.system.resources.hope.value,
|
||||||
|
resolve
|
||||||
|
).render(true)
|
||||||
|
: new NpcRollSelectionDialog(this.system.experiences, resolve).render(true);
|
||||||
});
|
});
|
||||||
rollConfig = await dialogClosed;
|
rollConfig = await dialogClosed;
|
||||||
|
|
||||||
|
|
@ -173,7 +179,7 @@ export default class DhpActor extends Actor {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
if(this.type === 'character') {
|
if (this.type === 'character') {
|
||||||
const automateHope = await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Automation.Hope);
|
const automateHope = await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Automation.Hope);
|
||||||
|
|
||||||
if (automateHope && result.hopeUsed) {
|
if (automateHope && result.hopeUsed) {
|
||||||
|
|
@ -184,30 +190,36 @@ export default class DhpActor extends Actor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.type === 'character') {
|
if (this.type === 'character') {
|
||||||
formula = `1${hopeDice} + 1${fearDice}${advantage === true ? ` + 1d6` : advantage === false ? ` - 1d6` : ''}`
|
formula = `1${hopeDice} + 1${fearDice}${advantage === true ? ` + 1d6` : advantage === false ? ` - 1d6` : ''}`;
|
||||||
} else {
|
} else {
|
||||||
formula = `${advantage === true || advantage === false ? 2 : 1}d20${advantage === true ? 'kh' : advantage === false ? 'kl' : ''}`
|
formula = `${advantage === true || advantage === false ? 2 : 1}d20${advantage === true ? 'kh' : advantage === false ? 'kl' : ''}`;
|
||||||
}
|
}
|
||||||
formula += ` ${modifiers.map(x => `+ ${x.value}`).join(' ')}`;
|
formula += ` ${modifiers.map(x => `+ ${x.value}`).join(' ')}`;
|
||||||
const roll = await Roll.create(formula).evaluate();
|
const roll = await Roll.create(formula).evaluate();
|
||||||
|
|
||||||
if(this.type === 'character') {
|
if (this.type === 'character') {
|
||||||
setDiceSoNiceForDualityRoll(roll, advantageDice, disadvantageDice);
|
setDiceSoNiceForDualityRoll(roll, advantageDice, disadvantageDice);
|
||||||
hope = roll.dice[0].results[0].result;
|
hope = roll.dice[0].results[0].result;
|
||||||
fear = roll.dice[1].results[0].result;
|
fear = roll.dice[1].results[0].result;
|
||||||
if(game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Automation.Hope) && config.roll.type === 'action') {
|
if (
|
||||||
if(hope > fear) {
|
game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Automation.Hope) &&
|
||||||
|
config.roll.type === 'action'
|
||||||
|
) {
|
||||||
|
if (hope > fear) {
|
||||||
await this.update({
|
await this.update({
|
||||||
'system.resources.hope.value': Math.min(
|
'system.resources.hope.value': Math.min(
|
||||||
this.system.resources.hope.value + 1,
|
this.system.resources.hope.value + 1,
|
||||||
this.system.resources.hope.max
|
this.system.resources.hope.max
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
} else if(hope === fear) {
|
} else if (hope === fear) {
|
||||||
await this.update({
|
await this.update({
|
||||||
'system.resources': {
|
'system.resources': {
|
||||||
'hope.value': Math.min(this.system.resources.hope.value + 1, this.system.resources.hope.max),
|
'hope.value': Math.min(
|
||||||
|
this.system.resources.hope.value + 1,
|
||||||
|
this.system.resources.hope.max
|
||||||
|
),
|
||||||
'stress.value': Math.max(this.system.resources.stress.value - 1, 0)
|
'stress.value': Math.max(this.system.resources.stress.value - 1, 0)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -215,7 +227,7 @@ export default class DhpActor extends Actor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config.checkTarget) {
|
if (config.checkTarget) {
|
||||||
targets = Array.from(game.user.targets).map(x => ({
|
targets = Array.from(game.user.targets).map(x => ({
|
||||||
id: x.id,
|
id: x.id,
|
||||||
name: x.actor.name,
|
name: x.actor.name,
|
||||||
|
|
@ -225,7 +237,7 @@ export default class DhpActor extends Actor {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config.chatMessage) {
|
if (config.chatMessage) {
|
||||||
const configRoll = {
|
const configRoll = {
|
||||||
title: config.title,
|
title: config.title,
|
||||||
origin: this.id,
|
origin: this.id,
|
||||||
|
|
@ -233,46 +245,42 @@ export default class DhpActor extends Actor {
|
||||||
modifiers,
|
modifiers,
|
||||||
advantageState: advantage
|
advantageState: advantage
|
||||||
};
|
};
|
||||||
if(this.type === 'character') {
|
if (this.type === 'character') {
|
||||||
configRoll.hope = { dice: hopeDice, value: hope };
|
configRoll.hope = { dice: hopeDice, value: hope };
|
||||||
configRoll.fear = { dice: fearDice, value: fear };
|
configRoll.fear = { dice: fearDice, value: fear };
|
||||||
configRoll.advantage = { dice: advantageDice, value: roll.dice[2]?.results[0].result ?? null }
|
configRoll.advantage = { dice: advantageDice, value: roll.dice[2]?.results[0].result ?? null };
|
||||||
/* advantage: { dice: advantageDice, value: advantage },
|
/* advantage: { dice: advantageDice, value: advantage },
|
||||||
disadvantage: { dice: disadvantageDice, value: disadvantage } */
|
disadvantage: { dice: disadvantageDice, value: disadvantage } */
|
||||||
}
|
}
|
||||||
if(damage) configRoll.damage = damage;
|
if (damage) configRoll.damage = damage;
|
||||||
if(targets) configRoll.targets = targets;
|
if (targets) configRoll.targets = targets;
|
||||||
const systemData = this.type === 'character' && !config.roll.simple ? new DHDualityRoll(configRoll) : configRoll,
|
const systemData =
|
||||||
cls = getDocumentClass('ChatMessage'),
|
this.type === 'character' && !config.roll.simple ? new DHDualityRoll(configRoll) : configRoll,
|
||||||
msg = new cls({
|
cls = getDocumentClass('ChatMessage'),
|
||||||
type: config.chatMessage.type ?? 'dualityRoll',
|
msg = new cls({
|
||||||
sound: config.chatMessage.mute ? null : CONFIG.sounds.dice,
|
type: config.chatMessage.type ?? 'dualityRoll',
|
||||||
system: systemData,
|
sound: config.chatMessage.mute ? null : CONFIG.sounds.dice,
|
||||||
// user: config.chatMessage.user ?? game.user.id,
|
system: systemData,
|
||||||
content: await foundry.applications.handlebars.renderTemplate(
|
content: config.chatMessage.template,
|
||||||
config.chatMessage.template,
|
rolls: [roll]
|
||||||
systemData
|
});
|
||||||
),
|
|
||||||
rolls: [roll]
|
|
||||||
});
|
|
||||||
|
|
||||||
await cls.create(msg.toObject());
|
await cls.create(msg.toObject());
|
||||||
}
|
}
|
||||||
return roll;
|
return roll;
|
||||||
}
|
}
|
||||||
|
|
||||||
formatRollModifier(modifier) {
|
formatRollModifier(roll) {
|
||||||
return modifier.value !== null ? [
|
const modifier = roll.modifier ? Number.parseInt(roll.modifier) : null;
|
||||||
{
|
return roll.modifier !== null
|
||||||
value: modifier.value ? Number.parseInt(modifier.value) : 0,
|
? [
|
||||||
label:
|
{
|
||||||
modifier.value >= 0
|
value: modifier,
|
||||||
? `${modifier.title} +${modifier.value}`
|
label: modifier >= 0 ? `${roll.label} +${modifier}` : `${roll.label} ${modifier}`,
|
||||||
: `${modifier.title} ${modifier.value}`,
|
title: roll.label
|
||||||
title: modifier.title
|
}
|
||||||
}
|
]
|
||||||
]
|
: [];
|
||||||
: [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete when new roll logic test done
|
// Delete when new roll logic test done
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@
|
||||||
<div class="dice-roll daggerheart chat roll" data-action="expandRoll">
|
<div class="dice-roll daggerheart chat roll" data-action="expandRoll">
|
||||||
<div class="dice-flavor">{{title}}</div>
|
<div class="dice-flavor">{{title}}</div>
|
||||||
<div class="dice-result">
|
<div class="dice-result">
|
||||||
<div class="dice-formula">{{roll}}</div>
|
<div class="dice-formula">{{roll.formula}}</div>
|
||||||
<div class="dice-tooltip">
|
<div class="dice-tooltip">
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<section class="tooltip-part">
|
<section class="tooltip-part">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue