swade-mb-helpers/src/module/powers/growthShrink.js
2024-05-20 23:01:25 -05:00

142 lines
3.1 KiB
JavaScript

import { PowerEffect } from './basePowers.js';
export class GrowthShrinkEffect extends PowerEffect {
get name() {
return 'Growth/Shrink';
}
get icon() {
return 'icons/magic/control/silhouette-grow-shrink-tan.webp';
}
get basePowerPoints() {
return 0;
}
get duration() {
return this?.data?.duration ? 50 : 5;
}
get extraDescription() {
const target = this.targets?.[0];
let text = super.extraDescription + '<p>Minimum Size is -2. ';
if (target) {
text += `${target.name} is of Size ${target.actor.system.stats.size}. `;
}
text += `Select the number of Size steps to change the target. 2 points per
step. Negative is shrink, positive is growth.</p>`;
return text;
}
get isTargeted() {
return true;
}
get oneTarget() {
return true;
}
get isRaisable() {
return false;
}
get modifiers() {
const curSize = this.targets?.[0]?.actor?.system?.stats?.size ?? 0;
const minSteps = -2 - curSize;
return [
...super.modifiers,
{
name: 'Size Steps',
default: 1,
type: 'number',
min: minSteps,
value: 0,
id: 'steps',
epic: false,
effect: false,
},
{
name: 'Duration',
id: 'duration',
value: 2,
type: 'checkbox',
default: false,
epic: true,
effect: false,
},
{
name: 'Power',
id: 'power',
value: 2,
type: 'checkbox',
default: false,
epic: true,
effect: false,
},
];
}
async parseValues() {
await super.parseValues();
const steps = this.data.steps;
const curSize = this.targets?.[0]?.actor?.system?.stats?.size ?? 0;
const minSteps = -2 - curSize;
this.data.steps = Math.max(steps, minSteps);
}
get powerPoints() {
return super.powerPoints + Math.abs(this.data.steps) * 2;
}
getPrimaryEffectChanges() {
const steps = this.data.steps;
const changes = super.getPrimaryEffectChanges();
if (steps === 0) {
return changes;
}
changes.push({
key: 'system.stats.size',
value: steps,
priority: 0,
mode: foundry.CONST.ACTIVE_EFFECT_MODES.ADD,
});
if (steps < 0 && this.data.power) {
changes.push({
key: 'system.stats.toughness.value',
value: steps * -1,
priority: 0,
mode: foundry.CONST.ACTIVE_EFFECT_MODES.ADD,
});
} else {
changes.push({
key: 'system.attributes.strength.die.sides',
value: steps * 2,
priority: 0,
mode: foundry.CONST.ACTIVE_EFFECT_MODES.ADD,
});
}
return changes;
}
get effectName() {
if (this.data.steps >= 0) {
return 'Growth';
}
return 'Shrink';
}
get description() {
let text = super.description;
if (this.data.steps >= 0) {
text += `<p>Grow the target by ${this.data.steps} steps.</p>`;
} else {
text += `<p>Shrink the target by ${this.data.steps} steps`;
if (this.data.power) {
text += ' while retaining Strength and Toughness';
}
text += '.</p>';
}
return text;
}
}