From 57b58b4201f41637745669447554c80dfcfebf67 Mon Sep 17 00:00:00 2001 From: Mike Bloy Date: Tue, 12 Sep 2023 00:07:17 -0500 Subject: [PATCH] start of shape change --- scripts/powerEffects.js | 82 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/scripts/powerEffects.js b/scripts/powerEffects.js index 4839d2d..44720a3 100644 --- a/scripts/powerEffects.js +++ b/scripts/powerEffects.js @@ -472,6 +472,87 @@ class ProtectionEffect extends TargetedPowerEffect { } } +class ShapeChangeEffect extends TargetedPowerEffect { + get name () { + return 'Shape Change' + } + + get baseDurationRounds () { + return 5 + } + + get actorFolder () { + return 'Shape Change' + } + + async prepFolders () { + const folders = [] + const folderNames = [ + this.actorFolder, + `${this.actorFolder} - Default`, + `${this.actorFolder}/Default`, + `${this.actorFolder} - ${this.token.name}`, + `${this.actorFolder} - ${this.token.actor.name}`, + `${this.actorFolder}/${this.token.name}`, + `${this.actorFolder}/${this.token.actor.name}` + ] + for (const folderName of folderNames) { + const folder = shim.getActorFolderByPath(folderName) + if (folder) { + log(`Found actor folder ${folderName}`) + folders.push(folder) + } + } + if (folders.length > 1) { + folders.shift() + } + return folders + } + + async prepActors () { + const folders = await this.prepFolders() + const actors = {} + for (const folder of folders) { + const folderActors = shim.getActorsInFolder(folder) + for (const key in folderActors) { + actors[key] = folderActors[key] + } + } + return actors + } + + async prepMenu () { + const actors = await this.prepActors() + this.cancel = false + if (Object.keys(actors).length < 1) { + shim.notifications.error('No summonables found') + this.cancel = true + } + + function actorData (key) { + return { + value: actors[key].id, + html: key + } + } + + this.summonableActors = actors + + this.menuData.inputs = this.menuData.inputs.concat([ + { + type: 'select', + label: 'Turn into creature', + options: Object.keys(actors).filter( + k => !k.includes('_template')).sort().map(actorData) + }, { + type: 'checkbox', + label: 'Duration (+1, rounds to minutes)', + options: false + } + ]) + } +} + class SmiteEffect extends TargetedPowerEffect { get name () { return 'Smite' @@ -926,6 +1007,7 @@ const PowerClasses = { invisibility: InvisibilityEffect, 'lower trait': BoostLowerTraitEffect, protection: ProtectionEffect, + 'shape change': ShapeChangeEffect, smite: SmiteEffect, 'summon ally': SummonAllyEffect, 'summon animal': SummonAnimalEffect,