[Feature] Manual Character Editing (#490)

* Initial

* Added Character-Settings

* Finalized Character-Settings

* Hide CharacterSetup if any part is done manually

* Fixed class/subclass drag-drop

* Fixed relinking of Features from items created on Character

* Adding features on CharacterItems now adds them on the Character and relinks

* Made suggested items inactive in the Class sheet if rendered from inside a Character

* Added hope to CharacterSetting

* add style to textarea element, add spellcasting and domain class into char sheet and move rest buttons to another place

* Fixed characterCreation experience description

---------

Co-authored-by: moliloo <dev.murilobrito@gmail.com>
This commit is contained in:
WBHarry 2025-08-01 17:16:35 +02:00 committed by GitHub
parent 263dfa69ae
commit e1d8f8784a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
49 changed files with 1205 additions and 386 deletions

View file

@ -5,6 +5,7 @@ export { default as DamageReductionDialog } from './damageReductionDialog.mjs';
export { default as DamageSelectionDialog } from './damageSelectionDialog.mjs';
export { default as DeathMove } from './deathMove.mjs';
export { default as Downtime } from './downtime.mjs';
export { default as MulticlassChoiceDialog } from './multiclassChoiceDialog.mjs';
export { default as OwnershipSelection } from './ownershipSelection.mjs';
export { default as ResourceDiceDialog } from './resourceDiceDialog.mjs';
export { default as ActionSelectionDialog } from './actionSelectionDialog.mjs';

View file

@ -0,0 +1,73 @@
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
export default class MulticlassChoiceDialog extends HandlebarsApplicationMixin(ApplicationV2) {
constructor(actor, multiclass, options) {
super(options);
this.actor = actor;
this.multiclass = multiclass;
this.selectedDomain = null;
}
get title() {
return game.i18n.format('DAGGERHEART.APPLICATIONS.MulticlassChoice.title', { actor: this.actor.name });
}
static DEFAULT_OPTIONS = {
classes: ['daggerheart', 'dh-style', 'dialog', 'views', 'multiclass-choice'],
position: { width: 'auto', height: 'auto' },
window: { icon: 'fa-solid fa-person-rays' },
actions: {
save: MulticlassChoiceDialog.#save,
selectDomain: MulticlassChoiceDialog.#selectDomain
}
};
static PARTS = {
application: {
id: 'multiclass-choice',
template: 'systems/daggerheart/templates/dialogs/multiclassChoice.hbs'
}
};
async _prepareContext(_options) {
const context = await super._prepareContext(_options);
context.multiclass = this.multiclass;
context.domainChoices = this.multiclass.domains.map(value => {
const domain = CONFIG.DH.DOMAIN.domains[value];
return {
value: value,
label: game.i18n.localize(domain.label),
description: game.i18n.localize(domain.description),
src: domain.src,
selected: value === this.selectedDomain,
disabled: this.actor.system.domains.includes(value)
};
});
context.multiclassDisabled = !this.selectedDomain;
return context;
}
/** @override */
_onClose(options = {}) {
if (!options.submitted) this.move = null;
}
static async configure(actor, multiclass, options = {}) {
return new Promise(resolve => {
const app = new this(actor, multiclass, options);
app.addEventListener('close', () => resolve(app.selectedDomain), { once: true });
app.render({ force: true });
});
}
static #save() {
this.close({ submitted: true });
}
static #selectDomain(_event, button) {
this.selectedDomain = this.selectedDomain === button.dataset.domain ? null : button.dataset.domain;
this.render();
}
}

View file

@ -46,7 +46,8 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
tabs: { template: 'systems/daggerheart/templates/levelup/tabs/tab-navigation.hbs' },
advancements: { template: 'systems/daggerheart/templates/levelup/tabs/advancements.hbs' },
selections: { template: 'systems/daggerheart/templates/levelup/tabs/selections.hbs' },
summary: { template: 'systems/daggerheart/templates/levelup/tabs/summary.hbs' }
summary: { template: 'systems/daggerheart/templates/levelup/tabs/summary.hbs' },
footer: { template: 'systems/daggerheart/templates/levelup/tabs/footer.hbs' }
};
static TABS = {
@ -95,6 +96,7 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
const context = await super._prepareContext(_options);
context.levelup = this.levelup;
context.tabs = this._getTabs(this.constructor.TABS);
context.levelupAuto = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).levelupAuto;
return context;
}

View file

@ -1,4 +1,5 @@
export { default as ActionConfig } from './action-config.mjs';
export { default as CharacterSettings } from './character-settings.mjs';
export { default as AdversarySettings } from './adversary-settings.mjs';
export { default as CompanionSettings } from './companion-settings.mjs';
export { default as DowntimeConfig } from './downtimeConfig.mjs';

View file

@ -0,0 +1,143 @@
import DHBaseActorSettings from '../sheets/api/actor-setting.mjs';
/**@typedef {import('@client/applications/_types.mjs').ApplicationClickAction} ApplicationClickAction */
export default class DHCharacterSettings extends DHBaseActorSettings {
/**@inheritdoc */
static DEFAULT_OPTIONS = {
classes: ['character-settings'],
position: { width: 455, height: 'auto' },
actions: {
addExperience: DHCharacterSettings.#addExperience,
removeExperience: DHCharacterSettings.#removeExperience
},
dragDrop: [
{ dragSelector: null, dropSelector: '.tab.features' },
{ dragSelector: '.feature-item', dropSelector: null }
]
};
/**@override */
static PARTS = {
header: {
id: 'header',
template: 'systems/daggerheart/templates/sheets-settings/character-settings/header.hbs'
},
tabs: { template: 'systems/daggerheart/templates/sheets/global/tabs/tab-navigation.hbs' },
details: {
id: 'details',
template: 'systems/daggerheart/templates/sheets-settings/character-settings/details.hbs'
},
experiences: {
id: 'experiences',
template: 'systems/daggerheart/templates/sheets-settings/character-settings/experiences.hbs'
}
};
/** @override */
static TABS = {
primary: {
tabs: [{ id: 'details' }, { id: 'experiences' }],
initial: 'details',
labelPrefix: 'DAGGERHEART.GENERAL.Tabs'
}
};
/**@inheritdoc */
async _prepareContext(options) {
const context = await super._prepareContext(options);
context.levelupAuto = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).levelupAuto;
return context;
}
/* -------------------------------------------- */
/**
* Adds a new experience entry to the actor.
* @type {ApplicationClickAction}
*/
static async #addExperience() {
const newExperience = {
name: 'Experience',
modifier: 0
};
await this.actor.update({ [`system.experiences.${foundry.utils.randomID()}`]: newExperience });
}
/**
* Removes an experience entry from the actor.
* @type {ApplicationClickAction}
*/
static async #removeExperience(_, target) {
const experience = this.actor.system.experiences[target.dataset.experience];
const updates = {};
const relinkAchievementData = [];
const relinkSelectionData = [];
Object.keys(this.actor.system.levelData.levelups).forEach(key => {
const level = this.actor.system.levelData.levelups[key];
const achievementIncludesExp = level.achievements.experiences[target.dataset.experience];
if (achievementIncludesExp)
relinkAchievementData.push({ levelKey: key, experience: target.dataset.experience });
const selectionIndex = level.selections.findIndex(
x => x.optionKey === 'experience' && x.data[0] === target.dataset.experience
);
if (selectionIndex !== -1)
relinkSelectionData.push({ levelKey: key, selectionIndex, experience: target.dataset.experience });
});
if (relinkAchievementData.length > 0 || relinkSelectionData.length > 0) {
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: {
title: game.i18n.localize('DAGGERHEART.ACTORS.Character.experienceDataRemoveConfirmation.title')
},
content: game.i18n.localize('DAGGERHEART.ACTORS.Character.experienceDataRemoveConfirmation.text')
});
if (!confirmed) return;
}
if (relinkAchievementData.length > 0) {
relinkAchievementData.forEach(data => {
updates[`system.levelData.levelups.${data.levelKey}.achievements.experiences.-=${data.experience}`] =
null;
});
} else if (relinkSelectionData.length > 0) {
relinkSelectionData.forEach(data => {
updates[`system.levelData.levelups.${data.levelKey}.selections`] = this.actor.system.levelData.levelups[
data.levelKey
].selections.reduce((acc, selection, index) => {
if (
index === data.selectionIndex &&
selection.optionKey === 'experience' &&
selection.data.includes(data.experience)
) {
acc.push({ ...selection, data: selection.data.filter(x => x !== data.experience) });
} else {
acc.push(selection);
}
return acc;
}, []);
});
} else {
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: {
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
type: game.i18n.localize(`DAGGERHEART.GENERAL.Experience.single`),
name: experience.name
})
},
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: experience.name })
});
if (!confirmed) return;
}
await this.actor.update({
...updates,
[`system.experiences.-=${target.dataset.experience}`]: null
});
}
}

View file

@ -10,6 +10,8 @@ export default class DHCompanionSettings extends DHBaseActorSettings {
classes: ['companion-settings'],
position: { width: 455, height: 'auto' },
actions: {
addExperience: DHCompanionSettings.#addExperience,
removeExperience: DHCompanionSettings.#removeExperience,
levelUp: DHCompanionSettings.#levelUp
}
};
@ -88,6 +90,38 @@ export default class DHCompanionSettings extends DHBaseActorSettings {
if (!value) await this.actor.updateLevel(1);
}
/**
* Adds a new experience entry to the actor.
* @type {ApplicationClickAction}
*/
static async #addExperience() {
const newExperience = {
name: 'Experience',
modifier: 0
};
await this.actor.update({ [`system.experiences.${foundry.utils.randomID()}`]: newExperience });
}
/**
* Removes an experience entry from the actor.
* @type {ApplicationClickAction}
*/
static async #removeExperience(_, target) {
const experience = this.actor.system.experiences[target.dataset.experience];
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: {
title: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.title', {
type: game.i18n.localize(`DAGGERHEART.GENERAL.Experience.single`),
name: experience.name
})
},
content: game.i18n.format('DAGGERHEART.APPLICATIONS.DeleteConfirmation.text', { name: experience.name })
});
if (!confirmed) return;
await this.actor.update({ [`system.experiences.-=${target.dataset.experience}`]: null });
}
/**
* Opens the companion level-up dialog for the associated actor.
* @type {ApplicationClickAction}

View file

@ -716,10 +716,14 @@ export default class CharacterSheet extends DHBaseActorSheet {
});
}
/**
* Open the downtime application.
* @type {ApplicationClickAction}
*/
static useDowntime(_, button) {
new game.system.api.applications.dialogs.Downtime(this.document, button.dataset.type === 'shortRest').render(
true
);
new game.system.api.applications.dialogs.Downtime(this.document, button.dataset.type === 'shortRest').render({
force: true
});
}
async _onDragStart(event) {

View file

@ -417,17 +417,29 @@ export default function DHApplicationMixin(Base) {
const { documentClass, type, inVault, disabled } = target.dataset;
const parentIsItem = this.document.documentName === 'Item';
const parent =
parentIsItem && documentClass === 'Item'
? type === 'action'
? this.document.system
: null
: this.document;
this.document.parent?.type === 'character'
? this.document.parent
: parentIsItem && documentClass === 'Item'
? type === 'action'
? this.document.system
: null
: this.document;
let systemData = {};
if (parent?.type === 'character' && type === 'feature') {
systemData = {
originItemType: this.document.type,
originId: this.document.id,
identifier: this.document.system.isMulticlass ? 'multiclass' : null
};
}
const cls =
type === 'action' ? game.system.api.models.actions.actionsTypes.base : getDocumentClass(documentClass);
const data = {
name: cls.defaultName({ type, parent }),
type
type,
system: systemData
};
if (inVault) data['system.inVault'] = true;
if (disabled) data.disabled = true;

View file

@ -150,10 +150,24 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
static async #addFeature(_, target) {
const { type } = target.dataset;
const cls = foundry.documents.Item.implementation;
const item = await cls.create({
type: 'feature',
name: cls.defaultName({ type: 'feature' })
});
let systemData = {};
if (this.document.parent?.type === 'character') {
systemData = {
originItemType: this.document.type,
originId: this.document.id,
identifier: this.document.system.isMulticlass ? 'multiclass' : null
};
}
const item = await cls.create(
{
type: 'feature',
name: cls.defaultName({ type: 'feature' }),
system: systemData
},
{ parent: this.document.parent?.type === 'character' ? this.document.parent : undefined }
);
await this.document.update({
'system.features': [...this.document.system.features, { type, item }].map(x => ({
...x,

View file

@ -113,45 +113,47 @@ export default class ClassSheet extends DHBaseItemSheet {
});
} else if (item.type === 'feature') {
super._onDrop(event);
} else if (item.type === 'weapon') {
if (target.classList.contains('primary-weapon-section')) {
if (!item.system.secondary)
} else if (this.document.parent?.type !== 'character') {
if (item.type === 'weapon') {
if (target.classList.contains('primary-weapon-section')) {
if (!item.system.secondary)
await this.document.update({
'system.characterGuide.suggestedPrimaryWeapon': item.uuid
});
} else if (target.classList.contains('secondary-weapon-section')) {
if (item.system.secondary)
await this.document.update({
'system.characterGuide.suggestedSecondaryWeapon': item.uuid
});
}
} else if (item.type === 'armor') {
if (target.classList.contains('armor-section')) {
await this.document.update({
'system.characterGuide.suggestedPrimaryWeapon': item.uuid
});
} else if (target.classList.contains('secondary-weapon-section')) {
if (item.system.secondary)
await this.document.update({
'system.characterGuide.suggestedSecondaryWeapon': item.uuid
});
}
} else if (item.type === 'armor') {
if (target.classList.contains('armor-section')) {
await this.document.update({
'system.characterGuide.suggestedArmor': item.uuid
});
}
} else if (target.classList.contains('choice-a-section')) {
if (item.type === 'loot' || item.type === 'consumable') {
const filteredChoiceA = this.document.system.inventory.choiceA;
if (filteredChoiceA.length < 2)
await this.document.update({
'system.inventory.choiceA': [...filteredChoiceA.map(x => x.uuid), item.uuid]
});
}
} else if (item.type === 'loot') {
if (target.classList.contains('take-section')) {
const filteredTake = this.document.system.inventory.take.filter(x => x);
if (filteredTake.length < 3)
await this.document.update({
'system.inventory.take': [...filteredTake.map(x => x.uuid), item.uuid]
});
} else if (target.classList.contains('choice-b-section')) {
const filteredChoiceB = this.document.system.inventory.choiceB.filter(x => x);
if (filteredChoiceB.length < 2)
await this.document.update({
'system.inventory.choiceB': [...filteredChoiceB.map(x => x.uuid), item.uuid]
'system.characterGuide.suggestedArmor': item.uuid
});
}
} else if (target.classList.contains('choice-a-section')) {
if (item.type === 'loot' || item.type === 'consumable') {
const filteredChoiceA = this.document.system.inventory.choiceA;
if (filteredChoiceA.length < 2)
await this.document.update({
'system.inventory.choiceA': [...filteredChoiceA.map(x => x.uuid), item.uuid]
});
}
} else if (item.type === 'loot') {
if (target.classList.contains('take-section')) {
const filteredTake = this.document.system.inventory.take.filter(x => x);
if (filteredTake.length < 3)
await this.document.update({
'system.inventory.take': [...filteredTake.map(x => x.uuid), item.uuid]
});
} else if (target.classList.contains('choice-b-section')) {
const filteredChoiceB = this.document.system.inventory.choiceB.filter(x => x);
if (filteredChoiceB.length < 2)
await this.document.update({
'system.inventory.choiceB': [...filteredChoiceB.map(x => x.uuid), item.uuid]
});
}
}
}
}

View file

@ -87,7 +87,8 @@ export default class DhpAdversary extends BaseDataActor {
experiences: new fields.TypedObjectField(
new fields.SchemaField({
name: new fields.StringField(),
value: new fields.NumberField({ required: true, integer: true, initial: 1 })
value: new fields.NumberField({ required: true, integer: true, initial: 1 }),
description: new fields.StringField()
})
),
bonuses: new fields.SchemaField({

View file

@ -4,6 +4,7 @@ import DhLevelData from '../levelData.mjs';
import BaseDataActor from './base.mjs';
import { attributeField, resourceField, stressDamageReductionRule, bonusField } from '../fields/actorField.mjs';
import { ActionField } from '../fields/actionField.mjs';
import DHCharacterSettings from '../../applications/sheets-configs/character-settings.mjs';
export default class DhCharacter extends BaseDataActor {
static LOCALIZATION_PREFIXES = ['DAGGERHEART.ACTORS.Character'];
@ -12,6 +13,7 @@ export default class DhCharacter extends BaseDataActor {
return foundry.utils.mergeObject(super.metadata, {
label: 'TYPES.Actor.character',
type: 'character',
settingSheet: DHCharacterSettings,
isNPC: false
});
}
@ -22,7 +24,12 @@ export default class DhCharacter extends BaseDataActor {
return {
...super.defineSchema(),
resources: new fields.SchemaField({
hitPoints: resourceField(0, 'DAGGERHEART.GENERAL.HitPoints.plural', true),
hitPoints: resourceField(
0,
'DAGGERHEART.GENERAL.HitPoints.plural',
true,
'DAGGERHEART.ACTORS.Character.maxHPBonus'
),
stress: resourceField(6, 'DAGGERHEART.GENERAL.stress', true),
hope: resourceField(6, 'DAGGERHEART.GENERAL.hope')
}),
@ -56,7 +63,8 @@ export default class DhCharacter extends BaseDataActor {
experiences: new fields.TypedObjectField(
new fields.SchemaField({
name: new fields.StringField(),
value: new fields.NumberField({ integer: true, initial: 0 })
value: new fields.NumberField({ integer: true, initial: 0 }),
description: new fields.StringField()
})
),
gold: new fields.SchemaField({
@ -312,7 +320,7 @@ export default class DhCharacter extends BaseDataActor {
}
get needsCharacterSetup() {
return !this.class.value || !this.class.subclass;
return !(this.class.value || this.class.subclass || this.ancestry || this.community);
}
get spellcastModifier() {
@ -399,11 +407,16 @@ export default class DhCharacter extends BaseDataActor {
} else if (item.system.originItemType === CONFIG.DH.ITEM.featureTypes.subclass.id) {
if (this.class.subclass) {
const subclassState = this.class.subclass.system.featureState;
const subType = item.system.subType;
const subclass =
item.system.identifier === 'multiclass' ? this.multiclass.subclass : this.class.subclass;
const featureType = subclass
? (subclass.system.features.find(x => x.item?.uuid === item.uuid)?.type ?? null)
: null;
if (
subType === CONFIG.DH.ITEM.featureSubTypes.foundation ||
(subType === CONFIG.DH.ITEM.featureSubTypes.specialization && subclassState >= 2) ||
(subType === CONFIG.DH.ITEM.featureSubTypes.mastery && subclassState >= 3)
featureType === CONFIG.DH.ITEM.featureSubTypes.foundation ||
(featureType === CONFIG.DH.ITEM.featureSubTypes.specialization && subclassState >= 2) ||
(featureType === CONFIG.DH.ITEM.featureSubTypes.mastery && subclassState >= 3)
) {
subclassFeatures.push(item);
}
@ -502,7 +515,7 @@ export default class DhCharacter extends BaseDataActor {
}
prepareBaseData() {
this.evasion = this.class.value?.system?.evasion ?? 0;
this.evasion += this.class.value?.system?.evasion ?? 0;
const currentLevel = this.levelData.level.current;
const currentTier =
@ -511,37 +524,39 @@ export default class DhCharacter extends BaseDataActor {
: Object.values(game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.LevelTiers).tiers).find(
tier => currentLevel >= tier.levels.start && currentLevel <= tier.levels.end
).tier;
for (let levelKey in this.levelData.levelups) {
const level = this.levelData.levelups[levelKey];
if (game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).levelupAuto) {
for (let levelKey in this.levelData.levelups) {
const level = this.levelData.levelups[levelKey];
this.proficiency += level.achievements.proficiency;
this.proficiency += level.achievements.proficiency;
for (let selection of level.selections) {
switch (selection.type) {
case 'trait':
selection.data.forEach(data => {
this.traits[data].value += 1;
this.traits[data].tierMarked = selection.tier === currentTier;
});
break;
case 'hitPoint':
this.resources.hitPoints.max += selection.value;
break;
case 'stress':
this.resources.stress.max += selection.value;
break;
case 'evasion':
this.evasion += selection.value;
break;
case 'proficiency':
this.proficiency += selection.value;
break;
case 'experience':
Object.keys(this.experiences).forEach(key => {
const experience = this.experiences[key];
experience.value += selection.value;
});
break;
for (let selection of level.selections) {
switch (selection.type) {
case 'trait':
selection.data.forEach(data => {
this.traits[data].value += 1;
this.traits[data].tierMarked = selection.tier === currentTier;
});
break;
case 'hitPoint':
this.resources.hitPoints.max += selection.value;
break;
case 'stress':
this.resources.stress.max += selection.value;
break;
case 'evasion':
this.evasion += selection.value;
break;
case 'proficiency':
this.proficiency += selection.value;
break;
case 'experience':
selection.data.forEach(id => {
const experience = this.experiences[id];
if (experience) experience.value += selection.value;
});
break;
}
}
}
}

View file

@ -6,10 +6,15 @@ const attributeField = label =>
tierMarked: new fields.BooleanField({ initial: false })
});
const resourceField = (max = 0, label, reverse = false) =>
const resourceField = (max = 0, label, reverse = false, maxLabel) =>
new fields.SchemaField({
value: new fields.NumberField({ initial: 0, min: 0, integer: true, label }),
max: new fields.NumberField({ initial: max, integer: true }),
max: new fields.NumberField({
initial: max,
integer: true,
label:
maxLabel ?? game.i18n.format('DAGGERHEART.GENERAL.maxWithThing', { thing: game.i18n.localize(label) })
}),
isReversed: new fields.BooleanField({ initial: reverse })
});

View file

@ -125,6 +125,7 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
}
if (this.actor && this.actor.type === 'character' && this.features) {
const featureUpdates = {};
for (let f of this.features) {
const fBase = f.item ?? f;
const feature = fBase.system ? fBase : await foundry.utils.fromUuid(fBase.uuid);
@ -134,14 +135,26 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
system: {
originItemType: this.parent.type,
originId: data._id,
identifier: feature.identifier,
subType: feature.item ? feature.type : undefined
identifier: this.isMulticlass ? 'multiclass' : null
}
},
{ inplace: false }
);
await this.actor.createEmbeddedDocuments('Item', [createData]);
const [doc] = await this.actor.createEmbeddedDocuments('Item', [createData]);
if (!featureUpdates.features)
featureUpdates.features = this.features.map(x => (x.item ? { ...x, item: x.item.uuid } : x.uuid));
if (f.item) {
const existingFeature = featureUpdates.features.find(x => x.item === f.item.uuid);
existingFeature.item = doc.uuid;
} else {
const replaceIndex = featureUpdates.features.findIndex(x => x === f.uuid);
featureUpdates.features.splice(replaceIndex, 1, doc.uuid);
}
}
await this.updateSource(featureUpdates);
}
}

View file

@ -62,16 +62,37 @@ export default class DHClass extends BaseDataItem {
}
async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;
if (this.actor?.type === 'character') {
const path = data.system.isMulticlass ? 'system.multiclass.value' : 'system.class.value';
if (foundry.utils.getProperty(this.actor, path)) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.classAlreadySelected'));
return false;
const levelupAuto = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).levelupAuto;
if (levelupAuto) {
const path = data.system.isMulticlass ? 'system.multiclass.value' : 'system.class.value';
if (foundry.utils.getProperty(this.actor, path)) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.classAlreadySelected'));
return false;
}
} else {
if (this.actor.system.class.value) {
if (this.actor.system.multiclass.value) {
ui.notifications.warn(
game.i18n.localize('DAGGERHEART.UI.Notifications.multiclassAlreadyPresent')
);
return false;
} else {
const selectedDomain =
await game.system.api.applications.dialogs.MulticlassChoiceDialog.configure(
this.actor,
this
);
if (!selectedDomain) return false;
await this.updateSource({ isMulticlass: true, domains: [selectedDomain] });
}
}
}
}
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;
}
_onCreate(data, options, userId) {

View file

@ -23,7 +23,6 @@ export default class DHFeature extends BaseDataItem {
nullable: true,
initial: null
}),
subType: new fields.StringField({ choices: CONFIG.DH.ITEM.featureSubTypes, nullable: true, initial: null }),
originId: new fields.StringField({ nullable: true, initial: null }),
identifier: new fields.StringField()
};

View file

@ -41,27 +41,48 @@ export default class DHSubclass extends BaseDataItem {
}
async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;
if (this.actor?.type === 'character') {
const classData = this.actor.items.find(
x => x.type === 'class' && x.system.isMulticlass === data.system.isMulticlass
);
const subclassData = this.actor.items.find(
x => x.type === 'subclass' && x.system.isMulticlass === data.system.isMulticlass
);
if (!classData) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.missingClass'));
return false;
} else if (subclassData) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.subclassAlreadySelected'));
return false;
} else if (classData.system.subclasses.every(x => x.uuid !== (data.uuid ?? `Item.${data._id}`))) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.subclassNotInClass'));
return false;
if (this.actor.system.class.subclass) {
if (this.actor.system.multiclass.subclass) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.subclassesAlreadyPresent'));
return false;
} else {
if (!this.actor.system.multiclass.value) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.missingMulticlass'));
return false;
}
if (
this.actor.system.multiclass.value.system.subclasses.every(
x => x.uuid !== (data.uuid ?? `Item.${data._id}`)
)
) {
ui.notifications.error(
game.i18n.localize('DAGGERHEART.UI.Notifications.subclassNotInMulticlass')
);
return false;
}
await this.updateSource({ isMulticlass: true });
}
} else {
if (!this.actor.system.class.value) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.missingClass'));
return false;
}
if (
this.actor.system.class.value.system.subclasses.every(
x => x.uuid !== (data.uuid ?? `Item.${data._id}`)
)
) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.subclassNotInClass'));
return false;
}
}
}
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;
}
_onCreate(data, options, userId) {

View file

@ -14,6 +14,11 @@ export default class DhAutomation extends foundry.abstract.DataModel {
label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.hopeFear.players.label'
})
}),
levelupAuto: new fields.BooleanField({
required: true,
initial: true,
label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.levelupAuto.label'
}),
actionPoints: new fields.BooleanField({
required: true,
initial: false,

View file

@ -172,26 +172,30 @@ export default class DhpActor extends Actor {
}
async levelUp(levelupData) {
const levelupAuto = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).levelupAuto;
const levelups = {};
for (var levelKey of Object.keys(levelupData)) {
const level = levelupData[levelKey];
for (var experienceKey in level.achievements.experiences) {
const experience = level.achievements.experiences[experienceKey];
await this.update({
[`system.experiences.${experienceKey}`]: {
name: experience.name,
value: experience.modifier
}
});
if (this.system.companion) {
await this.system.companion.update({
if (levelupAuto) {
for (var experienceKey in level.achievements.experiences) {
const experience = level.achievements.experiences[experienceKey];
await this.update({
[`system.experiences.${experienceKey}`]: {
name: '',
name: experience.name,
value: experience.modifier
}
});
if (this.system.companion) {
await this.system.companion.update({
[`system.experiences.${experienceKey}`]: {
name: '',
value: experience.modifier
}
});
}
}
}
@ -250,74 +254,86 @@ export default class DhpActor extends Actor {
}
for (var addition of featureAdditions) {
for (var featureData of addition.features) {
const feature = new DHFeature({
...featureData,
description: game.i18n.localize(featureData.description)
});
const document = featureData.toPartner && this.system.partner ? this.system.partner : this;
const embeddedItem = await document.createEmbeddedDocuments('Item', [
{
if (levelupAuto) {
for (var featureData of addition.features) {
const feature = new DHFeature({
...featureData,
name: game.i18n.localize(featureData.name),
type: 'feature',
system: feature
}
]);
const newFeature = {
onPartner: Boolean(featureData.toPartner && this.system.partner),
id: embeddedItem[0].id
};
addition.checkbox.features = !addition.checkbox.features
? [newFeature]
: [...addition.checkbox.features, newFeature];
description: game.i18n.localize(featureData.description)
});
const document = featureData.toPartner && this.system.partner ? this.system.partner : this;
const embeddedItem = await document.createEmbeddedDocuments('Item', [
{
...featureData,
name: game.i18n.localize(featureData.name),
type: 'feature',
system: feature
}
]);
const newFeature = {
onPartner: Boolean(featureData.toPartner && this.system.partner),
id: embeddedItem[0].id
};
addition.checkbox.features = !addition.checkbox.features
? [newFeature]
: [...addition.checkbox.features, newFeature];
}
}
selections.push(addition.checkbox);
}
if (multiclass) {
const subclassItem = await foundry.utils.fromUuid(multiclass.secondaryData.subclass);
const subclassData = subclassItem.toObject();
const multiclassItem = await foundry.utils.fromUuid(multiclass.data[0]);
const multiclassData = multiclassItem.toObject();
if (levelupAuto) {
const subclassItem = await foundry.utils.fromUuid(multiclass.secondaryData.subclass);
const subclassData = subclassItem.toObject();
const multiclassItem = await foundry.utils.fromUuid(multiclass.data[0]);
const multiclassData = multiclassItem.toObject();
const embeddedItem = await this.createEmbeddedDocuments('Item', [
{
...multiclassData,
system: {
...multiclassData.system,
domains: [multiclass.secondaryData.domain],
isMulticlass: true
const embeddedItem = await this.createEmbeddedDocuments('Item', [
{
...multiclassData,
system: {
...multiclassData.system,
domains: [multiclass.secondaryData.domain],
isMulticlass: true
}
}
}
]);
]);
await this.createEmbeddedDocuments('Item', [
{
...subclassData,
system: {
...subclassData.system,
isMulticlass: true
await this.createEmbeddedDocuments('Item', [
{
...subclassData,
system: {
...subclassData.system,
isMulticlass: true
}
}
}
]);
selections.push({ ...multiclass, itemUuid: embeddedItem[0].uuid });
]);
selections.push({ ...multiclass, itemUuid: embeddedItem[0].uuid });
} else {
selections.push({ ...multiclass });
}
}
for (var domainCard of domainCards) {
const item = await foundry.utils.fromUuid(domainCard.data[0]);
const embeddedItem = await this.createEmbeddedDocuments('Item', [item.toObject()]);
selections.push({ ...domainCard, itemUuid: embeddedItem[0].uuid });
if (levelupAuto) {
const item = await foundry.utils.fromUuid(domainCard.data[0]);
const embeddedItem = await this.createEmbeddedDocuments('Item', [item.toObject()]);
selections.push({ ...domainCard, itemUuid: embeddedItem[0].uuid });
} else {
selections.push({ ...domainCard });
}
}
const achievementDomainCards = [];
for (var card of Object.values(level.achievements.domainCards)) {
const item = await foundry.utils.fromUuid(card.uuid);
const embeddedItem = await this.createEmbeddedDocuments('Item', [item.toObject()]);
card.itemUuid = embeddedItem[0].uuid;
achievementDomainCards.push(card);
if (levelupAuto) {
for (var card of Object.values(level.achievements.domainCards)) {
const item = await foundry.utils.fromUuid(card.uuid);
const embeddedItem = await this.createEmbeddedDocuments('Item', [item.toObject()]);
card.itemUuid = embeddedItem[0].uuid;
achievementDomainCards.push(card);
}
}
if (subclassFeatureState.class) {