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

@ -367,6 +367,7 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
type: 'adversaryRoll',
sound: CONFIG.sounds.dice,
system: {
title: button.dataset.name,
origin: this.document.id,
roll: roll._formula,
advantageState,

View file

@ -4,6 +4,7 @@ import DhpDowntime from '../downtime.mjs';
import DhpLevelup from '../levelup.mjs';
import AncestrySelectionDialog from '../ancestrySelectionDialog.mjs';
import DaggerheartSheet from './daggerheart-sheet.mjs';
import { abilities } from '../../config/actorConfig.mjs';
const { ActorSheetV2 } = foundry.applications.sheets;
export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
@ -480,9 +481,9 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
this.render();
}
static async rollAttribute(event, target) {
static async rollAttribute(event, button) {
const { roll, hope, fear, advantage, disadvantage, modifiers } = await this.document.dualityRoll(
{ title: 'Attribute Bonus', value: event.target.dataset.value },
{ title: 'Attribute Bonus', value: button.dataset.value },
event.shiftKey
);
@ -490,6 +491,10 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
const msgData = {
type: 'dualityRoll',
system: {
title: game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', {
ability: game.i18n.localize(abilities[button.dataset.attribute].label)
}),
origin: this.document.id,
roll: roll._formula,
modifiers: modifiers,
hope: hope,
@ -550,8 +555,8 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
await this.document.update({ [update]: newValue });
}
static async attackRoll(_, event) {
const weapon = await fromUuid(event.currentTarget.dataset.weapon);
static async attackRoll(event, button) {
const weapon = await fromUuid(button.dataset.weapon);
const damage = {
value: `${this.document.system.proficiency.value}${weapon.system.damage.value}`,
type: weapon.system.damage.type,
@ -579,7 +584,10 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
type: 'dualityRoll',
sound: CONFIG.sounds.dice,
system: {
title: weapon.name,
origin: this.document.id,
roll: roll._formula,
modifiers: modifiers,
hope: hope,

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;
});

View file

@ -207,10 +207,9 @@ export default class DhpActor extends Actor {
}
const hope = rollResult.dice[0].results[0].result;
const advantage = advantageDice ? rollResult.dice[1].results[0].result : null;
const disadvantage = disadvantageDice ? rollResult.dice[1].results[0].result : null;
const fear =
advantage || disadvantage ? rollResult.dice[2].results[0].result : rollResult.dice[1].results[0].result;
const fear = rollResult.dice[1].results[0].result;
const advantage = advantageDice ? rollResult.dice[2].results[0].result : null;
const disadvantage = disadvantageDice ? rollResult.dice[2].results[0].result : null;
if (disadvantage) {
rollResult = { ...rollResult, total: rollResult.total - Math.max(hope, disadvantage) };
@ -250,7 +249,7 @@ export default class DhpActor extends Actor {
};
}
async damageRoll(damage, targets, shiftKey) {
async damageRoll(title, damage, targets, shiftKey) {
let rollString = damage.value;
let bonusDamage = damage.bonusDamage?.filter(x => x.initiallySelected) ?? [];
if (!shiftKey) {
@ -291,6 +290,7 @@ export default class DhpActor extends Actor {
user: game.user.id,
sound: CONFIG.sounds.dice,
system: {
title: game.i18n.format('DAGGERHEART.Chat.DamageRoll.Title', { damage: title }),
roll: rollString,
damage: {
total: rollResult.total,

View file

@ -55,6 +55,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
if (!actor || !game.user.isGM) return true;
await actor.damageRoll(
message.system.title,
message.system.damage,
message.system.targets.filter(x => x.hit).map(x => ({ id: x.id, name: x.name, img: x.img })),
event.shiftKey