diff --git a/source/index.ts b/source/index.ts index b048aa7..4dd726a 100644 --- a/source/index.ts +++ b/source/index.ts @@ -86,6 +86,10 @@ Hooks.once("init", async () => { return param.replace(regex, ""); }); + Handlebars.registerHelper("contains", (label: string, contains: string) => { + return label.toLowerCase().includes(contains.toLowerCase()); + }); + // Default Sheet für Items definieren und das Standardsheet deaktivieren Items.unregisterSheet("core", ItemSheet); Items.registerSheet("midgard5", M5ItemSheet, { makeDefault: true }); @@ -105,6 +109,100 @@ Hooks.once("setup", () => { Logger.log("Template module is being setup."); }); +Hooks.on("getChatLogEntryContext", function (html, options) { + options.push( + { + name: "LP & AP Schaden", + icon: '', + condition: (li) => { + // Only show this context menu if there are re-rollable dice in the message + const damageRolls = li.find(".apply-damage").length; + + // All must be true to show the reroll dialogue + return damageRolls > 0; + }, + callback: (li) => applyDamage(li, 2), + }, + { + name: "AP Schaden", + icon: '', + condition: (li) => { + // Only show this context menu if there are re-rollable dice in the message + const damageRolls = li.find(".apply-damage").length; + + // All must be true to show the reroll dialogue + return damageRolls > 0; + }, + callback: (li) => applyDamage(li, 1), + }, + { + name: "LP & AP Heilen", + icon: '', + condition: (li) => { + // Only show this context menu if there are re-rollable dice in the message + const damageRolls = li.find(".apply-damage").length; + + // All must be true to show the reroll dialogue + return damageRolls > 0; + }, + callback: (li) => applyDamage(li, -1), + }, + { + name: "AP Schaden", + icon: '', + condition: (li) => { + // Only show this context menu if there are re-rollable dice in the message + const damageRolls = li.find(".apply-damage").length; + + // All must be true to show the reroll dialogue + return damageRolls > 0; + }, + callback: (li) => applyDamage(li, -2), + } + ); +}); + Hooks.once("ready", () => { Logger.ok("Template module is now ready."); }); + +async function applyDamage(roll, direction) { + const damageValue = Array.from(roll.find(".apply-damage") as HTMLElement[]) + .map((x) => Number(x.innerText)) + .reduce((prev, curr) => prev + curr, 0); + console.log(damageValue); + const userId = game["user"].character.id; + const viewedSceneId = game["user"].viewedScene; + const token = game["actors"].get(userId).getDependentTokens(viewedSceneId)[0]?.delta.syntheticActor; + const actor = game["user"].character; + console.log(token); + console.log(actor); + + if (token) { + switch (direction) { + case 2: + token["system"].lp.value -= damageValue; + case 1: + token["system"].ap.value -= damageValue; + break; + case -1: + token.delta.system.lp += damageValue; + case -2: + token.delta.system.ap += damageValue; + } + } else { + switch (direction) { + case 2: + actor["system"].lp.value -= damageValue; + case 1: + actor["system"].ap.value -= damageValue; + break; + case -1: + actor["system"].lp.value += damageValue; + case -2: + actor["system"].ap.value += damageValue; + } + } + + actor.render(); +} diff --git a/templates/chat/roll-m5.hbs b/templates/chat/roll-m5.hbs index c7e816d..856e72b 100644 --- a/templates/chat/roll-m5.hbs +++ b/templates/chat/roll-m5.hbs @@ -82,7 +82,7 @@ {{roll.label}} - {{roll.totalStr}} + {{roll.totalStr}} {{roll.result}}