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

@ -735,9 +735,13 @@
},
"Chat": {
"DualityRoll": {
"AdvantageChooseTitle": "Select Hope Dice"
"AbilityCheckTitle": "{ability} Check"
},
"AttackRoll": {
"Title": "Attack - {attack}"
},
"DamageRoll": {
"Title": "Damage - {damage}",
"DealDamageToTargets": "Damage Hit Targets",
"DealDamage": "Deal Damage"
},

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

View file

@ -29,11 +29,14 @@
}
&.roll {
.dice-flavor {
text-align: center;
font-weight: bold;
}
.dice-tooltip {
.dice-rolls.duality {
display: flex;
align-items: center;
justify-content: space-around;
.dice-hope-container {
display: flex;
@ -57,12 +60,18 @@
-webkit-text-stroke-color: @hope;
-webkit-text-stroke-width: 1.5px;
font-weight: 400;
&:not(.discarded) {
filter: none;
}
}
&.fear {
color: white;
-webkit-text-stroke-color: @fear;
-webkit-text-stroke-width: 1.5px;
font-weight: 400;
&:not(.discarded) {
filter: none;
}
}
&.disadvantage {
color: white;

View file

@ -1760,10 +1760,13 @@
.daggerheart.chat.downtime .downtime-refresh-container .refresh-title {
font-weight: bold;
}
.daggerheart.chat.roll .dice-flavor {
text-align: center;
font-weight: bold;
}
.daggerheart.chat.roll .dice-tooltip .dice-rolls.duality {
display: flex;
align-items: center;
justify-content: space-around;
}
.daggerheart.chat.roll .dice-tooltip .dice-rolls.duality .dice-hope-container {
display: flex;
@ -1783,12 +1786,18 @@
-webkit-text-stroke-width: 1.5px;
font-weight: 400;
}
.daggerheart.chat.roll .dice-tooltip .dice-rolls.duality .roll.die.hope:not(.discarded) {
filter: none;
}
.daggerheart.chat.roll .dice-tooltip .dice-rolls.duality .roll.die.fear {
color: white;
-webkit-text-stroke-color: #430070;
-webkit-text-stroke-width: 1.5px;
font-weight: 400;
}
.daggerheart.chat.roll .dice-tooltip .dice-rolls.duality .roll.die.fear:not(.discarded) {
filter: none;
}
.daggerheart.chat.roll .dice-tooltip .dice-rolls.duality .roll.die.disadvantage {
color: white;
-webkit-text-stroke-color: #b30000;

View file

@ -1,4 +1,5 @@
<div class="dice-roll daggerheart chat roll" data-action="expandRoll">
<div class="dice-flavor">{{localize "DAGGERHEART.Chat.AttackRoll.Title" attack=this.title}}</div>
<div class="dice-result">
<div class="dice-formula">{{roll}}</div>
<div class="dice-tooltip">
@ -7,7 +8,7 @@
<div class="dice">
<header class="part-header flexrow">
<span class="part-formula">{{this.dice.rolls.length}}{{this.dice.type}}</span>
<span class="part-total">{{this.total}}</span>
<span class="part-total">{{this.dice.rollTotal}}</span>
</header>
<div class="flexrow">
<ol class="dice-rolls">
@ -23,7 +24,7 @@
</div>
<div class="dice-total">
<div class="dice-total-value">{{total}}</div>
<div class="dice-total-value">{{this.total}}</div>
</div>
{{#if (gt targets.length 0)}}
<div class="target-section">

View file

@ -1,35 +1,64 @@
<div class="dice-roll daggerheart chat roll">
<div class="dice-roll daggerheart chat roll" data-action="expandRoll">
<div class="dice-flavor">{{localize "DAGGERHEART.Chat.AttackRoll.Title" attack=this.title}}</div>
<div class="dice-result">
<div class="dice-formula">{{roll}}</div>
<div class="dice-tooltip {{#if advantage.value}}expanded{{/if}}">
<ol class="dice-rolls">
<div class="dice-hope-container">
<li id="hope" class="roll die {{hope.dice}} hope {{#if (or (eq advantageSelected 2) (and disadvantage.value (gt hope.value disadvantage.value)))}}unused{{/if}} {{#if (and advantage.value (eq advantageSelected 0))}}advantage{{/if}}">{{hope.value}}</li>
<div class="dice-tooltip">
<div class="wrapper">
<section class="tooltip-part">
<div class="dice">
<header class="part-header flexrow">
<span class="part-formula">
<span>1{{hope.dice}}</span>
|
<span>1{{fear.dice}}</span>
</span>
<span class="part-total">{{this.highestRoll}}</span>
</header>
<div class="flexrow">
<ol class="dice-rolls duality">
<li class="roll die {{hope.dice}} {{#if hope.discarded}}discarded{{/if}} hope min" title="{{localize "DAGGERHEART.General.Hope"}}">{{hope.value}}</li>
<li class="roll die {{fear.dice}} {{#if fear.discarded}}discarded{{/if}} fear min" title="{{localize "DAGGERHEART.General.Fear"}}">{{fear.value}}</li>
</ol>
</div>
</div>
{{#if advantage.value}}
<li class="roll die {{advantage.dice}} hope {{#if (eq advantageSelected 1)}}unused{{/if}} {{#if (eq advantageSelected 0)}}advantage{{/if}}">{{ advantage.value}}</li>
<div class="dice">
<header class="part-header flexrow">
<span class="part-formula">
<span>1{{advantage.dice}}</span>
</span>
<span class="part-total">{{advantage.value}}</span>
</header>
<div class="flexrow">
<ol class="dice-rolls">
<li class="roll die {{advantage.dice}} hope min">{{advantage.value}}</li>
</ol>
</div>
</div>
{{/if}}
{{#if disadvantage.value}}
<li class="roll die {{disadvantage.dice}} disadvantage {{#if (gte disadvantage.value hope.value)}}unused{{/if}}">{{disadvantage.value}}</li>
<div class="dice">
<header class="part-header flexrow">
<span class="part-formula">
<span>1{{disadvantage.dice}}</span>
</span>
<span class="part-total">{{disadvantage.value}}</span>
</header>
<div class="flexrow">
<ol class="dice-rolls">
<li class="roll die {{disadvantage.dice}} hope min">{{disadvantage.value}}</li>
</ol>
</div>
</div>
{{/if}}
</div>
<li class="roll die {{fear.dice}} fear">{{fear.value}}</li>
<div class="modifiers-container">
{{#each modifiers}}
<li class="modifier-value" data-value="{{this.value}}" title="{{this.title}}">{{this.label}}</li>
{{/each}}
</div>
</ol>
</section>
</div>
</div>
<div class="dice-total">
<div class="dice-total-label">{{totalLabel}}</div>
<div class="dice-total-value">
{{#if total.alternate}}
{{#with dualityDiceStates}}
<span class="{{this.hope}}">{{../total.normal}}</span> - <span class="{{this.alternate}}">{{../total.alternate}}</span>
{{/with}}
{{else}}
{{total.normal}}
{{/if}}
{{this.total}}
</div>
</div>
{{#if (gt targets.length 0)}}
@ -44,6 +73,8 @@
{{/each}}
</div>
{{/if}}
<button class="roll-damage-button" data-value="{{this.total.normal}}" data-damage="{{this.damage.value}}" data-damage-type="{{this.damage.type}}" {{#if this.damage.disabled}}disabled{{/if}}><span>Roll Damage</span></button>
<div class="flexrow">
<button class="roll-damage-button" data-value="{{this.total}}" data-damage="{{this.damage.value}}" data-damage-type="{{this.damage.type}}" {{#if this.damage.disabled}}disabled{{/if}}><span>Roll Damage</span></button>
</div>
</div>
</div>

View file

@ -1,4 +1,5 @@
<div class="dice-roll daggerheart chat roll" data-action="expandRoll">
<div class="dice-flavor">{{this.title}}</div>
<div class="dice-result">
<div class="dice-formula">{{this.roll}}</div>

View file

@ -1,7 +1,62 @@
<div class="dice-roll daggerheart chat roll">
<div class="dice-roll daggerheart chat roll" data-action="expandRoll">
<div class="dice-flavor">{{this.title}}</div>
<div class="dice-result">
<div class="dice-formula">{{roll}}</div>
<div class="dice-tooltip {{#if advantage.value}}expanded{{/if}}">
<div class="dice-tooltip">
<div class="wrapper">
<section class="tooltip-part">
<div class="dice">
<header class="part-header flexrow">
<span class="part-formula">
<span>1{{hope.dice}}</span>
|
<span>1{{fear.dice}}</span>
</span>
<span class="part-total">{{this.highestRoll}}</span>
</header>
<div class="flexrow">
<ol class="dice-rolls duality">
<li class="roll die {{hope.dice}} {{#if hope.discarded}}discarded{{/if}} hope min" title="{{localize "DAGGERHEART.General.Hope"}}">{{hope.value}}</li>
<li class="roll die {{fear.dice}} {{#if fear.discarded}}discarded{{/if}} fear min" title="{{localize "DAGGERHEART.General.Fear"}}">{{fear.value}}</li>
</ol>
</div>
</div>
{{#if advantage.value}}
<div class="dice">
<header class="part-header flexrow">
<span class="part-formula">
<span>1{{advantage.dice}}</span>
</span>
<span class="part-total">{{advantage.value}}</span>
</header>
<div class="flexrow">
<ol class="dice-rolls">
<li class="roll die {{advantage.dice}} hope min">{{advantage.value}}</li>
</ol>
</div>
</div>
{{/if}}
{{#if disadvantage.value}}
<div class="dice">
<header class="part-header flexrow">
<span class="part-formula">
<span>1{{disadvantage.dice}}</span>
</span>
<span class="part-total">{{disadvantage.value}}</span>
</header>
<div class="flexrow">
<ol class="dice-rolls">
<li class="roll die {{disadvantage.dice}} hope min">{{disadvantage.value}}</li>
</ol>
</div>
</div>
{{/if}}
</section>
</div>
</div>
{{!-- <div class="dice-tooltip {{#if advantage.value}}expanded{{/if}}">
<ol class="dice-rolls duality">
<div class="dice-hope-container">
<li id="hope" class="roll die {{hope.dice}} hope" title="{{localize "DAGGERHEART.General.Hope"}}">{{hope.value}}</li>
@ -19,7 +74,7 @@
{{/each}}
</div>
</ol>
</div>
</div> --}}
<div class="dice-total">
<div class="dice-total-label">{{totalLabel}}</div>
<div class="dice-total-value">
@ -27,42 +82,4 @@
</div>
</div>
</div>
</div>
{{!-- V1.3 --}}
{{!-- <div class="dice-roll daggerheart chat roll">
<div class="dice-result">
<div class="dice-formula">{{roll}}</div>
<div class="dice-tooltip {{#if advantage.value}}expanded{{/if}}">
<ol class="dice-rolls">
<div class="dice-hope-container">
<li id="hope" class="roll die {{hope.dice}} hope {{#if (or (eq advantageSelected 2) (and disadvantage.value (gt hope.value disadvantage.value)))}}unused{{/if}} {{#if (and advantage.value (eq advantageSelected 0))}}advantage{{/if}}">{{hope.value}}</li>
{{#if advantage.value}}
<li class="roll die {{advantage.dice}} hope {{#if (eq advantageSelected 1)}}unused{{/if}} {{#if (eq advantageSelected 0)}}advantage{{/if}}">{{ advantage.value}}</li>
{{/if}}
{{#if disadvantage.value}}
<li class="roll die {{disadvantage.dice}} disadvantage {{#if (gte disadvantage.value hope.value)}}unused{{/if}}">{{disadvantage.value}}</li>
{{/if}}
</div>
<li class="roll die {{fear.dice}} fear">{{fear.value}}</li>
<div class="modifiers-container">
{{#each modifiers}}
<li class="modifier-value" data-value="{{this.value}}" title="{{this.title}}">{{this.label}}</li>
{{/each}}
</div>
</ol>
</div>
<div class="dice-total">
<div class="dice-total-label">{{totalLabel}}</div>
<div class="dice-total-value">
{{#if total.alternate}}
{{#with dualityDiceStates}}
<span class="{{this.hope}}">{{../total.normal}}</span> - <span class="{{this.alternate}}">{{../total.alternate}}</span>
{{/with}}
{{else}}
{{total.normal}}
{{/if}}
</div>
</div>
</div>
</div> --}}
</div>

View file

@ -175,7 +175,7 @@
<div class="statistic-row">
<label class="statistic-title">{{localize "DAGGERHEART.Sheets.Adversary.Attack.Modifier"}}:</label>
<span class="statistic-value">+{{this.data.attack.attackModifier}}</span>
<img class="adversary-roll" data-action="attackRoll" data-value="{{this.data.attack.attackModifier}}" data-damage="{{this.data.attack.damage.value}}" data-damage-type="{{this.data.attack.damage.type}}" src="icons/svg/d20-grey.svg" />
<img class="adversary-roll" data-action="attackRoll" data-value="{{this.data.attack.attackModifier}}" data-name="{{this.data.attack.name}}" data-damage="{{this.data.attack.damage.value}}" data-damage-type="{{this.data.attack.damage.type}}" src="icons/svg/d20-grey.svg" />
</div>
<div class="statistic-row">
<label class="statistic-title">{{localize this.data.attack.name}}</label>

View file

@ -7,7 +7,7 @@
{{#each this.attributes as |attribute key|}}
<div class="attribute">
<div class="attribute-banner">
<img class="attribute-roll" data-action="attributeRoll" data-value="{{attribute.data.value}}" src="icons/svg/d12-grey.svg" />
<img class="attribute-roll" data-action="attributeRoll" data-attribute="{{key}}" data-value="{{attribute.data.value}}" src="icons/svg/d12-grey.svg" />
<div class="attribute-text">{{key}}</div>
</div>
<div class="attribute-mark {{#if (and (not attribute.levelMark) (and (not (includes attribute.levelMarks ../document.system.levelData.currentLevel)) (gt ../document.system.availableAttributeMarks.length 0)))}}selectable{{/if}}" data-action="toggleAttributeMark" data-attribute="{{key}}">