Fix removal when de-leveling

This commit is contained in:
Carlos Fernandez 2026-05-19 23:36:28 -04:00
parent 13bcadf142
commit f95e511a4d

View file

@ -233,16 +233,14 @@ export default class DhpActor extends Actor {
if (multiclass) { if (multiclass) {
const multiclassItem = this.items.find(x => x.uuid === multiclass.itemUuid); const multiclassItem = this.items.find(x => x.uuid === multiclass.itemUuid);
const multiclassFeatures = this.items.filter( const multiclassRelatedFeatures = this.items.filter(
x => x.system.originItemType === 'class' && x.system.multiclassOrigin x => ['class', 'subclass'].includes(x.system.originItemType) && x.system.multiclassOrigin
);
const subclassFeatures = this.items.filter(
x => x.system.originItemType === 'subclass' && x.system.multiclassOrigin
); );
if (!multiclassItem) console.error('Unexpected missing multiclass item to remove');
this.deleteEmbeddedDocuments( this.deleteEmbeddedDocuments(
'Item', 'Item',
[multiclassItem, ...multiclassFeatures, ...subclassFeatures].map(x => x.id) [multiclassItem, ...multiclassRelatedFeatures].filter(i => !!i).map(x => x.id)
); );
this.update({ this.update({
@ -394,6 +392,7 @@ export default class DhpActor extends Actor {
const embeddedItem = await this.createEmbeddedDocuments('Item', [ const embeddedItem = await this.createEmbeddedDocuments('Item', [
{ {
...multiclassData, ...multiclassData,
uuid: multiclassItem.uuid, // todo: replace with setting an id and using keepId
_stats: getStatsWithSource(multiclassItem), _stats: getStatsWithSource(multiclassItem),
system: { system: {
...multiclassData.system, ...multiclassData.system,
@ -407,6 +406,7 @@ export default class DhpActor extends Actor {
await this.createEmbeddedDocuments('Item', [ await this.createEmbeddedDocuments('Item', [
{ {
...subclassData, ...subclassData,
uuid: subclassItem.uuid, // todo: replace with setting an id and using keepId
_stats: getStatsWithSource(subclassItem), _stats: getStatsWithSource(subclassItem),
system: { system: {
...subclassData.system, ...subclassData.system,
@ -427,6 +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, // todo: replace with setting an id and using keepId
_stats: getStatsWithSource(cardItem), _stats: getStatsWithSource(cardItem),
system: { system: {
...cardData.system, ...cardData.system,