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