Skip to content

Commit

Permalink
Automationf for Aeon Stone pearly white spindle
Browse files Browse the repository at this point in the history
fix minor error bug
  • Loading branch information
ChasarooniZ committed May 16, 2024
1 parent 7791d2a commit 8ef8b5d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
6 changes: 6 additions & 0 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
}
Expand Down
35 changes: 27 additions & 8 deletions scripts/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ 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) ?? []));
}
await updateFrequencyOfActors(
actors,
total,
diff
!game.combat ? "updateTime" : "default"
);
});
Expand Down Expand Up @@ -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");
Expand All @@ -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 (
Expand Down Expand Up @@ -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;
}
8 changes: 8 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});

0 comments on commit 8ef8b5d

Please sign in to comment.