From 46a946df2c6adf976b8c63971611e292e317adc3 Mon Sep 17 00:00:00 2001 From: Mike Bloy Date: Sun, 10 Sep 2023 01:05:24 -0500 Subject: [PATCH] summon increased effect --- scripts/powerEffects.js | 93 +++++++++++++++++++++++++++++++++++------ 1 file changed, 81 insertions(+), 12 deletions(-) diff --git a/scripts/powerEffects.js b/scripts/powerEffects.js index a658d8b..424570f 100644 --- a/scripts/powerEffects.js +++ b/scripts/powerEffects.js @@ -36,7 +36,7 @@ class PowerEffect { } get durationRounds () { - return this.baseDurationRounds() + return this.baseDurationRounds } get baseDurationRounds () { @@ -595,17 +595,22 @@ class SummonEffect extends PowerEffect { this.summonableActors = actors - this.menuData.inputs.push({ - type: 'select', - label: 'Creature to summon', - options: Object.keys(actors).filter( - k => !k.includes('_template')).sort().map(actorData) - }) - this.menuData.inputs.push({ - type: 'number', - label: 'Number to spawn (+half base cost per)', - options: 1 - }) + this.menuData.inputs = this.menuData.inputs.concat([ + { + type: 'select', + label: 'Creature to summon', + options: Object.keys(actors).filter( + k => !k.includes('_template')).sort().map(actorData) + }, { + type: 'number', + label: 'Number to spawn (+half base cost per)', + options: 1 + }, { + type: 'checkbox', + label: 'Add Increased Trait(s)? (+1 per trait)', + options: false + } + ]) } async prepResult () { @@ -615,6 +620,8 @@ class SummonEffect extends PowerEffect { this.actor = shim.actors.get(this.actorId) this.icon = this.actor.prototypeToken.texture.src this.protoDoc = await this.actor.getTokenDocument() + this.increasedTrait = !!(this.inputs[this.inputIndex + 2]) + this.inputIndex += 2 this.spawnOptions = { controllingActor: this.token.actor, duplicates: this.number, @@ -648,7 +655,69 @@ class SummonEffect extends PowerEffect { } } + async prepAdditional () { + await this.prepIncreasedTrait() + } + + async prepIncreasedTrait () { + if (!this.increasedTrait) { + return + } + const traitMenuOptions = { + title: `${this.name} Summon Trait Increase`, + defaultButton: 'Cancel', + options: {} + } + const skillSet = new Set() + for (const skill of this.actor.items.filter(i => i.type === 'skill')) { + skillSet.add(skill.name) + } + for (const item of Object.values(this.spawnMutation.embedded.Item).filter(i => i.type === 'skill')) { + skillSet.add(item.name) + } + const skillList = Array.from(skillSet) + const attrList = ['Agility', 'Smarts', 'Spirit', 'Strength', 'Vigor'] + skillList.sort() + const traitMenuData = { + inputs: [ + { type: 'header', label: 'Increase Attributes (+1 each)' } + ], + buttons: [ + { label: 'Apply', value: 'apply' }, + { label: 'Increase no traits', value: 'cancel' } + ] + } + traitMenuData.inputs = traitMenuData.inputs.concat( + attrList.map((x) => { return { type: 'checkbox', label: x, options: false } })) + traitMenuData.inputs.push({ type: 'header', label: 'Increase Skills (+1 each)' }) + traitMenuData.inputs = traitMenuData.inputs.concat( + skillList.map((x) => { return { type: 'checkbox', label: x, options: false } })) + const { buttons, inputs } = await shim.warpgateMenu(traitMenuData, traitMenuOptions) + if (!buttons || buttons === 'cancel') { + return + } + const modKeys = [] + for (let i = 0; i < attrList.length; i++) { + if (inputs[i + 1]) { + modKeys.push(`system.attributes.${attrList[i].toLowerCase()}.die.sides`) + } + } + for (let i = 0; i < skillList.length; i++) { + if (inputs[i + 7]) { + modKeys.push(`@Skill{${skillList[i]}}[system.die.sides]`) + } + } + const effectDoc = shim.createEffectDocument(this.ICON, 'Increased Trait', this.durationRounds) + effectDoc.changes = modKeys.map(key => { + return { + key, mode: CONST.FOUNDRY.ACTIVE_EFFECT_MODES.ADD, value: '+2', priority: 0 + } + }) + this.spawnMutation.embedded.ActiveEffect[effectDoc.name] = effectDoc + } + async applyResult () { + await this.prepAdditional() await shim.warpgateSpawn(this.protoDoc, this.spawnMutation, {}, this.spawnOptions) } }