diff --git a/SKSE/Plugins/EnderalSEEasyCrafting.dll b/SKSE/Plugins/EnderalSEEasyCrafting.dll index db27de7..ba0012b 100644 Binary files a/SKSE/Plugins/EnderalSEEasyCrafting.dll and b/SKSE/Plugins/EnderalSEEasyCrafting.dll differ diff --git a/src/src/EventListener.cpp b/src/src/EventListener.cpp index 52c5c50..21a2a53 100644 --- a/src/src/EventListener.cpp +++ b/src/src/EventListener.cpp @@ -29,7 +29,15 @@ auto EventListener::ProcessEvent( }); } } - } + } else if (a_event->eventName == "Enderal_StartSpectralizing") { + SKSE::GetTaskInterface()->AddTask([]() { + FetchSpectralizingSupplies(); + }); + } else if (a_event->eventName == "Enderal_FinishSpectralizing") { + SKSE::GetTaskInterface()->AddTask([]() { + ReturnSupplies(); + }); + } return RE::BSEventNotifyControl::kContinue; } diff --git a/src/src/Util.h b/src/src/Util.h index ed5d805..0ef3675 100644 --- a/src/src/Util.h +++ b/src/src/Util.h @@ -93,6 +93,31 @@ inline void FetchSuppliesByType(RE::FormType formType) } } + +inline void FetchSuppliesByForm(RE::TESForm* a_form) +{ + if (!a_form) { + return; + } + + const auto chest = RE::TESForm::LookupByID(0x5C132)->As(); + const auto targetRef = RE::PlayerCharacter::GetSingleton(); + + const auto inv = chest->GetInventory([&](RE::TESBoundObject& a_xform) { + return a_form == &a_xform; + }); + + RE::ITEM_REMOVE_REASON iReason = RE::ITEM_REMOVE_REASON::kStoreInContainer; + + for (const auto& [item, data] : inv) { + const auto& [count, entry] = data; + if (count > 0) { + supplyCount.insert({ item, count }); + chest->RemoveItem(item, count, iReason, nullptr, targetRef, 0, 0); + } + } +} + inline void ReturnSupplies() { if (!bSuppliesFetched) { @@ -248,4 +273,18 @@ inline void FetchSupplies(RE::TESFurniture* a_furn) inline bool GetSuppliesFetched() { return bSuppliesFetched; -} \ No newline at end of file +} + +inline void FetchSpectralizingSupplies() +{ + if (GetSettings().at("ShowFetchingNotification")) { + RE::DebugNotification("Fetching spectralizing supplies..."); + } + + bSuppliesFetched = true; + + supplyCount.clear(); + FetchSuppliesByType(RE::FormType::SoulGem); + FetchSuppliesByForm(RE::TESForm::LookupByID(0x34CDD)); // Bone Meal + FetchSuppliesByForm(RE::TESForm::LookupByID(0x3AD63)); // Ectoplasm +}