mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 11:41:08 +01:00
Merge pull request #128 from Foundryborne/ChatMessage-Fixing
Chat Message Fixing
This commit is contained in:
commit
31ef31a417
7 changed files with 91 additions and 75 deletions
|
|
@ -3,6 +3,15 @@ import DHDualityRoll from '../data/chat-message/dualityRoll.mjs';
|
|||
|
||||
export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
||||
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. */
|
||||
const html = await super.renderHTML();
|
||||
|
||||
|
|
|
|||
|
|
@ -285,12 +285,14 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
}
|
||||
|
||||
static async rollAttribute(event, button) {
|
||||
const abilityLabel = game.i18n.localize(abilities[button.dataset.attribute].label);
|
||||
const config = {
|
||||
event: event,
|
||||
title: game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', {
|
||||
ability: game.i18n.localize(abilities[button.dataset.attribute].label)
|
||||
ability: abilityLabel
|
||||
}),
|
||||
roll: {
|
||||
label: abilityLabel,
|
||||
modifier: button.dataset.value
|
||||
},
|
||||
chatMessage: {
|
||||
|
|
@ -368,7 +370,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
|
||||
static async attackRoll(event, button) {
|
||||
const weapon = await fromUuid(button.dataset.weapon);
|
||||
if(!weapon) return;
|
||||
if (!weapon) return;
|
||||
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 diceField = () =>
|
||||
|
|
@ -23,8 +23,7 @@ export default class DHDualityRoll extends foundry.abstract.TypeDataModel {
|
|||
modifiers: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
value: new fields.NumberField({ integer: true }),
|
||||
label: new fields.StringField({}),
|
||||
title: new fields.StringField({})
|
||||
label: new fields.StringField({})
|
||||
})
|
||||
),
|
||||
hope: diceField(),
|
||||
|
|
|
|||
|
|
@ -144,18 +144,24 @@ export default class DhpActor extends Actor {
|
|||
fearDice = 'd12',
|
||||
advantageDice = 'd6',
|
||||
disadvantageDice = 'd6',
|
||||
advantage = config.event.altKey ?? config.event.ctrlKey ? false : null,
|
||||
advantage = config.event.altKey ? true : config.event.ctrlKey ? false : null,
|
||||
targets,
|
||||
damage = config.damage,
|
||||
modifiers = this.formatRollModifier(config.roll.modifier),
|
||||
modifiers = this.formatRollModifier(config.roll),
|
||||
rollConfig,
|
||||
formula,
|
||||
hope,
|
||||
fear;
|
||||
|
||||
|
||||
if (!config.event.shiftKey && !config.event.altKey && !config.event.ctrlKey) {
|
||||
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;
|
||||
|
||||
|
|
@ -164,7 +170,7 @@ export default class DhpActor extends Actor {
|
|||
advantage = rollConfig.advantage;
|
||||
hopeDice = rollConfig.hope;
|
||||
fearDice = rollConfig.fear;
|
||||
|
||||
|
||||
rollConfig.experiences.forEach(x =>
|
||||
modifiers.push({
|
||||
value: x.value,
|
||||
|
|
@ -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);
|
||||
|
||||
if (automateHope && result.hopeUsed) {
|
||||
|
|
@ -184,30 +190,36 @@ export default class DhpActor extends Actor {
|
|||
}
|
||||
}
|
||||
|
||||
if(this.type === 'character') {
|
||||
formula = `1${hopeDice} + 1${fearDice}${advantage === true ? ` + 1d6` : advantage === false ? ` - 1d6` : ''}`
|
||||
if (this.type === 'character') {
|
||||
formula = `1${hopeDice} + 1${fearDice}${advantage === true ? ` + 1d6` : advantage === false ? ` - 1d6` : ''}`;
|
||||
} 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(' ')}`;
|
||||
const roll = await Roll.create(formula).evaluate();
|
||||
|
||||
if(this.type === 'character') {
|
||||
if (this.type === 'character') {
|
||||
setDiceSoNiceForDualityRoll(roll, advantageDice, disadvantageDice);
|
||||
hope = roll.dice[0].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(hope > fear) {
|
||||
if (
|
||||
game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Automation.Hope) &&
|
||||
config.roll.type === 'action'
|
||||
) {
|
||||
if (hope > fear) {
|
||||
await this.update({
|
||||
'system.resources.hope.value': Math.min(
|
||||
this.system.resources.hope.value + 1,
|
||||
this.system.resources.hope.max
|
||||
)
|
||||
});
|
||||
} else if(hope === fear) {
|
||||
} else if (hope === fear) {
|
||||
await this.update({
|
||||
'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)
|
||||
}
|
||||
});
|
||||
|
|
@ -215,7 +227,7 @@ export default class DhpActor extends Actor {
|
|||
}
|
||||
}
|
||||
|
||||
if(config.checkTarget) {
|
||||
if (config.checkTarget) {
|
||||
targets = Array.from(game.user.targets).map(x => ({
|
||||
id: x.id,
|
||||
name: x.actor.name,
|
||||
|
|
@ -225,7 +237,7 @@ export default class DhpActor extends Actor {
|
|||
}));
|
||||
}
|
||||
|
||||
if(config.chatMessage) {
|
||||
if (config.chatMessage) {
|
||||
const configRoll = {
|
||||
title: config.title,
|
||||
origin: this.id,
|
||||
|
|
@ -233,46 +245,42 @@ export default class DhpActor extends Actor {
|
|||
modifiers,
|
||||
advantageState: advantage
|
||||
};
|
||||
if(this.type === 'character') {
|
||||
if (this.type === 'character') {
|
||||
configRoll.hope = { dice: hopeDice, value: hope };
|
||||
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 },
|
||||
disadvantage: { dice: disadvantageDice, value: disadvantage } */
|
||||
}
|
||||
if(damage) configRoll.damage = damage;
|
||||
if(targets) configRoll.targets = targets;
|
||||
const systemData = this.type === 'character' && !config.roll.simple ? new DHDualityRoll(configRoll) : configRoll,
|
||||
cls = getDocumentClass('ChatMessage'),
|
||||
msg = new cls({
|
||||
type: config.chatMessage.type ?? 'dualityRoll',
|
||||
sound: config.chatMessage.mute ? null : CONFIG.sounds.dice,
|
||||
system: systemData,
|
||||
// user: config.chatMessage.user ?? game.user.id,
|
||||
content: await foundry.applications.handlebars.renderTemplate(
|
||||
config.chatMessage.template,
|
||||
systemData
|
||||
),
|
||||
rolls: [roll]
|
||||
});
|
||||
if (damage) configRoll.damage = damage;
|
||||
if (targets) configRoll.targets = targets;
|
||||
const systemData =
|
||||
this.type === 'character' && !config.roll.simple ? new DHDualityRoll(configRoll) : configRoll,
|
||||
cls = getDocumentClass('ChatMessage'),
|
||||
msg = new cls({
|
||||
type: config.chatMessage.type ?? 'dualityRoll',
|
||||
sound: config.chatMessage.mute ? null : CONFIG.sounds.dice,
|
||||
system: systemData,
|
||||
content: config.chatMessage.template,
|
||||
rolls: [roll]
|
||||
});
|
||||
|
||||
await cls.create(msg.toObject());
|
||||
}
|
||||
return roll;
|
||||
}
|
||||
|
||||
formatRollModifier(modifier) {
|
||||
return modifier.value !== null ? [
|
||||
{
|
||||
value: modifier.value ? Number.parseInt(modifier.value) : 0,
|
||||
label:
|
||||
modifier.value >= 0
|
||||
? `${modifier.title} +${modifier.value}`
|
||||
: `${modifier.title} ${modifier.value}`,
|
||||
title: modifier.title
|
||||
}
|
||||
]
|
||||
: [];
|
||||
formatRollModifier(roll) {
|
||||
const modifier = roll.modifier !== null ? Number.parseInt(roll.modifier) : null;
|
||||
return modifier !== null
|
||||
? [
|
||||
{
|
||||
value: modifier,
|
||||
label: modifier >= 0 ? `${roll.label} +${modifier}` : `${roll.label} ${modifier}`,
|
||||
title: roll.label
|
||||
}
|
||||
]
|
||||
: [];
|
||||
}
|
||||
|
||||
// Delete when new roll logic test done
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ export function dualityRollEnricher(match, _options) {
|
|||
}
|
||||
|
||||
export function getDualityMessage(roll) {
|
||||
const attributeLabel =
|
||||
roll.attribute && abilities[roll.attribute]
|
||||
const traitLabel =
|
||||
roll.trait && abilities[roll.trait]
|
||||
? game.i18n.format('DAGGERHEART.General.Check', {
|
||||
check: game.i18n.localize(abilities[roll.attribute].label)
|
||||
check: game.i18n.localize(abilities[roll.trait].label)
|
||||
})
|
||||
: null;
|
||||
const label = attributeLabel ?? game.i18n.localize('DAGGERHEART.General.Duality');
|
||||
const label = traitLabel ?? game.i18n.localize('DAGGERHEART.General.Duality');
|
||||
|
||||
const dualityElement = document.createElement('span');
|
||||
dualityElement.innerHTML = `
|
||||
|
|
@ -23,7 +23,7 @@ export function getDualityMessage(roll) {
|
|||
data-label="${label}"
|
||||
data-hope="${roll.hope ?? 'd12'}"
|
||||
data-fear="${roll.fear ?? 'd12'}"
|
||||
${roll.attribute && abilities[roll.attribute] ? `data-attribute="${roll.attribute}"` : ''}
|
||||
${roll.trait && abilities[roll.trait] ? `data-trait="${roll.trait}"` : ''}
|
||||
${roll.advantage ? 'data-advantage="true"' : ''}
|
||||
${roll.disadvantage ? 'data-disadvantage="true"' : ''}
|
||||
>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue