From 7f8799f2dc84d43b5e72d8f834390412014b22cd Mon Sep 17 00:00:00 2001 From: Dapoolp Date: Sat, 14 Jun 2025 11:17:48 +0200 Subject: [PATCH] Cost & Range #1 --- module/applications/config/Action.mjs | 2 + .../sheets/activeEffectConfig.mjs | 1 + module/applications/sheets/adversary.mjs | 2 +- module/config/actionConfig.mjs | 14 ++- module/config/generalConfig.mjs | 22 ++++- module/data/action/action.mjs | 96 ++++++++++++------- module/data/item/feature.mjs | 1 - module/documents/actor.mjs | 4 +- templates/views/action.hbs | 10 +- templates/views/actionTypes/range-target.hbs | 7 +- 10 files changed, 112 insertions(+), 47 deletions(-) diff --git a/module/applications/config/Action.mjs b/module/applications/config/Action.mjs index 6453f896..5c992ae8 100644 --- a/module/applications/config/Action.mjs +++ b/module/applications/config/Action.mjs @@ -62,6 +62,7 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { if (!!this.action.effects) context.effects = this.action.effects.map(e => this.action.item.effects.get(e._id)); if (this.action.damage?.hasOwnProperty('includeBase')) context.hasBaseDamage = !!this.action.parent.damage; context.getRealIndex = this.getRealIndex.bind(this); + console.log(context) return context; } @@ -132,6 +133,7 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { data = this.action.toObject(); data.effects.push({ _id: created._id }); this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); + this.action.item.effects.get(created._id).sheet.render(true); } /** diff --git a/module/applications/sheets/activeEffectConfig.mjs b/module/applications/sheets/activeEffectConfig.mjs index 585086a1..0fac15ef 100644 --- a/module/applications/sheets/activeEffectConfig.mjs +++ b/module/applications/sheets/activeEffectConfig.mjs @@ -45,6 +45,7 @@ export default class DhActiveEffectConfig extends ActiveEffectConfig { break; } + console.log(context, partContext) return partContext; } diff --git a/module/applications/sheets/adversary.mjs b/module/applications/sheets/adversary.mjs index 234d49b9..c2a8b9ca 100644 --- a/module/applications/sheets/adversary.mjs +++ b/module/applications/sheets/adversary.mjs @@ -51,7 +51,7 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) { const context = await super._prepareContext(_options); context.document = this.document; context.tabs = super._getTabs(this.constructor.TABS); - +console.log(context) return context; } diff --git a/module/config/actionConfig.mjs b/module/config/actionConfig.mjs index 4db96a64..8c67de17 100644 --- a/module/config/actionConfig.mjs +++ b/module/config/actionConfig.mjs @@ -46,8 +46,16 @@ export const targetTypes = { id: 'self', label: 'Self' }, - other: { - id: 'other', - label: 'Other' + friendly: { + id: 'friendly', + label: 'Friendly' + }, + adversary: { + id: 'adversary', + label: 'Adversary' + }, + any: { + id: 'any', + label: 'Any' } }; diff --git a/module/config/generalConfig.mjs b/module/config/generalConfig.mjs index 978e32cb..cea1fe55 100644 --- a/module/config/generalConfig.mjs +++ b/module/config/generalConfig.mjs @@ -319,7 +319,27 @@ export const abilityCosts = { }, stress: { id: 'stress', - label: 'Stress' + label: 'DAGGERHEART.HealingType.Stress.Name' + }, + armor: { + id: 'armor', + label: 'Armor Stack' + }, + hp: { + id: 'hp', + label: 'DAGGERHEART.HealingType.HitPoints.Name' + }, + prayer: { + id: 'prayer', + label: 'Prayer Dice' + }, + favor: { + id: 'favor', + label: 'Favor Points' + }, + slayer: { + id: 'slayer', + label: 'Slayer Dice' } }; diff --git a/module/data/action/action.mjs b/module/data/action/action.mjs index 5de1e341..7a976f29 100644 --- a/module/data/action/action.mjs +++ b/module/data/action/action.mjs @@ -1,41 +1,6 @@ import { abilities } from '../../config/actorConfig.mjs'; import { DHActionDiceData, DHDamageData, DHDamageField } from './actionDice.mjs'; -export default class DHAction extends foundry.abstract.DataModel { - static defineSchema() { - const fields = foundry.data.fields; - return { - id: new fields.DocumentIdField(), - name: new fields.StringField({ initial: 'New Action' }), - damage: new fields.SchemaField({ - type: new fields.StringField({ choices: SYSTEM.GENERAL.damageTypes, nullable: true, initial: null }), - value: new fields.StringField({}) - }), - healing: new fields.SchemaField({ - type: new fields.StringField({ choices: SYSTEM.GENERAL.healingTypes, nullable: true, initial: null }), - value: new fields.StringField() - }), - conditions: new fields.ArrayField( - new fields.SchemaField({ - name: new fields.StringField(), - icon: new fields.StringField(), - description: new fields.StringField() - }) - ), - cost: new fields.SchemaField({ - type: new fields.StringField({ choices: SYSTEM.GENERAL.abilityCosts, nullable: true, initial: null }), - value: new fields.NumberField({ nullable: true, initial: null }) - }), - target: new fields.SchemaField({ - type: new fields.StringField({ - choices: SYSTEM.ACTIONS.targetTypes, - initial: SYSTEM.ACTIONS.targetTypes.other.id - }) - }) - }; - } -} - const fields = foundry.data.fields; /* @@ -57,6 +22,7 @@ export class DHBaseAction extends foundry.abstract.DataModel { _id: new fields.DocumentIdField(), type: new fields.StringField({ initial: undefined, readonly: true, required: true }), name: new fields.StringField({ initial: undefined }), + description: new fields.HTMLField(), img: new fields.FilePathField({ initial: undefined, categories: ['IMAGE'], base64: false }), actionType: new fields.StringField({ choices: SYSTEM.ITEM.actionTypes, initial: 'action', nullable: true }), cost: new fields.ArrayField( @@ -128,6 +94,16 @@ export class DHBaseAction extends foundry.abstract.DataModel { } async use(event) { + if(this.cost?.length) { + const hasCost = await this.checkCost(); + if(!hasCost) return ui.notifications.warn("You don't have the resources to use that action."); + } + if(this.target?.type) { + const hasTarget = await this.checkTarget(); + } + if(this.range) { + const hasRange = await this.checkRange(); + } if (this.roll.type && this.roll.trait) { const modifierValue = this.actor.system.traits[this.roll.trait].value; const config = { @@ -156,6 +132,50 @@ export class DHBaseAction extends foundry.abstract.DataModel { return this.actor.diceRoll(config); } } + + async checkCost() { + if(!this.cost.length || !this.actor) return true; + console.log(this.actor, this.cost) + return this.cost.reduce((a, c) => a && this.actor.system.resources[c.type]?.value >= (c.value * (c.scalable ? c.step : 1)), true); + } + + async checkTarget() { + /* targets = Array.from(game.user.targets).map(x => { + const target = { + id: x.id, + name: x.actor.name, + img: x.actor.img, + difficulty: x.actor.system.difficulty, + evasion: x.actor.system.evasion?.value + }; + + target.hit = target.difficulty ? roll.total >= target.difficulty : roll.total >= target.evasion; + + return target; + }); */ + const targets = targets = Array.from(game.user.targets).map(x => { + return { + id, + name: this.actor.name, + img: x.actor.img, + difficulty: x.actor.system.difficulty, + evasion: x.actor.system.evasion?.value + } + }); + console.log(this.target) + if(this.target.type === SYSTEM.ACTIONS.targetTypes.self.id) return this.actor; + if(this.target.amount) { + + } + } + + async checkRange() { + console.log(this.range) + } +} + +const tmpTargetObject = () => { + } const extraDefineSchema = (field, option) => { @@ -173,8 +193,10 @@ const extraDefineSchema = (field, option) => { target: new fields.SchemaField({ type: new fields.StringField({ choices: SYSTEM.ACTIONS.targetTypes, - initial: SYSTEM.ACTIONS.targetTypes.other.id - }) + initial: SYSTEM.ACTIONS.targetTypes.any.id, + nullable: true, initial: null + }), + amount: new fields.NumberField({ nullable: true, initial: null, integer: true, min: 0 }) }), effects: new fields.ArrayField( // ActiveEffect new fields.SchemaField({ diff --git a/module/data/item/feature.mjs b/module/data/item/feature.mjs index 026580c3..0e502eb6 100644 --- a/module/data/item/feature.mjs +++ b/module/data/item/feature.mjs @@ -1,5 +1,4 @@ import { getTier } from '../../helpers/utils.mjs'; -import DHAction from '../action/action.mjs'; import BaseDataItem from './base.mjs'; import ActionField from '../fields/actionField.mjs'; diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index fea4a426..7391a075 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -552,7 +552,7 @@ export default class DhpActor extends Actor { } //Move to action-scope? - async useAction(action) { + /* async useAction(action) { const userTargets = Array.from(game.user.targets); const otherTarget = action.target.type === SYSTEM.ACTIONS.targetTypes.other.id; if (otherTarget && userTargets.length === 0) { @@ -614,5 +614,5 @@ export default class DhpActor extends Actor { cls.create(msg.toObject()); } - } + } */ } diff --git a/templates/views/action.hbs b/templates/views/action.hbs index 6de3bda8..55a6ba9a 100644 --- a/templates/views/action.hbs +++ b/templates/views/action.hbs @@ -22,7 +22,14 @@ {{formField fields.actionType value=source.actionType label="Type" name="actionType" localize=true}} - {{#if fields.roll}}{{> 'systems/daggerheart/templates/views/actionTypes/roll.hbs' fields=fields.roll.fields source=source.roll}}{{/if}} +
+ +
Description
+
+
+ {{formInput fields.description value=source.description name="description" }} +
+
{{> 'systems/daggerheart/templates/views/actionTypes/uses.hbs' fields=fields.uses.fields source=source.uses}} @@ -30,6 +37,7 @@ {{#if fields.target}}{{> 'systems/daggerheart/templates/views/actionTypes/range-target.hbs' fields=(object range=fields.range target=fields.target.fields) source=(object target=source.target range=source.range)}}{{/if}}
+ {{#if fields.roll}}{{> 'systems/daggerheart/templates/views/actionTypes/roll.hbs' fields=fields.roll.fields source=source.roll}}{{/if}} {{#if fields.damage}}{{> 'systems/daggerheart/templates/views/actionTypes/damage.hbs' fields=fields.damage.fields.parts.element.fields source=source.damage}}{{/if}} {{#if fields.healing}}{{> 'systems/daggerheart/templates/views/actionTypes/healing.hbs' fields=fields.healing.fields source=source.healing}}{{/if}} {{#if fields.resource}}{{> 'systems/daggerheart/templates/views/actionTypes/resource.hbs' fields=fields.resource.fields source=source.resource}}{{/if}} diff --git a/templates/views/actionTypes/range-target.hbs b/templates/views/actionTypes/range-target.hbs index a408ebf6..741e7ec9 100644 --- a/templates/views/actionTypes/range-target.hbs +++ b/templates/views/actionTypes/range-target.hbs @@ -7,7 +7,12 @@
{{#if fields.target}}
- {{formField fields.target.type value=source.target.type label="Target" name="target.type" localize=true}} +
+ {{#if (and source.target.type (not (eq source.target.type 'self')))}} + {{ formField fields.target.amount value=source.target.amount label="Amount" name="target.amount" }} + {{/if}} + {{ formField fields.target.type value=source.target.type label="Target" name="target.type" localize=true }} +
{{/if}} \ No newline at end of file