Fixed Check Rolls, Attack Rolls and Damage Rolls for PCs

This commit is contained in:
WBHarry 2025-05-24 16:56:01 +02:00
parent 707e47bc1b
commit 5a501d6769
16 changed files with 204 additions and 95 deletions

View file

@ -3,6 +3,7 @@ export default class DhpAdversaryRoll extends foundry.abstract.TypeDataModel {
const fields = foundry.data.fields;
return {
title: new fields.StringField(),
origin: new fields.StringField({ required: true }),
roll: new fields.StringField({}),
total: new fields.NumberField({ integer: true }),
@ -37,18 +38,31 @@ export default class DhpAdversaryRoll extends foundry.abstract.TypeDataModel {
prepareDerivedData() {
const diceKeys = Object.keys(this.dice.rolls);
const highestIndex = 0;
for (var index in diceKeys) {
const resultIndex = Number.parseInt(index);
if (highestIndex === resultIndex) continue;
const current = this.dice.rolls[resultIndex];
const highest = this.dice.rolls[highestIndex];
if (current.value > highest.value) this.dice.rolls[highestIndex].discarded = true;
else this.dice.rolls[resultIndex].discarded = true;
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
}));
}
// const highestIndex = 0;
// for (var index in diceKeys) {
// const resultIndex = Number.parseInt(index);
// if (highestIndex === resultIndex) continue;
// const current = this.dice.rolls[resultIndex];
// const highest = this.dice.rolls[highestIndex];
// if (current.value > highest.value) this.dice.rolls[highestIndex].discarded = true;
// else this.dice.rolls[resultIndex].discarded = true;
// }
this.targets.forEach(target => {
target.hit = target.difficulty ? this.total >= target.difficulty : this.total >= target.evasion;
});
@ -71,6 +85,6 @@ class DhpAdversaryRollDice extends foundry.abstract.DataModel {
}
get rollTotal() {
return this.rolls.reduce((acc, roll) => acc + roll.value, 0);
return this.rolls.reduce((acc, roll) => acc + (!roll.discarded ? roll.value : 0), 0);
}
}

View file

@ -3,6 +3,7 @@ export default class DhpDamageRoll extends foundry.abstract.TypeDataModel {
const fields = foundry.data.fields;
return {
title: new fields.StringField(),
roll: new fields.StringField({ required: true }),
damage: new fields.SchemaField({
total: new fields.NumberField({ required: true, integer: true }),

View file

@ -8,6 +8,8 @@ const diceField = () =>
export default class DhpDualityRoll extends foundry.abstract.TypeDataModel {
static defineSchema() {
return {
title: new fields.StringField(),
origin: new fields.StringField({ required: true }),
roll: new fields.StringField({}),
modifiers: new fields.ArrayField(
new fields.SchemaField({
@ -20,7 +22,6 @@ export default class DhpDualityRoll extends foundry.abstract.TypeDataModel {
fear: diceField(),
advantage: diceField(),
disadvantage: diceField(),
advantageSelected: new fields.NumberField({ initial: 0 }),
targets: new fields.ArrayField(
new fields.SchemaField({
id: new fields.StringField({}),
@ -57,8 +58,16 @@ export default class DhpDualityRoll extends foundry.abstract.TypeDataModel {
get total() {
const modifiers = this.modifiers.reduce((acc, x) => acc + x.value, 0);
const advantage = (this.advantage.value ?? this.disadvantage.value) ? -this.disadvantage.value : 0;
return this.hope.value + this.fear.value + advantage + modifiers;
const advantage = this.advantage.value
? this.advantage.value
: this.disadvantage.value
? -this.disadvantage.value
: 0;
return this.highestRoll + advantage + modifiers;
}
get highestRoll() {
return Math.max(this.hope.value, this.fear.value);
}
get totalLabel() {
@ -75,6 +84,9 @@ export default class DhpDualityRoll extends foundry.abstract.TypeDataModel {
prepareDerivedData() {
const total = this.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;
});