|
|
|
@ -269,9 +269,7 @@ namespace ArtifactTracker |
|
|
|
|
g_bBookShelf = false; |
|
|
|
|
std::thread([]() { |
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1200)); |
|
|
|
|
SKSE::GetTaskInterface()->AddTask([&]() { |
|
|
|
|
ArtifactTracker::SyncCellStorage(); |
|
|
|
|
}); |
|
|
|
|
ArtifactTracker::SyncCellStorage(); |
|
|
|
|
}).detach(); |
|
|
|
|
} else { |
|
|
|
|
SyncCellStorage(); |
|
|
|
@ -377,8 +375,8 @@ namespace ArtifactTracker |
|
|
|
|
log::info("Adding new storage in {}", cell->GetName()); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
SKSE::GetTaskInterface()->AddTask([&]() { |
|
|
|
|
cellStorage = RE::PlayerCharacter::GetSingleton()->PlaceObjectAtMe(g_cellContainer, true).get(); |
|
|
|
|
SKSE::GetTaskInterface()->AddTask([]() { |
|
|
|
|
const auto cellStorage = RE::PlayerCharacter::GetSingleton()->PlaceObjectAtMe(g_cellContainer, true).get(); |
|
|
|
|
|
|
|
|
|
if (cellStorage) { |
|
|
|
|
cellStorage->Disable(); |
|
|
|
@ -406,83 +404,86 @@ namespace ArtifactTracker |
|
|
|
|
log::info("Running SyncCellStorage"); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
std::unordered_set<RE::FormID> cellItems; |
|
|
|
|
const RE::FormID ignoreFormID = a_ignoreRef ? a_ignoreRef->formID : NULL; |
|
|
|
|
|
|
|
|
|
const auto cell = g_cellStorage->GetParentCell(); |
|
|
|
|
const auto inv = g_cellStorage->GetInventory(); |
|
|
|
|
SKSE::GetTaskInterface()->AddTask([ignoreFormID]() { |
|
|
|
|
std::unordered_set<RE::FormID> cellItems; |
|
|
|
|
|
|
|
|
|
cell->ForEachReference([&](RE::TESObjectREFR& a_ref) { |
|
|
|
|
if (a_ignoreRef && a_ignoreRef->formID == a_ref.formID) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
const auto cell = g_cellStorage->GetParentCell(); |
|
|
|
|
const auto inv = g_cellStorage->GetInventory(); |
|
|
|
|
|
|
|
|
|
const auto baseObj = a_ref.GetBaseObject(); |
|
|
|
|
|
|
|
|
|
if (IsValidContainer(&a_ref)) { |
|
|
|
|
if (g_cellContainer == baseObj || baseObj->formID == 0xDC9E7 || g_persistentMap.contains(a_ref.formID)) { // skip persistent and PlayerBookShelfContainer
|
|
|
|
|
cell->ForEachReference([&](RE::TESObjectREFR& a_ref) { |
|
|
|
|
if (ignoreFormID && ignoreFormID == a_ref.formID) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const auto contInv = a_ref.GetInventory([&](RE::TESBoundObject& a_object) -> bool { |
|
|
|
|
return !cellItems.contains(a_object.formID) && IsArtifact(&a_object); |
|
|
|
|
}); |
|
|
|
|
const auto baseObj = a_ref.GetBaseObject(); |
|
|
|
|
|
|
|
|
|
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 (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 { |
|
|
|
|
return !cellItems.contains(a_object.formID) && IsArtifact(&a_object); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (a_ref.IsDisabled() || a_ref.IsMarkedForDeletion() || cellItems.contains(baseObj->formID) || !IsArtifact(baseObj)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
cellItems.insert(baseObj->formID); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (inv.find(baseObj) == inv.end()) { |
|
|
|
|
g_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr); |
|
|
|
|
} |
|
|
|
|
if (a_ref.IsDisabled() || a_ref.IsMarkedForDeletion() || cellItems.contains(baseObj->formID) || !IsArtifact(baseObj)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!g_listStored->HasForm(baseObj)) { |
|
|
|
|
ListRemoveItem(g_listNew, baseObj); |
|
|
|
|
ListRemoveItem(g_listFound, baseObj); |
|
|
|
|
g_listStored->AddForm(baseObj); |
|
|
|
|
} |
|
|
|
|
cellItems.insert(baseObj->formID); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
}); |
|
|
|
|
if (inv.find(baseObj) == inv.end()) { |
|
|
|
|
g_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (const auto& [item, data] : inv) { |
|
|
|
|
const auto& [count, entry] = data; |
|
|
|
|
if (count > 0 && !cellItems.contains(item->formID)) { |
|
|
|
|
if (!g_listStored->HasForm(baseObj)) { |
|
|
|
|
ListRemoveItem(g_listNew, baseObj); |
|
|
|
|
ListRemoveItem(g_listFound, baseObj); |
|
|
|
|
g_listStored->AddForm(baseObj); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
g_cellStorage->RemoveItem(item, count, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr); |
|
|
|
|
return true; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
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(); |
|
|
|
|
cellItems.clear(); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void OnContainerChanged(const RE::TESContainerChangedEvent* a_event, RE::TESForm* form) |
|
|
|
@ -759,7 +760,7 @@ namespace ArtifactTracker |
|
|
|
|
g_iFollowerIndex = iCurrentFollowers; |
|
|
|
|
std::thread([]() { |
|
|
|
|
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(); |
|
|
|
|
}); |
|
|
|
|
}).detach(); |
|
|
|
|