working summon

This commit is contained in:
Mike Bloy 2023-09-10 22:19:22 -05:00
parent 7dce7780b9
commit e35046cecb
2 changed files with 38 additions and 29 deletions

View File

@ -728,6 +728,10 @@ class SummonAllyEffect extends SummonEffect {
return `${super.actorFolder}/Summon Ally` return `${super.actorFolder}/Summon Ally`
} }
get mirrorFolder () {
return `${super.actorFolder}/Mirror Selves`
}
async prepMenu () { async prepMenu () {
await super.prepMenu() await super.prepMenu()
this.menuData.inputs = this.menuData.inputs.concat([ this.menuData.inputs = this.menuData.inputs.concat([
@ -836,36 +840,38 @@ class SummonAllyEffect extends SummonEffect {
if (this.actor.name !== 'Mirror Self') { if (this.actor.name !== 'Mirror Self') {
return return
} }
const actorFolder = shim.getActorFolderByPath(this.mirrorFolder)
const oldActor = actorFolder.contents.find(a => a.name === `Mirror ${this.token.name}`)
if (oldActor) {
await oldActor.delete()
}
const actorDoc = this.token.actor.clone({ const actorDoc = this.token.actor.clone({
type: 'npc',
name: `Mirror ${this.token.actor.name}`,
folder: actorFolder.id,
'system.wildcard': false, 'system.wildcard': false,
'system.fatigue.value': 0, 'system.fatigue.value': 0,
'system.wounds.value': 0, 'system.wounds.value': 0,
'system.wounds.max': 0, 'system.wounds.max': 0,
'system.bennies.max': 0, 'system.bennies.max': 0,
'system.bennies.value': 0 'system.bennies.value': 0,
'prototypeToken.actorLink': false,
'prototypeToken.name': `Mirror ${this.token.name}`,
'prototypeToken.texture.scaleX': this.token.document.texture.scaleX * -1
}) })
await shim.mergeObject( const mirrorActor = this.actor
this.spawnMutation.actor, { this.actor = await shim.Actor.create(actorDoc)
name: `Mirrored ${this.token.actor.name}`, this.actorId = this.actor.id
img: this.token.actor.img, this.icon = this.actor.prototypeToken.texture.src
system: actorDoc.system this.protoDoc = await this.actor.getTokenDocument()
}, { inplace: true, recursive: true } this.spawnOptions.crosshairs.icon = this.icon
) for (const mirrorItem of mirrorActor.items) {
await shim.mergeObject( this.spawnMutation.embedded.Item[mirrorItem.name] =
this.spawnMutation.token, { mirrorActor.getEmbeddedDocument('Item', mirrorItem.id)
actorLink: false, }
disposition: this.token.document.disposition, this.spawnMutation.embedded.Item['Summon Ally'] = CONST.WARPGATE.DELETE
light: this.token.document.light,
sight: this.token.document.sight,
name: `Mirrored ${this.token.name}`,
texture: this.token.document.texture
}, { inplace: true, recursive: true })
this.spawnMutation.token.texture.scaleX = -1 * this.token.document.texture.scaleX
const effectChanges = [] const effectChanges = []
for (const item of this.token.actor.items) { for (const item of this.token.actor.items.filter(i => i.type === 'skill')) {
this.spawnMutation.embedded.Item[item.name] =
this.token.actor.getEmbeddedDocument('Item', item.id)
if (item.type === 'skill') {
effectChanges.push({ effectChanges.push({
key: `@Skill{${item.name}}[system.die.sides]`, key: `@Skill{${item.name}}[system.die.sides]`,
mode: CONST.FOUNDRY.ACTIVE_EFFECT_MODES.ADD, mode: CONST.FOUNDRY.ACTIVE_EFFECT_MODES.ADD,
@ -873,7 +879,6 @@ class SummonAllyEffect extends SummonEffect {
priority: 0 priority: 0
}) })
} }
}
this.spawnMutation.embedded.ActiveEffect['Mirror Self'] = this.spawnMutation.embedded.ActiveEffect['Mirror Self'] =
shim.createEffectDocument(this.ICON, 'Mirror Self', shim.createEffectDocument(this.ICON, 'Mirror Self',
this.durationRounds, effectChanges) this.durationRounds, effectChanges)

View File

@ -17,6 +17,10 @@ export class shim {
return ActiveEffect return ActiveEffect
} }
static get Actor () {
return Actor
}
static get folders () { static get folders () {
return game.folders return game.folders
} }