diff --git a/daggerheart.mjs b/daggerheart.mjs index 82fae3c9..2cb02170 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -35,7 +35,7 @@ CONFIG.Dice.daggerheart = { FateRoll: FateRoll }; -Object.assign(CONFIG.Dice.termTypes, dice.diceTypes); +CONFIG.Dice.termTypes.DualityDie = dice.diceTypes.DualityDie; CONFIG.Actor.documentClass = documents.DhpActor; CONFIG.Actor.dataModels = models.actors.config; diff --git a/module/applications/dialogs/tagTeamDialog.mjs b/module/applications/dialogs/tagTeamDialog.mjs index 2d363471..33ddfbc0 100644 --- a/module/applications/dialogs/tagTeamDialog.mjs +++ b/module/applications/dialogs/tagTeamDialog.mjs @@ -452,12 +452,8 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio const dieIndex = diceType === 'hope' ? 0 : diceType === 'fear' ? 1 : 2; const newRoll = game.system.api.dice.DualityRoll.fromData(memberData.rollData); const dice = newRoll.dice[dieIndex]; - await dice.reroll(`/r1=${dice.total}`, { - liveRoll: { - roll: newRoll, - isReaction: true - } - }); + await dice.reroll(`/r1=${dice.total}`, { liveRoll: true }); + await newRoll._evaluate(); const rollData = newRoll.toJSON(); this.updatePartyData( { @@ -698,7 +694,6 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio const joinedRoll = await this.getJoinedRoll(); const mainRoll = joinedRoll.rollData; - const finalRoll = foundry.utils.deepClone(joinedRoll.roll); const mainActor = this.party.system.partyMembers.find(x => x.uuid === mainRoll.options.source.actor); mainRoll.options.title = game.i18n.localize('DAGGERHEART.APPLICATIONS.TagTeamSelect.chatMessageRollTitle'); @@ -717,33 +712,34 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio await cls.create(msgData); /* Handle resource updates from the finished TagTeamRoll */ - const tagTeamData = this.party.system.tagTeam; - const fearUpdate = { key: 'fear', value: null, total: null, enabled: true }; - for (let memberId in tagTeamData.members) { - const resourceUpdates = []; - const rollGivesHope = finalRoll.isCritical || finalRoll.withHope; - if (memberId === tagTeamData.initiator.memberId) { - const value = tagTeamData.initiator.cost - ? rollGivesHope - ? 1 - tagTeamData.initiator.cost - : -tagTeamData.initiator.cost - : 1; - resourceUpdates.push({ key: 'hope', value: value, total: -value, enabled: true }); - } else if (rollGivesHope) { - resourceUpdates.push({ key: 'hope', value: 1, total: -1, enabled: true }); - } - if (finalRoll.isCritical) resourceUpdates.push({ key: 'stress', value: -1, total: 1, enabled: true }); - if (finalRoll.withFear) { - fearUpdate.value = fearUpdate.value === null ? 1 : fearUpdate.value + 1; - fearUpdate.total = fearUpdate.total === null ? -1 : fearUpdate.total - 1; - } + // const tagTeamData = this.party.system.tagTeam; + // const fearUpdate = { key: 'fear', value: null, total: null, enabled: true }; + // for (let memberId in tagTeamData.members) { + // const resourceUpdates = []; + // const rollGivesHope = mainRoll.options.roll.isCritical || mainRoll.options.roll.result.duality === 1; + // if (memberId === tagTeamData.initiator.memberId) { + // const value = tagTeamData.initiator.cost + // ? rollGivesHope + // ? 1 - tagTeamData.initiator.cost + // : -tagTeamData.initiator.cost + // : 1; + // resourceUpdates.push({ key: 'hope', value: value, total: -value, enabled: true }); + // } else if (rollGivesHope) { + // resourceUpdates.push({ key: 'hope', value: 1, total: -1, enabled: true }); + // } + // if (mainRoll.options.roll.isCritical) + // resourceUpdates.push({ key: 'stress', value: -1, total: 1, enabled: true }); + // if (mainRoll.options.roll.result.duality === -1) { + // fearUpdate.value = fearUpdate.value === null ? 1 : fearUpdate.value + 1; + // fearUpdate.total = fearUpdate.total === null ? -1 : fearUpdate.total - 1; + // } - game.actors.get(memberId).modifyResource(resourceUpdates); - } + // game.actors.get(memberId).modifyResource(resourceUpdates); + // } - if (fearUpdate.value) { - mainActor.modifyResource([fearUpdate]); - } + // if (fearUpdate.value) { + // mainActor.modifyResource([fearUpdate]); + // } /* Fin */ this.cancelRoll({ confirm: false }); diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index fc826425..79f12e7f 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -218,6 +218,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo isReaction: message.system.roll.options.actionType === 'reaction' } }); + // await message.system.roll._evaluate(); await message.update({ rolls: [message.system.roll.toJSON()] }); diff --git a/module/dice/_module.mjs b/module/dice/_module.mjs index e1206f82..523f15c1 100644 --- a/module/dice/_module.mjs +++ b/module/dice/_module.mjs @@ -4,4 +4,4 @@ export { default as DamageRoll } from './damageRoll.mjs'; export { default as DHRoll } from './dhRoll.mjs'; export { default as DualityRoll } from './dualityRoll.mjs'; export { default as FateRoll } from './fateRoll.mjs'; -export { diceTypes } from './die/_module.mjs'; +export { Dice, diceTypes } from './die/_module.mjs'; diff --git a/module/dice/die/_module.mjs b/module/dice/die/_module.mjs index ed892f6a..e2a96208 100644 --- a/module/dice/die/_module.mjs +++ b/module/dice/die/_module.mjs @@ -1,9 +1,7 @@ import DualityDie from './dualityDie.mjs'; -import AdvantageDie from './advantageDie.mjs'; -import DisadvantageDie from './disadvantageDie.mjs'; + +export const Dice = [DualityDie]; export const diceTypes = { - DualityDie, - AdvantageDie, - DisadvantageDie + DualityDie }; diff --git a/module/dice/die/advantageDie.mjs b/module/dice/die/advantageDie.mjs deleted file mode 100644 index 9c2f0b03..00000000 --- a/module/dice/die/advantageDie.mjs +++ /dev/null @@ -1,7 +0,0 @@ -export default class AdvantageDie extends foundry.dice.terms.Die { - constructor(options) { - super(options); - - this.modifiers = []; - } -} diff --git a/module/dice/die/disadvantageDie.mjs b/module/dice/die/disadvantageDie.mjs deleted file mode 100644 index f56ebe96..00000000 --- a/module/dice/die/disadvantageDie.mjs +++ /dev/null @@ -1,7 +0,0 @@ -export default class DisadvantageDie extends foundry.dice.terms.Die { - constructor(options) { - super(options); - - this.modifiers = []; - } -} diff --git a/module/dice/dualityRoll.mjs b/module/dice/dualityRoll.mjs index 291b8995..56cecfd7 100644 --- a/module/dice/dualityRoll.mjs +++ b/module/dice/dualityRoll.mjs @@ -17,6 +17,22 @@ export default class DualityRoll extends D20Roll { static DefaultDialog = D20RollDialog; + /**@inheritdoc */ + static instantiateAST(ast) { + /* First two dice are always the DualityDice */ + const nodes = CONFIG.Dice.parser.flattenTree(ast); + const dieNodes = nodes.filter(x => x.class === 'DiceTerm'); + if (dieNodes.length > 1) { + dieNodes[0].class = 'DualityDie'; + dieNodes[1].class = 'DualityDie'; + } + + return nodes.map(node => { + const cls = foundry.dice.terms[node.class] ?? foundry.dice.terms.RollTerm; + return cls.fromParseNode(node); + }); + } + get title() { return game.i18n.localize( `DAGGERHEART.GENERAL.${this.options?.actionType === 'reaction' ? 'reactionRoll' : 'dualityRoll'}` @@ -24,31 +40,27 @@ export default class DualityRoll extends D20Roll { } get dHope() { - if (!(this.dice[0] instanceof game.system.api.dice.diceTypes.DualityDie)) this.createBaseDice(); + if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice(); return this.dice[0]; } set dHope(faces) { - // TODO this should not be asymmetrical with the getter. updateRollConfiguration() should use dHope.faces - this.dHope.faces = this.getFaces(faces); + if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice(); + this.dice[0].faces = this.getFaces(faces); } get dFear() { - if (!(this.dice[1] instanceof game.system.api.dice.diceTypes.DualityDie)) this.createBaseDice(); + if (!(this.dice[1] instanceof foundry.dice.terms.Die)) this.createBaseDice(); return this.dice[1]; } set dFear(faces) { - // TODO this should not be asymmetrical with the getter. updateRollConfiguration() should use dFear.faces - this.dFear.faces = this.getFaces(faces); + if (!(this.dice[1] instanceof foundry.dice.terms.Die)) this.createBaseDice(); + this.dice[1].faces = this.getFaces(faces); } get dAdvantage() { - return this.dice[2] instanceof game.system.api.dice.diceTypes.AdvantageDie ? this.dice[2] : null; - } - - get dDisadvantage() { - return this.dice[2] instanceof game.system.api.dice.diceTypes.DisadvantageDie ? this.dice[2] : null; + return this.dice[2]; } get advantageFaces() { @@ -67,11 +79,6 @@ export default class DualityRoll extends D20Roll { this._advantageNumber = Number(value); } - get extraDice() { - const { DualityDie, AdvantageDie, DisadvantageDie } = game.system.api.dice.diceTypes; - return this.dice.filter(x => ![DualityDie, AdvantageDie, DisadvantageDie].some(die => x instanceof die)); - } - /* This isn't fullproof, but trying to cover parathetical situations is ridiculously complex */ get modifierTotal() { let modifierTotal = 0; @@ -138,16 +145,6 @@ export default class DualityRoll extends D20Roll { return [...(hooks ?? []), 'Duality']; } - /** @inheritDoc */ - static fromData(data) { - data.terms[0].class = 'DualityDie'; - data.terms[2].class = 'DualityDie'; - if (data.options.roll.advantage?.type && data.terms[4]?.faces) { - data.terms[4].class = data.options.roll.advantage.type === 1 ? 'AdvantageDie' : 'DisadvantageDie'; - } - return super.fromData(data); - } - createBaseDice() { if ( this.dice[0] instanceof game.system.api.dice.diceTypes.DualityDie && diff --git a/module/dice/fateRoll.mjs b/module/dice/fateRoll.mjs index ec03715a..418c8465 100644 --- a/module/dice/fateRoll.mjs +++ b/module/dice/fateRoll.mjs @@ -21,8 +21,8 @@ export default class FateRoll extends D20Roll { } set dHope(faces) { - // TODO this should not be asymmetrical with the getter. updateRollConfiguration() should use dHope.faces - this.dHope.faces = this.getFaces(faces); + if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice(); + this.dice[0].faces = this.getFaces(faces); } get dFear() { @@ -31,8 +31,8 @@ export default class FateRoll extends D20Roll { } set dFear(faces) { - // TODO this should not be asymmetrical with the getter. updateRollConfiguration() should use dFear.faces - this.dFear.faces = this.getFaces(faces); + if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice(); + this.dice[0].faces = this.getFaces(faces); } get isCritical() { @@ -43,22 +43,6 @@ export default class FateRoll extends D20Roll { return this.data.fateType; } - get withHope() { - if (!this._evaluatedl) return; - return this.dHope.total >= this.dFear.total; - } - - get withFear() { - if (!this._evaluated) return; - return this.dHope.total < this.dFear.total; - } - - get totalLabel() { - const label = this.withHope ? 'DAGGERHEART.GENERAL.hope' : 'DAGGERHEART.GENERAL.fear'; - - return game.i18n.localize(label); - } - static getHooks(hooks) { return [...(hooks ?? []), 'Fate']; } diff --git a/module/documents/chatMessage.mjs b/module/documents/chatMessage.mjs index 307677bb..920b2875 100644 --- a/module/documents/chatMessage.mjs +++ b/module/documents/chatMessage.mjs @@ -84,8 +84,11 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage { } if (this.type === 'fateRoll') { html.classList.add('fate'); - if (this.system.roll?.fateDie) { - html.classList.add(this.system.roll.fateDie.toLowerCase()); + if (this.system.roll?.fate.fateDie == 'Hope') { + html.classList.add('hope'); + } + if (this.system.roll?.fate.fateDie == 'Fear') { + html.classList.add('fear'); } } diff --git a/templates/dialogs/dice-roll/rollSelection.hbs b/templates/dialogs/dice-roll/rollSelection.hbs index 64a3cdcb..4451160b 100644 --- a/templates/dialogs/dice-roll/rollSelection.hbs +++ b/templates/dialogs/dice-roll/rollSelection.hbs @@ -53,14 +53,14 @@ {{#if @root.advantage}} {{#if (eq @root.advantage 1)}}
- +
{{localize "DAGGERHEART.GENERAL.Advantage.full"}}
{{else if (eq @root.advantage -1)}}
- +
{{localize "DAGGERHEART.GENERAL.Disadvantage.full"}}
@@ -158,7 +158,7 @@ {{/times}}
{{#if abilities}} diff --git a/templates/ui/chat/parts/roll-part.hbs b/templates/ui/chat/parts/roll-part.hbs index 850f0e92..b823b270 100644 --- a/templates/ui/chat/parts/roll-part.hbs +++ b/templates/ui/chat/parts/roll-part.hbs @@ -29,20 +29,20 @@
- {{#if roll.fateDie}} - {{#if (eq roll.fateDie "Hope")}} + {{#if roll.fate}} + {{#if (eq roll.fate.fateDie "Hope")}}
-
- {{roll.dHope.total}} +
+ {{roll.fate.value}}
{{/if}} - {{#if (eq roll.fateDie "Fear")}} + {{#if (eq roll.fate.fateDie "Fear")}}
-
- {{roll.dFear.total}} +
+ {{roll.fate.value}}
{{/if}} @@ -63,14 +63,14 @@
{{#if roll.dAdvantage}} -
- -
{{roll.dAdvantage.total}}
-
- {{else if roll.dDisadvantage}} -
- -
{{roll.dDisadvantage.total}}
+
+ {{#if roll.hasAdvantage}} + +
{{roll.dAdvantage.total}}
+ {{else}} + +
{{roll.dAdvantage.total}}
+ {{/if}}
{{/if}} {{#if roll.rally.dice}} @@ -79,11 +79,15 @@
{{roll.rally.value}}
{{/if}} - {{#each roll.extraDice}} -
- -
{{this.total}}
-
+ {{#each roll.extra}} + {{#each results}} + {{#unless discarded}} +
+ +
{{result}}
+
+ {{/unless}} + {{/each}} {{/each}} {{else}} {{#each roll.dice}}