Skip to content

Commit

Permalink
Wipe system.location.value when creating and constructing consumabl…
Browse files Browse the repository at this point in the history
…e spells (#14165)
  • Loading branch information
stwlam committed Mar 11, 2024
1 parent 7805152 commit 50ea160
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/module/item/consumable/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class ConsumablePF2e<TParent extends ActorPF2e | null = ActorPF2e | null> extend
if (!this.actor) throw ErrorPF2e(`No owning actor found for "${this.name}" (${this.id})`);
if (!this.system.spell) return null;

const spellSource = fu.mergeObject(this.system.spell, { "system.location.value": null }, { inplace: false });
const context = { parent: this.actor, parentItem: this };
const spell = new ItemProxyPF2e(fu.deepClone(this.system.spell), context) as SpellPF2e<NonNullable<TParent>>;
const spell = new ItemProxyPF2e(spellSource, context) as SpellPF2e<NonNullable<TParent>>;

const alterations = this.actor.rules.filter((r): r is ItemAlterationRuleElement => r.key === "ItemAlteration");
for (const alteration of alterations) {
Expand Down
10 changes: 6 additions & 4 deletions src/module/item/consumable/spell-consumables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async function createConsumableFromSpell(

const consumableSource = { ...consumable.toObject(), _id: null }; // Clear _id

const { traits } = consumableSource.system;
const traits = consumableSource.system.traits;
traits.value = R.uniq([...traits.value, ...spell.traits]);
traits.rarity = spell.rarity;
if (traits.value.includes("magical") && traits.value.some((t) => setHasElement(MAGIC_TRADITIONS, t))) {
Expand All @@ -112,9 +112,11 @@ async function createConsumableFromSpell(

// Cantrip deck casts at level 1
if (type !== "cantripDeck5") {
consumableSource.system.spell = spell
.clone({ _id: fu.randomID(), "system.location.heightenedLevel": heightenedLevel }, { keepId: true })
.toObject();
consumableSource.system.spell = fu.mergeObject(
spell._source,
{ _id: fu.randomID(), system: { location: { value: null, heightenedLevel } } },
{ inplace: false },
);
}

if (mystified) {
Expand Down

0 comments on commit 50ea160

Please sign in to comment.