mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 15:39:02 +01:00
ChatMessage & takeDamage updates
This commit is contained in:
parent
7e382d2e08
commit
92feddce1b
13 changed files with 158 additions and 90 deletions
|
|
@ -140,28 +140,22 @@ export default class D20Roll extends DHRoll {
|
|||
return modifiers;
|
||||
}
|
||||
|
||||
static async buildEvaluate(roll, config = {}, message = {}) {
|
||||
if (config.evaluate !== false) await roll.evaluate();
|
||||
|
||||
this.postEvaluate(roll, config);
|
||||
}
|
||||
|
||||
static postEvaluate(roll, config = {}) {
|
||||
super.postEvaluate(roll, config);
|
||||
const data = super.postEvaluate(roll, config);
|
||||
if (config.targets?.length) {
|
||||
config.targets.forEach(target => {
|
||||
const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion;
|
||||
target.hit = this.isCritical || roll.total >= difficulty;
|
||||
});
|
||||
} else if (config.roll.difficulty)
|
||||
config.roll.success = roll.isCritical || roll.total >= config.roll.difficulty;
|
||||
config.roll.advantage = {
|
||||
data.success = roll.isCritical || roll.total >= config.roll.difficulty;
|
||||
data.advantage = {
|
||||
type: config.roll.advantage,
|
||||
dice: roll.dAdvantage?.denomination,
|
||||
value: roll.dAdvantage?.total
|
||||
};
|
||||
config.roll.isCritical = roll.isCritical;
|
||||
config.roll.extra = roll.dice
|
||||
data.isCritical = roll.isCritical;
|
||||
data.extra = roll.dice
|
||||
.filter(d => !roll.baseTerms.includes(d))
|
||||
.map(d => {
|
||||
return {
|
||||
|
|
@ -169,7 +163,8 @@ export default class D20Roll extends DHRoll {
|
|||
value: d.total
|
||||
};
|
||||
});
|
||||
config.roll.modifierTotal = this.calculateTotalModifiers(roll);
|
||||
data.modifierTotal = this.calculateTotalModifiers(roll);
|
||||
return data;
|
||||
}
|
||||
|
||||
resetFormula() {
|
||||
|
|
|
|||
|
|
@ -14,14 +14,18 @@ export default class DamageRoll extends DHRoll {
|
|||
if ( config.evaluate !== false ) {
|
||||
for ( const roll of config.roll ) await roll.roll.evaluate();
|
||||
}
|
||||
config.roll = config.roll.map(r => this.postEvaluate(r.roll));
|
||||
const parts = config.roll.map(r => this.postEvaluate(r));
|
||||
config.roll = this.unifyDamageRoll(parts);
|
||||
}
|
||||
|
||||
static postEvaluate(roll, config = {}) {
|
||||
return {
|
||||
...super.postEvaluate(roll, config),
|
||||
...roll,
|
||||
...super.postEvaluate(roll.roll, config),
|
||||
damageTypes: [...roll.damageTypes],
|
||||
roll: roll.roll,
|
||||
type: config.type,
|
||||
modifierTotal: this.calculateTotalModifiers(roll)
|
||||
modifierTotal: this.calculateTotalModifiers(roll.roll)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -33,6 +37,43 @@ export default class DamageRoll extends DHRoll {
|
|||
}
|
||||
}
|
||||
|
||||
static unifyDamageRoll(rolls) {
|
||||
const unified = {};
|
||||
rolls.forEach(r => {
|
||||
const resource = unified[r.applyTo] ?? { formula: '', total: 0, parts: [] };
|
||||
resource.formula += `${resource.formula !== '' ? ' + ' : ''}${r.formula}`;
|
||||
resource.total += r.total;
|
||||
resource.parts.push(r);
|
||||
unified[r.applyTo] = resource;
|
||||
})
|
||||
return unified;
|
||||
}
|
||||
|
||||
static formatGlobal(rolls) {
|
||||
let formula, total;
|
||||
const applyTo = new Set(rolls.flatMap(r => r.applyTo));
|
||||
if(applyTo.size > 1) {
|
||||
const data = {};
|
||||
rolls.forEach(r => {
|
||||
if(data[r.applyTo]) {
|
||||
data[r.applyTo].formula += ` + ${r.formula}` ;
|
||||
data[r.applyTo].total += r.total ;
|
||||
} else {
|
||||
data[r.applyTo] = {
|
||||
formula: r.formula,
|
||||
total: r.total
|
||||
}
|
||||
}
|
||||
});
|
||||
formula = Object.entries(data).reduce((a, [k,v]) => a + ` ${k}: ${v.formula}`, '');
|
||||
total = Object.entries(data).reduce((a, [k,v]) => a + ` ${k}: ${v.total}`, '');
|
||||
} else {
|
||||
formula = rolls.map(r => r.formula).join(' + ');
|
||||
total = rolls.reduce((a,c) => a + c.total, 0)
|
||||
}
|
||||
return {formula, total}
|
||||
}
|
||||
|
||||
applyBaseBonus(part) {
|
||||
const modifiers = [],
|
||||
type = this.options.messageType ?? 'damage',
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ export default class DHRoll extends Roll {
|
|||
|
||||
static async buildEvaluate(roll, config = {}, message = {}) {
|
||||
if (config.evaluate !== false) await roll.evaluate();
|
||||
config.roll = this.postEvaluate(roll);
|
||||
config.roll = this.postEvaluate(roll, config);
|
||||
}
|
||||
|
||||
static async buildPost(roll, config, message) {
|
||||
|
|
@ -57,8 +57,9 @@ export default class DHRoll extends Roll {
|
|||
|
||||
// Create Chat Message
|
||||
if (config.source?.message) {
|
||||
if(Array.isArray(config.roll)) {
|
||||
const pool = foundry.dice.terms.PoolTerm.fromRolls(config.roll);
|
||||
console.log(config)
|
||||
if(Array.isArray(config.roll?.parts)) {
|
||||
const pool = foundry.dice.terms.PoolTerm.fromRolls(config.roll.parts.map(r => r.roll));
|
||||
roll = Roll.fromTerms([pool]);
|
||||
}
|
||||
if (game.modules.get('dice-so-nice')?.active) await game.dice3d.showForRoll(roll, game.user, true);
|
||||
|
|
@ -67,7 +68,7 @@ export default class DHRoll extends Roll {
|
|||
}
|
||||
}
|
||||
|
||||
static postEvaluate(roll) {
|
||||
static postEvaluate(roll, config = {}) {
|
||||
return {
|
||||
total: roll.total,
|
||||
formula: roll.formula,
|
||||
|
|
|
|||
|
|
@ -161,21 +161,21 @@ export default class DualityRoll extends D20Roll {
|
|||
}
|
||||
|
||||
static postEvaluate(roll, config = {}) {
|
||||
super.postEvaluate(roll, config);
|
||||
const data = super.postEvaluate(roll, config);
|
||||
|
||||
config.roll.hope = {
|
||||
data.hope = {
|
||||
dice: roll.dHope.denomination,
|
||||
value: roll.dHope.total
|
||||
};
|
||||
config.roll.fear = {
|
||||
data.fear = {
|
||||
dice: roll.dFear.denomination,
|
||||
value: roll.dFear.total
|
||||
};
|
||||
config.roll.rally = {
|
||||
data.rally = {
|
||||
dice: roll.dRally?.denomination,
|
||||
value: roll.dRally?.total
|
||||
};
|
||||
config.roll.result = {
|
||||
data.result = {
|
||||
duality: roll.withHope ? 1 : roll.withFear ? -1 : 0,
|
||||
total: roll.dHope.total + roll.dFear.total,
|
||||
label: roll.totalLabel
|
||||
|
|
@ -184,6 +184,8 @@ export default class DualityRoll extends D20Roll {
|
|||
if(roll._rallyIndex && roll.data?.parent)
|
||||
roll.data.parent.deleteEmbeddedDocuments('ActiveEffect', [roll._rallyIndex]);
|
||||
|
||||
setDiceSoNiceForDualityRoll(roll, config.roll.advantage.type);
|
||||
setDiceSoNiceForDualityRoll(roll, data.advantage.type);
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue