[Feature] Countdown Actions (#1302)

* Added countdown actions

* Added a CountdownAutomation setting to enable/disable countdown automation

* Added Looping

* Added characterSpotlight automation

* Countdown max as formula to enable random countdowns

* Updated compendiums with countdowns

* .

* Fixed lightmode colouration

* Raised system version

* Added automation for ActionRolls on countdowns

* Added automation on fear to countdowns

* Corrected attackAction countdown automation

* Added initial countdown upon creating a CountdownAction

* Improved ActionCountdown initial name to be 'Start Countdown'
This commit is contained in:
WBHarry 2025-11-20 11:46:00 +01:00 committed by GitHub
parent 0233979a9f
commit 207220ff7b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
54 changed files with 1742 additions and 635 deletions

View file

@ -232,7 +232,8 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
hasRoll: true,
skips: {
createMessage: true,
resources: !isLeader
resources: !isLeader,
updateCountdowns: !isLeader
}
};
const result = await actor.diceRoll({
@ -291,7 +292,8 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
},
hasRoll: true,
skips: {
createMessage: true
createMessage: true,
updateCountdowns: true
}
};
const result = await actor.diceRoll({

View file

@ -136,7 +136,10 @@ export default class DhCombatTracker extends foundry.applications.sidebar.tabs.C
if (this.viewed.turn !== toggleTurn) {
const { updateCountdowns } = game.system.api.applications.ui.DhCountdowns;
await updateCountdowns(CONFIG.DH.GENERAL.countdownTypes.spotlight.id);
await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.spotlight.id);
if (combatant.actor.type === 'character') {
await updateCountdowns(CONFIG.DH.GENERAL.countdownProgressionTypes.characterSpotlight.id);
}
const autoPoints = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).actionPoints;
if (autoPoints) {

View file

@ -44,18 +44,30 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
context.ownershipDefaultOptions = CONFIG.DH.GENERAL.basicOwnershiplevels;
context.defaultOwnership = this.data.defaultOwnership;
context.countdownBaseTypes = CONFIG.DH.GENERAL.countdownBaseTypes;
context.countdownTypes = CONFIG.DH.GENERAL.countdownTypes;
context.countdownProgressionTypes = CONFIG.DH.GENERAL.countdownProgressionTypes;
context.countdownLoopingTypes = CONFIG.DH.GENERAL.countdownLoopingTypes;
context.hideNewCountdowns = this.hideNewCountdowns;
context.countdowns = Object.keys(this.data.countdowns).reduce((acc, key) => {
const countdown = this.data.countdowns[key];
const isLooping = countdown.progress.looping !== CONFIG.DH.GENERAL.countdownLoopingTypes.noLooping;
const loopTooltip = isLooping
? countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.increasing.id
? 'DAGGERHEART.UI.Countdowns.increasingLoop'
: countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.decreasing.id
? 'DAGGERHEART.UI.Countdowns.decreasingLoop'
: 'DAGGERHEART.UI.Countdowns.loop'
: null;
acc[key] = {
...countdown,
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownBaseTypes[countdown.type].name),
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownBaseTypes[countdown.type].label),
progress: {
...countdown.progress,
typeName: game.i18n.localize(CONFIG.DH.GENERAL.countdownTypes[countdown.progress.type].label)
typeName: game.i18n.localize(
CONFIG.DH.GENERAL.countdownProgressionTypes[countdown.progress.type].label
)
},
editing: this.editingCountdowns.has(key)
editing: this.editingCountdowns.has(key),
loopTooltip
};
return acc;

View file

@ -33,6 +33,7 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
actions: {
toggleViewMode: DhCountdowns.#toggleViewMode,
editCountdowns: DhCountdowns.#editCountdowns,
loopCountdown: DhCountdowns.#loopCountdown,
decreaseCountdown: (_, target) => this.editCountdown(false, target),
increaseCountdown: (_, target) => this.editCountdown(true, target)
},
@ -111,11 +112,26 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
return acc;
}, []);
const nonGmPlayers = game.users.filter(x => !x.isGM);
const countdownEditable = game.user.isGM || ownership === CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER;
const isLooping = countdown.progress.looping !== CONFIG.DH.GENERAL.countdownLoopingTypes.noLooping;
const loopTooltip = isLooping
? countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.increasing.id
? 'DAGGERHEART.UI.Countdowns.increasingLoop'
: countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.decreasing.id
? 'DAGGERHEART.UI.Countdowns.decreasingLoop'
: 'DAGGERHEART.UI.Countdowns.loop'
: null;
const loopDisabled =
!countdownEditable || (isLooping && (countdown.progress.current > 0 || countdown.progress.max === '0'));
acc[key] = {
...countdown,
editable: game.user.isGM || ownership === CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER,
playerAccess: playersWithAccess.length !== nonGmPlayers.length ? playersWithAccess : [],
noPlayerAccess: nonGmPlayers.length && playersWithAccess.length === 0
editable: countdownEditable,
noPlayerAccess: nonGmPlayers.length && playersWithAccess.length === 0,
shouldLoop: isLooping && countdown.progress.current === 0 && countdown.progress.max > 0,
loopDisabled: isLooping ? loopDisabled : null,
loopTooltip: isLooping && game.i18n.localize(loopTooltip)
};
return acc;
}, {});
@ -161,6 +177,28 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
new game.system.api.applications.ui.CountdownEdit().render(true);
}
static async #loopCountdown(_, target) {
if (!DhCountdowns.canPerformEdit()) return;
const settings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Countdowns);
const countdown = settings.countdowns[target.id];
const newMax =
countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.increasing.id
? countdown.progress.max + 1
: countdown.progress.looping === CONFIG.DH.GENERAL.countdownLoopingTypes.decreasing.id
? Math.max(countdown.progress.max - 1, 0)
: countdown.progress.max;
await settings.updateSource({
[`countdowns.${target.id}.progress`]: {
current: newMax,
max: newMax
}
});
await emitAsGM(GMUpdateEvent.UpdateCountdowns, DhCountdowns.gmSetSetting.bind(settings), settings, null, {
refreshType: RefreshType.Countdown
});
}
static async editCountdown(increase, target) {
if (!DhCountdowns.canPerformEdit()) return;
@ -197,6 +235,9 @@ export default class DhCountdowns extends HandlebarsApplicationMixin(Application
}
static async updateCountdowns(progressType) {
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];