Split methods

This commit is contained in:
Dapoolp 2025-06-15 13:22:29 +02:00
parent 42df9c6318
commit b09cd8a692
14 changed files with 437 additions and 213 deletions

View file

@ -62,7 +62,6 @@ 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.effects) context.effects = this.action.effects.map(e => this.action.item.effects.get(e._id));
if (this.action.damage?.hasOwnProperty('includeBase') && this.action.type === 'attack') context.hasBaseDamage = !!this.action.parent.damage; if (this.action.damage?.hasOwnProperty('includeBase') && this.action.type === 'attack') context.hasBaseDamage = !!this.action.parent.damage;
context.getRealIndex = this.getRealIndex.bind(this); context.getRealIndex = this.getRealIndex.bind(this);
console.log(context)
return context; return context;
} }

View file

@ -0,0 +1,64 @@
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
export default class CostSelectionDialog extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(cost, resolve) {
super({});
this.cost = cost;
this.resolve = resolve;
}
static DEFAULT_OPTIONS = {
tag: 'form',
classes: ['daggerheart', 'views', 'damage-selection'],
position: {
width: 400,
height: 'auto'
},
actions: {
sendHope: this.sendHope
},
form: {
handler: this.updateForm,
submitOnChange: true,
closeOnSubmit: false
}
};
/** @override */
static PARTS = {
damageSelection: {
id: 'costSelection',
template: 'systems/daggerheart/templates/views/costSelection.hbs'
}
};
/* -------------------------------------------- */
/** @inheritDoc */
get title() {
return `Cost Options`;
}
async _prepareContext(_options) {
return {
cost: this.cost.map(c => {
c.scale = c.scale ?? 1;
c.step = c.step ?? 1;
c.total = c.value * c.scale * c.step;
c.enabled = c.hasOwnProperty('enabled') ? c.enabled : true;
return c
})
};
}
static async updateForm(event, _, formData) {
this.cost = foundry.utils.mergeObject(this.cost, foundry.utils.expandObject(formData.object));
this.render(true)
}
static sendHope(event) {
event.preventDefault();
this.resolve(this.cost.filter(c => c.enabled));
this.close();
}
}

View file

@ -50,9 +50,9 @@ export const targetTypes = {
id: 'friendly', id: 'friendly',
label: 'Friendly' label: 'Friendly'
}, },
adversary: { hostile: {
id: 'adversary', id: 'hostile',
label: 'Adversary' label: 'Hostile'
}, },
any: { any: {
id: 'any', id: 'any',

View file

@ -1,3 +1,5 @@
import DamageSelectionDialog from '../../applications/damageSelectionDialog.mjs';
import CostSelectionDialog from '../../applications/costSelectionDialog.mjs';
import { abilities } from '../../config/actorConfig.mjs'; import { abilities } from '../../config/actorConfig.mjs';
import { DHActionDiceData, DHDamageData, DHDamageField } from './actionDice.mjs'; import { DHActionDiceData, DHDamageData, DHDamageField } from './actionDice.mjs';
@ -15,6 +17,8 @@ const fields = foundry.data.fields;
- Area of effect and measurement placement - Area of effect and measurement placement
- Auto use costs and action - Auto use costs and action
- Auto disable selected Cost from other cost list
Activity Types List Activity Types List
- Attack => Weapon Attack, Spell Attack, etc... - Attack => Weapon Attack, Spell Attack, etc...
- Effects => Like Attack without damage - Effects => Like Attack without damage
@ -27,6 +31,8 @@ const fields = foundry.data.fields;
*/ */
export class DHBaseAction extends foundry.abstract.DataModel { export class DHBaseAction extends foundry.abstract.DataModel {
static extraSchemas = [];
static defineSchema() { static defineSchema() {
return { return {
_id: new fields.DocumentIdField(), _id: new fields.DocumentIdField(),
@ -34,6 +40,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
name: new fields.StringField({ initial: undefined }), name: new fields.StringField({ initial: undefined }),
description: new fields.HTMLField(), description: new fields.HTMLField(),
img: new fields.FilePathField({ initial: undefined, categories: ['IMAGE'], base64: false }), img: new fields.FilePathField({ initial: undefined, categories: ['IMAGE'], base64: false }),
chatDisplay: new fields.BooleanField({ initial: true, label: 'Display in chat' }),
actionType: new fields.StringField({ choices: SYSTEM.ITEM.actionTypes, initial: 'action', nullable: true }), actionType: new fields.StringField({ choices: SYSTEM.ITEM.actionTypes, initial: 'action', nullable: true }),
cost: new fields.ArrayField( cost: new fields.ArrayField(
new fields.SchemaField({ new fields.SchemaField({
@ -62,10 +69,53 @@ export class DHBaseAction extends foundry.abstract.DataModel {
required: false, required: false,
blank: true, blank: true,
initial: null initial: null
}) }),
...this.defineExtraSchema()
}; };
} }
static defineExtraSchema() {
const extraFields = {
damage: new DHDamageField(),
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 })
}),
save: new fields.SchemaField({
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.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({
_id: new fields.DocumentIdField()
})
),
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)
})
},
extraSchemas = {};
this.extraSchemas.forEach(s => extraSchemas[s] = extraFields[s]);
return extraSchemas;
}
prepareData() {} prepareData() {}
get index() { get index() {
@ -81,7 +131,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
} }
get chatTemplate() { get chatTemplate() {
return 'systems/daggerheart/templates/chat/attack-roll.hbs'; return 'systems/daggerheart/templates/chat/duality-roll.hbs';
} }
static getRollType(parent) { static getRollType(parent) {
@ -117,98 +167,132 @@ export class DHBaseAction extends foundry.abstract.DataModel {
} }
async use(event, ...args) { async use(event, ...args) {
// throw new Error("Activity must implement a 'use' method."); let config = {
const data = { event,
itemUUID: this.item, title: this.item.name,
activityId: this.id source: {
itemId: this.item._id,
actionId: this._id
},
hasDamage: !!this.damage?.parts?.length,
chatMessage: {
template: this.chatTemplate
}
}; };
this.proceedChatDisplay(config);
if(this.cost?.length) { // Display Costs Dialog & Check if Actor get enough resources
const hasCost = await this.checkCost(); config.costs = await this.getCost(config);
if(!hasCost) return ui.notifications.warn("You don't have the resources to use that action."); if(!config.costs.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 = {
event: event,
title: this.item.name,
roll: {
modifier: modifierValue,
label: game.i18n.localize(abilities[this.roll.trait].label),
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 ?
}
data.roll = await this.actor.diceRoll(config);
}
if(this.withMessage || true) {
} // Filter selected targets based on Target parameters
config.targets = await this.getTarget(config);
if(!config.targets) return ui.notifications.warn("Too many targets selected for that actions.");
// Filter selected targets based on Range parameters
config.range = await this.checkRange(config);
if(!config.range.hasRange) return ui.notifications.warn("No Target within range.");
return data; // Proceed with Roll
await this.proceedRoll(config);
if (this.effects.length) {
// Apply Active Effects. In Chat Message ?
}
// Update Actor resources based on Action Cost configuration
this.spendCost(config.costs.values);
return config;
} }
async checkCost() { /* ROLL */
if(!this.cost.length || !this.actor) return true; async proceedRoll(config) {
console.log(this.actor, this.cost) if (!this.roll?.type || !this.roll?.trait) return;
return this.cost.reduce((a, c) => a && this.actor.system.resources[c.type]?.value >= (c.value * (c.scalable ? c.step : 1)), true); const modifierValue = this.actor.system.traits[this.roll.trait].value;
config = {
...config,
roll: {
modifier: modifierValue,
label: game.i18n.localize(abilities[this.roll.trait].label),
type: this.actionType,
difficulty: this.roll?.difficulty
}
}
config.roll.evaluated = await this.actor.diceRoll(config);
}
/* ROLL */
/* COST */
async getCost(config) {
if(!this.cost?.length || !this.actor) return {values: [], hasCost: true};
let cost = foundry.utils.deepClone(this.cost);
if (!config.event.shiftKey) {
const dialogClosed = new Promise((resolve, _) => {
new CostSelectionDialog(cost, resolve).render(true);
});
cost = await dialogClosed;
}
return {values: cost, hasCost: cost.reduce((a, c) => a && this.actor.system.resources[c.type]?.value >= (c.total ?? c.value), true)};
} }
async checkTarget() { async spendCost(config) {
/* targets = Array.from(game.user.targets).map(x => { if(!config.costs?.values?.length) return;
const target = { return await this.actor.modifyResource(config.costs.values);
id: x.id, }
name: x.actor.name, /* COST */
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; /* TARGET */
async getTarget(config) {
if(this.target.type === SYSTEM.ACTIONS.targetTypes.self.id) return this.formatTarget(this.actor.token ?? this.actor.prototypeToken);
let targets = Array.from(game.user.targets);
// foundry.CONST.TOKEN_DISPOSITIONS.FRIENDLY
if(this.target?.type && this.target.type !== SYSTEM.ACTIONS.targetTypes.any.id) {
targets = targets.filter(t => this.isTargetFriendly(t));
if(this.target.amount && targets.length > this.target.amount) return false;
}
return targets.map(t => this.formatTarget(t));
}
return target; isTargetFriendly(target) {
}); */ const actorDisposition = this.actor.token ? this.actor.token.disposition : this.actor.prototypeToken.disposition,
const targets = targets = Array.from(game.user.targets).map(x => { targetDisposition = target.document.disposition;
return { return (this.target.type === SYSTEM.ACTIONS.targetTypes.friendly.id && actorDisposition === targetDisposition) || (this.target.type === SYSTEM.ACTIONS.targetTypes.hostile.id && (actorDisposition + targetDisposition === 0))
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) {
formatTarget(actor) {
return {
id: actor.id,
name: actor.actor.name,
img: actor.actor.img,
difficulty: actor.actor.system.difficulty,
evasion: actor.actor.system.evasion?.value
} }
} }
/* TARGET */
async checkRange() { /* RANGE */
console.log(this.range) async checkRange(config) {
if(!this.range || !this.actor) return true;
return {values: [], hasRange: true};
} }
/* RANGE */
/* EFFECTS */
async applyEffects(config) {
if(!this.effects?.length) return;
}
/* EFFECTS */
/* CHAT */
async proceedChatDisplay(config) {
if(!this.chatDisplay) return;
}
/* CHAT */
} }
const extraDefineSchema = (field, option) => { /* const extraDefineSchema = (field, option) => {
return { return {
[field]: { [field]: {
// damage: new fields.SchemaField({ // damage: new fields.SchemaField({
@ -239,56 +323,120 @@ const extraDefineSchema = (field, option) => {
) )
}[field] }[field]
}; };
}; }; */
export class DHDamageAction extends DHBaseAction { export class DHDamageAction extends DHBaseAction {
directDamage = true; directDamage = true;
static defineSchema() { static extraSchemas = ['damage', 'target', 'effects'];
/* static defineSchema() {
return { return {
...super.defineSchema(), ...super.defineSchema(),
...extraDefineSchema('damage'), ...extraDefineSchema('damage'),
...extraDefineSchema('target'), ...extraDefineSchema('target'),
...extraDefineSchema('effects') ...extraDefineSchema('effects')
}; };
} } */
async use(event, ...args) { async use(event, ...args) {
const messageData = await super.use(event, args); const messageData = await super.use(event, args);
if(!this.directDamage) return; if(!this.directDamage) return;
const roll = await this.rollDamage(); return await this.rollDamage(event, messageData);
}
async rollDamage(event, messageData) {
let formula = this.damage.parts.map(p => p.getFormula(this.actor)).join(' + ');
if (!formula || formula == '') return;
let roll = { formula: formula, total: formula },
bonusDamage = [];
if (!event.shiftKey) {
const dialogClosed = new Promise((resolve, _) => {
new DamageSelectionDialog(formula, bonusDamage, resolve).render(true);
});
const result = await dialogClosed;
bonusDamage = result.bonusDamage;
formula = result.rollString;
/* const automateHope = await game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Automation.Hope);
if (automateHope && result.hopeUsed) {
await this.update({
'system.resources.hope.value': this.system.resources.hope.value - result.hopeUsed
});
} */
}
if (isNaN(formula)) {
roll = await new Roll(formula, this.getRollData()).evaluate();
}
if(!roll) return; if(!roll) return;
const cls = getDocumentClass('ChatMessage'), const dice = [],
modifiers = [];
for (var i = 0; i < roll.terms.length; i++) {
const term = roll.terms[i];
if (term.faces) {
dice.push({
type: `d${term.faces}`,
rolls: term.results.map(x => x.result),
total: term.results.reduce((acc, x) => acc + x.result, 0)
});
} else if (term.operator) {
} else if (term.number) {
const operator = i === 0 ? '' : roll.terms[i - 1].operator;
modifiers.push({ value: term.number, operator: operator });
}
}
// if(messageData?.system?.damage) {
// } else {
const cls = getDocumentClass('ChatMessage'),
systemData = {
title: game.i18n.format('DAGGERHEART.Chat.DamageRoll.Title', { damage: this.name }),
roll: formula,
damage: {
total: roll.total,
type: this.damage.parts[0].type // Handle multiple type damage
},
dice: dice,
modifiers: modifiers,
targets: []
},
msg = new cls({
type: 'damageRoll',
user: game.user.id,
sound: CONFIG.sounds.dice,
system: systemData,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/damage-roll.hbs',
systemData
),
rolls: [roll]
});
cls.create(msg.toObject());
// }
/* const cls = getDocumentClass('ChatMessage'),
msg = new cls({ msg = new cls({
user: game.user.id, user: game.user.id,
content: await foundry.applications.handlebars.renderTemplate( content: await foundry.applications.handlebars.renderTemplate(
this.chatTemplate, this.chatTemplate,
{ {
...roll, ...{
roll: roll.formula,
total: roll.total,
dice: roll.dice,
type: this.damage.parts.map(p => p.type)
},
...messageData ...messageData
} }
) )
}); });
cls.create(msg.toObject()); cls.create(msg.toObject()); */
}
async rollDamage() {
const formula = this.damage.parts.map(p => p.getFormula(this.actor)).join(' + ');
console.log(this, formula)
if (!formula || formula == '') return;
let roll = { formula: formula, total: formula };
if (isNaN(formula)) {
roll = await new Roll(formula, this.getRollData()).evaluate();
}
console.log(roll)
return {
roll: roll.formula,
total: roll.total,
dice: roll.dice,
type: this.damage.parts.map(p => p.type)
}
} }
get chatTemplate() { get chatTemplate() {
@ -338,21 +486,24 @@ export class DHDamageAction extends DHBaseAction {
export class DHAttackAction extends DHDamageAction { export class DHAttackAction extends DHDamageAction {
directDamage = false; directDamage = false;
// static extraSchemas = [];
static defineSchema() { static extraSchemas = [...super.extraSchemas, ...['roll', 'save']];
/* static defineSchema() {
return { return {
...super.defineSchema(), ...super.defineSchema(),
...extraDefineSchema('roll'), ...extraDefineSchema('roll'),
...extraDefineSchema('save') ...extraDefineSchema('save')
}; };
} } */
static getRollType(parent) { static getRollType(parent) {
return parent.type === 'weapon' ? 'weapon' : 'spellcast'; return parent.type === 'weapon' ? 'weapon' : 'spellcast';
} }
get chatTemplate() { get chatTemplate() {
return 'systems/daggerheart/templates/chat/attack-roll.hbs'; return 'systems/daggerheart/templates/chat/duality-roll.hbs';
} }
prepareData() { prepareData() {
@ -400,23 +551,7 @@ export class DHAttackAction extends DHDamageAction {
} */ } */
export class DHHealingAction extends DHBaseAction { export class DHHealingAction extends DHBaseAction {
static defineSchema() { static extraSchemas = ['target', 'effects', 'healing'];
return {
...super.defineSchema(),
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, ...args) { async use(event, ...args) {
const messageData = await super.use(event, args), const messageData = await super.use(event, args),
@ -488,12 +623,7 @@ export class DHSummonAction extends DHBaseAction {
} }
export class DHEffectAction extends DHBaseAction { export class DHEffectAction extends DHBaseAction {
static defineSchema() { static extraSchemas = ['effects'];
return {
...super.defineSchema(),
...extraDefineSchema('effects')
};
}
} }
export class DHMacroAction extends DHBaseAction { export class DHMacroAction extends DHBaseAction {

View file

@ -28,13 +28,18 @@ export default class DHAdversaryRoll extends foundry.abstract.TypeDataModel {
hit: new fields.BooleanField({ initial: false }) hit: new fields.BooleanField({ initial: false })
}) })
), ),
damage: new fields.SchemaField( hasDamage: new fields.BooleanField({ initial: false }),
/* damage: new fields.SchemaField(
{ {
value: new fields.StringField({}), value: new fields.StringField({}),
type: new fields.StringField({ choices: Object.keys(SYSTEM.GENERAL.damageTypes), integer: false }) type: new fields.StringField({ choices: Object.keys(SYSTEM.GENERAL.damageTypes), integer: false })
}, },
{ nullable: true, initial: null } { nullable: true, initial: null }
) ), */
action: new fields.SchemaField({
itemId: new fields.StringField(),
actionId: new fields.StringField()
})
}; };
} }

View file

@ -39,26 +39,31 @@ export default class DHDualityRoll extends foundry.abstract.TypeDataModel {
hit: new fields.BooleanField({ initial: false }) hit: new fields.BooleanField({ initial: false })
}) })
), ),
damage: new fields.SchemaField({ hasDamage: new fields.BooleanField({ initial: false }),
value: new fields.StringField({}), // damage: new fields.SchemaField({
type: new fields.StringField({ choices: Object.keys(SYSTEM.GENERAL.damageTypes), integer: false }), // value: new fields.StringField({}),
bonusDamage: new fields.ArrayField( // type: new fields.StringField({ choices: Object.keys(SYSTEM.GENERAL.damageTypes), integer: false }),
new fields.SchemaField({ // bonusDamage: new fields.ArrayField(
value: new fields.StringField({}), // new fields.SchemaField({
type: new fields.StringField({ // value: new fields.StringField({}),
choices: Object.keys(SYSTEM.GENERAL.damageTypes), // type: new fields.StringField({
integer: false // choices: Object.keys(SYSTEM.GENERAL.damageTypes),
}), // integer: false
initiallySelected: new fields.BooleanField(), // }),
appliesOn: new fields.StringField( // initiallySelected: new fields.BooleanField(),
{ choices: Object.keys(SYSTEM.EFFECTS.applyLocations) }, // appliesOn: new fields.StringField(
{ nullable: true, initial: null } // { choices: Object.keys(SYSTEM.EFFECTS.applyLocations) },
), // { nullable: true, initial: null }
description: new fields.StringField({}), // ),
hopeIncrease: new fields.StringField({ nullable: true }) // description: new fields.StringField({}),
}), // hopeIncrease: new fields.StringField({ nullable: true })
{ nullable: true, initial: null } // }),
) // { nullable: true, initial: null }
// )
// }),
action: new fields.SchemaField({
itemId: new fields.StringField(),
actionId: new fields.StringField()
}) })
}; };
} }

View file

@ -256,7 +256,7 @@ export default class DhpActor extends Actor {
* @param {boolean} [config.roll.simple=false] * @param {boolean} [config.roll.simple=false]
* @param {string} [config.roll.type] * @param {string} [config.roll.type]
* @param {number} [config.roll.difficulty] * @param {number} [config.roll.difficulty]
* @param {any} [config.damage] * @param {boolean} [config.hasDamage]
* @param {object} [config.chatMessage] * @param {object} [config.chatMessage]
* @param {string} config.chatMessage.template * @param {string} config.chatMessage.template
* @param {boolean} [config.chatMessage.mute] * @param {boolean} [config.chatMessage.mute]
@ -269,7 +269,6 @@ export default class DhpActor extends Actor {
disadvantageDice = 'd6', disadvantageDice = 'd6',
advantage = config.event.altKey ? true : config.event.ctrlKey ? false : null, advantage = config.event.altKey ? true : config.event.ctrlKey ? false : null,
targets, targets,
damage = config.damage,
modifiers = this.formatRollModifier(config.roll), modifiers = this.formatRollModifier(config.roll),
rollConfig, rollConfig,
formula, formula,
@ -354,18 +353,9 @@ export default class DhpActor extends Actor {
} }
} }
if (config.checkTarget) { if (config.targets?.length) {
targets = Array.from(game.user.targets).map(x => { targets = config.targets.map(target => {
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; target.hit = target.difficulty ? roll.total >= target.difficulty : roll.total >= target.evasion;
return target; return target;
}); });
} }
@ -377,14 +367,16 @@ export default class DhpActor extends Actor {
dice, dice,
roll, roll,
modifiers: modifiers.filter(x => x.label), modifiers: modifiers.filter(x => x.label),
advantageState: advantage advantageState: advantage,
action: config.source,
hasDamage: config.hasDamage
}; };
if (this.type === 'character') { if (this.type === 'character') {
configRoll.hope = { dice: hopeDice, value: hope }; configRoll.hope = { dice: hopeDice, value: hope };
configRoll.fear = { dice: fearDice, value: fear }; configRoll.fear = { dice: fearDice, value: fear };
configRoll.advantage = { dice: advantageDice, value: roll.dice[2]?.results[0].result ?? null }; configRoll.advantage = { dice: advantageDice, value: roll.dice[2]?.results[0].result ?? null };
} }
if (damage) configRoll.damage = damage; // if (damage) configRoll.damage = damage;
if (targets) configRoll.targets = targets; if (targets) configRoll.targets = targets;
const systemData = const systemData =
this.type === 'character' && !config.roll.simple ? new DHDualityRoll(configRoll) : configRoll, this.type === 'character' && !config.roll.simple ? new DHDualityRoll(configRoll) : configRoll,
@ -396,7 +388,7 @@ export default class DhpActor extends Actor {
content: config.chatMessage.template, content: config.chatMessage.template,
rolls: [roll] rolls: [roll]
}); });
await cls.create(msg.toObject()); await cls.create(msg.toObject());
} }
return roll; return roll;
@ -494,7 +486,7 @@ export default class DhpActor extends Actor {
: damage >= this.system.damageThresholds.minor : damage >= this.system.damageThresholds.minor
? 1 ? 1
: 0; : 0;
await this.modifyResource(hpDamage, type); await this.modifyResource({value: hpDamage, type});
/* const update = { /* const update = {
'system.resources.hitPoints.value': Math.min( 'system.resources.hitPoints.value': Math.min(
this.system.resources.hitPoints.value + hpDamage, this.system.resources.hitPoints.value + hpDamage,
@ -516,33 +508,39 @@ export default class DhpActor extends Actor {
} */ } */
} }
async modifyResource(value, type) { async modifyResource(resources) {
let resource, target, update; if(!resources.length) return;
switch (type) { let updates = { actor: { target: this, resources: {} }, armor: { target: this.armor, resources: {} } };
case 'armorStrack': resources.forEach(r => {
resource = 'system.stacks.value'; switch (type) {
target = this.armor; case 'armorStrack':
update = Math.min(this.marks.value + value, this.marks.max); // resource = 'system.stacks.value';
break; // target = this.armor;
default: // update = Math.min(this.marks.value + value, this.marks.max);
resource = `system.resources.${type}`; updates.armor.resources['system.stacks.value'] = Math.min(this.marks.value + value, this.marks.max);
target = this; break;
update = Math.min(this.resources[type].value + value, this.resources[type].max); default:
break; // resource = `system.resources.${type}`;
} // target = this;
if(!resource || !target || !update) return; // update = Math.min(this.resources[type].value + value, this.resources[type].max);
if (game.user.isGM) { updates.armor.resources[`system.resources.${type}`] = Math.min(this.resources[type].value + value, this.resources[type].max);
await target.update(update); break;
} else { }
await game.socket.emit(`system.${SYSTEM.id}`, { })
action: socketEvent.GMUpdate, Object.values(updates).forEach(async (u) => {
data: { if (game.user.isGM) {
action: GMUpdateEvent.UpdateDocument, await u.target.update(u.resources);
uuid: target.uuid, } else {
update: update await game.socket.emit(`system.${SYSTEM.id}`, {
} action: socketEvent.GMUpdate,
}); data: {
} action: GMUpdateEvent.UpdateDocument,
uuid: u.target.uuid,
update: u.resources
}
});
}
})
} }
/* async takeHealing(healing, type) { /* async takeHealing(healing, type) {

View file

@ -53,13 +53,19 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
event.stopPropagation(); event.stopPropagation();
const actor = game.actors.get(message.system.origin); const actor = game.actors.get(message.system.origin);
if (!actor || !game.user.isGM) return true; if (!actor || !game.user.isGM) return true;
if(message.system.action?.itemId && message.system.action?.actionId) {
await actor.damageRoll( const item = actor.items.get(message.system.action?.itemId),
message.system.title, action = item?.system?.actions?.find(a => a._id === message.system.action.actionId);
message.system.damage, if(!item || !action || !action?.rollDamage) return;
message.system.targets.filter(x => x.hit).map(x => ({ id: x.id, name: x.name, img: x.img })), await action.rollDamage(event, this);
event.shiftKey } else {
); await actor.damageRoll(
message.system.title,
message.system.damage,
message.system.targets.filter(x => x.hit).map(x => ({ id: x.id, name: x.name, img: x.img })),
event.shiftKey
);
}
}; };
hoverTarget = event => { hoverTarget = event => {
@ -107,7 +113,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
ui.notifications.info(game.i18n.localize('DAGGERHEART.Notification.Info.NoTargetsSelected')); ui.notifications.info(game.i18n.localize('DAGGERHEART.Notification.Info.NoTargetsSelected'));
for (var target of targets) { for (var target of targets) {
await target.actor.modifyResource(healing, event.currentTarget.dataset.type); await target.actor.modifyResource([{value: healing, type: event.currentTarget.dataset.type}]);
} }
}; };

View file

@ -41,7 +41,7 @@
</div> </div>
{{/if}} {{/if}}
<div class="flexrow"> <div class="flexrow">
<button class="duality-action" data-value="{{roll.total}}" data-damage="{{damage.value}}" data-damage-type="{{damage.type}}"{{#if damage.disabled}} disabled{{/if}}><span>Roll Damage</span></button> <button class="duality-action" data-value="{{roll.total}}"><span>Roll Damage</span></button>
</div> </div>
</div> </div>
</div> </div>

View file

@ -23,7 +23,7 @@
</section> </section>
</div> </div>
</div> </div>
<div class="dice-total">{{total}}</div> <div class="dice-total">{{damage.total}}</div>
<div class="dice-actions"> <div class="dice-actions">
<button class="damage-button" data-target-hit="true" {{#if (eq targets.length 0)}}disabled{{/if}}>{{localize "DAGGERHEART.Chat.DamageRoll.DealDamageToTargets"}}</button> <button class="damage-button" data-target-hit="true" {{#if (eq targets.length 0)}}disabled{{/if}}>{{localize "DAGGERHEART.Chat.DamageRoll.DealDamageToTargets"}}</button>
<button class="damage-button">{{localize "DAGGERHEART.Chat.DamageRoll.DealDamage"}}</button> <button class="damage-button">{{localize "DAGGERHEART.Chat.DamageRoll.DealDamage"}}</button>

View file

@ -128,9 +128,9 @@
{{/each}} {{/each}}
</div> </div>
{{/if}} {{/if}}
<div class="dice-actions{{#unless damage.value}} duality-alone{{/unless}}"> <div class="dice-actions{{#unless hasDamage}} duality-alone{{/unless}}">
{{#if damage.value}} {{#if hasDamage}}
<button class="duality-action" data-value="{{roll.total}}" data-damage="{{damage.value}}" data-damage-type="{{damage.type}}" {{#if damage.disabled}}disabled{{/if}}><span>{{localize "DAGGERHEART.Chat.AttackRoll.RollDamage"}}</span></button> <button class="duality-action" data-value="{{roll.total}}"><span>{{localize "DAGGERHEART.Chat.AttackRoll.RollDamage"}}</span></button>
{{/if}} {{/if}}
<div class="duality-result"> <div class="duality-result">
<div>{{roll.total}} {{#if (eq dualityResult 1)}}With Hope{{else}}{{#if (eq dualityResult 2)}}With Fear{{else}}Critical Success{{/if}}{{/if}}</div> <div>{{roll.total}} {{#if (eq dualityResult 1)}}With Hope{{else}}{{#if (eq dualityResult 2)}}With Fear{{else}}Critical Success{{/if}}{{/if}}</div>

View file

@ -20,6 +20,7 @@
{{formField fields.name value=source.name label="Name" name="name"}} {{formField fields.name value=source.name label="Name" name="name"}}
{{formField fields.img value=source.img label="Icon" name="img"}} {{formField fields.img value=source.img label="Icon" name="img"}}
{{formField fields.actionType value=source.actionType label="Type" name="actionType" localize=true}} {{formField fields.actionType value=source.actionType label="Type" name="actionType" localize=true}}
{{formField fields.chatDisplay value=source.chatDisplay name="chatDisplay"}}
</div> </div>
</fieldset> </fieldset>
<fieldset class="action-category"> <fieldset class="action-category">

View file

@ -0,0 +1,16 @@
<div>
{{#each cost as | c index |}}
<div class="form-group">
<div class="form-fields">
<label for="{{type}}">{{type}}: {{total}}</label>
<input name="{{index}}.enabled" type="checkbox"{{#if enabled}} checked{{/if}}>
{{#if scalable}}
<input type="range" value="{{scale}}" min="1" max="10" step="{{step}}" name="{{index}}.scale">
{{/if}}
</div>
</div>
{{/each}}
<footer>
<button data-action="sendHope">Accept</button>
</footer>
</div>

View file

@ -2,10 +2,10 @@
<div class="form-group"> <div class="form-group">
<label><strong>Total Damage</strong></label> <label><strong>Total Damage</strong></label>
<div class="form-fields"> <div class="form-fields">
<input type="text" value="{{this.rollString}}" disabled /> <input type="text" value="{{rollString}}" disabled />
</div> </div>
</div> </div>
{{#each this.bonusDamage as |damage index|}} {{#each bonusDamage as |damage index|}}
<div class="form-group"> <div class="form-group">
<label><strong>{{damage.description}}</strong></label> <label><strong>{{damage.description}}</strong></label>
<div class="form-fields"> <div class="form-fields">