Feature/200 beastform (#255)

* Temp

* Dialog setup

* Fixed basic beastform

* Reworked beastform to hold it's data entirely in the beastformEffect

* UpdateActorTokens fix

* Removed hardcoded tierlimit on beastform

* PR fixes
This commit is contained in:
WBHarry 2025-07-04 02:02:14 +02:00 committed by GitHub
parent c4448226e0
commit d071fadf7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 1102 additions and 298 deletions

View file

@ -1,6 +1,7 @@
import { DHActionDiceData, DHActionRollData, DHDamageData, DHDamageField } from './actionDice.mjs';
import DhpActor from '../../documents/actor.mjs';
import D20RollDialog from '../../dialogs/d20RollDialog.mjs';
import BeastformDialog from '../../dialogs/beastformDialog.mjs';
const fields = foundry.data.fields;
@ -106,6 +107,11 @@ export class DHBaseAction extends foundry.abstract.DataModel {
}),
value: new fields.EmbeddedDataField(DHActionDiceData),
valueAlt: new fields.EmbeddedDataField(DHActionDiceData)
}),
beastform: new fields.SchemaField({
tierAccess: new fields.SchemaField({
exact: new fields.NumberField({ integer: true, nullable: true, initial: null })
})
})
},
extraSchemas = {};
@ -757,3 +763,50 @@ export class DHMacroAction extends DHBaseAction {
}
}
}
export class DhBeastformAction extends DHBaseAction {
static extraSchemas = ['beastform'];
async use(event, ...args) {
const beastformConfig = this.prepareBeastformConfig();
const abort = await this.handleActiveTransformations();
if (abort) return;
const beastformUuid = await BeastformDialog.configure(beastformConfig);
if (!beastformUuid) return;
await this.transform(beastformUuid);
}
prepareBeastformConfig(config) {
const settingsTiers = game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.LevelTiers).tiers;
const actorLevel = this.actor.system.levelData.level.current;
const actorTier =
Object.values(settingsTiers).find(
tier => actorLevel >= tier.levels.start && actorLevel <= tier.levels.end
) ?? 1;
return {
tierLimit: this.beastform.tierAccess.exact ?? actorTier
};
}
async transform(beastformUuid) {
const beastform = await foundry.utils.fromUuid(beastformUuid);
this.actor.createEmbeddedDocuments('Item', [beastform.toObject()]);
}
async handleActiveTransformations() {
const beastformEffects = this.actor.effects.filter(x => x.type === 'beastform');
if (beastformEffects.length > 0) {
for (let effect of beastformEffects) {
await effect.delete();
}
return true;
}
return false;
}
}