Fixed advantage/disadvantage

This commit is contained in:
WBHarry 2026-03-30 20:58:13 +02:00
parent 686c660e86
commit a6500f6801
8 changed files with 51 additions and 37 deletions

View file

@ -35,7 +35,7 @@ CONFIG.Dice.daggerheart = {
FateRoll: FateRoll FateRoll: FateRoll
}; };
CONFIG.Dice.termTypes.DualityDie = dice.diceTypes.DualityDie; Object.assign(CONFIG.Dice.termTypes, dice.diceTypes);
CONFIG.Actor.documentClass = documents.DhpActor; CONFIG.Actor.documentClass = documents.DhpActor;
CONFIG.Actor.dataModels = models.actors.config; CONFIG.Actor.dataModels = models.actors.config;

View file

@ -4,4 +4,4 @@ export { default as DamageRoll } from './damageRoll.mjs';
export { default as DHRoll } from './dhRoll.mjs'; export { default as DHRoll } from './dhRoll.mjs';
export { default as DualityRoll } from './dualityRoll.mjs'; export { default as DualityRoll } from './dualityRoll.mjs';
export { default as FateRoll } from './fateRoll.mjs'; export { default as FateRoll } from './fateRoll.mjs';
export { Dice, diceTypes } from './die/_module.mjs'; export { diceTypes } from './die/_module.mjs';

View file

@ -1,7 +1,9 @@
import DualityDie from './dualityDie.mjs'; import DualityDie from './dualityDie.mjs';
import AdvantageDie from './advantageDie.mjs';
export const Dice = [DualityDie]; import DisadvantageDie from './disadvantageDie.mjs';
export const diceTypes = { export const diceTypes = {
DualityDie DualityDie,
AdvantageDie,
DisadvantageDie
}; };

View file

@ -0,0 +1,7 @@
export default class AdvantageDie extends foundry.dice.terms.Die {
constructor(options) {
super(options);
this.modifiers = [];
}
}

View file

@ -0,0 +1,7 @@
export default class DisadvantageDie extends foundry.dice.terms.Die {
constructor(options) {
super(options);
this.modifiers = [];
}
}

View file

@ -17,22 +17,6 @@ export default class DualityRoll extends D20Roll {
static DefaultDialog = D20RollDialog; 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() { get title() {
return game.i18n.localize( return game.i18n.localize(
`DAGGERHEART.GENERAL.${this.options?.actionType === 'reaction' ? 'reactionRoll' : 'dualityRoll'}` `DAGGERHEART.GENERAL.${this.options?.actionType === 'reaction' ? 'reactionRoll' : 'dualityRoll'}`
@ -40,27 +24,31 @@ export default class DualityRoll extends D20Roll {
} }
get dHope() { get dHope() {
if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice(); if (!(this.dice[0] instanceof game.system.api.dice.diceTypes.DualityDie)) this.createBaseDice();
return this.dice[0]; return this.dice[0];
} }
set dHope(faces) { set dHope(faces) {
if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice(); if (!(this.dice[0] instanceof game.system.api.dice.diceTypes.DualityDie)) this.createBaseDice();
this.dice[0].faces = this.getFaces(faces); this.dice[0].faces = this.getFaces(faces);
} }
get dFear() { get dFear() {
if (!(this.dice[1] instanceof foundry.dice.terms.Die)) this.createBaseDice(); if (!(this.dice[1] instanceof game.system.api.dice.diceTypes.DualityDie)) this.createBaseDice();
return this.dice[1]; return this.dice[1];
} }
set dFear(faces) { set dFear(faces) {
if (!(this.dice[1] instanceof foundry.dice.terms.Die)) this.createBaseDice(); if (!(this.dice[1] instanceof game.system.api.dice.diceTypes.DualityDie)) this.createBaseDice();
this.dice[1].faces = this.getFaces(faces); this.dice[1].faces = this.getFaces(faces);
} }
get dAdvantage() { get dAdvantage() {
return this.dice[2]; 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;
} }
get advantageFaces() { get advantageFaces() {
@ -145,6 +133,16 @@ export default class DualityRoll extends D20Roll {
return [...(hooks ?? []), 'Duality']; return [...(hooks ?? []), 'Duality'];
} }
/** @inheritDoc */
static fromData(data) {
data.terms[0].class = 'DualityDie';
data.terms[2].class = 'DualityDie';
if (data.options.roll.advantage?.type === 1) data.terms[4].class = 'AdvantageDie';
else if (data.options.roll.advantage?.type === -1) data.terms[4].class = 'DisadvantageDie';
return super.fromData(data);
}
createBaseDice() { createBaseDice() {
if ( if (
this.dice[0] instanceof game.system.api.dice.diceTypes.DualityDie && this.dice[0] instanceof game.system.api.dice.diceTypes.DualityDie &&

View file

@ -53,14 +53,14 @@
{{#if @root.advantage}} {{#if @root.advantage}}
{{#if (eq @root.advantage 1)}} {{#if (eq @root.advantage 1)}}
<div class="dice-option"> <div class="dice-option">
<img class="dice-icon" src="{{concat 'systems/daggerheart/assets/icons/dice/adv/' @root.roll.dAdvantage.denomination '.svg'}}" alt=""> <img class="dice-icon" src="{{concat 'systems/daggerheart/assets/icons/dice/adv/d' @root.roll.advantageFaces '.svg'}}" alt="">
<div class="dice-select"> <div class="dice-select">
<span class="label">{{localize "DAGGERHEART.GENERAL.Advantage.full"}}</span> <span class="label">{{localize "DAGGERHEART.GENERAL.Advantage.full"}}</span>
</div> </div>
</div> </div>
{{else if (eq @root.advantage -1)}} {{else if (eq @root.advantage -1)}}
<div class="dice-option"> <div class="dice-option">
<img class="dice-icon" src="{{concat 'systems/daggerheart/assets/icons/dice/disadv/' @root.roll.dAdvantage.denomination '.svg'}}" alt=""> <img class="dice-icon" src="{{concat 'systems/daggerheart/assets/icons/dice/disadv/d' @root.roll.advantageFaces '.svg'}}" alt="">
<div class="dice-select"> <div class="dice-select">
<span class="label">{{localize "DAGGERHEART.GENERAL.Disadvantage.full"}}</span> <span class="label">{{localize "DAGGERHEART.GENERAL.Disadvantage.full"}}</span>
</div> </div>
@ -158,7 +158,7 @@
{{/times}} {{/times}}
</select> </select>
<select name="roll.dice.advantageFaces"{{#unless advantage}} disabled{{/unless}}> <select name="roll.dice.advantageFaces"{{#unless advantage}} disabled{{/unless}}>
{{selectOptions diceOptions selected=@root.roll.dAdvantage.denomination}} {{selectOptions diceOptions selected=(concat 'd' @root.roll.advantageFaces)}}
</select> </select>
</div> </div>
{{#if abilities}} {{#if abilities}}

View file

@ -63,14 +63,14 @@
</div> </div>
</div> </div>
{{#if roll.dAdvantage}} {{#if roll.dAdvantage}}
<div class="roll-die {{#if roll.hasAdvantage}}has-plus{{else}}has-minus{{/if}}"> <div class="roll-die has-plus">
{{#if roll.hasAdvantage}} <label>{{localize "DAGGERHEART.GENERAL.Advantage.short"}}</label>
<label>{{localize "DAGGERHEART.GENERAL.Advantage.short"}}</label> <div class="dice {{roll.dAdvantage.denomination}} color-adv">{{roll.dAdvantage.total}}</div>
<div class="dice {{roll.dAdavantage.denomination}} color-adv">{{roll.dAdvantage.total}}</div> </div>
{{else}} {{else if roll.dDisadvantage}}
<label>{{localize "DAGGERHEART.GENERAL.Disadvantage.short"}}</label> <div class="roll-die has-minus">
<div class="dice {{roll.dAdvantage.denomination}} color-dis">{{roll.dAdvantage.total}}</div> <label>{{localize "DAGGERHEART.GENERAL.Disadvantage.short"}}</label>
{{/if}} <div class="dice {{roll.dDisadvantage.denomination}} color-dis">{{roll.dDisadvantage.total}}</div>
</div> </div>
{{/if}} {{/if}}
{{#if roll.rally.dice}} {{#if roll.rally.dice}}