mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
Functioning setup
This commit is contained in:
parent
4b92001f97
commit
0cb7ede933
24 changed files with 350 additions and 72 deletions
|
|
@ -15,3 +15,4 @@ export * as chatMessages from './chat-message/_modules.mjs';
|
|||
export * as fields from './fields/_module.mjs';
|
||||
export * as items from './item/_module.mjs';
|
||||
export * as scenes from './scene/_module.mjs';
|
||||
export * as regionBehaviors from './regionBehavior/_module.mjs';
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ const fields = foundry.data.fields;
|
|||
*/
|
||||
|
||||
export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel) {
|
||||
static extraSchemas = ['cost', 'uses', 'range'];
|
||||
static extraSchemas = ['area', 'cost', 'uses', 'range'];
|
||||
|
||||
/** @inheritDoc */
|
||||
static defineSchema() {
|
||||
|
|
|
|||
|
|
@ -93,7 +93,10 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
|
|||
max: new fields.NumberField({ integer: true, label: 'DAGGERHEART.GENERAL.max' })
|
||||
},
|
||||
{ nullable: true, initial: null }
|
||||
)
|
||||
),
|
||||
targetDispositions: new fields.SetField(new fields.NumberField({
|
||||
choices: CONFIG.DH.GENERAL.simpleDispositions,
|
||||
}), { label: 'Affected Dispositions' }),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
export { default as AreaField } from './areaField.mjs';
|
||||
export { default as CostField } from './costField.mjs';
|
||||
export { default as CountdownField } from './countdownField.mjs';
|
||||
export { default as UsesField } from './usesField.mjs';
|
||||
|
|
|
|||
35
module/data/fields/action/areaField.mjs
Normal file
35
module/data/fields/action/areaField.mjs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
const fields = foundry.data.fields;
|
||||
|
||||
export default class AreaField extends fields.ArrayField {
|
||||
/**
|
||||
* Action Workflow order
|
||||
*/
|
||||
static order = 150;
|
||||
|
||||
/** @inheritDoc */
|
||||
constructor(options = {}, context = {}) {
|
||||
const element = new fields.SchemaField({
|
||||
type: new fields.StringField({
|
||||
nullable: false,
|
||||
choices: CONFIG.DH.ACTIONS.areaTypes,
|
||||
initial: CONFIG.DH.ACTIONS.areaTypes.placed.id,
|
||||
label: 'DAGGERHEART.GENERAL.type'
|
||||
}),
|
||||
shape: new fields.StringField({
|
||||
nullable: false,
|
||||
choices: CONFIG.DH.GENERAL.templateTypes,
|
||||
initial: CONFIG.DH.GENERAL.templateTypes.circle.id,
|
||||
label: 'DAGGERHEART.ACTIONS.Config.area.shape'
|
||||
}),
|
||||
/* Could be opened up to allow numbers to be input aswell. Probably best handled via an autocomplete in that case to allow the select options but also free text */
|
||||
size: new fields.StringField({
|
||||
nullable: false,
|
||||
choices: CONFIG.DH.GENERAL.range,
|
||||
initial: CONFIG.DH.GENERAL.range.veryClose.id,
|
||||
label: 'DAGGERHEART.ACTIONS.Config.area.size'
|
||||
}),
|
||||
effects: new fields.ArrayField(new fields.DocumentIdField()),
|
||||
});
|
||||
super(element, options, context);
|
||||
}
|
||||
}
|
||||
1
module/data/regionBehavior/_module.mjs
Normal file
1
module/data/regionBehavior/_module.mjs
Normal file
|
|
@ -0,0 +1 @@
|
|||
export { default as applyActiveEffect } from './applyActiveEffect.mjs';
|
||||
38
module/data/regionBehavior/applyActiveEffect.mjs
Normal file
38
module/data/regionBehavior/applyActiveEffect.mjs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
export default class DhApplyActiveEffect extends CONFIG.RegionBehavior.dataModels.applyActiveEffect {
|
||||
static async #getApplicableEffects(token) {
|
||||
const effects = await Promise.all(this.effects.map(fromUuid));
|
||||
return (effects).filter(effect => !effect.system.targetDispositions.size || effect.system.targetDispositions.has(token.disposition));
|
||||
}
|
||||
|
||||
static async #onTokenEnter(event) {
|
||||
if ( !event.user.isSelf ) return;
|
||||
const {token, movement} = event.data;
|
||||
const actor = token.actor;
|
||||
if ( !actor ) return;
|
||||
const resumeMovement = movement ? token.pauseMovement() : undefined;
|
||||
const effects = await DhApplyActiveEffect.#getApplicableEffects.bind(this)(event.data.token);
|
||||
const toCreate = [];
|
||||
for ( const effect of effects ) {
|
||||
const data = effect.toObject();
|
||||
delete data._id;
|
||||
if ( effect.compendium ) {
|
||||
data._stats.duplicateSource = null;
|
||||
data._stats.compendiumSource = effect.uuid;
|
||||
} else {
|
||||
data._stats.duplicateSource = effect.uuid;
|
||||
data._stats.compendiumSource = null;
|
||||
}
|
||||
data._stats.exportSource = null;
|
||||
data.origin = this.parent.uuid;
|
||||
toCreate.push(data);
|
||||
}
|
||||
if ( toCreate.length ) await actor.createEmbeddedDocuments("ActiveEffect", toCreate);
|
||||
await resumeMovement?.();
|
||||
}
|
||||
|
||||
/** @override */
|
||||
static events = {
|
||||
...CONFIG.RegionBehavior.dataModels.applyActiveEffect.events,
|
||||
[CONST.REGION_EVENTS.TOKEN_ENTER]: this.#onTokenEnter,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue