mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
Bug/chat roll fixes (#726)
* #635 & #637 * #653 * Fix: #681 #682 #685 #686 * Fix duplicate messages * Remove comments
This commit is contained in:
parent
5d0a4382cc
commit
f9cb0954f9
21 changed files with 242 additions and 546 deletions
|
|
@ -139,17 +139,17 @@ export default class D20Roll extends DHRoll {
|
|||
static postEvaluate(roll, config = {}) {
|
||||
const data = super.postEvaluate(roll, config);
|
||||
data.type = config.roll?.type;
|
||||
data.difficulty = config.roll.difficulty;
|
||||
if (config.targets?.length) {
|
||||
config.targetSelection = true;
|
||||
config.targets.forEach(target => {
|
||||
const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion;
|
||||
target.hit = roll.isCritical || roll.total >= difficulty;
|
||||
});
|
||||
data.success = config.targets.some(target => target.hit);
|
||||
} else if (config.roll.difficulty) {
|
||||
data.difficulty = config.roll.difficulty;
|
||||
data.success = config.targets.some(target => target.hit)
|
||||
} else if (config.roll.difficulty)
|
||||
data.success = roll.isCritical || roll.total >= config.roll.difficulty;
|
||||
}
|
||||
|
||||
data.advantage = {
|
||||
type: config.roll.advantage,
|
||||
dice: roll.dAdvantage?.denomination,
|
||||
|
|
|
|||
|
|
@ -30,16 +30,16 @@ export default class DamageRoll extends DHRoll {
|
|||
}
|
||||
|
||||
static async buildPost(roll, config, message) {
|
||||
const chatMessage = config.source?.message ? ui.chat.collection.get(config.source.message) : getDocumentClass('ChatMessage').applyRollMode({}, config.rollMode);
|
||||
if (game.modules.get('dice-so-nice')?.active) {
|
||||
const pool = foundry.dice.terms.PoolTerm.fromRolls(
|
||||
Object.values(config.damage).flatMap(r => r.parts.map(p => p.roll))
|
||||
),
|
||||
diceRoll = Roll.fromTerms([pool]);
|
||||
await game.dice3d.showForRoll(diceRoll, game.user, true);
|
||||
await game.dice3d.showForRoll(diceRoll, game.user, true, chatMessage.whisper, chatMessage.blind);
|
||||
}
|
||||
await super.buildPost(roll, config, message);
|
||||
if (config.source?.message) {
|
||||
const chatMessage = ui.chat.collection.get(config.source.message);
|
||||
chatMessage.update({ 'system.damage': config.damage });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import D20RollDialog from '../applications/dialogs/d20RollDialog.mjs';
|
|||
|
||||
export default class DHRoll extends Roll {
|
||||
baseTerms = [];
|
||||
constructor(formula, data, options) {
|
||||
constructor(formula, data = {}, options = {}) {
|
||||
super(formula, data, options);
|
||||
if (!this.data || !Object.keys(this.data).length) this.data = options.data;
|
||||
}
|
||||
|
|
@ -15,6 +15,8 @@ export default class DHRoll extends Roll {
|
|||
|
||||
static messageType = 'adversaryRoll';
|
||||
|
||||
static CHAT_TEMPLATE = 'systems/daggerheart/templates/ui/chat/roll.hbs';
|
||||
|
||||
static DefaultDialog = D20RollDialog;
|
||||
|
||||
static async build(config = {}, message = {}) {
|
||||
|
|
@ -92,9 +94,36 @@ export default class DHRoll extends Roll {
|
|||
system: config,
|
||||
rolls: [roll]
|
||||
};
|
||||
config.selectedRollMode ??= game.settings.get('core', 'rollMode');
|
||||
if(roll._evaluated) return await cls.create(msg, { rollMode: config.selectedRollMode });
|
||||
return msg;
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
async render({flavor, template=this.constructor.CHAT_TEMPLATE, isPrivate=false, ...options}={}) {
|
||||
if ( !this._evaluated ) return;
|
||||
const chatData = await this._prepareChatRenderContext({flavor, isPrivate, ...options});
|
||||
return foundry.applications.handlebars.renderTemplate(template, chatData);
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
async _prepareChatRenderContext({flavor, isPrivate=false, ...options}={}) {
|
||||
if(isPrivate) {
|
||||
return {
|
||||
user: game.user.id,
|
||||
flavor: null,
|
||||
title: "???",
|
||||
roll: {
|
||||
total: "??"
|
||||
},
|
||||
hasRoll: true,
|
||||
isPrivate
|
||||
}
|
||||
} else {
|
||||
options.message.system.user = game.user.id;
|
||||
return options.message.system;
|
||||
}
|
||||
}
|
||||
|
||||
static applyKeybindings(config) {
|
||||
if (config.event)
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ export default class DualityRoll extends D20Roll {
|
|||
}
|
||||
if (this.rallyFaces)
|
||||
this.terms.push(
|
||||
new foundry.dice.terms.OperatorTerm({ operator: this.hasDisadvantage ? '-' : '+' }),
|
||||
new foundry.dice.terms.OperatorTerm({ operator: '+' }),
|
||||
new foundry.dice.terms.Die({ faces: this.rallyFaces })
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue