diff --git a/scripts/allPowers.js b/scripts/allPowers.js index b95a1d1..631bd79 100644 --- a/scripts/allPowers.js +++ b/scripts/allPowers.js @@ -28,9 +28,7 @@ class PowerEffect { createEffectDocument (icon, name, changes = null) { if (changes === null) { - changes = [ - { key: 'flags.swade-mb-helpers.hasPower', value: 1, - priority: 0, mode: foundry.CONST.ACTIVE_EFFECT_MODES.OVERRIDE } ] + changes = [] } return { icon, @@ -66,10 +64,10 @@ class PowerEffect { } get name () { return 'Unknown Power' } + get effectName () { return this.name } get icon () { return 'icons/magic/symbols/question-stone-yellow.webp' } get duration () { return 5 } get basePowerPoints () { return 0 } - get powerPoints () { return this.basePowerPoints } get usePrimaryEffect () { return true } get modifiers () { return [ @@ -169,6 +167,7 @@ class PowerEffect { await this.parseValues() await this.apply() await this.sideEffects() + await this.chatMessage() } } @@ -207,8 +206,16 @@ class PowerEffect { return docs } + getPrimaryEffectChanges () { + const changes = [ + { key: 'flags.swade-mb-helpers.powerAffected', value: 1, + priority: 0, mode: foundry.CONST.ACTIVE_EFFECT_MODES.OVERRIDE } ] + return changes + } + async createPrimaryEffect (maintId) { - const doc = this.createEffectDocument(this.icon, this.name, []) + const doc = this.createEffectDocument(this.icon, this.effectName, + this.getPrimaryEffectChanges()) doc.flags[moduleName].maintId = maintId doc.duration.seconds = 594 return doc @@ -257,12 +264,60 @@ class PowerEffect { async sideEffects () { } + + get powerPoints () { + let total = this.basePowerPoints + for (const mod of this.modifiers) { + if (this.data.mods.has(mod.id)) { + total += mod.value + } + } + return total + } + + async chatMessage () { + let text = `Cast ${this.name}` + if (this.targets.length > 0) { + text += ` on ${this.targets.map(t => t.name).join(', ')}` + } + return ChatMessage.create({ + flavor: `Calculated cost: ${this.powerPoints} pp`, + speaker: ChatMessage.getSpeaker(this.source.actor), + content: text, + whisper: ChatMessage.getWhisperRecipients('GM', game.user.name), + }, { chatBubble: false }); + } } -class BurrowEffect extends PowerEffect { + +class AdditionalRecipientsMixin extends PowerEffect { + get additionalRecipientCost () { return 1 } + get menuInputs () { + const inputs = super.menuInputs + if (this.targets.length > 1) { + inputs[2].label += ` (${this.targets.length - 1} additional recipients ` + + ` +${this.additionalRecipientCost} ea.)` + } + return inputs + } + + get powerPoints () { + let pp = super.powerPoints + if (this.targets.length > 1) { + pp += (this.targets.length - 1) * this.additionalRecipientCost + } + return pp + } +} + + +class BurrowEffect extends PowerEffect, AdditionalRecipientsMixin { get name () { return 'Burrow' } get duration () { return 5 } get icon () { return 'icons/magic/earth/projectile-stone-landslide.webp' } + get effectName () { + return `${this.name} (${this.data.raise ? 'half' : 'full'} pace)` + } } export const PowerClasses = {