Correctly clone and remap default preset before returning

This commit is contained in:
Dev 2024-02-03 12:15:20 +00:00
parent e3cf4c3c92
commit 0a6a866ae8
3 changed files with 13 additions and 6 deletions

View File

@ -79,7 +79,7 @@ export class QuestController
for (const quest of allQuests)
{
// Player already accepted the quest, show it regardless of status
const questInProfile = profile.Quests.find((x) => x.qid === quest._id);
const questInProfile = profile.Quests.find((quest) => quest.qid === quest._id);
if (questInProfile)
{
quest.sptStatus = questInProfile.status;

View File

@ -1415,8 +1415,9 @@ export class ItemHelper
* Update a root items _id property value to be unique
* @param itemWithChildren Item to update root items _id property
* @param newId Optional: new id to use
* @returns New root id
*/
public remapRootItemId(itemWithChildren: Item[], newId = this.hashUtil.generate()): void
public remapRootItemId(itemWithChildren: Item[], newId = this.hashUtil.generate()): string
{
const rootItemExistingId = itemWithChildren[0]._id;
@ -1436,6 +1437,8 @@ export class ItemHelper
item.parentId = newId;
}
}
return newId;
}
}

View File

@ -272,7 +272,7 @@ export class QuestHelper
// Only process items with slots
if (this.itemHelper.itemHasSlots(questReward.items[0]._tpl))
{
// Attempt to pull default preset from globals and add child items to reward
// Attempt to pull default preset from globals and add child items to reward (clones questReward.items)
this.generateArmorRewardChildSlots(questReward.items[0], questReward);
}
}
@ -283,7 +283,8 @@ export class QuestHelper
{
item.upd = {};
}
// reward items are granted Found in Raid status
// Reward items are granted Found in Raid status
item.upd.SpawnedInSession = true;
// Is root item, fix stacks
@ -349,10 +350,13 @@ export class QuestHelper
if (defaultPreset)
{
// Preset exists, use mods to hydrate reward item
questReward.items = this.jsonUtil.clone(defaultPreset._items);
const presetAndMods: Item[] = this.itemHelper.replaceIDs(null, this.jsonUtil.clone(defaultPreset._items));
const newRootId = this.itemHelper.remapRootItemId(presetAndMods);
questReward.items = presetAndMods;
// Remap target id to the new presets id
questReward.target = questReward.items.find((item) => item._tpl === originalRewardRootItem._tpl)._id;
questReward.target = newRootId;
return;
}