mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-15 05:01:08 +01:00
Fixes to adversary rolls
This commit is contained in:
parent
564dcf8932
commit
dfb2c6bd3c
9 changed files with 54 additions and 188 deletions
|
|
@ -152,45 +152,6 @@ const renderDualityButton = async event => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await target.diceRoll(config);
|
await target.diceRoll(config);
|
||||||
|
|
||||||
// Delete when new roll logic test done
|
|
||||||
/* const button = event.currentTarget;
|
|
||||||
const attributeValue = button.dataset.attribute?.toLowerCase();
|
|
||||||
|
|
||||||
const target = getCommandTarget();
|
|
||||||
if (!target) return;
|
|
||||||
|
|
||||||
const rollModifier = attributeValue ? target.system.attributes[attributeValue].data.value : null;
|
|
||||||
const { roll, hope, fear, advantage, disadvantage, modifiers } = await target.diceRoll({
|
|
||||||
title: button.dataset.label,
|
|
||||||
value: rollModifier
|
|
||||||
});
|
|
||||||
|
|
||||||
const systemData = new DHDualityRoll({
|
|
||||||
title: button.dataset.label,
|
|
||||||
origin: target.id,
|
|
||||||
roll: roll._formula,
|
|
||||||
modifiers: modifiers,
|
|
||||||
hope: hope,
|
|
||||||
fear: fear,
|
|
||||||
advantage: advantage,
|
|
||||||
disadvantage: disadvantage
|
|
||||||
});
|
|
||||||
|
|
||||||
const cls = getDocumentClass('ChatMessage');
|
|
||||||
const msgData = {
|
|
||||||
type: 'dualityRoll',
|
|
||||||
sound: CONFIG.sounds.dice,
|
|
||||||
system: systemData,
|
|
||||||
user: game.user.id,
|
|
||||||
content: await foundry.applications.handlebars.renderTemplate(
|
|
||||||
'systems/daggerheart/templates/chat/duality-roll.hbs',
|
|
||||||
systemData
|
|
||||||
),
|
|
||||||
rolls: [roll]
|
|
||||||
};
|
|
||||||
|
|
||||||
await cls.create(msgData); */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Hooks.on('renderChatMessageHTML', (_, element) => {
|
Hooks.on('renderChatMessageHTML', (_, element) => {
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
|
||||||
event: event,
|
event: event,
|
||||||
title: `${this.actor.name} - Reaction Roll`,
|
title: `${this.actor.name} - Reaction Roll`,
|
||||||
roll: {
|
roll: {
|
||||||
modifier: 0,
|
modifier: null,
|
||||||
type: 'reaction'
|
type: 'reaction'
|
||||||
},
|
},
|
||||||
chatMessage: {
|
chatMessage: {
|
||||||
|
|
@ -75,31 +75,6 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.actor.diceRoll(config);
|
this.actor.diceRoll(config);
|
||||||
|
|
||||||
// Delete when new roll logic test done
|
|
||||||
/* const { roll, diceResults, modifiers } = await this.actor.diceRoll(
|
|
||||||
{ title: `${this.actor.name} - Reaction Roll`, value: 0 },
|
|
||||||
event.shiftKey
|
|
||||||
);
|
|
||||||
|
|
||||||
const cls = getDocumentClass('ChatMessage');
|
|
||||||
const systemData = {
|
|
||||||
roll: roll._formula,
|
|
||||||
total: roll._total,
|
|
||||||
modifiers: modifiers,
|
|
||||||
diceResults: diceResults
|
|
||||||
};
|
|
||||||
const msg = new cls({
|
|
||||||
type: 'adversaryRoll',
|
|
||||||
system: systemData,
|
|
||||||
content: await foundry.applications.handlebars.renderTemplate(
|
|
||||||
'systems/daggerheart/templates/chat/adversary-roll.hbs',
|
|
||||||
systemData
|
|
||||||
),
|
|
||||||
rolls: [roll]
|
|
||||||
});
|
|
||||||
|
|
||||||
cls.create(msg.toObject()); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async attackRoll(event) {
|
static async attackRoll(event) {
|
||||||
|
|
@ -120,49 +95,8 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
|
||||||
type: damage.type
|
type: damage.type
|
||||||
},
|
},
|
||||||
checkTarget: true
|
checkTarget: true
|
||||||
};
|
};
|
||||||
this.actor.diceRoll(config);
|
this.actor.diceRoll(config);
|
||||||
|
|
||||||
// Delete when new roll logic test done
|
|
||||||
/* const { modifier, damage, name: attackName } = this.actor.system.attack;
|
|
||||||
const { roll, dice, advantageState, modifiers } = await this.actor.diceRollOld(
|
|
||||||
{ title: `${this.actor.name} - Attack Roll`, value: modifier },
|
|
||||||
event.shiftKey
|
|
||||||
);
|
|
||||||
|
|
||||||
const targets = Array.from(game.user.targets).map(x => ({
|
|
||||||
id: x.id,
|
|
||||||
name: x.actor.name,
|
|
||||||
img: x.actor.img,
|
|
||||||
difficulty: x.actor.system.difficulty,
|
|
||||||
evasion: x.actor.system.evasion
|
|
||||||
}));
|
|
||||||
|
|
||||||
const cls = getDocumentClass('ChatMessage');
|
|
||||||
const systemData = {
|
|
||||||
title: attackName,
|
|
||||||
origin: this.document.id,
|
|
||||||
roll,
|
|
||||||
// roll: roll._formula,
|
|
||||||
advantageState,
|
|
||||||
// total: roll._total,
|
|
||||||
modifiers: modifiers,
|
|
||||||
// dice: dice,
|
|
||||||
targets: targets,
|
|
||||||
damage: { value: damage.value, type: damage.type }
|
|
||||||
};
|
|
||||||
const msg = new cls({
|
|
||||||
type: 'adversaryRoll',
|
|
||||||
sound: CONFIG.sounds.dice,
|
|
||||||
system: systemData,
|
|
||||||
content: await foundry.applications.handlebars.renderTemplate(
|
|
||||||
'systems/daggerheart/templates/chat/adversary-attack-roll.hbs',
|
|
||||||
systemData
|
|
||||||
),
|
|
||||||
rolls: [roll]
|
|
||||||
});
|
|
||||||
|
|
||||||
cls.create(msg.toObject()); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async addExperience() {
|
static async addExperience() {
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,18 @@ export default class DHAdversaryRoll extends foundry.abstract.TypeDataModel {
|
||||||
return {
|
return {
|
||||||
title: new fields.StringField(),
|
title: new fields.StringField(),
|
||||||
origin: new fields.StringField({ required: true }),
|
origin: new fields.StringField({ required: true }),
|
||||||
roll: new fields.StringField({}),
|
roll: new fields.DataField(),
|
||||||
total: new fields.NumberField({ integer: true }),
|
|
||||||
modifiers: new fields.ArrayField(
|
modifiers: new fields.ArrayField(
|
||||||
new fields.SchemaField({
|
new fields.SchemaField({
|
||||||
value: new fields.NumberField({ integer: true }),
|
value: new fields.NumberField({ integer: true }),
|
||||||
label: new fields.StringField({}),
|
label: new fields.StringField({})
|
||||||
title: new fields.StringField({})
|
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
advantageState: new fields.NumberField({ required: true, choices: [0, 1, 2], initial: 0 }),
|
advantageState: new fields.BooleanField({ nullable: true, initial: null }),
|
||||||
dice: new fields.EmbeddedDataField(DhpAdversaryRollDice),
|
advantage: new fields.SchemaField({
|
||||||
|
dice: new fields.StringField({}),
|
||||||
|
value: new fields.NumberField({ integer: true })
|
||||||
|
}),
|
||||||
targets: new fields.ArrayField(
|
targets: new fields.ArrayField(
|
||||||
new fields.SchemaField({
|
new fields.SchemaField({
|
||||||
id: new fields.StringField({}),
|
id: new fields.StringField({}),
|
||||||
|
|
@ -37,42 +38,8 @@ export default class DHAdversaryRoll extends foundry.abstract.TypeDataModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareDerivedData() {
|
prepareDerivedData() {
|
||||||
const diceKeys = Object.keys(this.dice.rolls);
|
|
||||||
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
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
this.targets.forEach(target => {
|
this.targets.forEach(target => {
|
||||||
target.hit = target.difficulty ? this.total >= target.difficulty : this.total >= target.evasion;
|
target.hit = target.difficulty ? this.total >= target.difficulty : this.total >= target.evasion;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DhpAdversaryRollDice extends foundry.abstract.DataModel {
|
|
||||||
static defineSchema() {
|
|
||||||
const fields = foundry.data.fields;
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: new fields.StringField({ required: true }),
|
|
||||||
rolls: new fields.ArrayField(
|
|
||||||
new fields.SchemaField({
|
|
||||||
value: new fields.NumberField({ required: true, integer: true }),
|
|
||||||
discarded: new fields.BooleanField({ initial: false })
|
|
||||||
})
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
get rollTotal() {
|
|
||||||
return this.rolls.reduce((acc, roll) => acc + (!roll.discarded ? roll.value : 0), 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ export default class DHDualityRoll extends foundry.abstract.TypeDataModel {
|
||||||
return {
|
return {
|
||||||
title: new fields.StringField(),
|
title: new fields.StringField(),
|
||||||
origin: new fields.StringField({ required: true }),
|
origin: new fields.StringField({ required: true }),
|
||||||
// roll: new fields.StringField({}),
|
|
||||||
roll: new fields.DataField({}),
|
roll: new fields.DataField({}),
|
||||||
modifiers: new fields.ArrayField(
|
modifiers: new fields.ArrayField(
|
||||||
new fields.SchemaField({
|
new fields.SchemaField({
|
||||||
|
|
@ -103,13 +102,7 @@ export default class DHDualityRoll extends foundry.abstract.TypeDataModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareDerivedData() {
|
prepareDerivedData() {
|
||||||
const total = this.roll.total;
|
|
||||||
|
|
||||||
this.hope.discarded = this.hope.value < this.fear.value;
|
this.hope.discarded = this.hope.value < this.fear.value;
|
||||||
this.fear.discarded = this.fear.value < this.hope.value;
|
this.fear.discarded = this.fear.value < this.hope.value;
|
||||||
|
|
||||||
this.targets.forEach(target => {
|
|
||||||
target.hit = target.difficulty ? total >= target.difficulty : total >= target.evasion;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,15 @@
|
||||||
import BaseDataItem from "./base.mjs";
|
import BaseDataItem from './base.mjs';
|
||||||
import FormulaField from "../fields/formulaField.mjs";
|
import FormulaField from '../fields/formulaField.mjs';
|
||||||
import ActionField from "../fields/actionField.mjs"
|
import ActionField from '../fields/actionField.mjs';
|
||||||
import { DHBaseAction, DHAttackAction } from "../action/action.mjs";
|
|
||||||
|
|
||||||
export default class DHWeapon extends BaseDataItem {
|
export default class DHWeapon extends BaseDataItem {
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
static get metadata() {
|
static get metadata() {
|
||||||
return foundry.utils.mergeObject(super.metadata, {
|
return foundry.utils.mergeObject(super.metadata, {
|
||||||
label: "TYPES.Item.weapon",
|
label: 'TYPES.Item.weapon',
|
||||||
type: "weapon",
|
type: 'weapon',
|
||||||
hasDescription: true,
|
hasDescription: true,
|
||||||
isQuantifiable: true,
|
isQuantifiable: true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -195,6 +195,7 @@ export default class DhpActor extends Actor {
|
||||||
}
|
}
|
||||||
formula += ` ${modifiers.map(x => `+ ${x.value}`).join(' ')}`;
|
formula += ` ${modifiers.map(x => `+ ${x.value}`).join(' ')}`;
|
||||||
const roll = await Roll.create(formula).evaluate();
|
const roll = await Roll.create(formula).evaluate();
|
||||||
|
roll.rolledDice = roll.dice; // Perpetuating getter field
|
||||||
|
|
||||||
if (this.type === 'character') {
|
if (this.type === 'character') {
|
||||||
setDiceSoNiceForDualityRoll(roll, advantage);
|
setDiceSoNiceForDualityRoll(roll, advantage);
|
||||||
|
|
@ -226,13 +227,19 @@ export default class DhpActor extends Actor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.checkTarget) {
|
if (config.checkTarget) {
|
||||||
targets = Array.from(game.user.targets).map(x => ({
|
targets = Array.from(game.user.targets).map(x => {
|
||||||
id: x.id,
|
const target = {
|
||||||
name: x.actor.name,
|
id: x.id,
|
||||||
img: x.actor.img,
|
name: x.actor.name,
|
||||||
difficulty: x.actor.system.difficulty,
|
img: x.actor.img,
|
||||||
evasion: x.actor.system.evasion.value ?? x.actor.system.evasion
|
difficulty: x.actor.system.difficulty,
|
||||||
}));
|
evasion: x.actor.system.evasion?.value
|
||||||
|
};
|
||||||
|
|
||||||
|
target.hit = target.difficulty ? roll.total >= target.difficulty : roll.total >= target.evasion;
|
||||||
|
|
||||||
|
return target;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.chatMessage) {
|
if (config.chatMessage) {
|
||||||
|
|
@ -240,7 +247,7 @@ export default class DhpActor extends Actor {
|
||||||
title: config.title,
|
title: config.title,
|
||||||
origin: this.id,
|
origin: this.id,
|
||||||
roll,
|
roll,
|
||||||
modifiers,
|
modifiers: modifiers.filter(x => x.label),
|
||||||
advantageState: advantage
|
advantageState: advantage
|
||||||
};
|
};
|
||||||
if (this.type === 'character') {
|
if (this.type === 'character') {
|
||||||
|
|
@ -272,7 +279,11 @@ export default class DhpActor extends Actor {
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
value: modifier,
|
value: modifier,
|
||||||
label: modifier >= 0 ? `${roll.label} +${modifier}` : `${roll.label} ${modifier}`,
|
label: roll.label
|
||||||
|
? modifier >= 0
|
||||||
|
? `${roll.label} +${modifier}`
|
||||||
|
: `${roll.label} ${modifier}`
|
||||||
|
: null,
|
||||||
title: roll.label
|
title: roll.label
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,18 @@
|
||||||
<section class="tooltip-part">
|
<section class="tooltip-part">
|
||||||
<div class="dice">
|
<div class="dice">
|
||||||
{{#each roll.dice}}
|
{{#each roll.dice}}
|
||||||
<header class="part-header flexrow">
|
<header class="part-header flexrow">
|
||||||
<span class="part-formula">{{number}}{{denomination}}</span>
|
<span class="part-formula">{{number}}{{denomination}}</span>
|
||||||
<span class="part-total">{{total}}</span>
|
<span class="part-total">{{total}}</span>
|
||||||
</header>
|
</header>
|
||||||
<div class="flexrow">
|
<div class="flexrow">
|
||||||
<ol class="dice-rolls">
|
<ol class="dice-rolls">
|
||||||
{{#each results}}
|
{{#each results}}
|
||||||
<li class="roll die {{../denomination}}{{#if discarded}} discarded{{/if}} min">{{result}}</li>
|
<li class="roll die {{../denomination}}{{#if discarded}} discarded{{/if}} min">{{result}}</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ol>
|
</ol>
|
||||||
<div class="attack-roll-advantage-container">{{#if (eq ../advantageState 1)}}{{localize "DAGGERHEART.General.Advantage.Full"}}{{/if}}{{#if (eq ../advantageState 2)}}{{localize "DAGGERHEART.General.Disadvantage.Full"}}{{/if}}</div>
|
<div class="attack-roll-advantage-container">{{#if (eq ../advantageState 1)}}{{localize "DAGGERHEART.General.Advantage.Full"}}{{/if}}{{#if (eq ../advantageState 2)}}{{localize "DAGGERHEART.General.Disadvantage.Full"}}{{/if}}</div>
|
||||||
</div>
|
</div>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,15 @@
|
||||||
data-tab='{{tabs.information.id}}'
|
data-tab='{{tabs.information.id}}'
|
||||||
data-group='{{tabs.information.group}}'
|
data-group='{{tabs.information.group}}'
|
||||||
>
|
>
|
||||||
<fieldset>
|
{{!-- <fieldset>
|
||||||
<legend>{{localize "DAGGERHEART.Sheets.Adversary.Description" }}</legend>
|
<legend>{{localize "DAGGERHEART.Sheets.Adversary.FIELDS.description.label" }}</legend>
|
||||||
|
|
||||||
{{formGroup systemFields.description value=source.system.description}}
|
{{formInput systemFields.description value=source.system.description}}
|
||||||
</fieldset>
|
</fieldset> --}}
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{{localize "DAGGERHEART.Sheets.Adversary.MotivesAndTactics" }}</legend>
|
<legend>{{localize "DAGGERHEART.Sheets.Adversary.FIELDS.motivesAndTactics.label" }}</legend>
|
||||||
|
|
||||||
{{formGroup systemFields.motivesAndTactics value=source.system.motivesAndTactics}}
|
{{formInput systemFields.motivesAndTactics value=source.system.motivesAndTactics}}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
data-group='{{tabs.main.group}}'
|
data-group='{{tabs.main.group}}'
|
||||||
>
|
>
|
||||||
<div class="adversary-container">
|
<div class="adversary-container">
|
||||||
|
<button data-action="reactionRoll">Reaction Test</button>
|
||||||
<fieldset class="two-columns even">
|
<fieldset class="two-columns even">
|
||||||
<legend>{{localize "DAGGERHEART.Sheets.Adversary.General"}}</legend>
|
<legend>{{localize "DAGGERHEART.Sheets.Adversary.General"}}</legend>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue