diff --git a/SPID/include/Distribute.h b/SPID/include/Distribute.h index a9b0751..f88545f 100644 --- a/SPID/include/Distribute.h +++ b/SPID/include/Distribute.h @@ -128,10 +128,10 @@ namespace Distribute // items template void for_each_form( - const NPCData& a_npcData, - Forms::Distributables
& a_distributables, - const PCLevelMult::Input& a_input, - std::function&, bool)> a_callback) + const NPCData& a_npcData, + Forms::Distributables& a_distributables, + const PCLevelMult::Input& a_input, + std::function&)> a_callback) { auto& vec = a_distributables.GetForms(a_input.onlyPlayerLevelEntries); @@ -140,20 +140,26 @@ namespace Distribute } std::map collectedForms{}; - bool hasLeveledItems = false; for (auto& formData : vec) { if (detail::passed_filters(a_npcData, a_input, formData)) { - if (formData.form->Is(RE::FormType::LeveledItem)) { - hasLeveledItems = true; + if (auto leveledItem = formData.form->As()) { + auto level = a_npcData.GetLevel(); + RE::BSScrapArray calcedObjects{}; + + leveledItem->CalculateCurrentFormList(level, formData.idxOrCount, calcedObjects, 0, true); + for (auto& calcObj : calcedObjects) { + collectedForms[static_cast(calcObj.form)] += calcObj.count; + } + } else { + collectedForms[formData.form] += formData.idxOrCount; } - collectedForms[formData.form] += formData.idxOrCount; ++formData.npcCount; } } if (!collectedForms.empty()) { - a_callback(collectedForms, hasLeveledItems); + a_callback(collectedForms); } } diff --git a/SPID/src/Distribute.cpp b/SPID/src/Distribute.cpp index c55a951..2f3d4de 100644 --- a/SPID/src/Distribute.cpp +++ b/SPID/src/Distribute.cpp @@ -123,7 +123,7 @@ namespace Distribute return false; }); - for_each_form(a_npcData, Forms::items, a_input, [&](std::map& a_objects, const bool a_hasLvlItem) { + for_each_form(a_npcData, Forms::items, a_input, [&](std::map& a_objects) { return npc->AddObjectsToContainer(a_objects, npc); });