Skip to content

Commit

Permalink
manually calc leveled items
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Mar 14, 2024
1 parent 1d96c85 commit f7fffe2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions SPID/include/Distribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ namespace Distribute
// items
template <class Form>
void for_each_form(
const NPCData& a_npcData,
Forms::Distributables<Form>& a_distributables,
const PCLevelMult::Input& a_input,
std::function<bool(std::map<Form*, IdxOrCount>&, bool)> a_callback)
const NPCData& a_npcData,
Forms::Distributables<Form>& a_distributables,
const PCLevelMult::Input& a_input,
std::function<bool(std::map<Form*, IdxOrCount>&)> a_callback)
{
auto& vec = a_distributables.GetForms(a_input.onlyPlayerLevelEntries);

Expand All @@ -140,20 +140,26 @@ namespace Distribute
}

std::map<Form*, IdxOrCount> 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<RE::TESLevItem>()) {
auto level = a_npcData.GetLevel();
RE::BSScrapArray<RE::CALCED_OBJECT> calcedObjects{};

leveledItem->CalculateCurrentFormList(level, formData.idxOrCount, calcedObjects, 0, true);
for (auto& calcObj : calcedObjects) {
collectedForms[static_cast<RE::TESBoundObject*>(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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion SPID/src/Distribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ namespace Distribute
return false;
});

for_each_form<RE::TESBoundObject>(a_npcData, Forms::items, a_input, [&](std::map<RE::TESBoundObject*, IdxOrCount>& a_objects, const bool a_hasLvlItem) {
for_each_form<RE::TESBoundObject>(a_npcData, Forms::items, a_input, [&](std::map<RE::TESBoundObject*, IdxOrCount>& a_objects) {
return npc->AddObjectsToContainer(a_objects, npc);
});

Expand Down

0 comments on commit f7fffe2

Please sign in to comment.