power overhaul part 2

This commit is contained in:
Mike Bloy 2024-04-29 23:59:38 -05:00
parent 9333be95fd
commit 2aa7af28a5
2 changed files with 66 additions and 43 deletions

View File

@ -7,20 +7,6 @@ class PowerEffect {
this.data = {} this.data = {}
} }
static async applyActiveEffects (token, effectDocuments) {
const mutation = {
embedded: { ActiveEffect: {} }
}
const mutateOptions = {
permanent: true,
description: effectDocuments[effectDocuments.length - 1]?.name
}
for (const effectDocument of effectDocuments) {
mutation.embedded.ActiveEffect[effectDocument.name] = effectDocument
}
await warpgate.mutate(token.document, mutation, {}, mutateOptions)
}
static async getStatus (label, name, favorite = true) { static async getStatus (label, name, favorite = true) {
const effect = deepClone( const effect = deepClone(
CONFIG.statusEffects.find(se => se.label === label)) CONFIG.statusEffects.find(se => se.label === label))
@ -38,7 +24,7 @@ class PowerEffect {
return effect return effect
} }
static createEffectDocument (icon, name, changes = null) { createEffectDocument (icon, name, changes = null) {
if (changes === null) { if (changes === null) {
changes = [] changes = []
} }
@ -47,12 +33,14 @@ class PowerEffect {
name, name,
changes, changes,
description: `<p>From <strong>${this.source.name}</strong> casting <em>${this.name}</em></p>`, description: `<p>From <strong>${this.source.name}</strong> casting <em>${this.name}</em></p>`,
duration: { rounds: 99 },
flags: { flags: {
[moduleName]: { [moduleName]: {
powerEffect: true powerEffect: true
}, swade: { },
favorite: true, swade: {
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt loseTurnOnHold: false,
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.StartOfTurnAuto
} }
} }
} }
@ -63,6 +51,7 @@ class PowerEffect {
get duration () { return 5 } get duration () { return 5 }
get basePowerPoints () { return 0 } get basePowerPoints () { return 0 }
get powerPoints () { return this.basePowerPoints } get powerPoints () { return this.basePowerPoints }
get usePrimaryEffect () { return true }
get modifiers () { get modifiers () {
return [ return [
{ name: 'Glow', { name: 'Glow',
@ -71,7 +60,7 @@ class PowerEffect {
advanced: false, advanced: false,
effect: true, effect: true,
icon: 'icons/magic/light/orb-shadow-blue.webp', icon: 'icons/magic/light/orb-shadow-blue.webp',
changes: [ { key: '@Skill{Stealth}[system.die.modifier', value: -2, changes: [ { key: '@Skill{Stealth}[system.die.modifier]', value: -2,
priority: 0, mode: foundry.CONST.ACTIVE_EFFECT_MODES.ADD } ] priority: 0, mode: foundry.CONST.ACTIVE_EFFECT_MODES.ADD } ]
}, },
{ name: 'Shroud', { name: 'Shroud',
@ -80,7 +69,7 @@ class PowerEffect {
advanced: false, advanced: false,
effect: true, effect: true,
icon: 'icons/magic/perception/shadow-stealth-eyes-purple.webp', icon: 'icons/magic/perception/shadow-stealth-eyes-purple.webp',
changes: [ { key: '@Skill{Stealth}[system.die.modifier', value: 1, changes: [ { key: '@Skill{Stealth}[system.die.modifier]', value: 1,
priority: 0, mode: foundry.CONST.ACTIVE_EFFECT_MODES.ADD } ] priority: 0, mode: foundry.CONST.ACTIVE_EFFECT_MODES.ADD } ]
}, },
{ name: 'Hinder', { name: 'Hinder',
@ -127,7 +116,7 @@ class PowerEffect {
type: 'checkbox', type: 'checkbox',
label: ( label: (
`${mod.advanced ? '⭐ ' : ''}${mod.name} ` + `${mod.advanced ? '⭐ ' : ''}${mod.name} ` +
`(${mod.value >= 0 ? '+' : ''}${mod.value}` `(${mod.value >= 0 ? '+' : ''}${mod.value})`
), ),
}) })
} }
@ -165,8 +154,6 @@ class PowerEffect {
} }
async parseValues () { async parseValues () {
log(this.data.values)
log(this.data.choice)
this.data.rawValues = deepClone(this.data.values) this.data.rawValues = deepClone(this.data.values)
this.data.raise = this.data.button === 'raise' this.data.raise = this.data.button === 'raise'
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
@ -181,39 +168,73 @@ class PowerEffect {
} }
} }
modifierEffects (helperId) { async createSecondaryEffects () {
const docs = [] const docs = []
for (const mod of this.modifiers) { for (const mod of this.modifiers) {
if (this.data.mods.has(mod.id) && mod.effect) { if (this.data.mods.has(mod.id) && mod.effect) {
const doc = this.createEffectDocument(mod.icon, mod.name, mod.changes) const doc = this.createEffectDocument(mod.icon, mod.name, mod.changes)
doc.flags[moduleName].helperId = helperId if (this.duration === 0 && !this.usePrimaryEffect) {
// set secondary effects of instant spells to expire on victim's next
// turn
doc.duration.rounds = 1
doc.flags.swade.expiration = CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.StartOfTurnAuto
}
docs.push(doc) docs.push(doc)
} }
} }
return docs return docs
} }
async createPrimaryEffect () {
const doc = this.createEffectDocument(this.icon, this.name, [])
return doc
}
async createMaintainEffect () {
const doc = this.createEffectDocument(
this.icon, `Maintaining ${this.name}`, [])
doc.duration.rounds = this.duration
doc.flags.swade.expiration = CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.StartOfTurnPrompt
doc.flags.swade.loseTurnOnHold = true
return doc
}
async secondaryDocsForTarget(docs, target) {
return deepClone(docs)
}
async primaryDocForTarget(doc, ids, target) {
const newDoc = deepClone(doc)
newDoc.flags[moduleName].secondaryDocIds = deepClone(ids)
return newDoc
}
async apply () { async apply () {
const secondaryDocs = await this.createSecondaryEffects()
const primaryDoc = await this.createPrimaryEffect()
const maintainDoc = await this.createMaintainEffect()
const primaryIds = []
for (const target of this.targets) {
const created = await target.actor.createEmbeddedDocuments(
'ActiveEffect', await this.secondaryDocsForTarget(secondaryDocs, target))
const createdIds = created.map(c => c.uuid)
if (this.duration > 0 || this.usePrimaryEffect) {
const pCreated = await target.actor.createEmbeddedDocuments(
'ActiveEffect', [await this.primaryDocForTarget(primaryDoc, createdIds, target)])
primaryIds.push(pCreated[0].uuid)
}
}
if (this.duration > 0) {
maintainDoc.flags[moduleName].secondaryDocIds = deepClone(primaryIds)
await this.source.actor.createEmbeddedDocuments('ActiveEffect', [maintainDoc])
}
} }
async sideEffects () { async sideEffects () {
} }
} }
class ActiveEffectPower extends PowerEffect { class BurrowEffect extends PowerEffect {
async secondaryDocuments (helperId) {
const secondaryDocs = this.modiferEffects(helperId)
return secondaryDocs
}
async apply () {
const helperId = randomID()
const secondaryDocs = this.secondaryDocuments(helperId)
const primaryDocument = this.primaryDocument(helperId)
}
}
class BurrowEffect extends ActiveEffectPower {
get name () { return 'Burrow' } get name () { return 'Burrow' }
get duration () { return 5 } get duration () { return 5 }
get icon () { return 'icons/magic/earth/projectile-stone-landslide.webp' } get icon () { return 'icons/magic/earth/projectile-stone-landslide.webp' }

View File

@ -1,10 +1,12 @@
import { log, moduleName } from './globals.js'
import { PowerClasses } from './allPowers.js' import { PowerClasses } from './allPowers.js'
export async function powerEffectManagementHook(effect, data, userId) { export async function powerEffectManagementHook(effect, data, userId) {
console.log('Power Effect Management') log('ids:', effect.getFlag(moduleName, 'secondaryDocIds'))
console.log(effect) log('Power Effect Management')
console.log(data) log('effect:', effect)
console.log(userId) log('data:', data)
log('userId:', userId)
} }
export async function powers (options = {}) { export async function powers (options = {}) {