mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-22 02:19:54 +02:00
[Fix] Reroll Countdown Automation (#2031)
* Fixed so that automated countdowns reverse progress from Fear when rerolling dice if the duality result changes * . * Removed overprep * Apply suggestion from @CarlosFdez --------- Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com>
This commit is contained in:
parent
cc16a726bf
commit
1492491998
2 changed files with 27 additions and 16 deletions
|
|
@ -342,29 +342,31 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
|
|||
* Sends updates of the countdowns to the GM player. Since this is asynchronous, be sure to
|
||||
* update all the countdowns at the same time.
|
||||
*
|
||||
* @param {...any} progressTypes Countdowns to be updated
|
||||
* @param {...(string | { type: string; undo?: boolean })} progressTypes Countdowns to be updated
|
||||
*/
|
||||
static async updateCountdowns(...progressTypes) {
|
||||
progressTypes = progressTypes.map(p => typeof p === 'string' ? { type: p } : p);
|
||||
const { countdownAutomation } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation);
|
||||
if (!countdownAutomation) return;
|
||||
|
||||
const countdownSetting = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
|
||||
const updatedCountdowns = Object.keys(countdownSetting.countdowns).reduce((acc, key) => {
|
||||
const countdown = countdownSetting.countdowns[key];
|
||||
if (progressTypes.indexOf(countdown.progress.type) !== -1 && countdown.progress.current > 0) {
|
||||
acc.push(key);
|
||||
const progressData = progressTypes.find(x => x.type === countdown.progress.type);
|
||||
if (progressData && countdown.progress.current > 0) {
|
||||
acc[key] = { value: progressData.undo ? 1 : -1 };
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
}, {});
|
||||
|
||||
const countdownData = countdownSetting.toObject();
|
||||
const settings = {
|
||||
...countdownData,
|
||||
countdowns: Object.keys(countdownData.countdowns).reduce((acc, key) => {
|
||||
const countdown = foundry.utils.deepClone(countdownData.countdowns[key]);
|
||||
if (updatedCountdowns.includes(key)) {
|
||||
countdown.progress.current -= 1;
|
||||
if (updatedCountdowns[key]) {
|
||||
countdown.progress.current += updatedCountdowns[key].value;
|
||||
}
|
||||
|
||||
acc[key] = countdown;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue