Updated attack rolls and damage rolls for adversaries

This commit is contained in:
WBHarry 2025-05-24 10:25:40 +02:00
parent ee6c97d134
commit faab60b45b
22 changed files with 356 additions and 204 deletions

View file

@ -1,6 +1,11 @@
export default class DhpChatMesssage extends ChatMessage {
async renderHTML() {
if (this.type === 'dualityRoll' || this.type === 'adversaryRoll' || this.type === 'abilityUse') {
if (
this.type === 'dualityRoll' ||
this.type === 'adversaryRoll' ||
this.type === 'damageRoll' ||
this.type === 'abilityUse'
) {
this.content = await foundry.applications.handlebars.renderTemplate(this.content, this.system);
}

View file

@ -1,7 +1,7 @@
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
export default class DamageSelectionDialog extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(rollString, bonusDamage, hope, resolve) {
constructor(rollString, bonusDamage, resolve, hope = 0) {
super({});
this.data = {

View file

@ -6,7 +6,6 @@ export default class NpcRollSelectionDialog extends FormApplication {
this.resolve = resolve;
this.selectedExperiences = [];
this.data = {
nrDice: 1,
advantage: null
};
}
@ -19,7 +18,7 @@ export default class NpcRollSelectionDialog extends FormApplication {
const defaults = super.defaultOptions;
const overrides = {
height: 'auto',
width: 400,
width: 500,
id: 'roll-selection',
template: 'systems/daggerheart/templates/views/npcRollSelection.hbs',
closeOnSubmit: false,
@ -34,11 +33,11 @@ export default class NpcRollSelectionDialog extends FormApplication {
async getData() {
const context = super.getData();
context.nrDice = this.data.nrDice;
context.advantage = this.data.advantage;
context.experiences = this.experiences.map(x => ({
context.experiences = Object.values(this.experiences).map(x => ({
...x,
selected: this.selectedExperiences.find(selected => selected.id === x.id)
selected: this.selectedExperiences.find(selected => selected.id === x.id),
value: `${x.value >= 0 ? '+' : '-'}${x.value}`
}));
return context;
@ -47,17 +46,10 @@ export default class NpcRollSelectionDialog extends FormApplication {
activateListeners(html) {
super.activateListeners(html);
html.find('.increase').click(_ => this.updateNrDice(1));
html.find('.decrease').click(_ => this.updateNrDice(-1));
html.find('.advantage').click(_ => this.updateIsAdvantage(true));
html.find('.disadvantage').click(_ => this.updateIsAdvantage(false));
html.find('.roll-button').click(this.finish.bind(this));
html.find('.roll-dialog-chip').click(this.selectExperience.bind(this));
}
updateNrDice(value) {
this.data.nrDice += value;
this.render();
html.find('.experience-chip').click(this.selectExperience.bind(this));
}
updateIsAdvantage(advantage) {
@ -66,9 +58,9 @@ export default class NpcRollSelectionDialog extends FormApplication {
}
selectExperience(event) {
const experience = this.experiences[event.currentTarget.dataset.key];
this.selectedExperiences = this.selectedExperiences.find(x => x.name === experience.name)
? this.selectedExperiences.filter(x => x.name !== experience.name)
const experience = Object.values(this.experiences).find(experience => experience.id === event.currentTarget.id);
this.selectedExperiences = this.selectedExperiences.find(x => x.id === experience.id)
? this.selectedExperiences.filter(x => x.id !== experience.id)
: [...this.selectedExperiences, experience];
this.render();

View file

@ -349,7 +349,7 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
static async attackRoll(event, button) {
const modifier = Number.parseInt(button.dataset.value);
const { roll, diceResults, modifiers } = await this.actor.diceRoll(
const { roll, dice, advantageState, modifiers } = await this.actor.diceRoll(
{ title: `${this.actor.name} - Attack Roll`, value: modifier },
event.shiftKey
);
@ -365,11 +365,14 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
type: 'adversaryRoll',
sound: CONFIG.sounds.dice,
system: {
origin: this.document.id,
roll: roll._formula,
advantageState,
total: roll._total,
modifiers: modifiers,
diceResults: diceResults,
dice: dice,
targets: targets,
damage: { value: button.dataset.damage, type: button.dataset.damageType }
},
@ -381,16 +384,15 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
}
static async addExperience() {
const experienceId = foundry.utils.randomID();
await this.document.update({
'system.experiences': [...this.document.system.experiences, { name: 'Experience', value: 1 }]
[`system.experiences.${experienceId}`]: { id: experienceId, name: 'Experience', value: 1 }
});
}
static async removeExperience(_, button) {
await this.document.update({
'system.experiences': this.document.system.experiences.filter(
(_, index) => index !== Number.parseInt(button.dataset.experience)
)
[`system.experiences.-=${button.dataset.experience}`]: null
});
}