Added support for equipment spectralization

This commit is contained in:
Eddoursul 2022-08-18 16:08:39 +02:00
parent ddb85480d2
commit 52b2ab878d
3 changed files with 49 additions and 2 deletions

View File

@ -29,6 +29,14 @@ 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;

View File

@ -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<RE::TESObjectREFR>();
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) {
@ -249,3 +274,17 @@ inline bool GetSuppliesFetched()
{
return bSuppliesFetched;
}
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
}