diff --git a/languages/en.json b/languages/en.json index 91bfdbc..349f69e 100644 --- a/languages/en.json +++ b/languages/en.json @@ -7,6 +7,12 @@ "name": "Include Canvas Tokens On Timebased Refreshed", "hint": "When enabled will not just check the party, but also all tokens on the canvas to see to refresh their uses" } + }, + "automate-item": { + "aeon-pearly-white": { + "name": "Automate Aeon Stone (Pearly White Spindle)", + "hint": "Automates the healing for aeon stone pearly white spindle (currently only out of combat" + } } } } diff --git a/scripts/module.js b/scripts/module.js index 16be5d1..3578838 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -35,7 +35,7 @@ Hooks.once("ready", function () { }); //Refreshing item usage count - Hooks.on("updateWorldTime", async (total, _diff) => { + Hooks.on("updateWorldTime", async (total, diff) => { const actors = game.actors.party.members; if (game.settings.get(MODULE_ID, "include-canvas.enabled")) { actors.push(...(canvas?.tokens?.placeables?.map((t) => t?.actor) ?? [])); @@ -43,6 +43,7 @@ Hooks.once("ready", function () { await updateFrequencyOfActors( actors, total, + diff !game.combat ? "updateTime" : "default" ); }); @@ -72,16 +73,16 @@ function checkActionSupport() { ); } -async function updateFrequencyOfActors(party, total, situation = "default") { +async function updateFrequencyOfActors(party, total, diff, situation = "default") { for (const character of party) { - await updateFrequency(character, total, situation); + await updateFrequency(character, total, diff, situation); } } -async function updateFrequency(character, total, situation = "default") { +async function updateFrequency(character, total, diff, situation = "default") { const items = character.items.contents; const relevantItems = items.filter((it) => - isItemRelevant(it, total, situation) + isItemRelevant(it, total, diff, situation) ); relevantItems.forEach((it) => { it.unsetFlag(MODULE_ID, "cooldown"); @@ -97,9 +98,10 @@ async function updateFrequency(character, total, situation = "default") { } } -export function isItemRelevant(item, total, situation) { - const { cooldown, _per } = item?.getFlag(MODULE_ID, "cooldown"); - if (!cooldown) return false; +export function isItemRelevant(item, total, diff, situation) { + const { cooldown = null } = item?.getFlag(MODULE_ID, "cooldown"); + const isSpecialCase = checkAndHandleSpecialCase(item, total, diff, situation); + if (!cooldown && !isSpecialCase) return false; switch (situation) { case "updateTime": return ( @@ -148,3 +150,20 @@ export function getCoolDownTime(frequency) { export function getCombatActor() { [...game.combat.combatants.values()].map((com) => com.token.actor); } + +export function checkAndHandleSpecialCase(item, _total, diff, _situation) { + const slug = item.system.slug; + const actor = item.actor; + switch(slug) { + case 'aeon-stone-pearly-white-spindle': + game.settings.get(MODULE_ID, "automate-item.aeon-pearly-white") + const health = Math.floor(diff/60); + if (health > 0) { + new Roll(`${health}[Healing]`).toMessage({flavor: item.name, speaker: ChatMessage.getSpeaker()}) + } + break; + default: + break; + } + return false; +} diff --git a/scripts/settings.js b/scripts/settings.js index 5fecdb0..29156bd 100644 --- a/scripts/settings.js +++ b/scripts/settings.js @@ -9,4 +9,12 @@ Hooks.on("init", () => { default: false, type: Boolean, }); + game.settings.register(MODULE_ID, "automate-item.aeon-pearly-white", { + name: game.i18n.localize(`${MODULE_ID}.module-settings.automate-item.aeon-pearly-white.name`), + hint: game.i18n.localize(`${MODULE_ID}.module-settings.automate-item.aeon-pearly-white.hint`), + scope: "world", + config: true, + default: false, + type: Boolean, + }); });