229 lines
8.1 KiB
JavaScript
229 lines
8.1 KiB
JavaScript
import { moduleName, moduleHelpers } from '../globals.js';
|
|
import { firstOwner, deleteActiveEffectsFromToken } from '../helpers.js';
|
|
import { ArcaneProtectionEffect } from './arcaneProtection.js';
|
|
import { BanishEffect } from './banish.js';
|
|
import { BarrierEffect } from './barrier.js';
|
|
import { BeastFriendEffect } from './beastFriend.js';
|
|
import { BlastEffect } from './blast.js';
|
|
import { BlindEffect } from './blind.js';
|
|
import { BoltEffect } from './bolt.js';
|
|
import { BurrowEffect } from './burrow.js';
|
|
import { BoostLowerTraitEffect } from './boostLowerTrait.js';
|
|
import { BurstEffect } from './burst.js';
|
|
import { ConfusionEffect } from './confusion.js';
|
|
import { ConjureItemEffect } from './conjureItem.js';
|
|
import { CurseEffect } from './curse.js';
|
|
import { DamageFieldEffect } from './damageField.js';
|
|
import { DarksightEffect } from './darksight.js';
|
|
import { DeflectionEffect } from './deflection.js';
|
|
import { DetectConcealArcanaEffect } from './detectConcealArcana.js';
|
|
import { DisguiseEffect } from './disguise.js';
|
|
import { DispelEffect } from './dispel.js';
|
|
import { DivinationEffect } from './divination.js';
|
|
import { DrainPowerPointsEffect } from './drainPowerPoints.js';
|
|
import { ElementalManipulationEffect } from './elementalManipulation.js';
|
|
import { EmpathyEffect } from './empathy.js';
|
|
import { EntangleEffect } from './entangle.js';
|
|
import { EnvironmentalProtectionEffect } from './environmentalProtection.js';
|
|
import { FarsightEffect } from './farsight.js';
|
|
import { FearEffect } from './fear.js';
|
|
import { FlyEffect } from './fly.js';
|
|
import { GrowthShrinkEffect } from './growthShrink.js';
|
|
import { HavocEffect } from './havoc.js';
|
|
import { HealingEffect } from './healing.js';
|
|
import { IllusionEffect } from './illusion.js';
|
|
import { IntangibilityEffect } from './intangibility.js';
|
|
import { InvisibliltyEffect } from './invisibility.js';
|
|
import { LightDarknessEffect } from './lightdarkness.js';
|
|
import { LocateEffect } from './locate.js';
|
|
import { MindLinkEffect } from './mindLink.js';
|
|
import { MindReadingEffect } from './mindReading.js';
|
|
import { MindWipeEffect } from './mindWipe.js';
|
|
import { ObjectReadingEffect } from './objectReading.js';
|
|
import { PlanarBindingEffect } from './planarBinding.js';
|
|
import { PlaneShiftEffect } from './planeShift.js';
|
|
import { ProtectionEffect } from './protection.js';
|
|
import { PuppetEffect } from './puppet.js';
|
|
import { ReliefEffect } from './relief.js';
|
|
import { ResurrectionEffect } from './resurrection.js';
|
|
import { SanctuaryEffect } from './sanctuary.js';
|
|
import { ScryingEffect } from './scrying.js';
|
|
import { ShapeChangeEffect } from './shapeChange.js';
|
|
|
|
const PowerClasses = {
|
|
'arcane-protection': ArcaneProtectionEffect,
|
|
banish: BanishEffect,
|
|
barrier: BarrierEffect,
|
|
'beast-friend': BeastFriendEffect,
|
|
blast: BlastEffect,
|
|
blind: BlindEffect,
|
|
bolt: BoltEffect,
|
|
'boost-lower-trait': BoostLowerTraitEffect,
|
|
'boostlower-trait': BoostLowerTraitEffect,
|
|
'boost-trait': BoostLowerTraitEffect,
|
|
burrow: BurrowEffect,
|
|
burst: BurstEffect,
|
|
'conceal-arcana': DetectConcealArcanaEffect,
|
|
confusion: ConfusionEffect,
|
|
'conjure-item': ConjureItemEffect,
|
|
curse: CurseEffect,
|
|
'damage-field': DamageFieldEffect,
|
|
darkness: LightDarknessEffect,
|
|
darksight: DarksightEffect,
|
|
deflection: DeflectionEffect,
|
|
'detect-arcana': DetectConcealArcanaEffect,
|
|
'detect-conceal-arcana': DetectConcealArcanaEffect,
|
|
'detectconceal-arcana': DetectConcealArcanaEffect,
|
|
disguise: DisguiseEffect,
|
|
dispel: DispelEffect,
|
|
divination: DivinationEffect,
|
|
'drain-power-points': DrainPowerPointsEffect,
|
|
'elemental-manipulation': ElementalManipulationEffect,
|
|
empathy: EmpathyEffect,
|
|
entangle: EntangleEffect,
|
|
'environmental-protection': EnvironmentalProtectionEffect,
|
|
farsight: FarsightEffect,
|
|
fear: FearEffect,
|
|
fly: FlyEffect,
|
|
growth: GrowthShrinkEffect,
|
|
'growth-shrink': GrowthShrinkEffect,
|
|
growthshrink: GrowthShrinkEffect,
|
|
havoc: HavocEffect,
|
|
healing: HealingEffect,
|
|
illusion: IllusionEffect,
|
|
intangibility: IntangibilityEffect,
|
|
invisibility: InvisibliltyEffect,
|
|
'light-darkness': LightDarknessEffect,
|
|
lightdarkness: LightDarknessEffect,
|
|
light: LightDarknessEffect,
|
|
locate: LocateEffect,
|
|
'lower-trait': BoostLowerTraitEffect,
|
|
'mind-link': MindLinkEffect,
|
|
'mind-reading': MindReadingEffect,
|
|
'mind-wipe': MindWipeEffect,
|
|
'object-reading': ObjectReadingEffect,
|
|
'planar-binding': PlanarBindingEffect,
|
|
'plane-shift': PlaneShiftEffect,
|
|
protection: ProtectionEffect,
|
|
puppet: PuppetEffect,
|
|
relief: ReliefEffect,
|
|
resurrection: ResurrectionEffect,
|
|
sanctuary: SanctuaryEffect,
|
|
scrying: ScryingEffect,
|
|
'shape-change': ShapeChangeEffect,
|
|
shrink: GrowthShrinkEffect,
|
|
};
|
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
export function visualActiveEffectPowerButtons(effect, buttons) {
|
|
if (!effect.flags?.[moduleName]?.buttons) {
|
|
return;
|
|
}
|
|
for (const button of effect.flags[moduleName].buttons) {
|
|
let callback = null;
|
|
switch (button.type) {
|
|
case 'roll':
|
|
callback = function () {
|
|
new CONFIG.Dice.SwadeRoll(button.formula ?? '3d6', null, {}).toMessage({
|
|
flavor: button.flavor ?? `${effect.name} roll`,
|
|
});
|
|
};
|
|
break;
|
|
case 'trait':
|
|
callback = function () {
|
|
let rollFunc = 'rollAttribute';
|
|
const rollType = button?.rollType ?? 'attribute';
|
|
const rollDesc = button?.rollDesc ?? 'agility';
|
|
let rollId = rollDesc.toLowerCase();
|
|
if (rollType === 'skill') {
|
|
rollFunc = 'rollSkill';
|
|
rollId = effect.parent.items
|
|
.filter((i) => i.type === 'skill')
|
|
.find(
|
|
(i) => i.system.swid === rollDesc.toLowerCase() || i.name.toLowerCase() === rollDesc.toLowerCase(),
|
|
)?.id;
|
|
}
|
|
const options = {
|
|
flavor: button?.flavor ?? `${effect.name} ${rollDesc} roll`,
|
|
};
|
|
if (button?.mods) {
|
|
options.additionalMods = button.mods;
|
|
}
|
|
effect.parent[rollFunc](rollId, options);
|
|
};
|
|
break;
|
|
case 'damage':
|
|
callback = function () {
|
|
const formula = button?.formula ?? '2d6x';
|
|
const ap = button?.ap ?? 0;
|
|
const flavor = button?.flavor ?? `${effect.name} damage roll`;
|
|
const options = {};
|
|
if (ap > 0) {
|
|
options.ap = ap;
|
|
}
|
|
new CONFIG.Dice.DamageRoll(formula, null, options).toMessage({ flavor });
|
|
};
|
|
break;
|
|
case 'callback':
|
|
callback =
|
|
button?.callback ||
|
|
function () {
|
|
console.log('not implemented');
|
|
};
|
|
break;
|
|
}
|
|
if (button?.label && callback) {
|
|
buttons.push({ label: button.label, callback });
|
|
}
|
|
}
|
|
}
|
|
|
|
export async function powerEffectManagementHook(effect, data, userId) {
|
|
if (game.user.id !== userId) {
|
|
return;
|
|
}
|
|
const maintId = effect.getFlag(moduleName, 'maintainingId');
|
|
if (!maintId) {
|
|
return;
|
|
}
|
|
const targetIds = effect.getFlag(moduleName, 'targetIds') || [];
|
|
for (const targetId of targetIds) {
|
|
const target = canvas.tokens.get(targetId);
|
|
if (!target) {
|
|
continue;
|
|
}
|
|
const effectIds = target.actor.effects.filter((e) => e.getFlag(moduleName, 'maintId') === maintId).map((e) => e.id);
|
|
if (effectIds.length === 0) {
|
|
continue;
|
|
}
|
|
const owner = firstOwner(target);
|
|
await moduleHelpers.socket.executeAsUser(
|
|
deleteActiveEffectsFromToken,
|
|
owner.id,
|
|
target.scene.id,
|
|
target.id,
|
|
effectIds,
|
|
);
|
|
}
|
|
}
|
|
|
|
export async function powers(options = {}) {
|
|
const token = 'token' in options ? options.token : null;
|
|
if (token === undefined || token === null) {
|
|
ui.notifications.error('Please select one token to be the caster');
|
|
return;
|
|
}
|
|
|
|
const targets = 'targets' in options ? Array.from(options.targets) : [];
|
|
const item = 'item' in options ? options.item : null;
|
|
const swid = options?.name || item?.system.swid || null;
|
|
|
|
if (swid in PowerClasses) {
|
|
const runner = new PowerClasses[swid](token, targets);
|
|
runner.render();
|
|
return;
|
|
}
|
|
ui.notifications.error(`No power effect found for ${swid}`);
|
|
}
|