zombie complete + summon costs setup macro

This commit is contained in:
2024-06-08 22:20:48 -05:00
parent 5cb15bcedd
commit 20871bcdef
7 changed files with 165 additions and 13 deletions
+8 -4
View File
@@ -1,8 +1,8 @@
import { BaseSummonEffect } from './summonSupport.js';
class BaseAllyEffect extends BaseSummonEffect {
get values() {
return {};
get actorFolder() {
return `${this.actorFolderBase}/Creatures`;
}
get basePowerPoints() {
@@ -229,13 +229,17 @@ export class SummonAllyEffect extends BaseAllyEffect {
return 'icons/magic/control/silhouette-hold-beam-blue.webp';
}
get values() {
return {
actorValue(actor) {
const values = {
attendant: 1,
bodyguard: 3,
sentinel: 5,
'mirror self': 7,
};
if (actor.name.toLowerCase() in values) {
return values[actor.name.toLowerCase()];
}
return 0;
}
get _edges() {
+100 -5
View File
@@ -1,5 +1,6 @@
/* globals Portal */
import { moduleName } from '../globals.js';
import { log, moduleHelpers, moduleName } from '../globals.js';
import { templates } from '../preloadTemplates.js';
import { ActorFolderEffect } from './basePowers.js';
export class BaseSummonEffect extends ActorFolderEffect {
@@ -11,10 +12,6 @@ export class BaseSummonEffect extends ActorFolderEffect {
return 'Summonables';
}
get actorFolder() {
return `${this.actorFolderBase}/Creatures`;
}
get summonCount() {
return 0;
}
@@ -49,3 +46,101 @@ export class BaseSummonEffect extends ActorFolderEffect {
}
}
}
export class SummonCostApplication extends FormApplication {
constructor(actors, powers) {
super();
this.actors = actors;
this.powers = powers;
}
static get defaultOptions() {
return mergeObject(super.defaultOptions, {
classes: ['sheet', 'mbSwadeForm', 'mbSwadeSummonCostForm'],
popOut: true,
template: templates['summonCosts.html'],
id: ['mbSwadeSummonCostFormApplication'],
title: 'Summoning Costs',
width: 750,
});
}
getData() {
const actorNames = Object.keys(this.actors).map((k) => {
let splitName = k.split(' | ');
splitName.pop();
let folder = splitName.length ? splitName.join(' | ') : '';
return { name: this.actors[k].name, folder, fullName: k };
});
actorNames.sort((a, b) => {
if (a.name < b.name) {
return -1;
} else if (a.name > b.name) {
return 1;
}
return 0;
});
const data = {
powers: this.powers,
actors: [],
};
for (const actor of actorNames) {
const summon = this.actors[actor.fullName].getFlag(moduleName, 'summonData') ?? {
cost: 0,
powers: {},
};
const hbSummon = {
cost: summon.cost,
powers: [],
};
for (const power of this.powers) {
hbSummon.powers.push({ power, value: summon.powers?.[power] ?? false });
}
data.actors.push({ actor, summon: hbSummon });
}
log('summon data');
log(data);
return data;
}
async _updateObject(ev, formData) {
const submit = ev?.submitter?.value ?? 'cancel';
if (submit === 'cancel') {
return;
}
log('FORMDATA |', formData);
const updates = {};
for (const key of Object.keys(formData)) {
const value = formData[key];
const [name, subKey] = key.split(':;:');
if (!(name in updates)) {
updates[name] = { powers: {} };
}
if (subKey === 'cost') {
updates[name].cost = value;
} else {
updates[name].powers[subKey] = value;
}
}
log('FORMUPDATES |', updates);
for (const key of Object.keys(updates)) {
const update = updates[key];
const flagValue = this.actors[key].getFlag(moduleName, 'summonData') ?? {};
mergeObject(flagValue, update);
const result = this.actors[key].setFlag(moduleName, 'summonData', flagValue);
console.log('update', key, result);
}
}
}
export function setSummonCosts(powers = [], folderName = null) {
if (!folderName) {
folderName = 'Summonables/Creatures';
}
const folder = moduleHelpers.getActorFolderByPath(folderName);
if (!folder) {
log(`ERROR: Could not find folder ${folderName}`);
}
const actors = moduleHelpers.getActorsInFolder(folder);
new SummonCostApplication(actors, powers).render(true);
}