diff --git a/scripts/powerEffects.js b/scripts/powerEffects.js index 3b4ce12..1c99bb0 100644 --- a/scripts/powerEffects.js +++ b/scripts/powerEffects.js @@ -728,6 +728,10 @@ class SummonAllyEffect extends SummonEffect { return `${super.actorFolder}/Summon Ally` } + get mirrorFolder () { + return `${super.actorFolder}/Mirror Selves` + } + async prepMenu () { await super.prepMenu() this.menuData.inputs = this.menuData.inputs.concat([ @@ -836,43 +840,44 @@ class SummonAllyEffect extends SummonEffect { if (this.actor.name !== 'Mirror Self') { 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({ + type: 'npc', + name: `Mirror ${this.token.actor.name}`, + folder: actorFolder.id, 'system.wildcard': false, 'system.fatigue.value': 0, 'system.wounds.value': 0, 'system.wounds.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( - this.spawnMutation.actor, { - name: `Mirrored ${this.token.actor.name}`, - img: this.token.actor.img, - system: actorDoc.system - }, { inplace: true, recursive: true } - ) - await shim.mergeObject( - this.spawnMutation.token, { - actorLink: false, - disposition: this.token.document.disposition, - 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 mirrorActor = this.actor + this.actor = await shim.Actor.create(actorDoc) + this.actorId = this.actor.id + this.icon = this.actor.prototypeToken.texture.src + this.protoDoc = await this.actor.getTokenDocument() + this.spawnOptions.crosshairs.icon = this.icon + for (const mirrorItem of mirrorActor.items) { + this.spawnMutation.embedded.Item[mirrorItem.name] = + mirrorActor.getEmbeddedDocument('Item', mirrorItem.id) + } + this.spawnMutation.embedded.Item['Summon Ally'] = CONST.WARPGATE.DELETE const effectChanges = [] - for (const item of this.token.actor.items) { - this.spawnMutation.embedded.Item[item.name] = - this.token.actor.getEmbeddedDocument('Item', item.id) - if (item.type === 'skill') { - effectChanges.push({ - key: `@Skill{${item.name}}[system.die.sides]`, - mode: CONST.FOUNDRY.ACTIVE_EFFECT_MODES.ADD, - value: '-2', - priority: 0 - }) - } + for (const item of this.token.actor.items.filter(i => i.type === 'skill')) { + effectChanges.push({ + key: `@Skill{${item.name}}[system.die.sides]`, + mode: CONST.FOUNDRY.ACTIVE_EFFECT_MODES.ADD, + value: '-2', + priority: 0 + }) } this.spawnMutation.embedded.ActiveEffect['Mirror Self'] = shim.createEffectDocument(this.ICON, 'Mirror Self', diff --git a/scripts/shim.js b/scripts/shim.js index 03d601b..b2d4adc 100644 --- a/scripts/shim.js +++ b/scripts/shim.js @@ -17,6 +17,10 @@ export class shim { return ActiveEffect } + static get Actor () { + return Actor + } + static get folders () { return game.folders }