Fixed domaincard level max for selections in a tier

This commit is contained in:
WBHarry 2025-06-12 17:44:48 +02:00
parent 6ef691445e
commit 43c8e54e5d
2 changed files with 28 additions and 11 deletions

View file

@ -204,9 +204,12 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
context.domainCards.push({
...(card.toObject?.() ?? card),
emptySubtexts: domainsData.map(domain => {
const levelMax = domain.multiclass
const levelBase = domain.multiclass
? Math.ceil(this.levelup.currentLevel / 2)
: this.levelup.currentLevel;
const levelMax = domainCard.secondaryData?.limit
? Math.min(domainCard.secondaryData.limit, levelBase)
: levelBase;
return game.i18n.format('DAGGERHEART.Application.LevelUp.Selections.emptyDomainCardHint', {
domain: game.i18n.localize(domains[domain.domain].label),
@ -216,7 +219,7 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
path: domainCard.data
? `${domainCard.path}.data`
: `levels.${domainCard.level}.achievements.domainCards.${key}.uuid`,
limit: domainCard.level,
limit: domainCard.secondaryData?.limit ?? null,
compendium: 'domains'
});
}
@ -582,10 +585,9 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
return;
}
if (
(isMulticlass ? Math.ceil(this.levelup.currentLevel / 2) : this.levelup.currentLevel) <
item.system.level
) {
const levelBase = isMulticlass ? Math.ceil(this.levelup.currentLevel / 2) : this.levelup.currentLevel;
const levelMax = target.dataset.limit ? Math.min(Number(target.dataset.limit), levelBase) : levelBase;
if (levelMax < item.system.level) {
ui.notifications.error(
game.i18n.localize('DAGGERHEART.Application.LevelUp.notifications.error.domainCardToHighLevel')
);
@ -668,15 +670,23 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
return;
}
update[
`levels.${this.levelup.currentLevel}.choices.${button.dataset.option}.${button.dataset.checkboxNr}`
] = {
const updateData = {
tier: Number(button.dataset.tier),
minCost: Number(button.dataset.cost),
amount: button.dataset.amount ? Number(button.dataset.amount) : null,
value: button.dataset.value,
type: button.dataset.type
};
if (button.dataset.type === 'domainCard') {
updateData.secondaryData = {
limit: Math.max(...this.levelup.tiers[button.dataset.tier].belongingLevels)
};
}
update[
`levels.${this.levelup.currentLevel}.choices.${button.dataset.option}.${button.dataset.checkboxNr}`
] = updateData;
}
await this.levelup.updateSource(update);

View file

@ -182,7 +182,7 @@ export class DhLevelup extends foundry.abstract.DataModel {
);
const { multiclass, subclasses } = this.classUpgradeChoices;
return tierKeys.map(tierKey => {
return tierKeys.map((tierKey, tierIndex) => {
const tier = this.tiers[tierKey];
const multiclassInTier = multiclass?.tier === Number(tierKey);
const subclassInTier = subclasses.some(x => x.tier === Number(tierKey));
@ -216,8 +216,15 @@ export class DhLevelup extends foundry.abstract.DataModel {
return checkbox;
});
let label = game.i18n.localize(option.label);
if (optionKey === 'domainCard') {
const maxLevel = tier.belongingLevels[tier.belongingLevels.length - 1];
label = game.i18n.format(option.label, { maxLevel });
}
return {
label: game.i18n.localize(option.label),
label: label,
checkboxGroups: chunkify(checkboxes, option.minCost, chunkedBoxes => {
const anySelected = chunkedBoxes.some(x => x.selected);
const anyDisabled = chunkedBoxes.some(x => x.disabled);