From cd517252fa6eb13cb92fc814fa542f1c4588f619 Mon Sep 17 00:00:00 2001 From: Dapoolp Date: Fri, 25 Jul 2025 22:38:19 +0200 Subject: [PATCH] Max Cards loadout switch & Homebrew setting --- lang/en.json | 6 ++++-- module/applications/sheets/actors/character.mjs | 9 +++++++-- .../applications/sheets/api/application-mixin.mjs | 4 ++++ module/data/actor/character.mjs | 14 +++++++++++++- module/data/settings/Homebrew.mjs | 7 +++++++ templates/settings/homebrew-settings.hbs | 1 + 6 files changed, 36 insertions(+), 5 deletions(-) diff --git a/lang/en.json b/lang/en.json index 81cb2d49..44719e68 100755 --- a/lang/en.json +++ b/lang/en.json @@ -1516,7 +1516,8 @@ "resetMovesText": "Are you sure you want to reset?", "FIELDS": { "maxFear": { "label": "Max Fear" }, - "traitArray": { "label": "Initial Trait Modifiers" } + "traitArray": { "label": "Initial Trait Modifiers" }, + "maxLoadout": { "label": "Max Cards in Loadout" } }, "currency": { "enabled": "Enable Overrides", @@ -1687,7 +1688,8 @@ "beastformMissingEffect": "The Beastform is missing a Beastform Effect. Cannot be used.", "beastformToManyAdvantages": "You cannot select any more advantages.", "beastformToManyFeatures": "You cannot select any more features.", - "beastformEquipWeapon": "You cannot use weapons while in a Beastform." + "beastformEquipWeapon": "You cannot use weapons while in a Beastform.", + "loadoutMaxReached": "You already have {max} cards in your loadout. Move atleast one to your vault before adding a new one." }, "Tooltip": { "disableEffect": "Disable Effect", diff --git a/module/applications/sheets/actors/character.mjs b/module/applications/sheets/actors/character.mjs index 9d5f6a45..e86a918c 100644 --- a/module/applications/sheets/actors/character.mjs +++ b/module/applications/sheets/actors/character.mjs @@ -259,7 +259,12 @@ export default class CharacterSheet extends DHBaseActorSheet { name: 'toLoadout', icon: 'fa-solid fa-arrow-up', condition: target => getDocFromElement(target).system.inVault, - callback: target => getDocFromElement(target).update({ 'system.inVault': false }) + callback: target => { + const elem = getDocFromElement(target), + actorLoadout = elem.actor?.system.loadoutSlot ?? null; + if(actorLoadout?.available) return elem.update({ 'system.inVault': false }); + ui.notifications.warn(game.i18n.format('DAGGERHEART.UI.Notifications.loadoutMaxReached', { max: actorLoadout.max })) + } }, { name: 'toVault', @@ -729,7 +734,7 @@ export default class CharacterSheet extends DHBaseActorSheet { const item = await Item.implementation.fromDropData(data); const itemData = item.toObject(); - if (item.type === 'domainCard' && this.document.system.domainCards.loadout.length >= 5) { + if (item.type === 'domainCard' && !this.document.system.loadoutSlot.available) { itemData.system.inVault = true; } diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index 544ab575..ee72321a 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -295,6 +295,10 @@ export default function DHApplicationMixin(Base) { options.unshift({ name: 'DAGGERHEART.APPLICATIONS.ContextMenu.useItem', icon: 'fa-solid fa-burst', + condition: target => { + const elem = getDocFromElement(target); + return !(elem.type === 'domainCard' && elem.system.inVault) + }, callback: (target, event) => getDocFromElement(target).use(event) }); diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index 5134c5e1..641df1a1 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -202,7 +202,8 @@ export default class DhCharacter extends BaseDataActor { hint: 'DAGGERHEART.GENERAL.Bonuses.rest.longRest.longRestMoves.hint' }) }) - }) + }), + maxLoadout : new fields.NumberField({ integer: true, initial: 0 }) }), companion: new ForeignDocumentUUIDField({ type: 'Actor', nullable: true, initial: null }), rules: new fields.SchemaField({ @@ -320,6 +321,17 @@ export default class DhCharacter extends BaseDataActor { }; } + get loadoutSlot() { + const loadoutCount = this.domainCards.loadout?.length ?? 0, + max = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).maxLoadout + this.bonuses.maxLoadout; + + return { + current: loadoutCount, + available: Math.max(max - loadoutCount, 0), + max + } + } + get armor() { return this.parent.items.find(x => x.type === 'armor' && x.system.equipped); } diff --git a/module/data/settings/Homebrew.mjs b/module/data/settings/Homebrew.mjs index 5619898e..29da1aa0 100644 --- a/module/data/settings/Homebrew.mjs +++ b/module/data/settings/Homebrew.mjs @@ -14,6 +14,13 @@ export default class DhHomebrew extends foundry.abstract.DataModel { initial: 12, label: 'DAGGERHEART.SETTINGS.Homebrew.FIELDS.maxFear.label' }), + maxLoadout: new fields.NumberField({ + required: true, + integer: true, + min: 0, + initial: 5, + label: 'DAGGERHEART.SETTINGS.Homebrew.FIELDS.maxLoadout.label' + }), traitArray: new fields.ArrayField(new fields.NumberField({ required: true, integer: true }), { initial: () => [2, 1, 1, 0, 0, -1] }), diff --git a/templates/settings/homebrew-settings.hbs b/templates/settings/homebrew-settings.hbs index ada2c7a9..6bfcbb9c 100644 --- a/templates/settings/homebrew-settings.hbs +++ b/templates/settings/homebrew-settings.hbs @@ -3,6 +3,7 @@

{{localize 'DAGGERHEART.SETTINGS.Menu.homebrew.name'}}

{{formGroup settingFields.schema.fields.maxFear value=settingFields._source.maxFear localize=true}} + {{formGroup settingFields.schema.fields.maxLoadout value=settingFields._source.maxLoadout localize=true}}

{{localize "DAGGERHEART.SETTINGS.Homebrew.FIELDS.traitArray.label"}}