shape change part 3

This commit is contained in:
Mike Bloy 2024-05-30 12:33:01 -05:00
parent 8aac513792
commit 5c9556471e
2 changed files with 32 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import { moduleName } from '../globals.js';
import { log, moduleName } from '../globals.js';
import { ActorFolderEffect } from './basePowers.js';
export class ShapeChangeEffect extends ActorFolderEffect {
@ -99,7 +99,7 @@ export class ShapeChangeEffect extends ActorFolderEffect {
}
this.data.tokenUpdates = {
flags: {
[moduleName]: { 'shapeChange.srcTokenId': this.target.id },
[moduleName]: { 'shapeChange.srcTokenUuid': this.target.document.uuid },
},
actorLink: false,
name: `${this.target.name} (${this.targetActor.prototypeToken.name} form)`,
@ -113,24 +113,33 @@ export class ShapeChangeEffect extends ActorFolderEffect {
Item: {},
};
for (const effect of this.target.actor.effects) {
const doc = await this.target.actor.getEmbeddedDocument('ActiveEffect', effect.id);
const doc = deepClone(await this.target.actor.getEmbeddedDocument('ActiveEffect', effect.id));
this.data.embeddedUpdates.ActiveEffect[effect.name] = doc;
}
for (const item of this.target.actor.items.filter(
(i) =>
(i.type === 'skill' && ['smarts', 'spirit'].includes(i.system.attribute)) ||
['power', 'edge', 'hindrance', 'action'].includes(i.type),
['edge', 'hindrance', 'action'].includes(i.type),
)) {
const doc = await this.target.actor.getEmbeddedDocument('Item', item.id);
const doc = deepClone(await this.target.actor.getEmbeddedDocument('Item', item.id));
if (doc.type === 'power' && doc?.system?.choiceSets?.length > 0 && !doc.system.choiceSets[0].choice) {
doc.system.choiceSets[0].choice = 1;
}
this.data.embeddedUpdates.Item[item.name] = doc;
}
}
async spawn() {
const target = this.target.document;
const size = target.parent.dimensions.size;
const protoWidth = this.targetActor.prototypeToken.width;
const protoHeight = this.targetActor.prototypeToken.height;
this.targetTokenDoc.updateSource({
x: this.target.x,
y: this.target.y,
elevation: this.target.elevation,
x: target.x - ((protoWidth - target.width) * size) / 2,
y: target.y - ((protoHeight - target.height) * size) / 2,
elevation: target.elevation,
hidden: target.hidden,
alpha: target.alpha,
});
return this.source.scene.createEmbeddedDocuments('Token', [this.targetTokenDoc]);
}
@ -175,8 +184,21 @@ export class ShapeChangeEffect extends ActorFolderEffect {
return updates;
}
async sideEffects() {
// await this.target.document.update({
// hidden: true,
// alpha: 0.1,
// });
}
get description() {
let desc = super.description;
desc += `<p>The caster ${this.data.transform === 'none' ? 'transforms' : 'causes the target to transform'}
into a <em>${this.targetActor.name}</em>.</p>`;
return desc;
}
}
export function shapeChangeTokenDeleteHandler(token, options, userId) {
log('TOKEN DELETED |', token, options, userId);
}

View File

@ -8,6 +8,7 @@ import { requestTokenRoll, addActiveEffectsToToken, deleteActiveEffectsFromToken
import { preDamageRollModifiers, preTraitRollModifiers } from './rollHelpers.js';
import { log, moduleHelpers } from './globals.js';
import { powerEffectManagementHook, visualActiveEffectPowerButtons } from './powers/powers.js';
import { shapeChangeTokenDeleteHandler } from './powers/shapeChange.js';
// Initialize module
Hooks.once('init', async () => {
@ -44,6 +45,7 @@ Hooks.on('swadePreRollAttribute', preTraitRollModifiers);
Hooks.on('swadePreRollSkill', preTraitRollModifiers);
Hooks.on('swadeRollDamage', preDamageRollModifiers);
Hooks.on('deleteActiveEffect', powerEffectManagementHook);
Hooks.on('deleteToken', shapeChangeTokenDeleteHandler);
Hooks.on('visual-active-effects.createEffectButtons', visualActiveEffectPowerButtons);
Hooks.on('visual-active-effects.createEffectButtons', SwadeVAEbuttons);