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 = {}
}
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) {
const effect = deepClone(
CONFIG.statusEffects.find(se => se.label === label))
@ -38,7 +24,7 @@ class PowerEffect {
return effect
}
static createEffectDocument (icon, name, changes = null) {
createEffectDocument (icon, name, changes = null) {
if (changes === null) {
changes = []
}
@ -47,12 +33,14 @@ class PowerEffect {
name,
changes,
description: `<p>From <strong>${this.source.name}</strong> casting <em>${this.name}</em></p>`,
duration: { rounds: 99 },
flags: {
[moduleName]: {
powerEffect: true
}, swade: {
favorite: true,
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt
},
swade: {
loseTurnOnHold: false,
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.StartOfTurnAuto
}
}
}
@ -63,6 +51,7 @@ class PowerEffect {
get duration () { return 5 }
get basePowerPoints () { return 0 }
get powerPoints () { return this.basePowerPoints }
get usePrimaryEffect () { return true }
get modifiers () {
return [
{ name: 'Glow',
@ -71,7 +60,7 @@ class PowerEffect {
advanced: false,
effect: true,
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 } ]
},
{ name: 'Shroud',
@ -80,7 +69,7 @@ class PowerEffect {
advanced: false,
effect: true,
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 } ]
},
{ name: 'Hinder',
@ -127,7 +116,7 @@ class PowerEffect {
type: 'checkbox',
label: (
`${mod.advanced ? '⭐ ' : ''}${mod.name} ` +
`(${mod.value >= 0 ? '+' : ''}${mod.value}`
`(${mod.value >= 0 ? '+' : ''}${mod.value})`
),
})
}
@ -165,8 +154,6 @@ class PowerEffect {
}
async parseValues () {
log(this.data.values)
log(this.data.choice)
this.data.rawValues = deepClone(this.data.values)
this.data.raise = this.data.button === 'raise'
for (let i = 0; i < 3; i++) {
@ -181,39 +168,73 @@ class PowerEffect {
}
}
modifierEffects (helperId) {
async createSecondaryEffects () {
const docs = []
for (const mod of this.modifiers) {
if (this.data.mods.has(mod.id) && mod.effect) {
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)
}
}
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 () {
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 () {
}
}
class ActiveEffectPower 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 {
class BurrowEffect extends PowerEffect {
get name () { return 'Burrow' }
get duration () { return 5 }
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'
export async function powerEffectManagementHook(effect, data, userId) {
console.log('Power Effect Management')
console.log(effect)
console.log(data)
console.log(userId)
log('ids:', effect.getFlag(moduleName, 'secondaryDocIds'))
log('Power Effect Management')
log('effect:', effect)
log('data:', data)
log('userId:', userId)
}
export async function powers (options = {}) {