Do not attempt returning when no supplies were transferred

This commit is contained in:
Eddoursul 2022-08-22 21:21:38 +02:00
parent 1512178edd
commit 40b946d83e
3 changed files with 24 additions and 16 deletions

View File

@ -59,10 +59,11 @@ auto EventListener::ProcessEvent(
} }
SKSE::GetTaskInterface()->AddTask([furn]() { SKSE::GetTaskInterface()->AddTask([furn]() {
if (!FetchSupplies(furn)) {
FetchSupplies(furn); return;
}
std::thread([]() { std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
SKSE::GetTaskInterface()->AddTask([]() { SKSE::GetTaskInterface()->AddTask([]() {
// Trigger item list update, this trick works only with the kCreateObject workbenches // Trigger item list update, this trick works only with the kCreateObject workbenches
if (auto scriptFactory = RE::IFormFactory::GetConcreteFormFactoryByType<RE::Script>()) { if (auto scriptFactory = RE::IFormFactory::GetConcreteFormFactoryByType<RE::Script>()) {
@ -117,17 +118,22 @@ auto EventListener::ProcessEvent(
return; return;
} }
SKSE::GetTaskInterface()->AddTask([furn]() { SKSE::GetTaskInterface()->AddTask([furn]() {
FetchSupplies(furn); if (!FetchSupplies(furn)) {
return;
}
std::thread([]() {
const auto playerRef = RE::PlayerCharacter::GetSingleton();
while (playerRef->GetSitSleepState() == RE::SIT_SLEEP_STATE::kWantToSit || playerRef->GetSitSleepState() == RE::SIT_SLEEP_STATE::kWaitingForSitAnim) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
if (!RE::UI::GetSingleton()->IsMenuOpen(RE::CraftingMenu::MENU_NAME)) {
SKSE::GetTaskInterface()->AddTask([]() {
ReturnSupplies();
});
}
}).detach();
}); });
while (playerRef->GetSitSleepState() == RE::SIT_SLEEP_STATE::kWantToSit || playerRef->GetSitSleepState() == RE::SIT_SLEEP_STATE::kWaitingForSitAnim) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
if (!RE::UI::GetSingleton()->IsMenuOpen(RE::CraftingMenu::MENU_NAME)) {
SKSE::GetTaskInterface()->AddTask([]() {
ReturnSupplies();
});
}
}).detach(); }).detach();
return RE::BSEventNotifyControl::kContinue; return RE::BSEventNotifyControl::kContinue;

View File

@ -239,10 +239,10 @@ inline void ReturnSupplies()
}).detach(); }).detach();
} }
inline void FetchSupplies(RE::TESFurniture* a_furn) inline bool FetchSupplies(RE::TESFurniture* a_furn)
{ {
if (!a_furn) { if (!a_furn) {
return; return false;
} }
supplyCount.clear(); supplyCount.clear();
@ -264,7 +264,7 @@ inline void FetchSupplies(RE::TESFurniture* a_furn)
} }
if (!bAllowFetch) { if (!bAllowFetch) {
return; return false;
} }
bSuppliesFetched = true; bSuppliesFetched = true;
@ -299,6 +299,8 @@ inline void FetchSupplies(RE::TESFurniture* a_furn)
} }
}); });
}).detach(); }).detach();
return true;
} }
inline bool GetSuppliesFetched() inline bool GetSuppliesFetched()