From 8130a80e0555da05da22ba8f161ec50ca8041a07 Mon Sep 17 00:00:00 2001 From: Eddoursul Date: Fri, 9 Sep 2022 23:10:55 +0200 Subject: [PATCH] Quest potion support --- src/src/Util.h | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/src/Util.h b/src/src/Util.h index b21ef71..5f30b23 100644 --- a/src/src/Util.h +++ b/src/src/Util.h @@ -158,6 +158,23 @@ inline void FetchSuppliesByForm(RE::TESForm* a_form) } } +inline bool IsQuestItem(RE::TESForm* a_form, RE::TESQuest* questElixir, RE::TESQuest* questCuthbert) +{ + if (questElixir) { + if (a_form->formID == 0x34D22 || a_form->formID == 0x727E0 || a_form->formID == 0x3AD6F || a_form->formID == 0x59B86) { + return true; + } + } + + if (questCuthbert) { + if (a_form->formID == 0x891AF || a_form->formID == 0x34C5D || a_form->formID == 0x34D32) { + return true; + } + } + + return false; +} + inline void ReturnSupplies() { if (!bSuppliesFetched) { @@ -171,8 +188,21 @@ inline void ReturnSupplies() const auto chest = GetChest(); const auto playerRef = RE::PlayerCharacter::GetSingleton(); + auto questElixir = RE::TESDataHandler::GetSingleton()->LookupForm(0x1C82F, "Enderal - Forgotten Stories.esm"); // FS_NQ05 + auto questCuthbert = RE::TESDataHandler::GetSingleton()->LookupForm(0x1CA09, "Enderal - Forgotten Stories.esm"); // FS_NQ07 + + if (questElixir->currentStage != 35) { + questElixir = nullptr; + } + + if (questCuthbert->currentStage != 115) { + questCuthbert = nullptr; + } + for (auto& item : supplyCount) { - playerRef->RemoveItem(item.first->As(), item.second, iRemoveReason, nullptr, chest, 0, 0); + if (!IsQuestItem(item.first, questElixir, questCuthbert)) { + playerRef->RemoveItem(item.first->As(), item.second, iRemoveReason, nullptr, chest, 0, 0); + } } supplyCount.clear(); @@ -199,9 +229,7 @@ inline void ReturnSupplies() const auto keywords = component->obj->As(); - if (component->obj->Is(RE::FormType::Ingredient)) { - suppliesToStore.insert(component->obj); - } else if (component->obj->Is(RE::FormType::Misc) && !component->obj->IsGold() && !component->obj->IsLockpick()) { + if (component->obj->Is(RE::FormType::Misc) && !component->obj->IsGold() && !component->obj->IsLockpick()) { if (keywords->HasKeyword(kOreIngot) || keywords->HasKeyword(kAnimalPart) || keywords->HasKeyword(kAnimalHide) || keywords->HasKeyword(kFirewood) || keywords->HasKeyword(kTool) || keywords->HasKeyword(kClutter) || keywords->HasKeyword(kFoodRaw)) { suppliesToStore.insert(component->obj); } @@ -214,12 +242,12 @@ inline void ReturnSupplies() } const auto inv = playerRef->GetInventory([&](RE::TESBoundObject& a_form) { - return suppliesToStore.contains(&a_form); + return a_form.Is(RE::FormType::Ingredient) || suppliesToStore.contains(&a_form); }); for (const auto& [item, data] : inv) { const auto& [count, entry] = data; - if (count > 0 && !entry->IsFavorited() && !entry->IsQuestObject()) { + if (count > 0 && !entry->IsFavorited() && !entry->IsQuestObject() && !IsQuestItem(item, questElixir, questCuthbert)) { playerRef->RemoveItem(item, count, iRemoveReason, nullptr, chest, 0, 0); } }