This commit is contained in:
WBHarry 2025-08-05 16:12:34 +02:00
parent 110bfa3492
commit c8babc5873
5 changed files with 70 additions and 37 deletions

View file

@ -1,5 +1,6 @@
import { abilities } from '../../config/actorConfig.mjs'; import { abilities } from '../../config/actorConfig.mjs';
import { burden } from '../../config/generalConfig.mjs'; import { burden } from '../../config/generalConfig.mjs';
import { createEmbeddedItemWithEffects } from '../../helpers/utils.mjs';
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api; const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
@ -550,34 +551,46 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
} }
}; };
await this.character.createEmbeddedDocuments('Item', [ancestry]); await createEmbeddedItemWithEffects(this.character, ancestry);
await this.character.createEmbeddedDocuments('Item', [this.setup.community]); await createEmbeddedItemWithEffects(this.character, this.setup.community);
await this.character.createEmbeddedDocuments('Item', [this.setup.class]); await createEmbeddedItemWithEffects(this.character, this.setup.class);
await this.character.createEmbeddedDocuments('Item', [this.setup.subclass]); await createEmbeddedItemWithEffects(this.character, this.setup.subclass);
await this.character.createEmbeddedDocuments('Item', Object.values(this.setup.domainCards));
if (this.equipment.armor.uuid)
await this.character.createEmbeddedDocuments('Item', [
{ ...this.equipment.armor, system: { ...this.equipment.armor.system, equipped: true } }
]);
if (this.equipment.primaryWeapon.uuid)
await this.character.createEmbeddedDocuments('Item', [
{ ...this.equipment.primaryWeapon, system: { ...this.equipment.primaryWeapon.system, equipped: true } }
]);
if (this.equipment.secondaryWeapon.uuid)
await this.character.createEmbeddedDocuments('Item', [
{
...this.equipment.secondaryWeapon,
system: { ...this.equipment.secondaryWeapon.system, equipped: true }
}
]);
if (this.equipment.inventory.choiceA.uuid)
await this.character.createEmbeddedDocuments('Item', [this.equipment.inventory.choiceA]);
if (this.equipment.inventory.choiceB.uuid)
await this.character.createEmbeddedDocuments('Item', [this.equipment.inventory.choiceB]);
await this.character.createEmbeddedDocuments( await this.character.createEmbeddedDocuments(
'Item', 'Item',
this.setup.class.system.inventory.take.filter(x => x) Object.values(this.setup.domainCards).map(x => ({
...x,
effects: x.effects?.map(effect => effect.toObject())
}))
);
if (this.equipment.armor.uuid)
await createEmbeddedItemWithEffects(this.character, this.equipment.armor, {
...this.equipment.armor,
system: { ...this.equipment.armor.system, equipped: true }
});
if (this.equipment.primaryWeapon.uuid)
await createEmbeddedItemWithEffects(this.character, this.equipment.primaryWeapon, {
...this.equipment.primaryWeapon,
system: { ...this.equipment.primaryWeapon.system, equipped: true }
});
if (this.equipment.secondaryWeapon.uuid)
await createEmbeddedItemWithEffects(this.character, this.equipment.secondaryWeapon, {
...this.equipment.secondaryWeapon,
system: { ...this.equipment.secondaryWeapon.system, equipped: true }
});
if (this.equipment.inventory.choiceA.uuid)
await createEmbeddedItemWithEffects(this.character, this.equipment.inventory.choiceA);
if (this.equipment.inventory.choiceB.uuid)
await createEmbeddedItemWithEffects(this.character, this.equipment.inventory.choiceB);
await this.character.createEmbeddedDocuments(
'Item',
this.setup.class.system.inventory.take
.filter(x => x)
.map(x => ({
...x,
effects: x.effects?.map(effect => effect.toObject())
}))
); );
await this.character.update({ await this.character.update({

View file

@ -46,12 +46,13 @@ export default class DHDomainCard extends BaseDataItem {
if (allowed === false) return; if (allowed === false) return;
if (this.actor?.type === 'character') { if (this.actor?.type === 'character') {
if (!this.actor.system.class.value) { const actorClasses = this.actor.items.filter(x => x.type === 'class');
if (!actorClasses.length) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noClassSelected')); ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noClassSelected'));
return false; return false;
} }
if (!this.actor.system.domains.find(x => x === this.domain)) { if (!actorClasses.some(c => c.system.domains.find(x => x === this.domain))) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.lacksDomain')); ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.lacksDomain'));
return false; return false;
} }

View file

@ -158,16 +158,19 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
x.type === 'subclass' && x.type === 'subclass' &&
x.system.isMulticlass === (this.parent.system.identifier === 'multiclass') x.system.isMulticlass === (this.parent.system.identifier === 'multiclass')
); );
const featureState = subclass.system.featureState;
const featureType = subclass
? (subclass.system.features.find(x => x.item?.uuid === this.parent.uuid)?.type ?? null)
: null;
if ( if (subclass) {
(featureType === CONFIG.DH.ITEM.featureSubTypes.specialization && featureState < 2) || const featureState = subclass.system.featureState;
(featureType === CONFIG.DH.ITEM.featureSubTypes.mastery && featureState < 3) const featureType = subclass
) { ? (subclass.system.features.find(x => x.item?.uuid === this.parent.uuid)?.type ?? null)
this.transfer = false; : null;
if (
(featureType === CONFIG.DH.ITEM.featureSubTypes.specialization && featureState < 2) ||
(featureType === CONFIG.DH.ITEM.featureSubTypes.mastery && featureState < 3)
) {
this.transfer = false;
}
} }
} }
} }

View file

@ -40,6 +40,8 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
elements.forEach(e => { elements.forEach(e => {
const uuid = e.dataset.permId, const uuid = e.dataset.permId,
document = fromUuidSync(uuid); document = fromUuidSync(uuid);
if (!document) return;
e.setAttribute('data-view-perm', document.testUserPermission(game.user, 'OBSERVER')); e.setAttribute('data-view-perm', document.testUserPermission(game.user, 'OBSERVER'));
e.setAttribute('data-use-perm', document.testUserPermission(game.user, 'OWNER')); e.setAttribute('data-use-perm', document.testUserPermission(game.user, 'OWNER'));
}); });

View file

@ -355,3 +355,17 @@ export function createScrollText(actor, optionsData) {
}); });
} }
} }
export async function createEmbeddedItemWithEffects(actor, baseData, update) {
const data = baseData.uuid.startsWith('Compendium') ? await foundry.utils.fromUuid(baseData.uuid) : baseData;
const [doc] = await actor.createEmbeddedDocuments('Item', [
{
...(update ?? data),
id: data.id,
uuid: data.uuid,
effects: data.effects?.map(effect => effect.toObject())
}
]);
return doc;
}