Always run SyncCellStorage as a task
This commit is contained in:
parent
1fedd07be1
commit
deaac1c723
Binary file not shown.
@ -269,9 +269,7 @@ namespace ArtifactTracker
|
|||||||
g_bBookShelf = false;
|
g_bBookShelf = false;
|
||||||
std::thread([]() {
|
std::thread([]() {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1200));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1200));
|
||||||
SKSE::GetTaskInterface()->AddTask([&]() {
|
ArtifactTracker::SyncCellStorage();
|
||||||
ArtifactTracker::SyncCellStorage();
|
|
||||||
});
|
|
||||||
}).detach();
|
}).detach();
|
||||||
} else {
|
} else {
|
||||||
SyncCellStorage();
|
SyncCellStorage();
|
||||||
@ -377,8 +375,8 @@ namespace ArtifactTracker
|
|||||||
log::info("Adding new storage in {}", cell->GetName());
|
log::info("Adding new storage in {}", cell->GetName());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SKSE::GetTaskInterface()->AddTask([&]() {
|
SKSE::GetTaskInterface()->AddTask([]() {
|
||||||
cellStorage = RE::PlayerCharacter::GetSingleton()->PlaceObjectAtMe(g_cellContainer, true).get();
|
const auto cellStorage = RE::PlayerCharacter::GetSingleton()->PlaceObjectAtMe(g_cellContainer, true).get();
|
||||||
|
|
||||||
if (cellStorage) {
|
if (cellStorage) {
|
||||||
cellStorage->Disable();
|
cellStorage->Disable();
|
||||||
@ -406,83 +404,86 @@ namespace ArtifactTracker
|
|||||||
log::info("Running SyncCellStorage");
|
log::info("Running SyncCellStorage");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::unordered_set<RE::FormID> cellItems;
|
const RE::FormID ignoreFormID = a_ignoreRef ? a_ignoreRef->formID : NULL;
|
||||||
|
|
||||||
const auto cell = g_cellStorage->GetParentCell();
|
SKSE::GetTaskInterface()->AddTask([ignoreFormID]() {
|
||||||
const auto inv = g_cellStorage->GetInventory();
|
std::unordered_set<RE::FormID> cellItems;
|
||||||
|
|
||||||
cell->ForEachReference([&](RE::TESObjectREFR& a_ref) {
|
const auto cell = g_cellStorage->GetParentCell();
|
||||||
if (a_ignoreRef && a_ignoreRef->formID == a_ref.formID) {
|
const auto inv = g_cellStorage->GetInventory();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto baseObj = a_ref.GetBaseObject();
|
cell->ForEachReference([&](RE::TESObjectREFR& a_ref) {
|
||||||
|
if (ignoreFormID && ignoreFormID == a_ref.formID) {
|
||||||
if (IsValidContainer(&a_ref)) {
|
|
||||||
if (g_cellContainer == baseObj || baseObj->formID == 0xDC9E7 || g_persistentMap.contains(a_ref.formID)) { // skip persistent and PlayerBookShelfContainer
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto contInv = a_ref.GetInventory([&](RE::TESBoundObject& a_object) -> bool {
|
const auto baseObj = a_ref.GetBaseObject();
|
||||||
return !cellItems.contains(a_object.formID) && IsArtifact(&a_object);
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const auto& [item, data] : contInv) {
|
if (IsValidContainer(&a_ref)) {
|
||||||
if (data.first > 0) {
|
if (g_cellContainer == baseObj || baseObj->formID == 0xDC9E7 || g_persistentMap.contains(a_ref.formID)) { // skip persistent and PlayerBookShelfContainer
|
||||||
cellItems.insert(item->formID);
|
return true;
|
||||||
if (inv.find(item) == inv.end()) {
|
}
|
||||||
g_cellStorage->AddObjectToContainer(item, nullptr, 1, nullptr);
|
|
||||||
|
const auto contInv = a_ref.GetInventory([&](RE::TESBoundObject& a_object) -> bool {
|
||||||
|
return !cellItems.contains(a_object.formID) && IsArtifact(&a_object);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const auto& [item, data] : contInv) {
|
||||||
|
if (data.first > 0) {
|
||||||
|
cellItems.insert(item->formID);
|
||||||
|
if (inv.find(item) == inv.end()) {
|
||||||
|
g_cellStorage->AddObjectToContainer(item, nullptr, 1, nullptr);
|
||||||
|
}
|
||||||
|
if (!g_listStored->HasForm(item)) {
|
||||||
|
ListRemoveItem(g_listNew, item);
|
||||||
|
ListRemoveItem(g_listFound, item);
|
||||||
|
g_listStored->AddForm(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!g_listStored->HasForm(item)) {
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a_ref.IsDisabled() || a_ref.IsMarkedForDeletion() || cellItems.contains(baseObj->formID) || !IsArtifact(baseObj)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
cellItems.insert(baseObj->formID);
|
||||||
|
|
||||||
|
if (inv.find(baseObj) == inv.end()) {
|
||||||
|
g_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!g_listStored->HasForm(baseObj)) {
|
||||||
|
ListRemoveItem(g_listNew, baseObj);
|
||||||
|
ListRemoveItem(g_listFound, baseObj);
|
||||||
|
g_listStored->AddForm(baseObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const auto& [item, data] : inv) {
|
||||||
|
const auto& [count, entry] = data;
|
||||||
|
if (count > 0 && !cellItems.contains(item->formID)) {
|
||||||
|
g_cellStorage->RemoveItem(item, count, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr);
|
||||||
|
|
||||||
|
if (!RefListHasItem(g_persistentStorage, item->formID)) {
|
||||||
|
ListRemoveItem(g_listStored, item);
|
||||||
|
if (GetItemCount(RE::PlayerCharacter::GetSingleton(), item) || FollowersHaveItem(item)) {
|
||||||
ListRemoveItem(g_listNew, item);
|
ListRemoveItem(g_listNew, item);
|
||||||
|
g_listFound->AddForm(item);
|
||||||
|
} else {
|
||||||
ListRemoveItem(g_listFound, item);
|
ListRemoveItem(g_listFound, item);
|
||||||
g_listStored->AddForm(item);
|
g_listNew->AddForm(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a_ref.IsDisabled() || a_ref.IsMarkedForDeletion() || cellItems.contains(baseObj->formID) || !IsArtifact(baseObj)) {
|
cellItems.clear();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
cellItems.insert(baseObj->formID);
|
|
||||||
|
|
||||||
if (inv.find(baseObj) == inv.end()) {
|
|
||||||
g_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!g_listStored->HasForm(baseObj)) {
|
|
||||||
ListRemoveItem(g_listNew, baseObj);
|
|
||||||
ListRemoveItem(g_listFound, baseObj);
|
|
||||||
g_listStored->AddForm(baseObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const auto& [item, data] : inv) {
|
|
||||||
const auto& [count, entry] = data;
|
|
||||||
if (count > 0 && !cellItems.contains(item->formID)) {
|
|
||||||
|
|
||||||
g_cellStorage->RemoveItem(item, count, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr);
|
|
||||||
|
|
||||||
if (!RefListHasItem(g_persistentStorage, item->formID)) {
|
|
||||||
ListRemoveItem(g_listStored, item);
|
|
||||||
if (GetItemCount(RE::PlayerCharacter::GetSingleton(), item) || FollowersHaveItem(item)) {
|
|
||||||
ListRemoveItem(g_listNew, item);
|
|
||||||
g_listFound->AddForm(item);
|
|
||||||
} else {
|
|
||||||
ListRemoveItem(g_listFound, item);
|
|
||||||
g_listNew->AddForm(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cellItems.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnContainerChanged(const RE::TESContainerChangedEvent* a_event, RE::TESForm* form)
|
void OnContainerChanged(const RE::TESContainerChangedEvent* a_event, RE::TESForm* form)
|
||||||
@ -759,7 +760,7 @@ namespace ArtifactTracker
|
|||||||
g_iFollowerIndex = iCurrentFollowers;
|
g_iFollowerIndex = iCurrentFollowers;
|
||||||
std::thread([]() {
|
std::thread([]() {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // wait for followers to load into the new cell
|
std::this_thread::sleep_for(std::chrono::milliseconds(3000)); // wait for followers to load into the new cell
|
||||||
SKSE::GetTaskInterface()->AddTask([&]() {
|
SKSE::GetTaskInterface()->AddTask([]() {
|
||||||
RescanFoundArtifacts();
|
RescanFoundArtifacts();
|
||||||
});
|
});
|
||||||
}).detach();
|
}).detach();
|
||||||
|
@ -84,22 +84,26 @@ auto EventListener::ProcessEvent(
|
|||||||
SKSE::log::info("MenuOpenCloseEvent");
|
SKSE::log::info("MenuOpenCloseEvent");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (a_event->opening) {
|
bool bOpening = a_event->opening;
|
||||||
RE::BSInputDeviceManager::GetSingleton()->AddEventSink(EventListener::GetSingleton());
|
|
||||||
} else {
|
|
||||||
RE::BSInputDeviceManager::GetSingleton()->RemoveEventSink(EventListener::GetSingleton());
|
|
||||||
if (ArtifactTracker::g_bTakeAll && ArtifactTracker::g_bNotifyNewArtifact && ArtifactTracker::g_bTakeAllCount > 0) {
|
|
||||||
//RE::DebugNotification(fmt::format("{} new artifact(s) acquired", ArtifactTracker::g_bTakeAllCount).c_str());
|
|
||||||
RE::BSTSmartPointer<RE::BSScript::IStackCallbackFunctor> stackCallback;
|
|
||||||
RE::BSScript::Internal::VirtualMachine::GetSingleton()->DispatchStaticCall("ETR_NewArtifactsCombinedNotification", "Show", RE::MakeFunctionArguments<std::uint32_t>(std::move(ArtifactTracker::g_bTakeAllCount)), stackCallback);
|
|
||||||
}
|
|
||||||
ArtifactTracker::g_bTakeAll = false;
|
|
||||||
ArtifactTracker::g_bTakeAllCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ArtifactTracker::IsHome()) {
|
SKSE::GetTaskInterface()->AddTask([bOpening]() {
|
||||||
ArtifactTracker::SetContainerMode(a_event->opening);
|
if (bOpening) {
|
||||||
}
|
RE::BSInputDeviceManager::GetSingleton()->AddEventSink(EventListener::GetSingleton());
|
||||||
|
} else {
|
||||||
|
RE::BSInputDeviceManager::GetSingleton()->RemoveEventSink(EventListener::GetSingleton());
|
||||||
|
if (ArtifactTracker::g_bTakeAll && ArtifactTracker::g_bNotifyNewArtifact && ArtifactTracker::g_bTakeAllCount > 0) {
|
||||||
|
//RE::DebugNotification(fmt::format("{} new artifact(s) acquired", ArtifactTracker::g_bTakeAllCount).c_str());
|
||||||
|
RE::BSTSmartPointer<RE::BSScript::IStackCallbackFunctor> stackCallback;
|
||||||
|
RE::BSScript::Internal::VirtualMachine::GetSingleton()->DispatchStaticCall("ETR_NewArtifactsCombinedNotification", "Show", RE::MakeFunctionArguments<std::uint32_t>(std::move(ArtifactTracker::g_bTakeAllCount)), stackCallback);
|
||||||
|
}
|
||||||
|
ArtifactTracker::g_bTakeAll = false;
|
||||||
|
ArtifactTracker::g_bTakeAllCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ArtifactTracker::IsHome()) {
|
||||||
|
ArtifactTracker::SetContainerMode(bOpening);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return RE::BSEventNotifyControl::kContinue;
|
return RE::BSEventNotifyControl::kContinue;
|
||||||
@ -116,9 +120,7 @@ auto EventListener::ProcessEvent(
|
|||||||
if (ref && ArtifactTracker::IsArtifact(ref->GetBaseObject())) {
|
if (ref && ArtifactTracker::IsArtifact(ref->GetBaseObject())) {
|
||||||
std::thread([]() {
|
std::thread([]() {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||||
SKSE::GetTaskInterface()->AddTask([&]() {
|
ArtifactTracker::SyncCellStorage();
|
||||||
ArtifactTracker::SyncCellStorage();
|
|
||||||
});
|
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user