mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-15 21:21:08 +01:00
Fixed RiskItAll resource handling method
This commit is contained in:
parent
7ca4a5fae2
commit
89ba240998
6 changed files with 72 additions and 55 deletions
|
|
@ -2135,6 +2135,7 @@
|
||||||
"dropActorsHere": "Drop Actors here",
|
"dropActorsHere": "Drop Actors here",
|
||||||
"dropFeaturesHere": "Drop Features here",
|
"dropFeaturesHere": "Drop Features here",
|
||||||
"duality": "Duality",
|
"duality": "Duality",
|
||||||
|
"dualityDice": "Duality Dice",
|
||||||
"dualityRoll": "Duality Roll",
|
"dualityRoll": "Duality Roll",
|
||||||
"enabled": "Enabled",
|
"enabled": "Enabled",
|
||||||
"evasion": "Evasion",
|
"evasion": "Evasion",
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,13 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
|
||||||
const target = this.actor.uuid;
|
const target = this.actor.uuid;
|
||||||
const config = await enrichedFateRoll({
|
const config = await enrichedFateRoll({
|
||||||
target,
|
target,
|
||||||
title: 'Avoid Death Hope Fate Roll',
|
title: game.i18n.localize('DAGGERHEART.CONFIG.DeathMoves.avoidDeath.name'),
|
||||||
label: 'test',
|
label: `${game.i18n.localize('DAGGERHEART.GENERAL.hope')} ${game.i18n.localize('DAGGERHEART.GENERAL.fateRoll')}`,
|
||||||
fateType: 'Hope'
|
fateType: 'Hope'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!config.roll.fate) return;
|
||||||
|
|
||||||
if (config.roll.fate.value <= this.actor.system.levelData.level.current) {
|
if (config.roll.fate.value <= this.actor.system.levelData.level.current) {
|
||||||
// apply scarring - for now directly apply - later add a button.
|
// apply scarring - for now directly apply - later add a button.
|
||||||
const newScarAmount = this.actor.system.scars + 1;
|
const newScarAmount = this.actor.system.scars + 1;
|
||||||
|
|
@ -69,36 +71,30 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
|
||||||
return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.avoidScar');
|
return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.avoidScar');
|
||||||
}
|
}
|
||||||
|
|
||||||
async clearAllStressAndHitpoints() {
|
|
||||||
await this.actor.update({
|
|
||||||
system: {
|
|
||||||
resources: {
|
|
||||||
hitPoints: {
|
|
||||||
value: 0
|
|
||||||
},
|
|
||||||
stress: {
|
|
||||||
value: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async handleRiskItAll() {
|
async handleRiskItAll() {
|
||||||
const config = await enrichedDualityRoll({
|
const config = await enrichedDualityRoll({
|
||||||
reaction: true,
|
reaction: true,
|
||||||
traitValue: null,
|
traitValue: null,
|
||||||
target: null,
|
target: this.actor,
|
||||||
difficulty: null,
|
difficulty: null,
|
||||||
title: 'Risk It All',
|
title: game.i18n.localize('DAGGERHEART.CONFIG.DeathMoves.riskItAll.name'),
|
||||||
label: 'test',
|
label: game.i18n.localize('DAGGERHEART.GENERAL.dualityDice'),
|
||||||
actionType: null,
|
actionType: null,
|
||||||
advantage: null
|
advantage: null,
|
||||||
|
customConfig: { skips: { resources: true } }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!config.roll.result) return;
|
||||||
|
|
||||||
|
const clearAllStressAndHitpointsUpdates = [
|
||||||
|
{ key: 'hitPoints', clear: true },
|
||||||
|
{ key: 'stress', clear: true }
|
||||||
|
];
|
||||||
|
|
||||||
|
let chatMessage = '';
|
||||||
if (config.roll.isCritical) {
|
if (config.roll.isCritical) {
|
||||||
this.clearAllStressAndHitpoints();
|
config.resourceUpdates.addResources(clearAllStressAndHitpointsUpdates);
|
||||||
return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllCritical');
|
chatMessage = game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllCritical');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.roll.result.duality == 1) {
|
if (config.roll.result.duality == 1) {
|
||||||
|
|
@ -108,15 +104,18 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
|
||||||
config.roll.hope.value >=
|
config.roll.hope.value >=
|
||||||
this.actor.system.resources.hitPoints.value + this.actor.system.resources.stress.value
|
this.actor.system.resources.hitPoints.value + this.actor.system.resources.stress.value
|
||||||
) {
|
) {
|
||||||
this.clearAllStressAndHitpoints();
|
config.resourceUpdates.addResources(clearAllStressAndHitpointsUpdates);
|
||||||
return 'Hope roll value is more than the marked Stress and Hit Points, clearing both.';
|
chatMessage = 'Hope roll value is more than the marked Stress and Hit Points, clearing both.';
|
||||||
}
|
}
|
||||||
return 'TODO - need to clear Stress and/or Hit Points up to: ' + config.roll.hope.value;
|
chatMessage = 'TODO - need to clear Stress and/or Hit Points up to: ' + config.roll.hope.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.roll.result.duality == -1) {
|
if (config.roll.result.duality == -1) {
|
||||||
return game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllFailure');
|
chatMessage = game.i18n.localize('DAGGERHEART.UI.Chat.deathMove.riskItAllFailure');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await config.resourceUpdates.updateResources();
|
||||||
|
return chatMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleBlazeOfGlory() {
|
async handleBlazeOfGlory() {
|
||||||
|
|
@ -162,6 +161,8 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
|
||||||
result = await this.handleRiskItAll();
|
result = await this.handleRiskItAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!result) return;
|
||||||
|
|
||||||
const autoExpandDescription = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance)
|
const autoExpandDescription = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance)
|
||||||
.expandRollMessage?.desc;
|
.expandRollMessage?.desc;
|
||||||
const cls = getDocumentClass('ChatMessage');
|
const cls = getDocumentClass('ChatMessage');
|
||||||
|
|
|
||||||
|
|
@ -364,14 +364,14 @@ export class ResourceUpdateMap extends Map {
|
||||||
if (!resource.key) continue;
|
if (!resource.key) continue;
|
||||||
|
|
||||||
const existing = this.get(resource.key);
|
const existing = this.get(resource.key);
|
||||||
if (existing) {
|
if (!existing || resource.clear) {
|
||||||
|
this.set(resource.key, resource);
|
||||||
|
} else if (!existing?.clear) {
|
||||||
this.set(resource.key, {
|
this.set(resource.key, {
|
||||||
...existing,
|
...existing,
|
||||||
value: existing.value + (resource.value ?? 0),
|
value: existing.value + (resource.value ?? 0),
|
||||||
total: existing.total + (resource.total ?? 0)
|
total: existing.total + (resource.total ?? 0)
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
this.set(resource.key, resource);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -754,16 +754,24 @@ export default class DhpActor extends Actor {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const valueFunc = (base, resource, baseMax) => {
|
||||||
|
if (resource.clear) return baseMax && base.inverted ? baseMax : 0;
|
||||||
|
|
||||||
|
return (base.value ?? base) + resource.value;
|
||||||
|
};
|
||||||
switch (r.key) {
|
switch (r.key) {
|
||||||
case 'fear':
|
case 'fear':
|
||||||
ui.resources.updateFear(
|
ui.resources.updateFear(
|
||||||
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear) + r.value
|
valueFunc(
|
||||||
|
game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear),
|
||||||
|
r
|
||||||
|
)
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'armor':
|
case 'armor':
|
||||||
if (this.system.armor?.system?.marks) {
|
if (this.system.armor?.system?.marks) {
|
||||||
updates.armor.resources['system.marks.value'] = Math.max(
|
updates.armor.resources['system.marks.value'] = Math.max(
|
||||||
Math.min(this.system.armor.system.marks.value + r.value, this.system.armorScore),
|
Math.min(valueFunc(this.system.armor.system.marks, r), this.system.armorScore),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -772,7 +780,7 @@ export default class DhpActor extends Actor {
|
||||||
if (this.system.resources?.[r.key]) {
|
if (this.system.resources?.[r.key]) {
|
||||||
updates.actor.resources[`system.resources.${r.key}.value`] = Math.max(
|
updates.actor.resources[`system.resources.${r.key}.value`] = Math.max(
|
||||||
Math.min(
|
Math.min(
|
||||||
this.system.resources[r.key].value + r.value,
|
valueFunc(this.system.resources[r.key], r, this.system.resources[r.key].max),
|
||||||
this.system.resources[r.key].max
|
this.system.resources[r.key].max
|
||||||
),
|
),
|
||||||
0
|
0
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ export const renderDualityButton = async event => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const enrichedDualityRoll = async (
|
export const enrichedDualityRoll = async (
|
||||||
{ reaction, traitValue, target, difficulty, title, label, advantage },
|
{ reaction, traitValue, target, difficulty, title, label, advantage, customConfig },
|
||||||
event
|
event
|
||||||
) => {
|
) => {
|
||||||
const config = {
|
const config = {
|
||||||
|
|
@ -94,7 +94,8 @@ export const enrichedDualityRoll = async (
|
||||||
type: reaction ? 'reaction' : null
|
type: reaction ? 'reaction' : null
|
||||||
},
|
},
|
||||||
type: 'trait',
|
type: 'trait',
|
||||||
hasRoll: true
|
hasRoll: true,
|
||||||
|
...(customConfig ?? {})
|
||||||
};
|
};
|
||||||
|
|
||||||
if (target) {
|
if (target) {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ export default function DhFateRollEnricher(match, _options) {
|
||||||
|
|
||||||
const fateTypeFromRoll = getFateType(roll?.type);
|
const fateTypeFromRoll = getFateType(roll?.type);
|
||||||
|
|
||||||
if (fateTypeFromRoll == "BAD") {
|
if (fateTypeFromRoll == 'BAD') {
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing'));
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -15,27 +15,37 @@ export default function DhFateRollEnricher(match, _options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFateType(fateTypeValue) {
|
export function getFateType(fateTypeValue) {
|
||||||
const fateTypeFromValue = fateTypeValue ?
|
const fateTypeFromValue = fateTypeValue
|
||||||
(fateTypeValue.toLowerCase() == "fear" ? "Fear" :
|
? fateTypeValue.toLowerCase() == 'fear'
|
||||||
(fateTypeValue.toLowerCase() == "hope" ? "Hope" : "BAD")) : "Hope";
|
? 'Fear'
|
||||||
|
: fateTypeValue.toLowerCase() == 'hope'
|
||||||
|
? 'Hope'
|
||||||
|
: 'BAD'
|
||||||
|
: 'Hope';
|
||||||
|
|
||||||
return fateTypeFromValue;
|
return fateTypeFromValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFateMessage(roll, flavor) {
|
function getFateMessage(roll, flavor) {
|
||||||
const fateType = getFateType(roll?.type);
|
const fateType = getFateType(roll?.type);
|
||||||
|
|
||||||
if (fateType == "BAD") {
|
if (fateType == 'BAD') {
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing'));
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing'));
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
const fateTypeLocalized = fateType === "Hope" ? game.i18n.localize("DAGGERHEART.GENERAL.hope") : game.i18n.localize("DAGGERHEART.GENERAL.fear");
|
const fateTypeLocalized =
|
||||||
|
fateType === 'Hope'
|
||||||
|
? game.i18n.localize('DAGGERHEART.GENERAL.hope')
|
||||||
|
: game.i18n.localize('DAGGERHEART.GENERAL.fear');
|
||||||
|
|
||||||
const title = flavor ?? fateTypeLocalized + ' ' +
|
const title =
|
||||||
game.i18n.localize('DAGGERHEART.GENERAL.fate') + ' ' +
|
flavor ??
|
||||||
game.i18n.localize('DAGGERHEART.GENERAL.roll');
|
fateTypeLocalized +
|
||||||
|
' ' +
|
||||||
|
game.i18n.localize('DAGGERHEART.GENERAL.fate') +
|
||||||
|
' ' +
|
||||||
|
game.i18n.localize('DAGGERHEART.GENERAL.roll');
|
||||||
|
|
||||||
const dataLabel = game.i18n.localize('DAGGERHEART.GENERAL.fate');
|
const dataLabel = game.i18n.localize('DAGGERHEART.GENERAL.fate');
|
||||||
|
|
||||||
|
|
@ -56,11 +66,11 @@ function getFateMessage(roll, flavor) {
|
||||||
export const renderFateButton = async event => {
|
export const renderFateButton = async event => {
|
||||||
const button = event.currentTarget,
|
const button = event.currentTarget,
|
||||||
target = getCommandTarget({ allowNull: true });
|
target = getCommandTarget({ allowNull: true });
|
||||||
console.log("button", button);
|
console.log('button', button);
|
||||||
|
|
||||||
const fateTypeFromButton = getFateType(button.dataset?.fatetype);
|
const fateTypeFromButton = getFateType(button.dataset?.fatetype);
|
||||||
|
|
||||||
if (fateTypeFromButton == "BAD") {
|
if (fateTypeFromButton == 'BAD') {
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing'));
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.fateTypeParsing'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -76,16 +86,12 @@ export const renderFateButton = async event => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const enrichedFateRoll = async (
|
export const enrichedFateRoll = async ({ target, title, label, fateType }, event) => {
|
||||||
{ target, title, label, fateType },
|
|
||||||
event
|
|
||||||
) => {
|
|
||||||
const config = {
|
const config = {
|
||||||
event: event ?? {},
|
event: event ?? {},
|
||||||
title: title,
|
title: title,
|
||||||
roll: {
|
headerTitle: label,
|
||||||
label: label,
|
roll: {},
|
||||||
},
|
|
||||||
hasRoll: true,
|
hasRoll: true,
|
||||||
fateType: fateType
|
fateType: fateType
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue