This commit is contained in:
Dapoolp 2025-06-12 22:36:55 +02:00
parent 7178148c80
commit fad34ae975
26 changed files with 688 additions and 371 deletions

View file

@ -1,6 +1,4 @@
import DHDamageData from "./damage.mjs";
import { abilities } from "../../config/actorConfig.mjs";
// import DHWeapon from "../item/weapon.mjs";
import { DHActionDiceData, DHDamageData, DHDamageField } from "./actionDice.mjs";
export default class DHAction extends foundry.abstract.DataModel {
static defineSchema() {
@ -39,8 +37,12 @@ export default class DHAction extends foundry.abstract.DataModel {
const fields = foundry.data.fields;
// Create Roll Field
// Create Damage Field
/*
ToDo
- Apply ActiveEffect => Add to Chat message like Damage Button ?
- Add Drag & Drop for documentUUID field (Macro & Summon)
- Add optionnal Role for Healing ?
*/
export class DHBaseAction extends foundry.abstract.DataModel {
static defineSchema() {
@ -50,11 +52,6 @@ export class DHBaseAction extends foundry.abstract.DataModel {
name: new fields.StringField({ initial: undefined }),
img: new fields.FilePathField({ initial: undefined, categories: ["IMAGE"], base64: false }),
actionType: new fields.StringField({ choices: SYSTEM.ITEM.actionTypes, initial: 'action', nullable: true }),
roll: new fields.SchemaField({
type: new fields.StringField({ nullable: true, initial: null, choices: SYSTEM.GENERAL.rollTypes }),
trait: new fields.StringField({ nullable: true, initial: null, choices: SYSTEM.ACTOR.abilities }),
difficulty: new fields.NumberField({ nullable: true, initial: null, integer: true, min: 0 })
}),
cost: new fields.ArrayField(
new fields.SchemaField({
type: new fields.StringField({ choices: SYSTEM.GENERAL.abilityCosts, nullable: false, required: true, initial: 'hope' }),
@ -62,30 +59,13 @@ export class DHBaseAction extends foundry.abstract.DataModel {
scalable: new fields.BooleanField({ initial: false }),
step: new fields.NumberField({ nullable: true, initial: null }),
})
/* ,
{ initial: [
{ type: "hope", value: 1, scalable: false, step: null },
{ type: "stress", value: 2, scalable: true, step: 2 }
]} */
),
uses: new fields.SchemaField({
value: new fields.NumberField({ nullable: true, initial: null }),
max: new fields.NumberField({ nullable: true, initial: null }),
recovery: new fields.StringField({ choices: SYSTEM.GENERAL.refreshTypes, initial: null, nullable: true })
}),
/* duration: new fields.SchemaField({
value: new fields.NumberField({ nullable: true, initial: null }),
units: new fields.StringField({ required: true, blank: false, initial: "instant" })
}), */
target: new fields.SchemaField({
type: new fields.StringField({ choices: SYSTEM.ACTIONS.targetTypes, initial: SYSTEM.ACTIONS.targetTypes.other.id })
}),
range: new fields.StringField({ choices: SYSTEM.GENERAL.range, required: true, blank: false, initial: "self" }),
effects: new fields.ArrayField( // ActiveEffect
new fields.SchemaField({
'_id': new fields.DocumentIdField()
})
)
range: new fields.StringField({ choices: SYSTEM.GENERAL.range, required: true, blank: false, initial: "self" })
}
}
@ -103,6 +83,10 @@ export class DHBaseAction extends foundry.abstract.DataModel {
return this.item?.actor;
}
get chatTemplate() {
return 'systems/daggerheart/templates/chat/attack-roll.hbs';
}
static getRollType() {
return 'ability';
}
@ -123,94 +107,66 @@ export class DHBaseAction extends foundry.abstract.DataModel {
}
async use(event) {
console.log(this)
// console.log(this.item.getRollData(), this.item.actor.getRollData())
// const weapon = await fromUuid(button.dataset.weapon);
let damage, modifier, roll, hope, fear, advantage, disadvantage, modifiers, bonusDamageString, targets;
if(this.damage.parts.length) {
damage = {
value: `${this.actor.system[this.damage.parts[0].multiplier].value}${this.damage.parts[0].dice}`,
type: this.damage.parts[0].type,
bonusDamage: [this.damage.parts[0].bonus ?? 0, ...this.actor.system.bonuses.damage]
};
damage.value = damage.value.concat(bonusDamageString);
}
if(this.roll.type && this.roll.trait) {
modifier = this.actor.system.traits[this.roll.trait].value;
({roll, hope, fear, advantage, disadvantage, modifiers, bonusDamageString} =
await this.actor.dualityRoll(
{ title: game.i18n.localize(abilities[this.roll.trait].label), value: modifier },
event.shiftKey,
damage?.bonusDamage ?? 0
));
const config = {
event: event,
title: this.item.name,
roll: {
modifier: this.actor.system.traits[this.roll.trait].value,
type: this.actionType,
difficulty: this.roll?.difficulty
},
chatMessage: {
template: this.chatTemplate
}
};
if(this.target?.type) config.checkTarget = true;
if(this.damage.parts.length) {
config.damage = {
value: this.damage.parts.map(p => p.getFormula(this.actor)).join(' + '),
type: this.damage.parts[0].type
};
}
if(this.effects.length) {
// Apply Active Effects. In Chat Message ?
}
return this.actor.diceRoll(config);
}
console.log(roll, hope, fear, advantage, disadvantage, modifiers, bonusDamageString)
// if(this.target?.type) {
targets = Array.from(game.user.targets).map(x => ({
id: x.id,
name: x.actor.name,
img: x.actor.img,
difficulty: x.actor.system.difficulty,
evasion: x.actor.system.evasion.value
}));
// }
const systemData = {
title: this.item.name,
origin: this.actor.id,
roll: roll._formula,
modifiers: modifiers,
hope: hope,
fear: fear,
advantage: advantage,
disadvantage: disadvantage,
damage: damage,
targets: targets
};
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
type: 'dualityRoll',
sound: CONFIG.sounds.dice,
system: systemData,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/attack-roll.hbs',
systemData
),
rolls: [roll]
});
await cls.create(msg.toObject());
}
}
const extraDefineSchema = (field, option) => {
return {
[field] : {
// damage: new fields.SchemaField({
// parts: new fields.ArrayField(new fields.EmbeddedDataField(DHDamageData))
// }),
damage: new DHDamageField(option),
roll: new fields.SchemaField({
type: new fields.StringField({ nullable: true, initial: null, choices: SYSTEM.GENERAL.rollTypes }),
trait: new fields.StringField({ nullable: true, initial: null, choices: SYSTEM.ACTOR.abilities }),
difficulty: new fields.NumberField({ nullable: true, initial: null, integer: true, min: 0 })
}),
target: new fields.SchemaField({
type: new fields.StringField({ choices: SYSTEM.ACTIONS.targetTypes, initial: SYSTEM.ACTIONS.targetTypes.other.id })
}),
effects: new fields.ArrayField( // ActiveEffect
new fields.SchemaField({
'_id': new fields.DocumentIdField()
})
)
}[field]
};
}
export class DHAttackAction extends DHBaseAction {
static defineSchema() {
return {
...super.defineSchema(),
/* attack: new fields.SchemaField({
trait: new fields.StringField({ required: true, choices: SYSTEM.ACTOR.abilities, initial: 'agility' }),
bonus: new fields.NumberField({ nullable: true, initial: null })
}), */
/* damage: new fields.SchemaField({
baseDamage: new fields.BooleanField({ initial: true }), // Add damage from source item ?
parts: new fields.ArrayField(
new fields.SchemaField({ // Create DamageField
type: new fields.StringField({
choices: SYSTEM.GENERAL.damageTypes,
initial: 'physical'
}),
value: new FormulaField({ initial: 'd6' }),
bonus: new fields.NumberField({ nullable: true, initial: null }),
base: new fields.BooleanField({ initial: false, readonly: true })
})
)
}) */
damage: new fields.SchemaField({
parts: new fields.ArrayField(new fields.EmbeddedDataField(DHDamageData)),
includeBase: new fields.BooleanField({ initial: true })
})
...extraDefineSchema('damage', true),
...extraDefineSchema('roll'),
...extraDefineSchema('target'),
...extraDefineSchema('effects')
}
}
@ -235,12 +191,21 @@ export class DHAttackAction extends DHBaseAction {
base: true
};
}
// Temporary until full formula parser
// getDamageFormula() {
// return this.damage.parts.map(p => p.formula).join(' + ');
// }
}
export class DHSpellCastAction extends DHBaseAction {
static defineSchema() {
return {
...super.defineSchema(),
...extraDefineSchema('damage'),
...extraDefineSchema('roll'),
...extraDefineSchema('target'),
...extraDefineSchema('effects')
}
}
@ -249,33 +214,97 @@ export class DHSpellCastAction extends DHBaseAction {
}
}
export class DHResourceAction extends DHBaseAction {
static defineSchema() {
return {
...super.defineSchema(),
resource: new fields.SchemaField({
target: new fields.StringField({ choices: [], required: true, blank: false, initial: "" }),
value: new fields.NumberField({ initial: 0 })
})
}
}
}
export class DHDamageAction extends DHBaseAction {
static defineSchema() {
return {
...super.defineSchema(),
damage: new fields.SchemaField({})
...extraDefineSchema('damage', false),
...extraDefineSchema('target'),
...extraDefineSchema('effects')
}
}
async use(event) {
const formula = this.damage.parts.map(p => p.getFormula(this.actor)).join(' + ');
if(!formula || formula == '') return;
let roll = { formula: formula, total: formula };
if (isNaN(formula)) {
roll = await new Roll(formula).evaluate();
}
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
user: game.user.id,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/damage-roll.hbs',
{
roll: roll.formula,
total: roll.total,
type: this.damage.parts.map(p => p.type)
}
)
});
cls.create(msg.toObject());
}
}
export class DHHealingAction extends DHBaseAction {
static defineSchema() {
return {
...super.defineSchema(),
type: new fields.StringField({ choices: SYSTEM.GENERAL.healingTypes, required: true, blan: false, initial: SYSTEM.GENERAL.healingTypes.health.id }),
healing: new fields.SchemaField({})
healing: new fields.SchemaField({
type: new fields.StringField({ choices: SYSTEM.GENERAL.healingTypes, required: true, blank: false, initial: SYSTEM.GENERAL.healingTypes.health.id, label: "Healing" }),
value: new fields.EmbeddedDataField(DHActionDiceData)
}),
...extraDefineSchema('target'),
...extraDefineSchema('effects')
}
}
async use(event) {
const formula = this.healing.value.getFormula(this.actor);
if(!formula || formula == '') return;
// const roll = await super.use(event);
let roll = { formula: formula, total: formula };
if (isNaN(formula)) {
roll = await new Roll(formula).evaluate();
}
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
user: game.user.id,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/healing-roll.hbs',
{
roll: roll.formula,
total: roll.total,
type: this.healing.type
}
)
});
cls.create(msg.toObject());
}
get chatTemplate() {
return 'systems/daggerheart/templates/chat/healing-roll.hbs';
}
}
export class DHResourceAction extends DHBaseAction {
static defineSchema() {
return {
...super.defineSchema(),
// ...extraDefineSchema('roll'),
...extraDefineSchema('target'),
...extraDefineSchema('effects'),
resource: new fields.SchemaField({
type: new fields.StringField({ choices: [], initial: "", label: "Resource" }),
value: new fields.NumberField({ initial: 0, label: "Value" })
})
}
}
}
@ -284,7 +313,7 @@ export class DHSummonAction extends DHBaseAction {
static defineSchema() {
return {
...super.defineSchema(),
healing: new fields.SchemaField({})
documentUUID: new fields.StringField({ blank: true, initial: "", placeholder:'Enter a Creature UUID' })
}
}
}
@ -292,7 +321,8 @@ export class DHSummonAction extends DHBaseAction {
export class DHEffectAction extends DHBaseAction {
static defineSchema() {
return {
...super.defineSchema()
...super.defineSchema(),
...extraDefineSchema('effects')
}
}
}
@ -300,7 +330,20 @@ export class DHEffectAction extends DHBaseAction {
export class DHMacroAction extends DHBaseAction {
static defineSchema() {
return {
...super.defineSchema()
...super.defineSchema(),
documentUUID: new fields.StringField({ blank: true, initial: "", placeholder:'Enter a macro UUID' })
}
}
async use(event) {
const fixUUID = !this.documentUUID.includes('Macro.') ? `Macro.${this.documentUUID}` : this.documentUUID,
macro = await fromUuid(fixUUID);
try {
if(!macro) throw new Error(`No macro found for the UUID: ${this.documentUUID}.`);
macro.execute();
} catch (error) {
ui.notifications.error(error);
}
}
}