mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-07 05:14:16 +02:00
Fix finishing levelup with a multiclass
This commit is contained in:
parent
6a2d09caac
commit
13bcadf142
3 changed files with 29 additions and 40 deletions
|
|
@ -718,7 +718,7 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
||||||
? {
|
? {
|
||||||
'system.linkedClass.uuid': {
|
'system.linkedClass.uuid': {
|
||||||
key: 'system.linkedClass.uuid',
|
key: 'system.linkedClass.uuid',
|
||||||
value: this.document.system.class.value._stats.compendiumSource
|
value: this.document.system.class.value?._stats.compendiumSource
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
|
|
|
||||||
|
|
@ -56,38 +56,30 @@ export default class DHSubclass extends BaseDataItem {
|
||||||
if (allowed === false) return;
|
if (allowed === false) return;
|
||||||
|
|
||||||
if (this.actor?.type === 'character') {
|
if (this.actor?.type === 'character') {
|
||||||
const dataUuid = data.uuid ?? data._stats.compendiumSource ?? `Item.${data._id}`;
|
const { value: actorClass, subclass: existingSubclass } = this.actor.system.class;
|
||||||
if (this.actor.system.class.subclass) {
|
const { value: multiclass, subclass: existingMultisubclass } = this.actor.system.multiclass;
|
||||||
if (this.actor.system.multiclass.subclass) {
|
if (!actorClass && !multiclass) {
|
||||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.subclassesAlreadyPresent'));
|
ui.notifications.warn('DAGGERHEART.UI.Notifications.missingClass', { localize: true });
|
||||||
return false;
|
return false;
|
||||||
} else {
|
}
|
||||||
const multiclass = this.actor.items.find(x => x.type === 'class' && x.system.isMulticlass);
|
if (existingSubclass && existingMultisubclass) {
|
||||||
if (!multiclass) {
|
ui.notifications.warn('DAGGERHEART.UI.Notifications.subclassesAlreadyPresent', { localize: true });
|
||||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.missingMulticlass'));
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
if (existingSubclass && !multiclass) {
|
||||||
|
ui.notifications.warn('DAGGERHEART.UI.Notifications.missingMulticlass', { localize: true });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (multiclass.system.subclasses.every(x => x.uuid !== dataUuid)) {
|
const match = [multiclass, actorClass].find(
|
||||||
ui.notifications.error(
|
c => c && (c._stats.compendiumSource ?? c.uuid) === this.linkedClass
|
||||||
game.i18n.localize('DAGGERHEART.UI.Notifications.subclassNotInMulticlass')
|
);
|
||||||
);
|
if (!match) {
|
||||||
return false;
|
const key = multiclass ? 'subclassNotInMulticlass' : 'subclassNotInClass';
|
||||||
}
|
ui.notifications.warn(`DAGGERHEART.UI.Notifications.${key}`, { localize: true });
|
||||||
|
return false;
|
||||||
await this.updateSource({ isMulticlass: true });
|
} else if (match.system.isMulticlass) {
|
||||||
}
|
await this.updateSource({ isMulticlass: true });
|
||||||
} else {
|
|
||||||
const actorClass = this.actor.items.find(x => x.type === 'class' && !x.system.isMulticlass);
|
|
||||||
if (!actorClass) {
|
|
||||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.missingClass'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((await actorClass.system.fetchSubclasses()).every(x => x.uuid !== dataUuid)) {
|
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.subclassNotInClass'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -281,6 +281,7 @@ export default class DhpActor extends Actor {
|
||||||
|
|
||||||
async levelUp(levelupData) {
|
async levelUp(levelupData) {
|
||||||
const levelupAuto = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).levelupAuto;
|
const levelupAuto = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).levelupAuto;
|
||||||
|
const getStatsWithSource = document => ({ ...(document._stats ?? {}), compendiumSource: document.uuid });
|
||||||
|
|
||||||
const levelups = {};
|
const levelups = {};
|
||||||
for (var levelKey of Object.keys(levelupData)) {
|
for (var levelKey of Object.keys(levelupData)) {
|
||||||
|
|
@ -393,8 +394,7 @@ export default class DhpActor extends Actor {
|
||||||
const embeddedItem = await this.createEmbeddedDocuments('Item', [
|
const embeddedItem = await this.createEmbeddedDocuments('Item', [
|
||||||
{
|
{
|
||||||
...multiclassData,
|
...multiclassData,
|
||||||
uuid: multiclassItem.uuid,
|
_stats: getStatsWithSource(multiclassItem),
|
||||||
_stats: multiclassItem._stats,
|
|
||||||
system: {
|
system: {
|
||||||
...multiclassData.system,
|
...multiclassData.system,
|
||||||
features: multiclassData.system.features.filter(x => x.type !== 'hope'),
|
features: multiclassData.system.features.filter(x => x.type !== 'hope'),
|
||||||
|
|
@ -407,8 +407,7 @@ export default class DhpActor extends Actor {
|
||||||
await this.createEmbeddedDocuments('Item', [
|
await this.createEmbeddedDocuments('Item', [
|
||||||
{
|
{
|
||||||
...subclassData,
|
...subclassData,
|
||||||
uuid: subclassItem.uuid,
|
_stats: getStatsWithSource(subclassItem),
|
||||||
_stats: subclassItem._stats,
|
|
||||||
system: {
|
system: {
|
||||||
...subclassData.system,
|
...subclassData.system,
|
||||||
isMulticlass: true
|
isMulticlass: true
|
||||||
|
|
@ -428,8 +427,7 @@ export default class DhpActor extends Actor {
|
||||||
const embeddedItem = await this.createEmbeddedDocuments('Item', [
|
const embeddedItem = await this.createEmbeddedDocuments('Item', [
|
||||||
{
|
{
|
||||||
...cardData,
|
...cardData,
|
||||||
uuid: cardItem.uuid,
|
_stats: getStatsWithSource(cardItem),
|
||||||
_stats: cardItem._stats,
|
|
||||||
system: {
|
system: {
|
||||||
...cardData.system,
|
...cardData.system,
|
||||||
inVault: true
|
inVault: true
|
||||||
|
|
@ -450,8 +448,7 @@ export default class DhpActor extends Actor {
|
||||||
const embeddedItem = await this.createEmbeddedDocuments('Item', [
|
const embeddedItem = await this.createEmbeddedDocuments('Item', [
|
||||||
{
|
{
|
||||||
...cardData,
|
...cardData,
|
||||||
uuid: cardItem.uuid,
|
_stats: getStatsWithSource(cardItem),
|
||||||
_stats: cardItem._stats,
|
|
||||||
system: {
|
system: {
|
||||||
...cardData.system,
|
...cardData.system,
|
||||||
inVault: true
|
inVault: true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue