mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49:02 +01:00
Added rerolls for damage dice in chat
This commit is contained in:
parent
a25007b994
commit
c4697637e0
4 changed files with 95 additions and 14 deletions
|
|
@ -228,19 +228,28 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
||||||
}
|
}
|
||||||
|
|
||||||
const target = event.target.closest('[data-die-index]');
|
const target = event.target.closest('[data-die-index]');
|
||||||
let originalRoll_parsed = message.rolls.map(roll => JSON.parse(roll))[0];
|
|
||||||
const rollClass =
|
|
||||||
game.system.api.dice[
|
|
||||||
message.type === 'dualityRoll' ? 'DualityRoll' : target.dataset.type === 'damage' ? 'DHRoll' : 'D20Roll'
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!game.modules.get('dice-so-nice')?.active) foundry.audio.AudioHelper.play({ src: CONFIG.sounds.dice });
|
if (target.dataset.type === 'damage') {
|
||||||
|
game.system.api.dice.DamageRoll.reroll(target, message);
|
||||||
|
} else {
|
||||||
|
let originalRoll_parsed = message.rolls.map(roll => JSON.parse(roll))[0];
|
||||||
|
const rollClass =
|
||||||
|
game.system.api.dice[
|
||||||
|
message.type === 'dualityRoll'
|
||||||
|
? 'DualityRoll'
|
||||||
|
: target.dataset.type === 'damage'
|
||||||
|
? 'DHRoll'
|
||||||
|
: 'D20Roll'
|
||||||
|
];
|
||||||
|
|
||||||
const { newRoll, parsedRoll } = await rollClass.reroll(originalRoll_parsed, target, message);
|
if (!game.modules.get('dice-so-nice')?.active) foundry.audio.AudioHelper.play({ src: CONFIG.sounds.dice });
|
||||||
|
|
||||||
await game.messages.get(message._id).update({
|
const { newRoll, parsedRoll } = await rollClass.reroll(originalRoll_parsed, target, message);
|
||||||
'system.roll': newRoll,
|
|
||||||
'rolls': [parsedRoll]
|
await game.messages.get(message._id).update({
|
||||||
});
|
'system.roll': newRoll,
|
||||||
|
'rolls': [parsedRoll]
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,4 +134,67 @@ export default class DamageRoll extends DHRoll {
|
||||||
}
|
}
|
||||||
return (part.roll._formula = this.constructor.getFormula(part.roll.terms));
|
return (part.roll._formula = this.constructor.getFormula(part.roll.terms));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static async reroll(target, message) {
|
||||||
|
const { damageType, part, dice, result } = target.dataset;
|
||||||
|
const rollPart = message.system.damage[damageType].parts[part];
|
||||||
|
|
||||||
|
let parsedRoll = game.system.api.dice.DamageRoll.fromData({
|
||||||
|
...rollPart.roll,
|
||||||
|
terms: rollPart.roll.terms.map((term, index) => ({
|
||||||
|
...term,
|
||||||
|
...(term.class === 'Die' ? { results: rollPart.dice[index].results } : {})
|
||||||
|
})),
|
||||||
|
class: 'DamageRoll',
|
||||||
|
evaluated: false
|
||||||
|
});
|
||||||
|
|
||||||
|
const term = parsedRoll.terms[dice];
|
||||||
|
const termResult = parsedRoll.terms[dice].results[result];
|
||||||
|
|
||||||
|
const newIndex = parsedRoll.terms[dice].results.length;
|
||||||
|
await term.reroll(`/r1=${termResult.result}`);
|
||||||
|
|
||||||
|
if (game.modules.get('dice-so-nice')?.active) {
|
||||||
|
const newResult = parsedRoll.terms[dice].results[newIndex];
|
||||||
|
const diceSoNiceRoll = {
|
||||||
|
_evaluated: true,
|
||||||
|
dice: [
|
||||||
|
new foundry.dice.terms.Die({
|
||||||
|
...term,
|
||||||
|
total: newResult.result,
|
||||||
|
faces: term._faces,
|
||||||
|
results: [newResult]
|
||||||
|
})
|
||||||
|
],
|
||||||
|
options: { appearance: {} }
|
||||||
|
};
|
||||||
|
|
||||||
|
await game.dice3d.showForRoll(diceSoNiceRoll, game.user, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
await parsedRoll.evaluate();
|
||||||
|
|
||||||
|
const results = parsedRoll.dice[dice].results.map(result => ({
|
||||||
|
...result,
|
||||||
|
discarded: !result.active
|
||||||
|
}));
|
||||||
|
const newResult = results.splice(results.length - 1, 1);
|
||||||
|
results.splice(Number(result) + 1, 0, newResult[0]);
|
||||||
|
|
||||||
|
const rerolledDice = {
|
||||||
|
dice: parsedRoll.dice[dice].denomination,
|
||||||
|
total: parsedRoll.dice[dice].total,
|
||||||
|
results: results
|
||||||
|
};
|
||||||
|
|
||||||
|
await game.messages.get(message._id).update({
|
||||||
|
[`system.damage.${damageType}.parts.${part}`]: {
|
||||||
|
...rollPart,
|
||||||
|
total: parsedRoll.total,
|
||||||
|
dice: [rerolledDice],
|
||||||
|
[`dice.${dice}`]: rerolledDice
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -522,10 +522,14 @@
|
||||||
.roll-die {
|
.roll-die {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-areas:
|
grid-template-areas:
|
||||||
". a a"
|
'. a a'
|
||||||
"c b b";
|
'c b b';
|
||||||
gap: 3px;
|
gap: 3px;
|
||||||
|
|
||||||
|
.reroll-button:hover {
|
||||||
|
filter: drop-shadow(0 0 3px @golden);
|
||||||
|
}
|
||||||
|
|
||||||
label {
|
label {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
height: var(--font-size-12);
|
height: var(--font-size-12);
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,12 @@
|
||||||
{{#each results}}
|
{{#each results}}
|
||||||
{{#unless discarded}}
|
{{#unless discarded}}
|
||||||
<div class="roll-die{{#unless @../first}} has-plus{{/unless}}">
|
<div class="roll-die{{#unless @../first}} has-plus{{/unless}}">
|
||||||
<div class="dice {{../dice}}">{{result}}</div>
|
<div
|
||||||
|
class="dice reroll-button {{../dice}}"
|
||||||
|
data-die-index="0" data-type="damage" data-damage-type="{{@../../../key}}" data-part="{{@../../key}}" data-dice="{{@../key}}" data-result="{{@key}}"
|
||||||
|
>
|
||||||
|
{{result}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue