1

Check player inventory in SyncCellStorage, remove items from storage if they are removed from the artifact list

This commit is contained in:
Eddoursul 2022-07-06 03:14:05 +02:00
parent ea48cd5a01
commit 00fe1f78a7
2 changed files with 18 additions and 21 deletions

Binary file not shown.

View File

@ -340,13 +340,12 @@ namespace ArtifactTracker
} }
const auto contInv = a_ref->GetInventory([&](RE::TESBoundObject& a_object) -> bool { const auto contInv = a_ref->GetInventory([&](RE::TESBoundObject& a_object) -> bool {
return !cellItems.contains(a_object.formID); return !cellItems.contains(a_object.formID) && IsArtifact(&a_object);
}); });
for (const auto& [item, data] : contInv) { for (const auto& [item, data] : contInv) {
if (data.first > 0) { if (data.first > 0) {
cellItems.insert(item->formID); cellItems.insert(item->formID);
if (IsArtifact(item)) {
if (inv.find(item) == inv.end()) { if (inv.find(item) == inv.end()) {
g_cellStorage->AddObjectToContainer(item, nullptr, 1, nullptr); g_cellStorage->AddObjectToContainer(item, nullptr, 1, nullptr);
} }
@ -357,25 +356,16 @@ namespace ArtifactTracker
} }
} }
} }
}
continue; continue;
} }
if (a_ref->IsDisabled() || a_ref->IsMarkedForDeletion()) { if (a_ref->IsDisabled() || a_ref->IsMarkedForDeletion() || cellItems.contains(baseObj->formID) || !IsArtifact(baseObj)) {
continue;
}
if (cellItems.contains(baseObj->formID)) {
continue; continue;
} }
cellItems.insert(baseObj->formID); cellItems.insert(baseObj->formID);
if (!IsArtifact(baseObj)) {
continue;
}
if (inv.find(baseObj) == inv.end()) { if (inv.find(baseObj) == inv.end()) {
g_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr); g_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr);
} }
@ -390,11 +380,18 @@ namespace ArtifactTracker
for (const auto& [item, data] : inv) { for (const auto& [item, data] : inv) {
const auto& [count, entry] = data; const auto& [count, entry] = data;
if (count > 0 && !cellItems.contains(item->formID)) { if (count > 0 && !cellItems.contains(item->formID)) {
g_cellStorage->RemoveItem(item, count, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr); g_cellStorage->RemoveItem(item, count, RE::ITEM_REMOVE_REASON::kRemove, nullptr, nullptr);
if (!RefListHasItem(g_persistentStorage, item->formID)) { if (!RefListHasItem(g_persistentStorage, item->formID)) {
ListRemoveItem(g_listNew, item);
ListRemoveItem(g_listStored, item); ListRemoveItem(g_listStored, item);
if (GetItemCount(RE::PlayerCharacter::GetSingleton(), item) || FollowersHaveItem(item)) {
ListRemoveItem(g_listNew, item);
g_listFound->AddForm(item); g_listFound->AddForm(item);
} else {
ListRemoveItem(g_listFound, item);
g_listNew->AddForm(item);
}
} }
} }
} }