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]() {
FetchSupplies(furn);
if (!FetchSupplies(furn)) {
return;
}
std::thread([]() {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
SKSE::GetTaskInterface()->AddTask([]() {
// Trigger item list update, this trick works only with the kCreateObject workbenches
if (auto scriptFactory = RE::IFormFactory::GetConcreteFormFactoryByType<RE::Script>()) {
@ -117,17 +118,22 @@ auto EventListener::ProcessEvent(
return;
}
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();
return RE::BSEventNotifyControl::kContinue;

View File

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