diff --git a/daggerheart.mjs b/daggerheart.mjs index 1f4ad561..f2fef669 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -152,45 +152,6 @@ const renderDualityButton = async event => { } }; await target.diceRoll(config); - - // Delete when new roll logic test done - /* const button = event.currentTarget; - const attributeValue = button.dataset.attribute?.toLowerCase(); - - const target = getCommandTarget(); - if (!target) return; - - const rollModifier = attributeValue ? target.system.attributes[attributeValue].data.value : null; - const { roll, hope, fear, advantage, disadvantage, modifiers } = await target.diceRoll({ - title: button.dataset.label, - value: rollModifier - }); - - const systemData = new DHDualityRoll({ - title: button.dataset.label, - origin: target.id, - roll: roll._formula, - modifiers: modifiers, - hope: hope, - fear: fear, - advantage: advantage, - disadvantage: disadvantage - }); - - const cls = getDocumentClass('ChatMessage'); - const msgData = { - type: 'dualityRoll', - sound: CONFIG.sounds.dice, - system: systemData, - user: game.user.id, - content: await foundry.applications.handlebars.renderTemplate( - 'systems/daggerheart/templates/chat/duality-roll.hbs', - systemData - ), - rolls: [roll] - }; - - await cls.create(msgData); */ }; Hooks.on('renderChatMessageHTML', (_, element) => { diff --git a/module/applications/sheets/adversary.mjs b/module/applications/sheets/adversary.mjs index 30467beb..234d49b9 100644 --- a/module/applications/sheets/adversary.mjs +++ b/module/applications/sheets/adversary.mjs @@ -65,7 +65,7 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) { event: event, title: `${this.actor.name} - Reaction Roll`, roll: { - modifier: 0, + modifier: null, type: 'reaction' }, chatMessage: { @@ -75,31 +75,6 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) { } }; this.actor.diceRoll(config); - - // Delete when new roll logic test done - /* const { roll, diceResults, modifiers } = await this.actor.diceRoll( - { title: `${this.actor.name} - Reaction Roll`, value: 0 }, - event.shiftKey - ); - - const cls = getDocumentClass('ChatMessage'); - const systemData = { - roll: roll._formula, - total: roll._total, - modifiers: modifiers, - diceResults: diceResults - }; - const msg = new cls({ - type: 'adversaryRoll', - system: systemData, - content: await foundry.applications.handlebars.renderTemplate( - 'systems/daggerheart/templates/chat/adversary-roll.hbs', - systemData - ), - rolls: [roll] - }); - - cls.create(msg.toObject()); */ } static async attackRoll(event) { @@ -120,49 +95,8 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) { type: damage.type }, checkTarget: true - }; + }; this.actor.diceRoll(config); - - // Delete when new roll logic test done - /* const { modifier, damage, name: attackName } = this.actor.system.attack; - const { roll, dice, advantageState, modifiers } = await this.actor.diceRollOld( - { title: `${this.actor.name} - Attack Roll`, value: modifier }, - event.shiftKey - ); - - const targets = Array.from(game.user.targets).map(x => ({ - id: x.id, - name: x.actor.name, - img: x.actor.img, - difficulty: x.actor.system.difficulty, - evasion: x.actor.system.evasion - })); - - const cls = getDocumentClass('ChatMessage'); - const systemData = { - title: attackName, - origin: this.document.id, - roll, - // roll: roll._formula, - advantageState, - // total: roll._total, - modifiers: modifiers, - // dice: dice, - targets: targets, - damage: { value: damage.value, type: damage.type } - }; - const msg = new cls({ - type: 'adversaryRoll', - sound: CONFIG.sounds.dice, - system: systemData, - content: await foundry.applications.handlebars.renderTemplate( - 'systems/daggerheart/templates/chat/adversary-attack-roll.hbs', - systemData - ), - rolls: [roll] - }); - - cls.create(msg.toObject()); */ } static async addExperience() { diff --git a/module/data/chat-message/adversaryRoll.mjs b/module/data/chat-message/adversaryRoll.mjs index d279d643..452cbb47 100644 --- a/module/data/chat-message/adversaryRoll.mjs +++ b/module/data/chat-message/adversaryRoll.mjs @@ -5,17 +5,18 @@ export default class DHAdversaryRoll extends foundry.abstract.TypeDataModel { return { title: new fields.StringField(), origin: new fields.StringField({ required: true }), - roll: new fields.StringField({}), - total: new fields.NumberField({ integer: true }), + roll: new fields.DataField(), modifiers: new fields.ArrayField( new fields.SchemaField({ value: new fields.NumberField({ integer: true }), - label: new fields.StringField({}), - title: new fields.StringField({}) + label: new fields.StringField({}) }) ), - advantageState: new fields.NumberField({ required: true, choices: [0, 1, 2], initial: 0 }), - dice: new fields.EmbeddedDataField(DhpAdversaryRollDice), + advantageState: new fields.BooleanField({ nullable: true, initial: null }), + advantage: new fields.SchemaField({ + dice: new fields.StringField({}), + value: new fields.NumberField({ integer: true }) + }), targets: new fields.ArrayField( new fields.SchemaField({ id: new fields.StringField({}), @@ -37,42 +38,8 @@ export default class DHAdversaryRoll extends foundry.abstract.TypeDataModel { } prepareDerivedData() { - const diceKeys = Object.keys(this.dice.rolls); - const highestDiceIndex = - diceKeys.length < 2 - ? null - : this.dice.rolls[diceKeys[0]].value > this.dice.rolls[diceKeys[1]].value - ? 0 - : 1; - if (highestDiceIndex !== null) { - this.dice.rolls = this.dice.rolls.map((roll, index) => ({ - ...roll, - discarded: this.advantageState === 1 ? index !== highestDiceIndex : index === highestDiceIndex - })); - } - this.targets.forEach(target => { target.hit = target.difficulty ? this.total >= target.difficulty : this.total >= target.evasion; }); } } - -class DhpAdversaryRollDice extends foundry.abstract.DataModel { - static defineSchema() { - const fields = foundry.data.fields; - - return { - type: new fields.StringField({ required: true }), - rolls: new fields.ArrayField( - new fields.SchemaField({ - value: new fields.NumberField({ required: true, integer: true }), - discarded: new fields.BooleanField({ initial: false }) - }) - ) - }; - } - - get rollTotal() { - return this.rolls.reduce((acc, roll) => acc + (!roll.discarded ? roll.value : 0), 0); - } -} diff --git a/module/data/chat-message/dualityRoll.mjs b/module/data/chat-message/dualityRoll.mjs index d183b114..60283b7d 100644 --- a/module/data/chat-message/dualityRoll.mjs +++ b/module/data/chat-message/dualityRoll.mjs @@ -18,7 +18,6 @@ export default class DHDualityRoll extends foundry.abstract.TypeDataModel { return { title: new fields.StringField(), origin: new fields.StringField({ required: true }), - // roll: new fields.StringField({}), roll: new fields.DataField({}), modifiers: new fields.ArrayField( new fields.SchemaField({ @@ -103,13 +102,7 @@ export default class DHDualityRoll extends foundry.abstract.TypeDataModel { } prepareDerivedData() { - const total = this.roll.total; - this.hope.discarded = this.hope.value < this.fear.value; this.fear.discarded = this.fear.value < this.hope.value; - - this.targets.forEach(target => { - target.hit = target.difficulty ? total >= target.difficulty : total >= target.evasion; - }); } } diff --git a/module/data/item/weapon.mjs b/module/data/item/weapon.mjs index 9ef04961..928d523d 100644 --- a/module/data/item/weapon.mjs +++ b/module/data/item/weapon.mjs @@ -1,16 +1,15 @@ -import BaseDataItem from "./base.mjs"; -import FormulaField from "../fields/formulaField.mjs"; -import ActionField from "../fields/actionField.mjs" -import { DHBaseAction, DHAttackAction } from "../action/action.mjs"; +import BaseDataItem from './base.mjs'; +import FormulaField from '../fields/formulaField.mjs'; +import ActionField from '../fields/actionField.mjs'; export default class DHWeapon extends BaseDataItem { /** @inheritDoc */ static get metadata() { return foundry.utils.mergeObject(super.metadata, { - label: "TYPES.Item.weapon", - type: "weapon", + label: 'TYPES.Item.weapon', + type: 'weapon', hasDescription: true, - isQuantifiable: true, + isQuantifiable: true }); } diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index f677d876..ca2eb777 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -195,6 +195,7 @@ export default class DhpActor extends Actor { } formula += ` ${modifiers.map(x => `+ ${x.value}`).join(' ')}`; const roll = await Roll.create(formula).evaluate(); + roll.rolledDice = roll.dice; // Perpetuating getter field if (this.type === 'character') { setDiceSoNiceForDualityRoll(roll, advantage); @@ -226,13 +227,19 @@ export default class DhpActor extends Actor { } if (config.checkTarget) { - targets = Array.from(game.user.targets).map(x => ({ - id: x.id, - name: x.actor.name, - img: x.actor.img, - difficulty: x.actor.system.difficulty, - evasion: x.actor.system.evasion.value ?? x.actor.system.evasion - })); + targets = Array.from(game.user.targets).map(x => { + const target = { + id: x.id, + name: x.actor.name, + img: x.actor.img, + difficulty: x.actor.system.difficulty, + evasion: x.actor.system.evasion?.value + }; + + target.hit = target.difficulty ? roll.total >= target.difficulty : roll.total >= target.evasion; + + return target; + }); } if (config.chatMessage) { @@ -240,7 +247,7 @@ export default class DhpActor extends Actor { title: config.title, origin: this.id, roll, - modifiers, + modifiers: modifiers.filter(x => x.label), advantageState: advantage }; if (this.type === 'character') { @@ -272,7 +279,11 @@ export default class DhpActor extends Actor { ? [ { value: modifier, - label: modifier >= 0 ? `${roll.label} +${modifier}` : `${roll.label} ${modifier}`, + label: roll.label + ? modifier >= 0 + ? `${roll.label} +${modifier}` + : `${roll.label} ${modifier}` + : null, title: roll.label } ] diff --git a/templates/chat/adversary-attack-roll.hbs b/templates/chat/adversary-attack-roll.hbs index 2a97fcd9..90c624cc 100644 --- a/templates/chat/adversary-attack-roll.hbs +++ b/templates/chat/adversary-attack-roll.hbs @@ -7,18 +7,18 @@
{{#each roll.dice}} -
- {{number}}{{denomination}} - {{total}} -
-
-
    - {{#each results}} -
  1. {{result}}
  2. - {{/each}} -
-
{{#if (eq ../advantageState 1)}}{{localize "DAGGERHEART.General.Advantage.Full"}}{{/if}}{{#if (eq ../advantageState 2)}}{{localize "DAGGERHEART.General.Disadvantage.Full"}}{{/if}}
-
+
+ {{number}}{{denomination}} + {{total}} +
+
+
    + {{#each results}} +
  1. {{result}}
  2. + {{/each}} +
+
{{#if (eq ../advantageState 1)}}{{localize "DAGGERHEART.General.Advantage.Full"}}{{/if}}{{#if (eq ../advantageState 2)}}{{localize "DAGGERHEART.General.Disadvantage.Full"}}{{/if}}
+
{{/each}}
diff --git a/templates/sheets/actors/adversary/information.hbs b/templates/sheets/actors/adversary/information.hbs index 6d6efb21..085f200c 100644 --- a/templates/sheets/actors/adversary/information.hbs +++ b/templates/sheets/actors/adversary/information.hbs @@ -3,15 +3,15 @@ data-tab='{{tabs.information.id}}' data-group='{{tabs.information.group}}' > -
- {{localize "DAGGERHEART.Sheets.Adversary.Description" }} + {{!--
+ {{localize "DAGGERHEART.Sheets.Adversary.FIELDS.description.label" }} - {{formGroup systemFields.description value=source.system.description}} -
+ {{formInput systemFields.description value=source.system.description}} +
--}}
- {{localize "DAGGERHEART.Sheets.Adversary.MotivesAndTactics" }} + {{localize "DAGGERHEART.Sheets.Adversary.FIELDS.motivesAndTactics.label" }} - {{formGroup systemFields.motivesAndTactics value=source.system.motivesAndTactics}} + {{formInput systemFields.motivesAndTactics value=source.system.motivesAndTactics}}
diff --git a/templates/sheets/actors/adversary/main.hbs b/templates/sheets/actors/adversary/main.hbs index 788af5ea..66718b66 100644 --- a/templates/sheets/actors/adversary/main.hbs +++ b/templates/sheets/actors/adversary/main.hbs @@ -4,6 +4,7 @@ data-group='{{tabs.main.group}}' >
+
{{localize "DAGGERHEART.Sheets.Adversary.General"}}