mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-21 18:09:54 +02:00
Compare commits
2 commits
20febb82d5
...
221b84726d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
221b84726d | ||
|
|
1274639ba8 |
9 changed files with 92 additions and 69 deletions
|
|
@ -6,6 +6,7 @@ import * as documents from './module/documents/_module.mjs';
|
||||||
import { macros } from './module/_module.mjs';
|
import { macros } from './module/_module.mjs';
|
||||||
import * as collections from './module/documents/collections/_module.mjs';
|
import * as collections from './module/documents/collections/_module.mjs';
|
||||||
import * as dice from './module/dice/_module.mjs';
|
import * as dice from './module/dice/_module.mjs';
|
||||||
|
import * as die from './module/dice/die/_module.mjs';
|
||||||
import * as fields from './module/data/fields/_module.mjs';
|
import * as fields from './module/data/fields/_module.mjs';
|
||||||
import RegisterHandlebarsHelpers from './module/helpers/handlebarsHelper.mjs';
|
import RegisterHandlebarsHelpers from './module/helpers/handlebarsHelper.mjs';
|
||||||
import { enricherConfig, enricherRenderSetup } from './module/enrichers/_module.mjs';
|
import { enricherConfig, enricherRenderSetup } from './module/enrichers/_module.mjs';
|
||||||
|
|
@ -38,6 +39,8 @@ CONFIG.RegionBehavior.dataModels = {
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.assign(CONFIG.Dice.termTypes, dice.diceTypes);
|
Object.assign(CONFIG.Dice.termTypes, dice.diceTypes);
|
||||||
|
CONFIG.Dice.terms.d = die.BaseDie;
|
||||||
|
CONFIG.Dice.types = [die.BaseDie, CONFIG.Dice.terms.f];
|
||||||
|
|
||||||
CONFIG.Actor.documentClass = documents.DhpActor;
|
CONFIG.Actor.documentClass = documents.DhpActor;
|
||||||
CONFIG.Actor.dataModels = models.actors.config;
|
CONFIG.Actor.dataModels = models.actors.config;
|
||||||
|
|
|
||||||
|
|
@ -179,15 +179,15 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
||||||
}
|
}
|
||||||
|
|
||||||
async onRollSimple(event, message) {
|
async onRollSimple(event, message) {
|
||||||
const buttonType = event.target.dataset.type ?? 'damage',
|
const buttonType = event.target.dataset.type ?? 'damage';
|
||||||
total = message.rolls.reduce((a, c) => a + Roll.fromJSON(c).total, 0),
|
const total = message.rolls.reduce((a, c) => a + Roll.fromJSON(c).total, 0);
|
||||||
damages = {
|
const damages = {
|
||||||
hitPoints: {
|
hitPoints: {
|
||||||
damageTypes: [],
|
damageTypes: [],
|
||||||
roll: { total }
|
roll: { total }
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
targets = Array.from(game.user.targets);
|
const targets = Array.from(game.user.targets);
|
||||||
|
|
||||||
if (targets.length === 0)
|
if (targets.length === 0)
|
||||||
return ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.noTargetsSelected'));
|
return ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.noTargetsSelected'));
|
||||||
|
|
@ -255,7 +255,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
||||||
|
|
||||||
if (target.dataset.type === 'damage') {
|
if (target.dataset.type === 'damage') {
|
||||||
const { damageType, dice, result } = target.dataset;
|
const { damageType, dice, result } = target.dataset;
|
||||||
await message.system.damage.rerollDamageDice(damageType, dice, result);
|
await message.system.damage.rerollDamageDie(damageType, dice, result);
|
||||||
await message.update({
|
await message.update({
|
||||||
'system.damage.types': {
|
'system.damage.types': {
|
||||||
[damageType]: {
|
[damageType]: {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { triggerChatRollFx } from '../../helpers/utils.mjs';
|
import { triggerChatRollFx } from '../../helpers/utils.mjs';
|
||||||
|
import { ChatDamageData } from './chatDamageData.mjs';
|
||||||
|
|
||||||
const fields = foundry.data.fields;
|
const fields = foundry.data.fields;
|
||||||
|
|
||||||
|
|
@ -29,60 +30,6 @@ export const originItemField = () =>
|
||||||
actionIndex: new fields.StringField()
|
actionIndex: new fields.StringField()
|
||||||
});
|
});
|
||||||
|
|
||||||
class ChatMessageRollDamage extends foundry.abstract.DataModel {
|
|
||||||
static defineSchema() {
|
|
||||||
return {
|
|
||||||
types: new fields.TypedObjectField(new fields.SchemaField({
|
|
||||||
roll: new fields.JSONField({validate: ChatMessageRollDamage.#validateRoll}),
|
|
||||||
damageTypes: new fields.ArrayField(new fields.StringField({ choices: CONFIG.DH.GENERAL.damageTypes }))
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
get active() {
|
|
||||||
return Boolean(Object.keys(this.types).length);
|
|
||||||
}
|
|
||||||
|
|
||||||
static #validateRoll(rollJSON) {
|
|
||||||
const roll = JSON.parse(rollJSON);
|
|
||||||
if (!roll.evaluated) throw new Error('Roll objects added to ChatMessage documents must be evaluated');
|
|
||||||
}
|
|
||||||
|
|
||||||
prepareRolls() {
|
|
||||||
for (const key of Object.keys(this.types)) {
|
|
||||||
const type = this.types[key];
|
|
||||||
try {
|
|
||||||
const roll = Roll.fromData(type.roll);
|
|
||||||
type.roll = roll;
|
|
||||||
type.roll.modifierTotal = CONFIG.Dice.daggerheart.DHRoll.calculateTotalModifiers(roll);
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async rerollDamageDice(damageType, dice, resultIndex) {
|
|
||||||
const reroll = this.types[damageType].roll;
|
|
||||||
const rerollDice = reroll.dice[dice];
|
|
||||||
const diceResult = rerollDice.results[resultIndex];
|
|
||||||
await rerollDice.reroll(`/r1=${diceResult.result}`);
|
|
||||||
await reroll._evaluate();
|
|
||||||
|
|
||||||
const rerolledResult = rerollDice.results[rerollDice.results.length - 1];
|
|
||||||
if (rerolledResult) {
|
|
||||||
const fakeRoll = {
|
|
||||||
_evaluated: true,
|
|
||||||
dice: [new foundry.dice.terms.Die({
|
|
||||||
...rerollDice,
|
|
||||||
results: [rerolledResult],
|
|
||||||
total: rerolledResult.value,
|
|
||||||
faces: rerollDice.faces
|
|
||||||
})],
|
|
||||||
options: { appearance: {} }
|
|
||||||
};
|
|
||||||
await triggerChatRollFx([fakeRoll]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
||||||
static defineSchema() {
|
static defineSchema() {
|
||||||
return {
|
return {
|
||||||
|
|
@ -103,7 +50,7 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
||||||
originItem: originItemField(),
|
originItem: originItemField(),
|
||||||
action: new fields.StringField()
|
action: new fields.StringField()
|
||||||
}),
|
}),
|
||||||
damage: new fields.EmbeddedDataField(ChatMessageRollDamage),
|
damage: new fields.EmbeddedDataField(ChatDamageData),
|
||||||
damageOptions: new fields.ObjectField(),
|
damageOptions: new fields.ObjectField(),
|
||||||
costs: new fields.ArrayField(new fields.ObjectField()),
|
costs: new fields.ArrayField(new fields.ObjectField()),
|
||||||
successConsumed: new fields.BooleanField({ initial: false })
|
successConsumed: new fields.BooleanField({ initial: false })
|
||||||
|
|
@ -186,7 +133,6 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Change how damage data is stored somehow to enable better rerolling */
|
|
||||||
async getRerolledDamage() {
|
async getRerolledDamage() {
|
||||||
if (!this.damage.active) return;
|
if (!this.damage.active) return;
|
||||||
|
|
||||||
|
|
|
||||||
56
module/data/chat-message/chatDamageData.mjs
Normal file
56
module/data/chat-message/chatDamageData.mjs
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
import { triggerChatRollFx } from '../../helpers/utils.mjs';
|
||||||
|
|
||||||
|
export class ChatDamageData extends foundry.abstract.DataModel {
|
||||||
|
static defineSchema() {
|
||||||
|
const fields = foundry.data.fields;
|
||||||
|
|
||||||
|
return {
|
||||||
|
types: new fields.TypedObjectField(new fields.SchemaField({
|
||||||
|
roll: new fields.JSONField({validate: ChatDamageData.#validateRoll}),
|
||||||
|
damageTypes: new fields.ArrayField(new fields.StringField({ choices: CONFIG.DH.GENERAL.damageTypes }))
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
get active() {
|
||||||
|
return Boolean(Object.keys(this.types).length);
|
||||||
|
}
|
||||||
|
|
||||||
|
static #validateRoll(rollJSON) {
|
||||||
|
const roll = JSON.parse(rollJSON);
|
||||||
|
if (!roll.evaluated) throw new Error('Roll objects added to ChatMessage documents must be evaluated');
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareRolls() {
|
||||||
|
for (const key of Object.keys(this.types)) {
|
||||||
|
const type = this.types[key];
|
||||||
|
try {
|
||||||
|
const roll = Roll.fromData(type.roll);
|
||||||
|
type.roll = roll;
|
||||||
|
type.roll.modifierTotal = CONFIG.Dice.daggerheart.DHRoll.calculateTotalModifiers(roll);
|
||||||
|
} catch {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async rerollDamageDie(damageType, dice, resultIndex) {
|
||||||
|
const reroll = this.types[damageType].roll;
|
||||||
|
const rerollDice = reroll.dice[dice];
|
||||||
|
await rerollDice.rerollResult(resultIndex);
|
||||||
|
await reroll._evaluate();
|
||||||
|
|
||||||
|
const rerolledResult = rerollDice.results[rerollDice.results.length - 1];
|
||||||
|
if (rerolledResult) {
|
||||||
|
const fakeRoll = {
|
||||||
|
_evaluated: true,
|
||||||
|
dice: [new foundry.dice.terms.Die({
|
||||||
|
...rerollDice,
|
||||||
|
results: [rerolledResult],
|
||||||
|
total: rerolledResult.value,
|
||||||
|
faces: rerollDice.faces
|
||||||
|
})],
|
||||||
|
options: { appearance: {} }
|
||||||
|
};
|
||||||
|
await triggerChatRollFx([fakeRoll]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ import HopeDie from './hopeDie.mjs';
|
||||||
import FearDie from './fearDie.mjs';
|
import FearDie from './fearDie.mjs';
|
||||||
import AdvantageDie from './advantageDie.mjs';
|
import AdvantageDie from './advantageDie.mjs';
|
||||||
import DisadvantageDie from './disadvantageDie.mjs';
|
import DisadvantageDie from './disadvantageDie.mjs';
|
||||||
|
export { default as BaseDie } from './baseDie.mjs';
|
||||||
|
|
||||||
export const diceTypes = {
|
export const diceTypes = {
|
||||||
DualityDie,
|
DualityDie,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
export default class AdvantageDie extends foundry.dice.terms.Die {
|
import BaseDie from './baseDie.mjs';
|
||||||
|
|
||||||
|
export default class AdvantageDie extends BaseDie {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|
||||||
|
|
|
||||||
12
module/dice/die/baseDie.mjs
Normal file
12
module/dice/die/baseDie.mjs
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
export default class BaseDie extends foundry.dice.terms.Die {
|
||||||
|
async rerollResult(resultIndex) {
|
||||||
|
const result = this.results[resultIndex];
|
||||||
|
result.rerolled = true;
|
||||||
|
result.active = false;
|
||||||
|
await this.roll({ reroll: true });
|
||||||
|
|
||||||
|
const rerolledResult = this.results[this.results.length - 1];
|
||||||
|
this.results.splice(this.results.length - 1, 1);
|
||||||
|
this.results.splice(resultIndex, 0, rerolledResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
export default class DisadvantageDie extends foundry.dice.terms.Die {
|
import BaseDie from './baseDie.mjs';
|
||||||
|
|
||||||
|
export default class DisadvantageDie extends BaseDie {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
import BaseDie from './baseDie.mjs';
|
||||||
import { updateResourcesForDualityReroll } from '../helpers.mjs';
|
import { updateResourcesForDualityReroll } from '../helpers.mjs';
|
||||||
|
|
||||||
export default class DualityDie extends foundry.dice.terms.Die {
|
export default class DualityDie extends BaseDie {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue