Roll classes

This commit is contained in:
Dapoolp 2025-06-17 03:04:20 +02:00
parent 4a044db77f
commit 7cc92d153b
25 changed files with 793 additions and 337 deletions

View file

@ -15,6 +15,7 @@ import { abilities } from './module/config/actorConfig.mjs';
import Resources from './module/applications/resources.mjs'; import Resources from './module/applications/resources.mjs';
import DHDualityRoll from './module/data/chat-message/dualityRoll.mjs'; import DHDualityRoll from './module/data/chat-message/dualityRoll.mjs';
import { DualityRollColor } from './module/data/settings/Appearance.mjs'; import { DualityRollColor } from './module/data/settings/Appearance.mjs';
import { DHRoll, DualityRoll, D20Roll, DamageRoll, DualityDie } from './module/applications/roll.mjs'
globalThis.SYSTEM = SYSTEM; globalThis.SYSTEM = SYSTEM;
@ -37,6 +38,16 @@ Hooks.once('init', () => {
name: game.i18n.localize(x.name) name: game.i18n.localize(x.name)
})); }));
CONFIG.Dice.daggerheart = {
DualityDie: DualityDie,
DHRoll: DHRoll,
DualityRoll: DualityRoll,
D20Roll: D20Roll,
DamageRoll: DamageRoll
};
CONFIG.Dice.rolls = [...CONFIG.Dice.rolls, ...[DHRoll, DualityRoll, D20Roll, DamageRoll]];
CONFIG.Item.documentClass = documents.DhpItem; CONFIG.Item.documentClass = documents.DhpItem;
//Registering the Item DataModel //Registering the Item DataModel

View file

@ -927,13 +927,17 @@
}, },
"AttackRoll": { "AttackRoll": {
"Title": "Attack - {attack}", "Title": "Attack - {attack}",
"RollDamage": "Roll Damage" "RollDamage": "Roll Damage",
"ApplyEffect": "Apply Effects"
}, },
"DamageRoll": { "DamageRoll": {
"Title": "Damage - {damage}", "Title": "Damage - {damage}",
"DealDamageToTargets": "Damage Hit Targets", "DealDamageToTargets": "Damage Hit Targets",
"DealDamage": "Deal Damage" "DealDamage": "Deal Damage"
}, },
"ApplyEffect": {
"Title": "Apply Effects - {name}"
},
"HealingRoll": { "HealingRoll": {
"Heal": "Heal" "Heal": "Heal"
}, },

View file

@ -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.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);
context.disableOption = this.disableOption.bind(this);
return context; return context;
} }
@ -70,6 +71,14 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) {
this.render(true); this.render(true);
} }
disableOption(index, options, choices) {
const filtered = foundry.utils.deepClone(options);
Object.keys(filtered).forEach(o => {
if(choices.find((c, idx) => c.type === o && index !== idx)) delete filtered[o];
});
return filtered
}
getRealIndex(index) { getRealIndex(index) {
const data = this.action.toObject(false); const data = this.action.toObject(false);
return data.damage.parts.find(d => d.base) ? index - 1 : index; return data.damage.parts.find(d => d.base) ? index - 1 : index;

View file

@ -1,9 +1,10 @@
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api; const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
export default class CostSelectionDialog extends HandlebarsApplicationMixin(ApplicationV2) { export default class CostSelectionDialog extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(cost, resolve) { constructor(costs, action, resolve) {
super({}); super({});
this.cost = cost; this.costs = costs;
this.action = action;
this.resolve = resolve; this.resolve = resolve;
} }
@ -15,7 +16,7 @@ export default class CostSelectionDialog extends HandlebarsApplicationMixin(Appl
height: 'auto' height: 'auto'
}, },
actions: { actions: {
sendHope: this.sendHope sendCost: this.sendCost
}, },
form: { form: {
handler: this.updateForm, handler: this.updateForm,
@ -26,7 +27,7 @@ export default class CostSelectionDialog extends HandlebarsApplicationMixin(Appl
/** @override */ /** @override */
static PARTS = { static PARTS = {
damageSelection: { costSelection: {
id: 'costSelection', id: 'costSelection',
template: 'systems/daggerheart/templates/views/costSelection.hbs' template: 'systems/daggerheart/templates/views/costSelection.hbs'
} }
@ -40,25 +41,21 @@ export default class CostSelectionDialog extends HandlebarsApplicationMixin(Appl
} }
async _prepareContext(_options) { async _prepareContext(_options) {
const updatedCosts = this.action.calcCosts(this.costs);
return { return {
cost: this.cost.map(c => { costs: updatedCosts,
c.scale = c.scale ?? 1; canUse: this.action.getRealCosts(updatedCosts)?.hasCost
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) { static async updateForm(event, _, formData) {
this.cost = foundry.utils.mergeObject(this.cost, foundry.utils.expandObject(formData.object)); this.costs = foundry.utils.mergeObject(this.costs, foundry.utils.expandObject(formData.object).costs);
this.render(true) this.render(true)
} }
static sendHope(event) { static sendCost(event) {
event.preventDefault(); event.preventDefault();
this.resolve(this.cost.filter(c => c.enabled)); this.resolve(this.action.getRealCosts(this.costs));
this.close(); this.close();
} }
} }

View file

@ -1,34 +1,344 @@
import D20RollDialog from '../dialogs/d20RollDialog.mjs';
export class DHRoll extends Roll {
constructor(formula, data, options) {
super(formula, data, options);
}
export default class DHRoll extends Roll {
static async build(config={}, message={}) { static async build(config={}, message={}) {
const roll = await this.buildConfigure(); const roll = await this.buildConfigure(config, message);
await this.buildEvaluate(config, message={}); await this.buildEvaluate(roll, config, message={});
await this.buildPost(config, message={}); await this.buildPost(roll, config, message={});
return roll; return roll;
} }
static async buildConfigure(config={}, message={}) { static async buildConfigure(config={}, message={}) {
config.hooks = [...(config.hooks ?? []), ""]; config.hooks = [...(config.hooks ?? []), ""];
config.dialog ??= {};
for ( const hook of config.hooks ) { for ( const hook of config.hooks ) {
if ( Hooks.call(`dnd5e.preRoll${hook.capitalize()}`, config, message) === false ) return null; if ( Hooks.call(`${SYSTEM.id}.preRoll${hook.capitalize()}`, config, message) === false ) return null;
} }
this.applyKeybindings(config);
// let roll;
// if(config.dialog?.configure === false) {
// roll = new this('', config.actor, config);
// } else {
if(config.dialog.configure !== false) {
// Open Roll Dialog
const DialogClass = config.dialog?.class ?? this.DefaultDialog;
config = await DialogClass.configure(config, message);
}
console.log(config)
let roll = new this('', config.actor, config);
for ( const hook of config.hooks ) {
if ( Hooks.call(`${SYSTEM.id}.post${hook.capitalize()}RollConfiguration`, roll, config, message) === false ) return [];
}
console.log(roll);
return roll;
} }
static async buildEvaluate(roll, config={}, message={}) { static async buildEvaluate(roll, config={}, message={}) {
if(config.evaluate !== false) await roll.evalutate(); if(config.evaluate !== false) await roll.evaluate();
this.postEvaluate(roll, config);
} }
static async buildPost(config, message) { static async buildPost(roll, config, message) {
for ( const hook of config.hooks ) { for ( const hook of config.hooks ) {
if ( Hooks.call(`dnd5e.postRoll${hook.capitalize()}`, config, message) === false ) return null; if ( Hooks.call(`${SYSTEM.id}.postRoll${hook.capitalize()}`, config, message) === false ) return null;
} }
// Create Chat Message // Create Chat Message
await this.toMessage(roll, message.data); if(message.data) {
} else {
const messageData = {};
await this.toMessage(roll, config);
}
} }
static async toMessage(roll, data) { static async postEvaluate(roll, config={}) {}
const cls = getDocumentClass("ChatMessage"); static async toMessage(roll, config) {
const msg = new cls(data); console.log(config)
const cls = getDocumentClass("ChatMessage"),
msg = {
type: this.messageType,
sound: config.mute ? null : CONFIG.sounds.dice,
system: config,
content: config.chatMessage.template,
rolls: [roll]
};
await cls.create(msg);
}
static applyKeybindings(config) {
config.dialog.configure ??= true;
}
}
// DHopeDie
// DFearDie
// DualityDie
// D20Die
export class DualityDie extends foundry.dice.terms.Die {
constructor({ number=1, faces=12, ...args }={}) {
super({ number, faces, ...args });
}
}
export class D20Roll extends DHRoll {
constructor(formula, data={}, options={}) {
super(formula, data, options);
// console.log(data, options)
// this.options = this._prepareData(data);
// this.options = options;
this.createBaseDice();
this.configureModifiers();
this._formula = this.resetFormula();
}
static ADV_MODE = {
NORMAL: 0,
ADVANTAGE: 1,
DISADVANTAGE: -1
};
static messageType = 'adversaryRoll';
static CRITICAL_TRESHOLD = 20;
static DefaultDialog = D20RollDialog;
get d20() {
if ( !(this.terms[0] instanceof foundry.dice.terms.Die) ) this.createBaseDice();
return this.terms[0];
}
set d20(faces) {
if ( !(this.terms[0] instanceof foundry.dice.terms.Die) ) this.createBaseDice();
this.terms[0].faces = faces;
}
get isCritical() {
if ( !this.d20._evaluated ) return;
return this.d20.total >= this.constructor.CRITICAL_TRESHOLD;
}
get hasAdvantage() {
return this.options.advantage === this.constructor.ADV_MODE.ADVANTAGE;
}
get hasDisadvantage() {
return this.options.advantage === this.constructor.ADV_MODE.DISADVANTAGE;
}
static applyKeybindings(config) {
const keys = {
normal: config.event.shiftKey || config.event.altKey || config.event.ctrlKey,
advantage: config.event.altKey,
disadvantage: config.event.ctrlKey
};
// Should the roll configuration dialog be displayed?
config.dialog.configure ??= !Object.values(keys).some(k => k);
// Determine advantage mode
const advantage = config.advantage || keys.advantage;
const disadvantage = config.disadvantage || keys.disadvantage;
if ( advantage && !disadvantage ) config.advantage = this.ADV_MODE.ADVANTAGE;
else if ( !advantage && disadvantage ) config.advantage = this.ADV_MODE.DISADVANTAGE;
else config.advantage = this.ADV_MODE.NORMAL;
}
static async postEvaluate(roll, config={}) {
if (config.targets?.length) {
targets = config.targets.map(target => {
const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion
target.hit = roll.total >= difficulty;
return target;
});
} else if(config.roll.difficulty) roll.success = roll.total >= config.roll.difficulty;
// config.roll.advantage = {
// dice: roll.dHope.faces,
// value: roll.dHope.total
// }
config.roll.total = roll.total;
}
createBaseDice() {
if ( this.terms[0] instanceof foundry.dice.terms.Die ) return;
this.terms[0] = new foundry.dice.terms.Die({ faces: 20 });
}
applyAdvantage() {
this.d20.modifiers.findSplice(m => ["kh", "kl"].includes(m));
if ( !this.hasAdvantage && !this.hasAdvantage ) this.number = 1;
else {
this.d20.number = 2;
this.d20.modifiers.push(this.hasAdvantage ? "kh" : "kl");
}
}
// Trait bonus != Adversary
configureModifiers() {
this.applyAdvantage();
this.applyBaseBonus();
this.options.experiences?.forEach(m => {
if(this.options.actor.experiences?.[m]) this.terms.push(...this.formatModifier(this.options.actor.experiences[m].total));
})
if(this.options.extraFormula) this.terms.push(new foundry.dice.terms.OperatorTerm({operator: '+'}), ...this.constructor.parse(this.options.extraFormula, this.getRollData()));
// this.resetFormula();
}
applyBaseBonus() {
// if(this.options.action) {
if(this.options.type === "attack") this.terms.push(...this.formatModifier(this.options.actor.system.attack.modifier));
this.options.roll.modifiers?.forEach(m => {
this.terms.push(...this.formatModifier(m));
})
// }
}
getRollData() {
return {...this.options.actor.getRollData(), ...(this.options.action?.getRollData() ?? {})}
}
formatModifier(modifier) {
const numTerm = modifier < 0 ? '-' : '+';
return [new foundry.dice.terms.OperatorTerm({operator: numTerm}), new foundry.dice.terms.NumericTerm({number: Math.abs(modifier)})];
}
resetFormula() {
return this._formula = this.constructor.getFormula(this.terms);
}
}
export class DualityRoll extends D20Roll {
constructor(formula, data={}, options={}) {
super(formula, data, options);
}
static messageType = 'dualityRoll';
static DefaultDialog = D20RollDialog;
get dHope() {
// if ( !(this.terms[0] instanceof foundry.dice.terms.Die) ) return;
if ( !(this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.createBaseDice();
return this.dice[0];
// return this.#hopeDice;
}
set dHope(faces) {
if ( !(this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.createBaseDice();
this.terms[0].faces = faces;
// this.#hopeDice = `d${face}`;
}
get dFear() {
// if ( !(this.terms[1] instanceof foundry.dice.terms.Die) ) return;
if ( !(this.dice[1] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.createBaseDice();
return this.dice[1];
// return this.#fearDice;
}
set dFear(faces) {
if ( !(this.dice[1] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.createBaseDice();
this.dice[1].faces = faces;
// this.#fearDice = `d${face}`;
}
get isCritical() {
if ( !this.dHope._evaluated || !this.dFear._evaluated ) return;
return this.dHope.total === this.dFear.total;
}
get withHope() {
if(!this._evaluated) return;
return this.dHope.total > this.dFear.total;
}
get withFear() {
if(!this._evaluated) return;
return this.dHope.total < this.dFear.total;
}
createBaseDice() {
if ( this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie && this.dice[1] instanceof CONFIG.Dice.daggerheart.DualityDie ) return;
if ( !(this.dice[0] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.terms[0] = new CONFIG.Dice.daggerheart.DualityDie();
this.terms[1] = new foundry.dice.terms.OperatorTerm({operator:'+'});
if ( !(this.dice[2] instanceof CONFIG.Dice.daggerheart.DualityDie) ) this.terms[2] = new CONFIG.Dice.daggerheart.DualityDie();
}
applyAdvantage() {
const dieFaces = 6,
bardRallyFaces = null,
advDie = new foundry.dice.terms.Die({faces: dieFaces});
// console.log(this.hasAdvantage, this.hasDisadvantage)
if(this.hasAdvantage || this.hasDisadvantage || bardRallyFaces) this.terms.push(new foundry.dice.terms.OperatorTerm({operator:'+'}));
if(bardRallyFaces) {
const rallyDie = new foundry.dice.terms.Die({faces: bardRallyFaces});
if(this.hasAdvantage) {
this.terms.push(new foundry.dice.terms.PoolTerm({
terms: [advDie.formula, rallyDie.formula],
modifiers: ["kh"]
}))
} else if(this.hasDisadvantage){
this.terms.push(advDie, new foundry.dice.terms.OperatorTerm({operator:'+'}), rallyDie);
}
} else if(this.hasAdvantage || this.hasDisadvantage) this.terms.push(advDie);
}
applyBaseBonus() {
// if(this.options.action) {
// console.log(this.options, this.options.actor.system.traits[this.options.roll.trait].bonus)
// console.log(this.options.actor.system);
if(this.options.roll?.trait) this.terms.push(...this.formatModifier(this.options.actor.traits[this.options.roll.trait].total));
this.options.roll.modifiers?.forEach(m => {
this.terms.push(...this.formatModifier(m.value));
})
// } else if(this.options.trait) this.terms.push(...this.formatModifier(this.options.actor.system.traits[this.options.roll.trait].total));
}
static async postEvaluate(roll, config={}) {
super.postEvaluate(roll, config);
config.roll.hope = {
dice: roll.dHope.faces,
value: roll.dHope.total
}
config.roll.fear = {
dice: roll.dFear.faces,
value: roll.dFear.total
}
config.roll.dualityResult = roll.withHope ? 1 : roll.withFear ? 2 : 0;
}
}
export class DamageRoll extends DHRoll {
constructor(formula, data={}, options={}) {
super(formula, data, options)
}
static messageType = 'damageRoll';
static DefaultDialog = D20RollDialog;
get messageType() {
return 'damageRoll';
}
get messageTemplate() {
return '';
} }
} }

View file

@ -1,10 +1,12 @@
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api; const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
export default class RollSelectionDialog extends HandlebarsApplicationMixin(ApplicationV2) { export default class RollSelectionDialog extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(experiences, hopeResource, resolve) { constructor(experiences, costs, action, resolve) {
super({}, {}); super({}, {});
this.experiences = experiences; this.experiences = experiences;
this.costs = costs;
this.action = action;
this.resolve = resolve; this.resolve = resolve;
this.isNpc; this.isNpc;
this.selectedExperiences = []; this.selectedExperiences = [];
@ -15,8 +17,7 @@ export default class RollSelectionDialog extends HandlebarsApplicationMixin(Appl
], ],
hope: ['d12'], hope: ['d12'],
fear: ['d12'], fear: ['d12'],
advantage: null, advantage: null
hopeResource: hopeResource
}; };
} }
@ -42,6 +43,10 @@ export default class RollSelectionDialog extends HandlebarsApplicationMixin(Appl
/** @override */ /** @override */
static PARTS = { static PARTS = {
costSelection: {
id: 'costSelection',
template: 'systems/daggerheart/templates/views/costSelection.hbs'
},
damageSelection: { damageSelection: {
id: 'damageSelection', id: 'damageSelection',
template: 'systems/daggerheart/templates/views/rollSelection.hbs' template: 'systems/daggerheart/templates/views/rollSelection.hbs'
@ -60,15 +65,19 @@ export default class RollSelectionDialog extends HandlebarsApplicationMixin(Appl
context.fear = this.data.fear; context.fear = this.data.fear;
context.advantage = this.data.advantage; context.advantage = this.data.advantage;
context.experiences = Object.keys(this.experiences).map(id => ({ id, ...this.experiences[id] })); context.experiences = Object.keys(this.experiences).map(id => ({ id, ...this.experiences[id] }));
context.hopeResource = this.data.hopeResource + 1; if(this.costs?.length) {
const updatedCosts = this.action.calcCosts(this.costs);
context.costs = updatedCosts
context.canRoll = this.action.getRealCosts(updatedCosts)?.hasCost;
} else context.canRoll = true;
return context; return context;
} }
static updateSelection(event, _, formData) { static updateSelection(event, _, formData) {
const { ...rest } = foundry.utils.expandObject(formData.object); const { ...rest } = foundry.utils.expandObject(formData.object);
this.data = foundry.utils.mergeObject(this.data, rest); this.data = foundry.utils.mergeObject(this.data, rest);
this.costs = foundry.utils.mergeObject(this.costs, rest.costs);
this.render(); this.render();
} }
@ -90,10 +99,10 @@ export default class RollSelectionDialog extends HandlebarsApplicationMixin(Appl
static async finish() { static async finish() {
const { diceOptions, ...rest } = this.data; const { diceOptions, ...rest } = this.data;
this.resolve({ this.resolve({
...rest, ...rest,
experiences: this.selectedExperiences.map(x => ({ id: x, ...this.experiences[x] })) experiences: this.selectedExperiences.map(x => ({ id: x, ...this.experiences[x] })),
costs: this.action.getRealCosts(this.costs)
}); });
this.close(); this.close();
} }

View file

@ -7,17 +7,24 @@ const fields = foundry.data.fields;
/* /*
ToDo ToDo
- Apply ActiveEffect => Add to Chat message like Damage Button ? - Target Check / Target Picker
- Add Drag & Drop for documentUUID field (Macro & Summon)
- Add optionnal Role for Healing ?
- Handle Roll result as part of formula if needed
- Target Check
- Cost Check
- Range Check - Range Check
- Area of effect and measurement placement - Area of effect and measurement placement
- Auto use costs and action - Handle Roll result as part of formula if needed
- Summon Action create method
- Create classes form Target, Cost, etc ?
Other
- Add optionnal Role for Healing ?
- Auto use action <= Into Roll
Done
- Cost Check
- Auto use costs
- Auto disable selected Cost from other cost list - Auto disable selected Cost from other cost list
- Apply ActiveEffect => Add to Chat message like Damage Button ?
- Add Drag & Drop for documentUUID field (Macro & Summon)
Activity Types List Activity Types List
- Attack => Weapon Attack, Spell Attack, etc... - Attack => Weapon Attack, Spell Attack, etc...
@ -28,6 +35,16 @@ const fields = foundry.data.fields;
- Summon - Summon
- Sequencer => Trigger a list of Activities set on the item one by one - Sequencer => Trigger a list of Activities set on the item one by one
- Macro - Macro
Actor Modifier
- Weapon Attack
- Spell Attack
- Weapon Damage
- Magical Damage
- Physical Damage ?
- Magical Damage ?
- Healing
- Bard Rally (Math.ceil(LeveL / 5))
*/ */
export class DHBaseAction extends foundry.abstract.DataModel { export class DHBaseAction extends foundry.abstract.DataModel {
@ -163,7 +180,8 @@ export class DHBaseAction extends foundry.abstract.DataModel {
...actorData.toObject(), ...actorData.toObject(),
prof: actorData.proficiency?.value ?? 1, prof: actorData.proficiency?.value ?? 1,
cast: actorData.spellcast?.value ?? 1, cast: actorData.spellcast?.value ?? 1,
scale: this.cost.length ? this.cost.reduce((a,c) => {a[c.type] = c.value; return a},{}) : 1 scale: this.cost.length ? this.cost.reduce((a,c) => {a[c.type] = c.value; return a},{}) : 1,
roll: {}
} }
} }
@ -175,7 +193,9 @@ export class DHBaseAction extends foundry.abstract.DataModel {
itemId: this.item._id, itemId: this.item._id,
actionId: this._id actionId: this._id
}, },
type: this.type,
hasDamage: !!this.damage?.parts?.length, hasDamage: !!this.damage?.parts?.length,
hasEffect: !!this.effects?.length,
chatMessage: { chatMessage: {
template: this.chatTemplate template: this.chatTemplate
} }
@ -183,10 +203,6 @@ export class DHBaseAction extends foundry.abstract.DataModel {
this.proceedChatDisplay(config); this.proceedChatDisplay(config);
// Display Costs Dialog & Check if Actor get enough resources
config.costs = await this.getCost(config);
if(!config.costs.hasCost) return ui.notifications.warn("You don't have the resources to use that action.");
// Filter selected targets based on Target parameters // Filter selected targets based on Target parameters
config.targets = await this.getTarget(config); config.targets = await this.getTarget(config);
if(!config.targets) return ui.notifications.warn("Too many targets selected for that actions."); if(!config.targets) return ui.notifications.warn("Too many targets selected for that actions.");
@ -195,33 +211,41 @@ export class DHBaseAction extends foundry.abstract.DataModel {
config.range = await this.checkRange(config); config.range = await this.checkRange(config);
if(!config.range.hasRange) return ui.notifications.warn("No Target within range."); if(!config.range.hasRange) return ui.notifications.warn("No Target within range.");
// Proceed with Roll // Display Costs Dialog & Check if Actor get enough resources
await this.proceedRoll(config); config.costs = await this.getCost(config);
if(!this.hasRoll() && !config.costs.hasCost) return ui.notifications.warn("You don't have the resources to use that action.");
if (this.effects.length) { // Proceed with Roll
// Apply Active Effects. In Chat Message ? config = await this.proceedRoll(config);
}
// Update Actor resources based on Action Cost configuration // Update Actor resources based on Action Cost configuration
this.spendCost(config.costs.values); this.spendCost(config.costs.values);
// console.log(config)
return config; return config;
} }
/* ROLL */ /* ROLL */
hasRoll() {
return this.roll?.type && this.roll?.trait;
}
async proceedRoll(config) { async proceedRoll(config) {
if (!this.roll?.type || !this.roll?.trait) return; if (!this.hasRoll()) return config;
const modifierValue = this.actor.system.traits[this.roll.trait].value; const modifierValue = this.actor.system.traits[this.roll.trait].value;
config = { config = {
...config, ...config,
roll: { roll: {
modifier: modifierValue, // modifier: modifierValue,
label: game.i18n.localize(abilities[this.roll.trait].label), modifier: [],
type: this.actionType, trait: this.roll?.trait,
difficulty: this.roll?.difficulty label: game.i18n.localize(abilities[this.roll.trait].label),
type: this.actionType,
difficulty: this.roll?.difficulty
}
} }
} return await this.actor.diceRoll(config, this);
config.roll.evaluated = await this.actor.diceRoll(config);
} }
/* ROLL */ /* ROLL */
@ -229,13 +253,32 @@ export class DHBaseAction extends foundry.abstract.DataModel {
async getCost(config) { async getCost(config) {
if(!this.cost?.length || !this.actor) return {values: [], hasCost: true}; if(!this.cost?.length || !this.actor) return {values: [], hasCost: true};
let cost = foundry.utils.deepClone(this.cost); let cost = foundry.utils.deepClone(this.cost);
if (!config.event.shiftKey) { if (!config.event.shiftKey && !this.hasRoll()) {
const dialogClosed = new Promise((resolve, _) => { const dialogClosed = new Promise((resolve, _) => {
new CostSelectionDialog(cost, resolve).render(true); new CostSelectionDialog(cost, this, resolve).render(true);
}); });
cost = await dialogClosed; cost = await dialogClosed;
} }
return {values: cost, hasCost: cost.reduce((a, c) => a && this.actor.system.resources[c.type]?.value >= (c.total ?? c.value), true)}; return cost;
}
getRealCosts(costs) {
const realCosts = costs?.length ? costs.filter(c => c.enabled) : [];
return {values: realCosts, hasCost: this.hasCost(realCosts)}
}
calcCosts(costs) {
return costs.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
})
}
hasCost(costs) {
return costs.reduce((a, c) => a && this.actor.system.resources[c.type]?.value >= (c.total ?? c.value), true)
} }
async spendCost(config) { async spendCost(config) {
@ -246,7 +289,7 @@ export class DHBaseAction extends foundry.abstract.DataModel {
/* TARGET */ /* TARGET */
async getTarget(config) { async getTarget(config) {
if(this.target.type === SYSTEM.ACTIONS.targetTypes.self.id) return this.formatTarget(this.actor.token ?? this.actor.prototypeToken); 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); let targets = Array.from(game.user.targets);
// foundry.CONST.TOKEN_DISPOSITIONS.FRIENDLY // foundry.CONST.TOKEN_DISPOSITIONS.FRIENDLY
if(this.target?.type && this.target.type !== SYSTEM.ACTIONS.targetTypes.any.id) { if(this.target?.type && this.target.type !== SYSTEM.ACTIONS.targetTypes.any.id) {
@ -281,8 +324,39 @@ export class DHBaseAction extends foundry.abstract.DataModel {
/* RANGE */ /* RANGE */
/* EFFECTS */ /* EFFECTS */
async applyEffects(config) { async applyEffects(event, data, force=false) {
if(!this.effects?.length) return; if(!this.effects?.length || !data.system.targets.length) return;
data.system.targets.forEach(async (token) => {
// console.log(token, force)
if(!token.hit && !force) return;
this.effects.forEach(async (e) => {
const actor = canvas.tokens.get(token.id)?.actor,
effect = this.item.effects.get(e._id);
if(!actor || !effect) return;
await this.applyEffect(effect, actor);
})
})
}
async applyEffect(effect, actor) {
// Enable an existing effect on the target if it originated from this effect
const existingEffect = actor.effects.find(e => e.origin === origin.uuid);
if ( existingEffect ) {
return existingEffect.update(foundry.utils.mergeObject({
...effect.constructor.getInitialDuration(),
disabled: false
}));
}
// Otherwise, create a new effect on the target
const effectData = foundry.utils.mergeObject({
...effect.toObject(),
disabled: false,
transfer: false,
origin: origin.uuid
});
await ActiveEffect.implementation.create(effectData, { parent: actor });
} }
/* EFFECTS */ /* EFFECTS */
@ -293,60 +367,19 @@ export class DHBaseAction extends foundry.abstract.DataModel {
/* CHAT */ /* CHAT */
} }
/* const extraDefineSchema = (field, option) => {
return {
[field]: {
// damage: new fields.SchemaField({
// parts: new fields.ArrayField(new fields.EmbeddedDataField(DHDamageData))
// }),
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()
})
)
}[field]
};
}; */
export class DHDamageAction extends DHBaseAction { export class DHDamageAction extends DHBaseAction {
directDamage = true; directDamage = true;
static extraSchemas = ['damage', 'target', 'effects']; static extraSchemas = ['damage', 'target', 'effects'];
/* static defineSchema() {
return {
...super.defineSchema(),
...extraDefineSchema('damage'),
...extraDefineSchema('target'),
...extraDefineSchema('effects')
};
} */
async use(event, ...args) { async use(event, ...args) {
const messageData = await super.use(event, args); const config = await super.use(event, args);
if(['error', 'warning'].includes(config.type)) return;
if(!this.directDamage) return; if(!this.directDamage) return;
return await this.rollDamage(event, messageData); return await this.rollDamage(event, config);
} }
async rollDamage(event, messageData) { async rollDamage(event, data) {
let formula = this.damage.parts.map(p => p.getFormula(this.actor)).join(' + '); let formula = this.damage.parts.map(p => p.getFormula(this.actor)).join(' + ');
if (!formula || formula == '') return; if (!formula || formula == '') return;
@ -360,13 +393,6 @@ export class DHDamageAction extends DHBaseAction {
const result = await dialogClosed; const result = await dialogClosed;
bonusDamage = result.bonusDamage; bonusDamage = result.bonusDamage;
formula = result.rollString; 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)) { if (isNaN(formula)) {
@ -390,115 +416,43 @@ export class DHDamageAction extends DHBaseAction {
} }
} }
// if(messageData?.system?.damage) { const cls = getDocumentClass('ChatMessage'),
// } else { systemData = {
const cls = getDocumentClass('ChatMessage'), title: game.i18n.format('DAGGERHEART.Chat.DamageRoll.Title', { damage: this.name }),
systemData = { roll: formula,
title: game.i18n.format('DAGGERHEART.Chat.DamageRoll.Title', { damage: this.name }), damage: {
roll: formula, total: roll.total,
damage: { type: this.damage.parts[0].type // Handle multiple type damage
total: roll.total,
type: this.damage.parts[0].type // Handle multiple type damage
},
dice: dice,
modifiers: modifiers,
targets: []
}, },
msg = new cls({ dice: dice,
type: 'damageRoll', modifiers: modifiers,
user: game.user.id, targets: (data.system?.targets ?? data.targets).map(x => ({ id: x.id, name: x.name, img: x.img, hit: true }))
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({
type: 'damageRoll',
user: game.user.id, user: game.user.id,
sound: CONFIG.sounds.dice,
system: systemData,
content: await foundry.applications.handlebars.renderTemplate( content: await foundry.applications.handlebars.renderTemplate(
this.chatTemplate, 'systems/daggerheart/templates/chat/damage-roll.hbs',
{ systemData
...{ ),
roll: roll.formula, rolls: [roll]
total: roll.total,
dice: roll.dice,
type: this.damage.parts.map(p => p.type)
},
...messageData
}
)
}); });
cls.create(msg.toObject()); */ cls.create(msg.toObject());
} }
get chatTemplate() { get chatTemplate() {
return 'systems/daggerheart/templates/chat/damage-roll.hbs'; return 'systems/daggerheart/templates/chat/damage-roll.hbs';
} }
/* async use(event, ...args) {
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());
} */
/* async applyDamage(targets, value) {
const promises = [];
for(let t of targets) {
if(!t) continue;
promises.push(new Promise(async (resolve, reject) => {
await t.takeDamage(value, 'physical'); // Apply one instance of damage per parts ?
resolve();
})
)
}
return Promise.all(promises).then((values) => {
return values;
});
} */
} }
export class DHAttackAction extends DHDamageAction { export class DHAttackAction extends DHDamageAction {
directDamage = false; directDamage = false;
// static extraSchemas = [];
static extraSchemas = [...super.extraSchemas, ...['roll', 'save']]; static extraSchemas = [...super.extraSchemas, ...['roll', 'save']];
/* static defineSchema() {
return {
...super.defineSchema(),
...extraDefineSchema('roll'),
...extraDefineSchema('save')
};
} */
static getRollType(parent) { static getRollType(parent) {
return parent.type === 'weapon' ? 'weapon' : 'spellcast'; return parent.type === 'weapon' ? 'weapon' : 'spellcast';
} }
@ -524,39 +478,15 @@ export class DHAttackAction extends DHDamageAction {
base: true base: true
}; };
} }
/* async use(event, ...args) {
} */
// 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')
};
}
static getRollType(parent) {
return 'spellcast';
}
} */
export class DHHealingAction extends DHBaseAction { export class DHHealingAction extends DHBaseAction {
static extraSchemas = ['target', 'effects', 'healing']; static extraSchemas = ['target', 'effects', 'healing'];
async use(event, ...args) { async use(event, ...args) {
const messageData = await super.use(event, args), const config = await super.use(event, args);
roll = await this.rollHealing(), if(['error', 'warning'].includes(config.type)) return;
const roll = await this.rollHealing(),
cls = getDocumentClass('ChatMessage'), cls = getDocumentClass('ChatMessage'),
msg = new cls({ msg = new cls({
user: game.user.id, user: game.user.id,
@ -564,7 +494,7 @@ export class DHHealingAction extends DHBaseAction {
this.chatTemplate, this.chatTemplate,
{ {
...roll, ...roll,
...messageData ...config
} }
) )
}); });
@ -593,49 +523,76 @@ export class DHHealingAction extends DHBaseAction {
} }
} }
/* 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: [],
blank: true,
required: false,
initial: '',
label: 'Resource'
}),
value: new fields.NumberField({ initial: 0, label: 'Value' })
})
};
}
} */
export class DHSummonAction extends DHBaseAction { export class DHSummonAction extends DHBaseAction {
static defineSchema() { static defineSchema() {
return { return {
...super.defineSchema(), ...super.defineSchema(),
documentUUID: new fields.StringField({ blank: true, initial: '', placeholder: 'Enter a Creature UUID' }) documentUUID: new fields.DocumentUUIDField({ type: 'Actor' })
}; };
} }
async use(event, ...args) {
if ( !this.canSummon || !canvas.scene ) return;
const config = await super.use(event, args);
}
get canSummon() {
return game.user.can("TOKEN_CREATE");
}
} }
export class DHEffectAction extends DHBaseAction { export class DHEffectAction extends DHBaseAction {
static extraSchemas = ['effects']; static extraSchemas = ['effects', 'target'];
async use(event, ...args) {
const config = await super.use(event, args);
if(['error', 'warning'].includes(config.type)) return;
return await this.chatApplyEffects(event, config);
}
async chatApplyEffects(event, data) {
// console.log(data, this.effects, this.effectsDetails)
const cls = getDocumentClass('ChatMessage'),
systemData = {
title: game.i18n.format('DAGGERHEART.Chat.ApplyEffect.Title', { name: this.name }),
origin: this.actor._id,
description: '',
targets: data.targets.map(x => ({ id: x.id, name: x.name, img: x.img, hit: true })),
action: {
itemId: this.item._id,
actionId: this._id
}
},
msg = new cls({
type: 'applyEffect',
user: game.user.id,
system: systemData,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/apply-effects.hbs',
systemData
)
});
cls.create(msg.toObject());
}
get chatTemplate() {
return 'systems/daggerheart/templates/chat/apply-effects.hbs';
}
} }
export class DHMacroAction extends DHBaseAction { export class DHMacroAction extends DHBaseAction {
static defineSchema() { static defineSchema() {
return { return {
...super.defineSchema(), ...super.defineSchema(),
documentUUID: new fields.StringField({ blank: true, initial: '', placeholder: 'Enter a macro UUID' }) documentUUID: new fields.DocumentUUIDField({ type: 'Macro' })
}; };
} }
async use(event, ...args) { async use(event, ...args) {
const config = await super.use(event, args);
if(['error', 'warning'].includes(config.type)) return;
const fixUUID = !this.documentUUID.includes('Macro.') ? `Macro.${this.documentUUID}` : this.documentUUID, const fixUUID = !this.documentUUID.includes('Macro.') ? `Macro.${this.documentUUID}` : this.documentUUID,
macro = await fromUuid(fixUUID); macro = await fromUuid(fixUUID);
try { try {

View file

@ -2,12 +2,14 @@ import DHAbilityUse from "./abilityUse.mjs";
import DHAdversaryRoll from "./adversaryRoll.mjs"; import DHAdversaryRoll from "./adversaryRoll.mjs";
import DHDamageRoll from "./damageRoll.mjs"; import DHDamageRoll from "./damageRoll.mjs";
import DHDualityRoll from "./dualityRoll.mjs"; import DHDualityRoll from "./dualityRoll.mjs";
import DHApplyEffect from './applyEffects.mjs'
export { export {
DHAbilityUse, DHAbilityUse,
DHAdversaryRoll, DHAdversaryRoll,
DHDamageRoll, DHDamageRoll,
DHDualityRoll, DHDualityRoll,
DHApplyEffect
} }
export const config = { export const config = {
@ -15,4 +17,5 @@ export const config = {
adversaryRoll: DHAdversaryRoll, adversaryRoll: DHAdversaryRoll,
damageRoll: DHDamageRoll, damageRoll: DHDamageRoll,
dualityRoll: DHDualityRoll, dualityRoll: DHDualityRoll,
applyEffect: DHApplyEffect
}; };

View file

@ -29,6 +29,7 @@ export default class DHAdversaryRoll extends foundry.abstract.TypeDataModel {
}) })
), ),
hasDamage: new fields.BooleanField({ initial: false }), hasDamage: new fields.BooleanField({ initial: false }),
hasEffect: new fields.BooleanField({ initial: false }),
/* damage: new fields.SchemaField( /* damage: new fields.SchemaField(
{ {
value: new fields.StringField({}), value: new fields.StringField({}),

View file

@ -0,0 +1,23 @@
export default class DHApplyEffect extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
title: new fields.StringField(),
origin: new fields.StringField({}),
description: new fields.StringField({}),
targets: new fields.ArrayField(
new fields.SchemaField({
id: new fields.StringField({ required: true }),
name: new fields.StringField(),
img: new fields.StringField(),
hit: new fields.BooleanField({ initial: false })
})
),
action: new fields.SchemaField({
itemId: new fields.StringField(),
actionId: new fields.StringField()
})
};
}
}

View file

@ -26,7 +26,8 @@ export default class DHDamageRoll extends foundry.abstract.TypeDataModel {
new fields.SchemaField({ new fields.SchemaField({
id: new fields.StringField({ required: true }), id: new fields.StringField({ required: true }),
name: new fields.StringField(), name: new fields.StringField(),
img: new fields.StringField() img: new fields.StringField(),
hit: new fields.BooleanField({ initial: false })
}) })
) )
}; };

View file

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

View file

@ -2,7 +2,7 @@ import BaseDataItem from './base.mjs';
import FormulaField from '../fields/formulaField.mjs'; import FormulaField from '../fields/formulaField.mjs';
import ActionField from '../fields/actionField.mjs'; import ActionField from '../fields/actionField.mjs';
import { weaponFeatures } from '../../config/itemConfig.mjs'; import { weaponFeatures } from '../../config/itemConfig.mjs';
import { actionsTypes } from '../../data/_module.mjs'; import { actionsTypes } from '../action/_module.mjs';
export default class DHWeapon extends BaseDataItem { export default class DHWeapon extends BaseDataItem {
/** @inheritDoc */ /** @inheritDoc */

View file

@ -0,0 +1,85 @@
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
export default class D20RollDialog extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(config={}, options={}) {
super(options);
this.config = config;
this.config.experiences = [];
}
static DEFAULT_OPTIONS = {
tag: 'form',
id: 'roll-selection',
classes: ['daggerheart', 'views', 'roll-selection'],
position: {
width: 400,
height: 'auto'
},
actions: {
updateIsAdvantage: this.updateIsAdvantage,
selectExperience: this.selectExperience,
// finish: this.finish
},
form: {
handler: this.updateRollConfiguration,
submitOnChange: true,
submitOnClose: false
}
};
/** @override */
static PARTS = {
costSelection: {
id: 'costSelection',
template: 'systems/daggerheart/templates/views/costSelection.hbs'
},
rollSelection: {
id: 'rollSelection',
template: 'systems/daggerheart/templates/views/rollSelection.hbs'
}
};
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.experiences = Object.keys(this.config.actor.experiences).map(id => ({ id, ...this.config.actor.experiences[id] }));
context.selectedExperiences = this.config.experiences;
context.advantage = this.config.advantage;
context.diceOptions = [{id:12, value: 'd12'},{id:20, value: 'd20'}]
if(this.config.costs?.length) {
const updatedCosts = this.config.action.calcCosts(this.config.costs);
context.costs = updatedCosts
context.canRoll = this.config.action.getRealCosts(updatedCosts)?.hasCost;
} else context.canRoll = true;
return context;
}
static updateRollConfiguration(event, _, formData) {
const { ...rest } = foundry.utils.expandObject(formData.object);
this.config.costs = foundry.utils.mergeObject(this.config.costs, rest.costs);
this.render();
}
static updateIsAdvantage(_, button) {
const advantage = Number(button.dataset.advantage);
this.config.advantage = this.config.advantage === advantage ? 0 : advantage;
this.render();
}
static selectExperience(_, button) {
if (this.config.experiences.find(x => x === button.dataset.key)) {
this.config.experiences = this.config.experiences.filter(x => x !== button.dataset.key);
} else {
this.config.experiences = [...this.config.experiences, button.dataset.key];
}
this.render();
}
static async configure(config={}) {
return new Promise(resolve => {
const app = new this(config);
app.addEventListener("close", () => resolve(app.config), { once: true });
app.render({ force: true });
});
}
}

View file

@ -257,13 +257,30 @@ export default class DhpActor extends Actor {
* @param {string} [config.roll.type] * @param {string} [config.roll.type]
* @param {number} [config.roll.difficulty] * @param {number} [config.roll.difficulty]
* @param {boolean} [config.hasDamage] * @param {boolean} [config.hasDamage]
* @param {boolean} [config.hasEffect]
* @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]
* @param {boolean} [config.checkTarget] * @param {object} [config.targets]
* @param {object} [config.costs]
*/ */
async diceRoll(config) { async diceRoll(config, action) {
let hopeDice = 'd12', // console.log(config)
const newConfig = {
// data: {
...config,
action,
actor: this.getRollData(),
// },
// options: {
// dialog: false,
// },
// event: config.event
}
// console.log(this, newConfig)
const roll = CONFIG.Dice.daggerheart[this.type === 'character' ? 'DualityRoll' : 'D20Roll'].build(newConfig)
return config;
/* let hopeDice = 'd12',
fearDice = 'd12', fearDice = 'd12',
advantageDice = 'd6', advantageDice = 'd6',
disadvantageDice = 'd6', disadvantageDice = 'd6',
@ -280,16 +297,21 @@ export default class DhpActor extends Actor {
this.type === 'character' this.type === 'character'
? new RollSelectionDialog( ? new RollSelectionDialog(
this.system.experiences, this.system.experiences,
this.system.resources.hope.value, config.costs,
action,
resolve resolve
).render(true) ).render(true)
: new NpcRollSelectionDialog(this.system.experiences, resolve).render(true); : new NpcRollSelectionDialog(
this.system.experiences,
resolve
).render(true);
}); });
rollConfig = await dialogClosed; rollConfig = await dialogClosed;
advantage = rollConfig.advantage; advantage = rollConfig.advantage;
hopeDice = rollConfig.hope; hopeDice = rollConfig.hope;
fearDice = rollConfig.fear; fearDice = rollConfig.fear;
if(rollConfig.costs) config.costs = rollConfig.costs;
rollConfig.experiences.forEach(x => rollConfig.experiences.forEach(x =>
modifiers.push({ modifiers.push({
@ -316,13 +338,14 @@ export default class DhpActor extends Actor {
formula = `${advantage === true || advantage === false ? 2 : 1}d20${advantage === true ? 'kh' : advantage === false ? 'kl' : ''}`; formula = `${advantage === true || advantage === false ? 2 : 1}d20${advantage === true ? 'kh' : advantage === false ? 'kl' : ''}`;
} }
formula += ` ${modifiers.map(x => `+ ${x.value}`).join(' ')}`; formula += ` ${modifiers.map(x => `+ ${x.value}`).join(' ')}`;
const roll = await Roll.create(formula).evaluate(); const roll = await Roll.create(formula).evaluate(),
const dice = roll.dice.flatMap(dice => ({ dice = roll.dice.flatMap(dice => ({
denomination: dice.denomination, denomination: dice.denomination,
number: dice.number, number: dice.number,
total: dice.total, total: dice.total,
results: dice.results.map(result => ({ result: result.result, discarded: !result.active })) results: dice.results.map(result => ({ result: result.result, discarded: !result.active }))
})); }));
config.roll.evaluated = roll;
if (this.type === 'character') { if (this.type === 'character') {
setDiceSoNiceForDualityRoll(roll, advantage); setDiceSoNiceForDualityRoll(roll, advantage);
@ -355,10 +378,11 @@ export default class DhpActor extends Actor {
if (config.targets?.length) { if (config.targets?.length) {
targets = config.targets.map(target => { targets = config.targets.map(target => {
target.hit = target.difficulty ? roll.total >= target.difficulty : roll.total >= target.evasion; const difficulty = config.roll.difficulty ?? target.difficulty ?? target.evasion
target.hit = roll.total >= difficulty;
return target; return target;
}); });
} } else if(config.roll.difficulty) roll.success = roll.total >= config.roll.difficulty;
if (config.chatMessage) { if (config.chatMessage) {
const configRoll = { const configRoll = {
@ -369,7 +393,8 @@ export default class DhpActor extends Actor {
modifiers: modifiers.filter(x => x.label), modifiers: modifiers.filter(x => x.label),
advantageState: advantage, advantageState: advantage,
action: config.source, action: config.source,
hasDamage: config.hasDamage hasDamage: config.hasDamage,
hasEffect: config.hasEffect
}; };
if (this.type === 'character') { if (this.type === 'character') {
configRoll.hope = { dice: hopeDice, value: hope }; configRoll.hope = { dice: hopeDice, value: hope };
@ -391,7 +416,8 @@ export default class DhpActor extends Actor {
await cls.create(msg.toObject()); await cls.create(msg.toObject());
} }
return roll;
return config; */
} }
formatRollModifier(roll) { formatRollModifier(roll) {

View file

@ -14,9 +14,12 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
} }
addChatListeners = async (app, html, data) => { addChatListeners = async (app, html, data) => {
html.querySelectorAll('.duality-action').forEach(element => html.querySelectorAll('.duality-action-damage').forEach(element =>
element.addEventListener('click', event => this.onRollDamage(event, data.message)) element.addEventListener('click', event => this.onRollDamage(event, data.message))
); );
html.querySelectorAll('.duality-action-effect').forEach(element =>
element.addEventListener('click', event => this.onApplyEffect(event, data.message))
);
html.querySelectorAll('.target-container').forEach(element => { html.querySelectorAll('.target-container').forEach(element => {
element.addEventListener('mouseenter', this.hoverTarget); element.addEventListener('mouseenter', this.hoverTarget);
element.addEventListener('mouseleave', this.unhoverTarget); element.addEventListener('mouseleave', this.unhoverTarget);
@ -57,7 +60,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
const item = actor.items.get(message.system.action?.itemId), const item = actor.items.get(message.system.action?.itemId),
action = item?.system?.actions?.find(a => a._id === message.system.action.actionId); action = item?.system?.actions?.find(a => a._id === message.system.action.actionId);
if(!item || !action || !action?.rollDamage) return; if(!item || !action || !action?.rollDamage) return;
await action.rollDamage(event, this); await action.rollDamage(event, message);
} else { } else {
await actor.damageRoll( await actor.damageRoll(
message.system.title, message.system.title,
@ -68,6 +71,18 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
} }
}; };
onApplyEffect = async (event, message) => {
event.stopPropagation();
const actor = game.actors.get(message.system.origin);
if (!actor || !game.user.isGM) return true;
if(message.system.action?.itemId && message.system.action?.actionId) {
const item = actor.items.get(message.system.action?.itemId),
action = item?.system?.actions?.find(a => a._id === message.system.action.actionId);
if(!item || !action) return;
await action.applyEffects(event, message);
}
}
hoverTarget = event => { hoverTarget = event => {
event.stopPropagation(); event.stopPropagation();
const token = canvas.tokens.get(event.currentTarget.dataset.token); const token = canvas.tokens.get(event.currentTarget.dataset.token);

View file

@ -202,6 +202,10 @@ div.daggerheart.views.multiclass {
} }
} }
#roll-selection-costSelection footer {
display: none;
}
.roll-dialog-container { .roll-dialog-container {
.disadvantage, .disadvantage,
.advantage { .advantage {
@ -342,6 +346,7 @@ div.daggerheart.views.multiclass {
} }
} }
.roll-dialog-experience-container { .roll-dialog-experience-container {
display: flex; display: flex;
align-items: flex-start; align-items: flex-start;

View file

@ -442,6 +442,10 @@
.duality-action { .duality-action {
border-radius: 0 6px 0 0; border-radius: 0 6px 0 0;
margin-left: -8px; margin-left: -8px;
&.duality-action-effect {
border-top-left-radius: 6px;
margin-left: initial;
}
} }
.duality-result { .duality-result {
border-radius: 6px 0 0 0; border-radius: 6px 0 0 0;

View file

@ -35,6 +35,9 @@
}, },
{ {
"name": "JimCanE" "name": "JimCanE"
},
{
"name": "Po0lp"
} }
], ],
"scripts": ["build/daggerheart.js"], "scripts": ["build/daggerheart.js"],
@ -252,7 +255,8 @@
"dualityRoll": {}, "dualityRoll": {},
"adversaryRoll": {}, "adversaryRoll": {},
"damageRoll": {}, "damageRoll": {},
"abilityUse": {} "abilityUse": {},
"applyEffect": {}
} }
}, },
"primaryTokenAttribute": "resources.health", "primaryTokenAttribute": "resources.health",

View file

@ -0,0 +1,9 @@
<div class="dice-roll daggerheart chat roll" data-action="expandRoll">
<div class="dice-flavor">{{title}}</div>
<div>{{{description}}}</div>
<div class="dice-result">
<div class="dice-actions">
<button class="duality-action-effect">{{localize "DAGGERHEART.Chat.AttackRoll.ApplyEffect"}}</button>
</div>
</div>
</div>

View file

@ -6,12 +6,12 @@
{{label}} {{label}}
</div> </div>
{{/each}} {{/each}}
{{#if advantageState}} {{#if (eq advantage 1)}}
<div class="duality-modifier"> <div class="duality-modifier">
{{localize "DAGGERHEART.General.Advantage.Full"}} {{localize "DAGGERHEART.General.Advantage.Full"}}
</div> </div>
{{/if}} {{/if}}
{{#if (eq advantageState false)}} {{#if (eq advantage -1)}}
<div class="duality-modifier"> <div class="duality-modifier">
{{localize "DAGGERHEART.General.Disadvantage.Full"}} {{localize "DAGGERHEART.General.Disadvantage.Full"}}
</div> </div>
@ -25,40 +25,40 @@
<div class="dice"> <div class="dice">
<header class="part-header flexrow"> <header class="part-header flexrow">
<span class="part-formula"> <span class="part-formula">
<span>1{{hope.dice}}</span> <span>1{{roll.hope.dice}}</span>
| |
<span>1{{fear.dice}}</span> <span>1{{roll.fear.dice}}</span>
</span> </span>
<span class="part-total">{{diceTotal}}</span> <span class="part-total">{{diceTotal}}</span>
</header> </header>
<div class="flexrow"> <div class="flexrow">
<ol class="dice-rolls duality"> <ol class="dice-rolls duality">
<li class="roll die {{hope.dice}}" title="{{localize "DAGGERHEART.General.Hope"}}"> <li class="roll die {{roll.hope.dice}}" title="{{localize "DAGGERHEART.General.Hope"}}">
<div class="dice-container"> <div class="dice-container">
<div class="dice-title">{{localize "DAGGERHEART.General.Hope"}}</div> <div class="dice-title">{{localize "DAGGERHEART.General.Hope"}}</div>
<div class="dice-inner-container hope" title="{{localize "DAGGERHEART.General.Hope"}}"> <div class="dice-inner-container hope" title="{{localize "DAGGERHEART.General.Hope"}}">
<div class="dice-wrapper"> <div class="dice-wrapper">
<img class="dice" src="../icons/svg/d12-grey.svg"/> <img class="dice" src="../icons/svg/d12-grey.svg"/>
</div> </div>
<div class="dice-value">{{hope.value}}</div> <div class="dice-value">{{roll.hope.value}}</div>
</div> </div>
</div> </div>
</li> </li>
<li class="roll die {{fear.dice}}" title="{{localize "DAGGERHEART.General.Fear"}}"> <li class="roll die {{roll.fear.dice}}" title="{{localize "DAGGERHEART.General.Fear"}}">
<div class="dice-container"> <div class="dice-container">
<div class="dice-title">{{localize "DAGGERHEART.General.Fear"}}</div> <div class="dice-title">{{localize "DAGGERHEART.General.Fear"}}</div>
<div class="dice-inner-container fear" title="{{localize "DAGGERHEART.General.Fear"}}"> <div class="dice-inner-container fear" title="{{localize "DAGGERHEART.General.Fear"}}">
<div class="dice-wrapper"> <div class="dice-wrapper">
<img class="dice" src="../icons/svg/d12-grey.svg"/> <img class="dice" src="../icons/svg/d12-grey.svg"/>
</div> </div>
<div class="dice-value">{{fear.value}}</div> <div class="dice-value">{{roll.fear.value}}</div>
</div> </div>
</div> </div>
</li> </li>
</ol> </ol>
</div> </div>
</div> </div>
{{#if advantageState}} {{#if (eq advantage 1)}}
<div class="dice"> <div class="dice">
<header class="part-header flexrow"> <header class="part-header flexrow">
<span class="part-formula"> <span class="part-formula">
@ -82,7 +82,7 @@
</div> </div>
</div> </div>
{{/if}} {{/if}}
{{#if (eq advantageState false)}} {{#if (eq advantage -1)}}
<div class="dice"> <div class="dice">
<header class="part-header flexrow"> <header class="part-header flexrow">
<span class="part-formula"> <span class="part-formula">
@ -110,7 +110,7 @@
</section> </section>
</div> </div>
</div> </div>
<div class="dice-total duality {{#if fear.discarded}}hope{{else}}{{#if hope.discarded}}fear{{else}}critical{{/if}}{{/if}}"> <div class="dice-total duality {{#if roll.fear.discarded}}hope{{else}}{{#if roll.hope.discarded}}fear{{else}}critical{{/if}}{{/if}}">
<div class="dice-total-label">{{totalLabel}}</div> <div class="dice-total-label">{{totalLabel}}</div>
<div class="dice-total-value"> <div class="dice-total-value">
{{roll.total}} {{roll.total}}
@ -128,12 +128,15 @@
{{/each}} {{/each}}
</div> </div>
{{/if}} {{/if}}
<div class="dice-actions{{#unless hasDamage}} duality-alone{{/unless}}"> <div class="dice-actions{{#unless (or hasDamage hasEffect)}} duality-alone{{/unless}}">
{{#if hasDamage}} {{#if hasDamage}}
<button class="duality-action" data-value="{{roll.total}}"><span>{{localize "DAGGERHEART.Chat.AttackRoll.RollDamage"}}</span></button> <button class="duality-action duality-action-damage" data-value="{{roll.total}}"><span>{{localize "DAGGERHEART.Chat.AttackRoll.RollDamage"}}</span></button>
{{/if}}
{{#if hasEffect}}
<button class="duality-action{{#if hasDamage}} duality-action-effect{{/if}}" data-value="{{roll.total}}"><span>{{localize "DAGGERHEART.Chat.AttackRoll.ApplyEffect"}}</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 roll.dualityResult 1)}}With Hope{{else}}{{#if (eq roll.dualityResult 2)}}With Fear{{else}}Critical Success{{/if}}{{/if}}</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -13,7 +13,7 @@
<li class="item inventory-item"> <li class="item inventory-item">
<div class="inventory-row" data-item-id="{{item.uuid}}"> <div class="inventory-row" data-item-id="{{item.uuid}}">
<div class="inventory-item-title-container"> <div class="inventory-item-title-container">
<div data-action="viewObject" data-value="{{item.uuid}}" class="inventory-item-title"> <div data-action="useItem" data-value="{{item.uuid}}" class="inventory-item-title">
<img src="{{item.img}}" /> <img src="{{item.img}}" />
{{item.name}} {{item.name}}
</div> </div>

View file

@ -7,7 +7,7 @@
{{#each source as |cost index|}} {{#each source as |cost index|}}
<fieldset> <fieldset>
<div class="multi-display"> <div class="multi-display">
{{formField ../fields.type label="Resource" value=cost.type name=(concat "cost." index ".type") localize=true}} {{formField ../fields.type choices=(@root.disableOption index ../fields.type.choices ../source) label="Resource" value=cost.type name=(concat "cost." index ".type") localize=true}}
{{formField ../fields.value label="Value" value=cost.value name=(concat "cost." index ".value")}} {{formField ../fields.value label="Value" value=cost.value name=(concat "cost." index ".value")}}
</div> </div>
<div class="multi-display"> <div class="multi-display">

View file

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

View file

@ -2,25 +2,25 @@
<div class="roll-dialog-container"> <div class="roll-dialog-container">
<div class="flexcol"> <div class="flexcol">
<div class="roll-dialog-experience-container"> <div class="roll-dialog-experience-container">
{{#each this.experiences}} {{#each experiences}}
{{#if this.description}} {{#if description}}
<div class="roll-dialog-chip {{#if this.selected}}selected{{/if}}" data-action="selectExperience" data-key="{{this.id}}"> <div class="roll-dialog-chip {{#if (includes ../selectedExperiences id)}}selected{{/if}}" data-action="selectExperience" data-key="{{id}}">
<span>{{this.description}}</span> <span>{{description}}</span>
<span>+{{this.value}}</span> <span>+{{value}}</span>
</div> </div>
{{/if}} {{/if}}
{{/each}} {{/each}}
</div> </div>
<div class="flexrow"> <div class="flexrow">
<button class="disadvantage flex1 {{#if this.advantage}}selected{{/if}}" data-action="updateIsAdvantage" data-advantage="true">{{localize "DAGGERHEART.General.Advantage.Full"}}</button> <button class="disadvantage flex1 {{#if (eq advantage 1)}}selected{{/if}}" data-action="updateIsAdvantage" data-advantage="1">{{localize "DAGGERHEART.General.Advantage.Full"}}</button>
<button class="disadvantage flex1 {{#if (eq this.advantage false)}}selected{{/if}}" data-action="updateIsAdvantage">{{localize "DAGGERHEART.General.Disadvantage.Full"}}</button> <button class="disadvantage flex1 {{#if (eq advantage -1)}}selected{{/if}}" data-action="updateIsAdvantage" data-advantage="-1">{{localize "DAGGERHEART.General.Disadvantage.Full"}}</button>
</div> </div>
{{#if (not this.isNpc)}} {{!-- {{#if (not isNpc)}} --}}
<div class="form-group"> <div class="form-group">
<label>Hope</label> <label>Hope</label>
<div class="form-fields"> <div class="form-fields">
<select name="hope"> <select name="hope">
{{selectOptions this.diceOptions selected=this.hope valueAttr="value" labelAttr="name" localize=true}} {{selectOptions diceOptions selected=hope valueAttr="value" labelAttr="name" localize=true}}
</select> </select>
</div> </div>
</div> </div>
@ -28,14 +28,14 @@
<label>Fear</label> <label>Fear</label>
<div class="form-fields"> <div class="form-fields">
<select name="fear"> <select name="fear">
{{selectOptions this.diceOptions selected=this.fear valueAttr="value" labelAttr="name" localize=true}} {{selectOptions diceOptions selected=fear valueAttr="value" labelAttr="name" localize=true}}
</select> </select>
</div> </div>
</div> </div>
{{/if}} {{!-- {{/if}} --}}
</div> </div>
<footer> <footer>
<button data-action="finish">Roll</button> <button data-action="close"{{#unless canRoll}} disabled{{/unless}}>Roll</button>
</footer> </footer>
</div> </div>
</div> </div>