This commit is contained in:
Chris Ryan 2026-01-10 10:28:46 +10:00 committed by GitHub
commit 54b0cda45a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 647 additions and 155 deletions

View file

@ -1,6 +1,10 @@
import { enrichedFateRoll } from '../../enrichers/FateRollEnricher.mjs';
import { enrichedDualityRoll } from '../../enrichers/DualityRollEnricher.mjs';
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
export default class DhpDeathMove extends HandlebarsApplicationMixin(ApplicationV2) {
export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(actor) {
super({});
@ -38,6 +42,99 @@ export default class DhpDeathMove extends HandlebarsApplicationMixin(Application
return context;
}
async handleAvoidDeath() {
const target = this.actor.uuid;
const config = await enrichedFateRoll({
target,
title: "Avoid Death Hope Fate Roll",
label: 'test',
fateType: "Hope"
});
if (config.roll.fate.value <= this.actor.system.levelData.level.current) {
// apply scarring - for now directly apply - later add a button.
const newScarAmount = this.actor.system.scars + 1;
await this.actor.update(
{
system: {
scars: newScarAmount
}
}
);
}
}
async clearAllStressAndHitpoints() {
await this.actor.update(
{
system: {
resources: {
hitPoints: {
value: 0
},
stress: {
value: 0
}
}
}
}
);
}
async handleRiskItAll() {
const config = await enrichedDualityRoll({
reaction: true,
traitValue: null,
target: null,
difficulty: null,
title: "Risk It All",
label: 'test',
actionType: null,
advantage: null
});
if (config.roll.isCritical) {
console.log("Clear all stress and HP");
this.clearAllStressAndHitpoints();
return;
}
// Hope
if (config.roll.result.duality == 1) {
console.log("Need to clear up Stress and HP up to hope value");
console.log("Hope rolled", config.roll.hope.value);
if (config.roll.hope.value >= (this.actor.system.resources.hitPoints.value + this.actor.system.resources.stress.value)) {
console.log("Hope roll value is more than the HP + Stress, auto- remove");
this.clearAllStressAndHitpoints();
}
return;
}
//Fear
if (config.roll.result.duality == -1) {
console.log("You have died...");
return;
}
}
async handleBlazeOfGlory() {
this.actor.createEmbeddedDocuments('ActiveEffect', [
{
name: game.i18n.localize('DAGGERHEART.CONFIG.DeathMoves.blazeOfGlory.name'),
description: game.i18n.localize('DAGGERHEART.CONFIG.DeathMoves.blazeOfGlory.description'),
img: CONFIG.DH.GENERAL.deathMoves.blazeOfGlory.img,
changes: [
{
key: 'system.rules.roll.guaranteedCritical',
mode: 2,
value: "true"
}
]
}
]);
}
static selectMove(_, button) {
const move = button.dataset.move;
this.selectedMove = CONFIG.DH.GENERAL.deathMoves[move];
@ -46,6 +143,10 @@ export default class DhpDeathMove extends HandlebarsApplicationMixin(Application
}
static async takeMove() {
const autoExpandDescription = game.settings.get(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.appearance
).expandRollMessage?.desc;
const cls = getDocumentClass('ChatMessage');
const msg = {
user: game.user.id,
@ -57,7 +158,9 @@ export default class DhpDeathMove extends HandlebarsApplicationMixin(Application
author: game.users.get(game.user.id),
title: game.i18n.localize(this.selectedMove.name),
img: this.selectedMove.img,
description: game.i18n.localize(this.selectedMove.description)
description: game.i18n.localize(this.selectedMove.description),
open: autoExpandDescription ? 'open' : '',
chevron: autoExpandDescription ? 'fa-chevron-up' : 'fa-chevron-down'
}
),
title: game.i18n.localize(
@ -74,5 +177,21 @@ export default class DhpDeathMove extends HandlebarsApplicationMixin(Application
cls.create(msg);
this.close();
if (CONFIG.DH.GENERAL.deathMoves.avoidDeath === this.selectedMove) {
this.handleAvoidDeath();
return;
}
if (CONFIG.DH.GENERAL.deathMoves.riskItAll === this.selectedMove) {
this.handleRiskItAll();
return;
}
if (CONFIG.DH.GENERAL.deathMoves.blazeOfGlory === this.selectedMove) {
this.handleBlazeOfGlory();
return;
}
}
}

View file

@ -1,5 +1,5 @@
import DHBaseActorSheet from '../api/base-actor.mjs';
import DhpDeathMove from '../../dialogs/deathMove.mjs';
import DhDeathMove from '../../dialogs/deathMove.mjs';
import { abilities } from '../../../config/actorConfig.mjs';
import { CharacterLevelup, LevelupViewMode } from '../../levelup/_module.mjs';
import DhCharacterCreation from '../../characterCreation/characterCreation.mjs';
@ -666,7 +666,7 @@ export default class CharacterSheet extends DHBaseActorSheet {
* @type {ApplicationClickAction}
*/
static async #makeDeathMove() {
await new DhpDeathMove(this.document).render({ force: true });
await new DhDeathMove(this.document).render({ force: true });
}
/**

View file

@ -78,12 +78,7 @@ export default class DhCharacter extends BaseDataActor {
bags: new fields.NumberField({ initial: 0, integer: true }),
chests: new fields.NumberField({ initial: 0, integer: true })
}),
scars: new fields.TypedObjectField(
new fields.SchemaField({
name: new fields.StringField({}),
description: new fields.StringField()
})
),
scars: new fields.NumberField({ initial: 0, integer: true, label: 'DAGGERHEART.GENERAL.scars' }),
biography: new fields.SchemaField({
background: new fields.HTMLField(),
connections: new fields.HTMLField(),
@ -283,6 +278,9 @@ export default class DhCharacter extends BaseDataActor {
runeWard: new fields.BooleanField({ initial: false }),
burden: new fields.SchemaField({
ignore: new fields.BooleanField()
}),
roll: new fields.SchemaField({
guaranteedCritical: new fields.BooleanField()
})
})
};
@ -624,7 +622,7 @@ export default class DhCharacter extends BaseDataActor {
? armor.system.baseThresholds.severe + this.levelData.level.current
: this.levelData.level.current * 2
};
this.resources.hope.max -= Object.keys(this.scars).length;
this.resources.hope.max -= this.scars;
this.resources.hitPoints.max += this.class.value?.system?.hitPoints ?? 0;
}
@ -696,4 +694,9 @@ export default class DhCharacter extends BaseDataActor {
t => !!t
);
}
static migrateData(source) {
if (typeof (source.scars) === 'object') source.scars = 0;
return super.migrateData(source);
}
}

View file

@ -8,6 +8,7 @@ export const config = {
adversaryRoll: DHActorRoll,
damageRoll: DHActorRoll,
dualityRoll: DHActorRoll,
fateRoll: DHActorRoll,
groupRoll: DHGroupRoll,
systemMessage: DHSystemMessage
};

View file

@ -3,3 +3,4 @@ export { default as D20Roll } from './d20Roll.mjs';
export { default as DamageRoll } from './damageRoll.mjs';
export { default as DHRoll } from './dhRoll.mjs';
export { default as DualityRoll } from './dualityRoll.mjs';
export { default as FateRoll } from './fateRoll.mjs';

View file

@ -12,6 +12,7 @@ export default class DualityRoll extends D20Roll {
constructor(formula, data = {}, options = {}) {
super(formula, data, options);
this.rallyChoices = this.setRallyChoices();
this.guaranteedCritical = options.guaranteedCritical;
}
static messageType = 'dualityRoll';
@ -25,29 +26,23 @@ export default class DualityRoll extends D20Roll {
}
get dHope() {
// if ( !(this.terms[0] instanceof foundry.dice.terms.Die) ) return;
if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice();
return this.dice[0];
// return this.#hopeDice;
}
set dHope(faces) {
if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice();
this.terms[0].faces = this.getFaces(faces);
// this.#hopeDice = `d${face}`;
this.dice[0].faces = this.getFaces(faces);
}
get dFear() {
// if ( !(this.terms[1] instanceof foundry.dice.terms.Die) ) return;
if (!(this.dice[1] instanceof foundry.dice.terms.Die)) this.createBaseDice();
return this.dice[1];
// return this.#fearDice;
}
set dFear(faces) {
if (!(this.dice[1] instanceof foundry.dice.terms.Die)) this.createBaseDice();
this.dice[1].faces = this.getFaces(faces);
// this.#fearDice = `d${face}`;
}
get dAdvantage() {
@ -90,26 +85,27 @@ export default class DualityRoll extends D20Roll {
}
get isCritical() {
if (this.guaranteedCritical) {
return true;
}
if (!this.dHope._evaluated || !this.dFear._evaluated) return;
return this.dHope.total === this.dFear.total;
}
get withHope() {
if (!this._evaluated) return;
if (!this._evaluated || this.guaranteedCritical) return;
return this.dHope.total > this.dFear.total;
}
get withFear() {
if (!this._evaluated) return;
if (!this._evaluated || this.guaranteedCritical) return;
return this.dHope.total < this.dFear.total;
}
get totalLabel() {
const label = this.withHope
? 'DAGGERHEART.GENERAL.hope'
: this.withFear
? 'DAGGERHEART.GENERAL.fear'
: 'DAGGERHEART.GENERAL.criticalSuccess';
const label = this.guaranteedCritical ? 'DAGGERHEART.GENERAL.guaranteedCriticalSuccess' :
this.isCritical ? 'DAGGERHEART.GENERAL.criticalSuccess' :
this.withHope ? 'DAGGERHEART.GENERAL.hope' : 'DAGGERHEART.GENERAL.fear';
return game.i18n.localize(label);
}
@ -120,6 +116,9 @@ export default class DualityRoll extends D20Roll {
/** @inheritDoc */
static fromData(data) {
if (data.options.guaranteedCritical) {
console.log("TODO: set the max values for Hope and Fear here?");
}
data.terms[0].class = foundry.dice.terms.Die.name;
data.terms[2].class = foundry.dice.terms.Die.name;
return super.fromData(data);
@ -173,6 +172,23 @@ export default class DualityRoll extends D20Roll {
return modifiers;
}
static async buildConfigure(config = {}, message = {}) {
console.log("buildConfigure, config", config);
config.dialog ??= {};
config.guaranteedCritical = config.data?.parent?.appliedEffects.reduce((a, c) => {
const change = c.changes.find(ch => ch.key === 'system.rules.roll.guaranteedCritical');
if (change) a = true;
return a;
}, false);
if (config.guaranteedCritical) {
config.dialog.configure = false;
}
return super.buildConfigure(config, message);
}
static async buildEvaluate(roll, config = {}, message = {}) {
await super.buildEvaluate(roll, config, message);
@ -190,7 +206,7 @@ export default class DualityRoll extends D20Roll {
data.hope = {
dice: roll.dHope.denomination,
value: roll.dHope.total,
value: this.guaranteedCritical ? 0 : roll.dHope.total,
rerolled: {
any: roll.dHope.results.some(x => x.rerolled),
rerolls: roll.dHope.results.filter(x => x.rerolled)
@ -198,7 +214,7 @@ export default class DualityRoll extends D20Roll {
};
data.fear = {
dice: roll.dFear.denomination,
value: roll.dFear.total,
value: this.guaranteedCritical ? 0 : roll.dFear.total,
rerolled: {
any: roll.dFear.results.some(x => x.rerolled),
rerolls: roll.dFear.results.filter(x => x.rerolled)
@ -210,7 +226,7 @@ export default class DualityRoll extends D20Roll {
};
data.result = {
duality: roll.withHope ? 1 : roll.withFear ? -1 : 0,
total: roll.dHope.total + roll.dFear.total,
total: this.guaranteedCritical ? 0 : roll.dHope.total + roll.dFear.total,
label: roll.totalLabel
};

101
module/dice/fateRoll.mjs Normal file
View file

@ -0,0 +1,101 @@
import D20RollDialog from '../applications/dialogs/d20RollDialog.mjs';
import D20Roll from './d20Roll.mjs';
import { setDiceSoNiceForHopeFateRoll, setDiceSoNiceForFearFateRoll } from '../helpers/utils.mjs';
export default class FateRoll extends D20Roll {
constructor(formula, data = {}, options = {}) {
super(formula, data, options);
}
static messageType = 'fateRoll';
static DefaultDialog = D20RollDialog;
get title() {
return game.i18n.localize(
`DAGGERHEART.GENERAL.fateRoll`
);
}
get dHope() {
// if ( !(this.terms[0] instanceof foundry.dice.terms.Die) ) return;
if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice();
return this.dice[0];
// return this.#hopeDice;
}
set dHope(faces) {
if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice();
this.dice[0].faces = this.getFaces(faces);
// this.#hopeDice = `d${face}`;
}
get dFear() {
// if ( !(this.terms[1] instanceof foundry.dice.terms.Die) ) return;
if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice();
return this.dice[0];
// return this.#fearDice;
}
set dFear(faces) {
if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice();
this.dice[0].faces = this.getFaces(faces);
// this.#fearDice = `d${face}`;
}
get isCritical() {
return false;
}
get fateDie() {
return this.data.fateType;
}
static getHooks(hooks) {
return [...(hooks ?? []), 'Fate'];
}
/** @inheritDoc */
static fromData(data) {
data.terms[0].class = foundry.dice.terms.Die.name;
return super.fromData(data);
}
createBaseDice() {
if (this.dice[0] instanceof foundry.dice.terms.Die) {
this.terms = [this.terms[0]];
return;
}
this.terms[0] = new foundry.dice.terms.Die({ faces: 12 });
}
static async buildEvaluate(roll, config = {}, message = {}) {
await super.buildEvaluate(roll, config, message);
if (roll.fateDie === "Hope") {
await setDiceSoNiceForHopeFateRoll(
roll,
config.roll.fate.dice
);
} else {
await setDiceSoNiceForFearFateRoll(
roll,
config.roll.fate.dice
);
}
}
static postEvaluate(roll, config = {}) {
const data = super.postEvaluate(roll, config);
data.fate = {
dice: roll.fateDie === "Hope" ? roll.dHope.denomination : roll.dFear.denomination,
value: roll.fateDie === "Hope" ? roll.dHope.total : roll.dFear.total,
fateDie: roll.fateDie
};
return data;
}
}

View file

@ -87,6 +87,15 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
break;
}
}
if (this.type === 'fateRoll') {
html.classList.add('fate');
if (this.system.roll?.fate.fateDie == 'Hope') {
html.classList.add('hope');
}
if (this.system.roll?.fate.fateDie == 'Fear') {
html.classList.add('fear');
}
}
const autoExpandRoll = game.settings.get(
CONFIG.DH.id,

View file

@ -105,4 +105,5 @@ export const enrichedDualityRoll = async (
config.source = { actor: null };
await CONFIG.Dice.daggerheart.DualityRoll.build(config);
}
return config;
};

View file

@ -0,0 +1,97 @@
import { getCommandTarget, rollCommandToJSON } from '../helpers/utils.mjs';
export default function DhFateRollEnricher(match, _options) {
const roll = rollCommandToJSON(match[1], match[0]);
if (!roll) return match[0];
const fateTypeFromRoll = getFateType(roll?.type);
if (fateTypeFromRoll == "BAD") {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing'));
return;
}
return getFateMessage(roll.result, roll?.flavor);
}
export function getFateType(fateTypeValue) {
const fateTypeFromValue = fateTypeValue ?
(fateTypeValue.toLowerCase() == "fear" ? "Fear" :
(fateTypeValue.toLowerCase() == "hope" ? "Hope" : "BAD")) : "Hope";
return fateTypeFromValue;
}
function getFateMessage(roll, flavor) {
const fateType = getFateType(roll?.type);
if (fateType == "BAD") {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing'));
return '';
}
const fateTypeLocalized = fateType === "Hope" ? game.i18n.localize("DAGGERHEART.GENERAL.hope") : game.i18n.localize("DAGGERHEART.GENERAL.fear");
const title = flavor ?? fateTypeLocalized + ' ' +
game.i18n.localize('DAGGERHEART.GENERAL.fate') + ' ' +
game.i18n.localize('DAGGERHEART.GENERAL.roll');
const dataLabel = game.i18n.localize('DAGGERHEART.GENERAL.fate');
const fateElement = document.createElement('span');
fateElement.innerHTML = `
<button type="button" class="fate-roll-button${roll?.inline ? ' inline' : ''}"
data-title="${title}"
data-label="${dataLabel}"
data-fateType="${fateType}"
>
${title}
</button>
`;
return fateElement;
}
export const renderFateButton = async event => {
const button = event.currentTarget,
target = getCommandTarget({ allowNull: true });
console.log("button", button);
const fateTypeFromButton = getFateType(button.dataset?.fatetype);
if (fateTypeFromButton == "BAD") {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing'));
return;
}
await enrichedFateRoll(
{
target,
title: button.dataset.title,
label: button.dataset.label,
fateType: fateTypeFromButton
},
event
);
};
export const enrichedFateRoll = async (
{ target, title, label, fateType },
event
) => {
const config = {
event: event ?? {},
title: title,
roll: {
label: label,
},
hasRoll: true,
fateType: fateType
};
config.data = { experiences: {}, traits: {}, fateType: fateType };
config.source = { actor: target?.uuid };
await CONFIG.Dice.daggerheart.FateRoll.build(config);
return config;
};

View file

@ -1,10 +1,11 @@
import { default as DhDamageEnricher, renderDamageButton } from './DamageEnricher.mjs';
import { default as DhDualityRollEnricher, renderDualityButton } from './DualityRollEnricher.mjs';
import { default as DhFateRollEnricher, renderFateButton } from './FateRollEnricher.mjs';
import { default as DhEffectEnricher } from './EffectEnricher.mjs';
import { default as DhTemplateEnricher, renderMeasuredTemplate } from './TemplateEnricher.mjs';
import { default as DhLookupEnricher } from './LookupEnricher.mjs';
export { DhDamageEnricher, DhDualityRollEnricher, DhEffectEnricher, DhTemplateEnricher };
export { DhDamageEnricher, DhDualityRollEnricher, DhEffectEnricher, DhTemplateEnricher, DhFateRollEnricher };
export const enricherConfig = [
{
@ -15,6 +16,10 @@ export const enricherConfig = [
pattern: /\[\[\/dr\s?(.*?)\]\]({[^}]*})?/g,
enricher: DhDualityRollEnricher
},
{
pattern: /\[\[\/fr\s?(.*?)\]\]({[^}]*})?/g,
enricher: DhFateRollEnricher
},
{
pattern: /@Effect\[([^\[\]]*)\]({[^}]*})?/g,
enricher: DhEffectEnricher
@ -38,6 +43,10 @@ export const enricherRenderSetup = element => {
.querySelectorAll('.duality-roll-button')
.forEach(element => element.addEventListener('click', renderDualityButton));
element
.querySelectorAll('.fate-roll-button')
.forEach(element => element.addEventListener('click', renderFateButton));
element
.querySelectorAll('.measured-template-button')
.forEach(element => element.addEventListener('click', renderMeasuredTemplate));

View file

@ -1,4 +1,4 @@
import { diceTypes, getDiceSoNicePresets, range } from '../config/generalConfig.mjs';
import { diceTypes, getDiceSoNicePresets, getDiceSoNicePreset, range } from '../config/generalConfig.mjs';
import Tagify from '@yaireo/tagify';
export const capitalize = string => {
@ -69,6 +69,20 @@ export const setDiceSoNiceForDualityRoll = async (rollResult, advantageState, ho
}
};
export const setDiceSoNiceForHopeFateRoll = async (rollResult, hopeFaces) => {
if (!game.modules.get('dice-so-nice')?.active) return;
const { diceSoNice } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance);
const diceSoNicePresets = await getDiceSoNicePreset(diceSoNice.hope, hopeFaces);
rollResult.dice[0].options = diceSoNicePresets;
};
export const setDiceSoNiceForFearFateRoll = async (rollResult, fearFaces) => {
if (!game.modules.get('dice-so-nice')?.active) return;
const { diceSoNice } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance);
const diceSoNicePresets = await getDiceSoNicePreset(diceSoNice.fear, fearFaces);
rollResult.dice[0].options = diceSoNicePresets;
};
export const chunkify = (array, chunkSize, mappingFunc) => {
var chunkifiedArray = [];
for (let i = 0; i < array.length; i += chunkSize) {