mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
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:
parent
c4448226e0
commit
d071fadf7d
41 changed files with 1102 additions and 298 deletions
|
|
@ -6,3 +6,4 @@ export * as items from './item/_module.mjs';
|
|||
export { actionsTypes } from './action/_module.mjs';
|
||||
export * as messages from './chat-message/_modules.mjs';
|
||||
export * as fields from './fields/_module.mjs';
|
||||
export * as activeEffects from './activeEffect/_module.mjs';
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
DHAttackAction,
|
||||
DHBaseAction,
|
||||
DhBeastformAction,
|
||||
DHDamageAction,
|
||||
DHEffectAction,
|
||||
DHHealingAction,
|
||||
|
|
@ -19,5 +20,6 @@ export const actionsTypes = {
|
|||
healing: DHHealingAction,
|
||||
summon: DHSummonAction,
|
||||
effect: DHEffectAction,
|
||||
macro: DHMacroAction
|
||||
macro: DHMacroAction,
|
||||
beastform: DhBeastformAction
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
7
module/data/activeEffect/_module.mjs
Normal file
7
module/data/activeEffect/_module.mjs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import beastformEffect from './beastformEffect.mjs';
|
||||
|
||||
export { beastformEffect };
|
||||
|
||||
export const config = {
|
||||
beastform: beastformEffect
|
||||
};
|
||||
40
module/data/activeEffect/beastformEffect.mjs
Normal file
40
module/data/activeEffect/beastformEffect.mjs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { updateActorTokens } from '../../helpers/utils.mjs';
|
||||
|
||||
export default class BeastformEffect extends foundry.abstract.TypeDataModel {
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
characterTokenData: new fields.SchemaField({
|
||||
tokenImg: new fields.FilePathField({
|
||||
categories: ['IMAGE'],
|
||||
base64: false,
|
||||
nullable: true
|
||||
}),
|
||||
tokenSize: new fields.SchemaField({
|
||||
height: new fields.NumberField({ integer: true, nullable: true }),
|
||||
width: new fields.NumberField({ integer: true, nullable: true })
|
||||
})
|
||||
}),
|
||||
advantageOn: new fields.ArrayField(new fields.StringField()),
|
||||
featureIds: new fields.ArrayField(new fields.StringField()),
|
||||
effectIds: new fields.ArrayField(new fields.StringField())
|
||||
};
|
||||
}
|
||||
|
||||
async _preDelete() {
|
||||
if (this.parent.parent.type === 'character') {
|
||||
const update = {
|
||||
height: this.characterTokenData.tokenSize.height,
|
||||
width: this.characterTokenData.tokenSize.width,
|
||||
texture: {
|
||||
src: this.characterTokenData.tokenImg
|
||||
}
|
||||
};
|
||||
|
||||
await updateActorTokens(this.parent.parent, update);
|
||||
|
||||
await this.parent.parent.deleteEmbeddedDocuments('Item', this.featureIds);
|
||||
await this.parent.parent.deleteEmbeddedDocuments('ActiveEffect', this.effectIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ import DHFeature from './feature.mjs';
|
|||
import DHMiscellaneous from './miscellaneous.mjs';
|
||||
import DHSubclass from './subclass.mjs';
|
||||
import DHWeapon from './weapon.mjs';
|
||||
import DHBeastform from './beastform.mjs';
|
||||
|
||||
export {
|
||||
DHAncestry,
|
||||
|
|
@ -19,7 +20,8 @@ export {
|
|||
DHFeature,
|
||||
DHMiscellaneous,
|
||||
DHSubclass,
|
||||
DHWeapon
|
||||
DHWeapon,
|
||||
DHBeastform
|
||||
};
|
||||
|
||||
export const config = {
|
||||
|
|
@ -32,5 +34,6 @@ export const config = {
|
|||
feature: DHFeature,
|
||||
miscellaneous: DHMiscellaneous,
|
||||
subclass: DHSubclass,
|
||||
weapon: DHWeapon
|
||||
weapon: DHWeapon,
|
||||
beastform: DHBeastform
|
||||
};
|
||||
|
|
|
|||
98
module/data/item/beastform.mjs
Normal file
98
module/data/item/beastform.mjs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
import { updateActorTokens } from '../../helpers/utils.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
import BaseDataItem from './base.mjs';
|
||||
|
||||
export default class DHBeastform extends BaseDataItem {
|
||||
static LOCALIZATION_PREFIXES = ['DAGGERHEART.Sheets.Beastform'];
|
||||
|
||||
/** @inheritDoc */
|
||||
static get metadata() {
|
||||
return foundry.utils.mergeObject(super.metadata, {
|
||||
label: 'TYPES.Item.beastform',
|
||||
type: 'beastform',
|
||||
hasDescription: false
|
||||
});
|
||||
}
|
||||
|
||||
/** @inheritDoc */
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
...super.defineSchema(),
|
||||
tier: new fields.StringField({
|
||||
required: true,
|
||||
choices: SYSTEM.GENERAL.tiers,
|
||||
initial: SYSTEM.GENERAL.tiers.tier1.id
|
||||
}),
|
||||
tokenImg: new fields.FilePathField({
|
||||
initial: 'icons/svg/mystery-man.svg',
|
||||
categories: ['IMAGE'],
|
||||
base64: false
|
||||
}),
|
||||
tokenSize: new fields.SchemaField({
|
||||
height: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true }),
|
||||
width: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true })
|
||||
}),
|
||||
examples: new fields.StringField(),
|
||||
advantageOn: new fields.ArrayField(new fields.StringField()),
|
||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||
};
|
||||
}
|
||||
|
||||
async _preCreate(data, options, user) {
|
||||
const allowed = await super._preCreate(data, options, user);
|
||||
if (allowed === false) return;
|
||||
|
||||
if (!this.actor) return;
|
||||
|
||||
if (this.actor.type !== 'character') {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.notifications.beastformInapplicable'));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.actor.items.find(x => x.type === 'beastform')) {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.notifications.beastformAlreadyApplied'));
|
||||
return false;
|
||||
}
|
||||
|
||||
const features = await this.parent.parent.createEmbeddedDocuments(
|
||||
'Item',
|
||||
this.features.map(x => x.toObject())
|
||||
);
|
||||
const effects = await this.parent.parent.createEmbeddedDocuments(
|
||||
'ActiveEffect',
|
||||
this.parent.effects.map(x => x.toObject())
|
||||
);
|
||||
|
||||
await this.parent.parent.createEmbeddedDocuments('ActiveEffect', [
|
||||
{
|
||||
type: 'beastform',
|
||||
name: game.i18n.localize('DAGGERHEART.Sheets.Beastform.beastformEffect'),
|
||||
img: 'icons/creatures/abilities/paw-print-pair-purple.webp',
|
||||
system: {
|
||||
isBeastform: true,
|
||||
characterTokenData: {
|
||||
tokenImg: this.parent.parent.prototypeToken.texture.src,
|
||||
tokenSize: {
|
||||
height: this.parent.parent.prototypeToken.height,
|
||||
width: this.parent.parent.prototypeToken.width
|
||||
}
|
||||
},
|
||||
advantageOn: this.advantageOn,
|
||||
featureIds: features.map(x => x.id),
|
||||
effectIds: effects.map(x => x.id)
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
||||
await updateActorTokens(this.parent.parent, {
|
||||
height: this.tokenSize.height,
|
||||
width: this.tokenSize.width,
|
||||
texture: {
|
||||
src: this.tokenImg
|
||||
}
|
||||
});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue