mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49:02 +01:00
Removed automatic deletion of features on delevel when not using levelup auto
This commit is contained in:
parent
ac16b00271
commit
6c258c6853
1 changed files with 78 additions and 72 deletions
|
|
@ -84,6 +84,8 @@ export default class DhpActor extends Actor {
|
||||||
|
|
||||||
await this.update({ 'system.levelData.level.changed': Math.min(newLevel, maxLevel) });
|
await this.update({ 'system.levelData.level.changed': Math.min(newLevel, maxLevel) });
|
||||||
} else {
|
} else {
|
||||||
|
const levelupAuto = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).levelupAuto;
|
||||||
|
|
||||||
const usedLevel = Math.max(newLevel, 1);
|
const usedLevel = Math.max(newLevel, 1);
|
||||||
if (newLevel < 1) {
|
if (newLevel < 1) {
|
||||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.tooLowLevel'));
|
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.tooLowLevel'));
|
||||||
|
|
@ -95,86 +97,90 @@ export default class DhpActor extends Actor {
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const features = [];
|
if (levelupAuto) {
|
||||||
const domainCards = [];
|
const features = [];
|
||||||
const experiences = [];
|
const domainCards = [];
|
||||||
const subclassFeatureState = { class: null, multiclass: null };
|
const experiences = [];
|
||||||
let multiclass = null;
|
const subclassFeatureState = { class: null, multiclass: null };
|
||||||
Object.keys(this.system.levelData.levelups)
|
let multiclass = null;
|
||||||
.filter(x => x > usedLevel)
|
Object.keys(this.system.levelData.levelups)
|
||||||
.forEach(levelKey => {
|
.filter(x => x > usedLevel)
|
||||||
const level = this.system.levelData.levelups[levelKey];
|
.forEach(levelKey => {
|
||||||
const achievementCards = level.achievements.domainCards.map(x => x.itemUuid);
|
const level = this.system.levelData.levelups[levelKey];
|
||||||
const advancementCards = level.selections.filter(x => x.type === 'domainCard').map(x => x.itemUuid);
|
const achievementCards = level.achievements.domainCards.map(x => x.itemUuid);
|
||||||
domainCards.push(...achievementCards, ...advancementCards);
|
const advancementCards = level.selections
|
||||||
experiences.push(...Object.keys(level.achievements.experiences));
|
.filter(x => x.type === 'domainCard')
|
||||||
features.push(...level.selections.flatMap(x => x.features));
|
.map(x => x.itemUuid);
|
||||||
|
domainCards.push(...achievementCards, ...advancementCards);
|
||||||
|
experiences.push(...Object.keys(level.achievements.experiences));
|
||||||
|
features.push(...level.selections.flatMap(x => x.features));
|
||||||
|
|
||||||
const subclass = level.selections.find(x => x.type === 'subclass');
|
const subclass = level.selections.find(x => x.type === 'subclass');
|
||||||
if (subclass) {
|
if (subclass) {
|
||||||
const path = subclass.secondaryData.isMulticlass === 'true' ? 'multiclass' : 'class';
|
const path = subclass.secondaryData.isMulticlass === 'true' ? 'multiclass' : 'class';
|
||||||
const subclassState = Number(subclass.secondaryData.featureState) - 1;
|
const subclassState = Number(subclass.secondaryData.featureState) - 1;
|
||||||
subclassFeatureState[path] = subclassFeatureState[path]
|
subclassFeatureState[path] = subclassFeatureState[path]
|
||||||
? Math.min(subclassState, subclassFeatureState[path])
|
? Math.min(subclassState, subclassFeatureState[path])
|
||||||
: subclassState;
|
: subclassState;
|
||||||
}
|
}
|
||||||
|
|
||||||
multiclass = level.selections.find(x => x.type === 'multiclass');
|
multiclass = level.selections.find(x => x.type === 'multiclass');
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let feature of features) {
|
for (let feature of features) {
|
||||||
if (feature.onPartner && !this.system.partner) continue;
|
if (feature.onPartner && !this.system.partner) continue;
|
||||||
|
|
||||||
const document = feature.onPartner ? this.system.partner : this;
|
const document = feature.onPartner ? this.system.partner : this;
|
||||||
document.items.get(feature.id)?.delete();
|
document.items.get(feature.id)?.delete();
|
||||||
}
|
|
||||||
|
|
||||||
if (experiences.length > 0) {
|
|
||||||
const getUpdate = () => ({
|
|
||||||
'system.experiences': experiences.reduce((acc, key) => {
|
|
||||||
acc[`-=${key}`] = null;
|
|
||||||
return acc;
|
|
||||||
}, {})
|
|
||||||
});
|
|
||||||
this.update(getUpdate());
|
|
||||||
if (this.system.companion) {
|
|
||||||
this.system.companion.update(getUpdate());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (subclassFeatureState.class) {
|
if (experiences.length > 0) {
|
||||||
this.system.class.subclass.update({ 'system.featureState': subclassFeatureState.class });
|
const getUpdate = () => ({
|
||||||
}
|
'system.experiences': experiences.reduce((acc, key) => {
|
||||||
|
acc[`-=${key}`] = null;
|
||||||
if (subclassFeatureState.multiclass) {
|
return acc;
|
||||||
this.system.multiclass.subclass.update({ 'system.featureState': subclassFeatureState.multiclass });
|
}, {})
|
||||||
}
|
});
|
||||||
|
this.update(getUpdate());
|
||||||
if (multiclass) {
|
if (this.system.companion) {
|
||||||
const multiclassItem = this.items.find(x => x.uuid === multiclass.itemUuid);
|
this.system.companion.update(getUpdate());
|
||||||
const multiclassFeatures = this.items.filter(
|
|
||||||
x => x.system.originItemType === 'class' && x.system.identifier === 'multiclass'
|
|
||||||
);
|
|
||||||
const subclassFeatures = this.items.filter(
|
|
||||||
x => x.system.originItemType === 'subclass' && x.system.identifier === 'multiclass'
|
|
||||||
);
|
|
||||||
|
|
||||||
this.deleteEmbeddedDocuments(
|
|
||||||
'Item',
|
|
||||||
[multiclassItem, ...multiclassFeatures, ...subclassFeatures].map(x => x.id)
|
|
||||||
);
|
|
||||||
|
|
||||||
this.update({
|
|
||||||
'system.multiclass': {
|
|
||||||
value: null,
|
|
||||||
subclass: null
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (let domainCard of domainCards) {
|
if (subclassFeatureState.class) {
|
||||||
const itemCard = this.items.find(x => x.uuid === domainCard);
|
this.system.class.subclass.update({ 'system.featureState': subclassFeatureState.class });
|
||||||
itemCard.delete();
|
}
|
||||||
|
|
||||||
|
if (subclassFeatureState.multiclass) {
|
||||||
|
this.system.multiclass.subclass.update({ 'system.featureState': subclassFeatureState.multiclass });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (multiclass) {
|
||||||
|
const multiclassItem = this.items.find(x => x.uuid === multiclass.itemUuid);
|
||||||
|
const multiclassFeatures = this.items.filter(
|
||||||
|
x => x.system.originItemType === 'class' && x.system.identifier === 'multiclass'
|
||||||
|
);
|
||||||
|
const subclassFeatures = this.items.filter(
|
||||||
|
x => x.system.originItemType === 'subclass' && x.system.identifier === 'multiclass'
|
||||||
|
);
|
||||||
|
|
||||||
|
this.deleteEmbeddedDocuments(
|
||||||
|
'Item',
|
||||||
|
[multiclassItem, ...multiclassFeatures, ...subclassFeatures].map(x => x.id)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.update({
|
||||||
|
'system.multiclass': {
|
||||||
|
value: null,
|
||||||
|
subclass: null
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let domainCard of domainCards) {
|
||||||
|
const itemCard = this.items.find(x => x.uuid === domainCard);
|
||||||
|
itemCard.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.update({
|
await this.update({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue