mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Downtime window now enumerates the actions/resources that will be refreshed upon completion. Resources can now specify their progression direction (#591)
This commit is contained in:
parent
645b8fef58
commit
599e9c7aa0
7 changed files with 140 additions and 2 deletions
|
|
@ -24,6 +24,8 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
|||
actor.system.bonuses.rest[`${shortrest ? 'short' : 'long'}Rest`].longMoves
|
||||
}
|
||||
};
|
||||
|
||||
this.refreshables = this.getRefreshables();
|
||||
}
|
||||
|
||||
get title() {
|
||||
|
|
@ -81,11 +83,56 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
|||
context.shortRestMoves = this.nrChoices.shortRest.max > 0 ? this.moveData.shortRest : null;
|
||||
context.longRestMoves = this.nrChoices.longRest.max > 0 ? this.moveData.longRest : null;
|
||||
|
||||
context.refreshables = this.refreshables;
|
||||
|
||||
context.disabledDowntime = shortRestMovesSelected === 0 && longRestMovesSelected === 0;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
getRefreshables() {
|
||||
const actionItems = this.actor.items.reduce((acc, x) => {
|
||||
if (x.system.actions) {
|
||||
const recoverable = x.system.actions.reduce((acc, action) => {
|
||||
if (action.uses.recovery && (action.uses.recovery === 'shortRest') === this.shortrest) {
|
||||
acc.push({
|
||||
title: x.name,
|
||||
name: action.name,
|
||||
uuid: action.uuid
|
||||
});
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
if (recoverable) {
|
||||
acc.push(...recoverable);
|
||||
}
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
const resourceItems = this.actor.items.reduce((acc, x) => {
|
||||
if (
|
||||
x.system.resource &&
|
||||
x.system.resource.type &&
|
||||
(x.system.resource.recovery === 'shortRest') === this.shortrest
|
||||
) {
|
||||
acc.push({
|
||||
title: game.i18n.localize(`TYPES.Item.${x.type}`),
|
||||
name: x.name,
|
||||
uuid: x.uuid
|
||||
});
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
return {
|
||||
actionItems,
|
||||
resourceItems
|
||||
};
|
||||
}
|
||||
|
||||
static selectMove(_, target) {
|
||||
const { category, move } = target.dataset;
|
||||
|
||||
|
|
@ -172,11 +219,24 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
|||
}
|
||||
}
|
||||
|
||||
// We can close the window when all moves are taken
|
||||
// We can close the window and refresh resources when all moves are taken
|
||||
if (
|
||||
this.nrChoices.shortRest.taken >= this.nrChoices.shortRest.max &&
|
||||
this.nrChoices.longRest.taken >= this.nrChoices.longRest.max
|
||||
) {
|
||||
for (var data of this.refreshables.actionItems) {
|
||||
const action = await foundry.utils.fromUuid(data.uuid);
|
||||
await action.parent.parent.update({ [`system.actions.${action.id}.uses.value`]: action.uses.max ?? 1 });
|
||||
}
|
||||
|
||||
for (var data of this.refreshables.resourceItems) {
|
||||
const feature = await foundry.utils.fromUuid(data.uuid);
|
||||
const increasing =
|
||||
feature.system.resource.progression === CONFIG.DH.ITEM.itemResourceProgression.increasing.id;
|
||||
const resetValue = increasing ? 0 : (feature.system.resource.max ?? 0);
|
||||
await feature.update({ 'system.resource.value': resetValue });
|
||||
}
|
||||
|
||||
this.close();
|
||||
} else {
|
||||
this.render();
|
||||
|
|
|
|||
|
|
@ -1473,6 +1473,17 @@ export const itemResourceTypes = {
|
|||
}
|
||||
};
|
||||
|
||||
export const itemResourceProgression = {
|
||||
increasing: {
|
||||
id: 'increasing',
|
||||
label: 'DAGGERHEART.CONFIG.ItemResourceProgression.increasing'
|
||||
},
|
||||
decreasing: {
|
||||
id: 'decreasing',
|
||||
label: 'DAGGERHEART.CONFIG.ItemResourceProgression.decreasing'
|
||||
}
|
||||
};
|
||||
|
||||
export const beastformTypes = {
|
||||
normal: {
|
||||
id: 'normal',
|
||||
|
|
|
|||
|
|
@ -56,6 +56,11 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
initial: null,
|
||||
nullable: true
|
||||
}),
|
||||
progression: new fields.StringField({
|
||||
required: true,
|
||||
choices: CONFIG.DH.ITEM.itemResourceProgression,
|
||||
initial: CONFIG.DH.ITEM.itemResourceProgression.increasing.id
|
||||
}),
|
||||
diceStates: new fields.TypedObjectField(
|
||||
new fields.SchemaField({
|
||||
value: new fields.NumberField({ integer: true, initial: 1, min: 1 }),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue