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
};
CONFIG.Dice.termTypes.DualityDie = dice.diceTypes.DualityDie;
Object.assign(CONFIG.Dice.termTypes, dice.diceTypes);
CONFIG.Actor.documentClass = documents.DhpActor;
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 DualityRoll } from './dualityRoll.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';
export const Dice = [DualityDie];
import AdvantageDie from './advantageDie.mjs';
import DisadvantageDie from './disadvantageDie.mjs';
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;
/**@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'}`
@ -40,27 +24,31 @@ export default class DualityRoll extends D20Roll {
}
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];
}
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);
}
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];
}
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);
}
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() {
@ -145,6 +133,16 @@ 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 === 1) data.terms[4].class = 'AdvantageDie';
else if (data.options.roll.advantage?.type === -1) data.terms[4].class = 'DisadvantageDie';
return super.fromData(data);
}
createBaseDice() {
if (
this.dice[0] instanceof game.system.api.dice.diceTypes.DualityDie &&

View file

@ -53,14 +53,14 @@
{{#if @root.advantage}}
{{#if (eq @root.advantage 1)}}
<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">
<span class="label">{{localize "DAGGERHEART.GENERAL.Advantage.full"}}</span>
</div>
</div>
{{else if (eq @root.advantage -1)}}
<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">
<span class="label">{{localize "DAGGERHEART.GENERAL.Disadvantage.full"}}</span>
</div>
@ -158,7 +158,7 @@
{{/times}}
</select>
<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>
</div>
{{#if abilities}}

View file

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