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,21 +340,19 @@ namespace ArtifactTracker
}
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) {
if (data.first > 0) {
cellItems.insert(item->formID);
if (IsArtifact(item)) {
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 (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);
}
}
}
@ -362,20 +360,12 @@ namespace ArtifactTracker
continue;
}
if (a_ref->IsDisabled() || a_ref->IsMarkedForDeletion()) {
continue;
}
if (cellItems.contains(baseObj->formID)) {
if (a_ref->IsDisabled() || a_ref->IsMarkedForDeletion() || cellItems.contains(baseObj->formID) || !IsArtifact(baseObj)) {
continue;
}
cellItems.insert(baseObj->formID);
if (!IsArtifact(baseObj)) {
continue;
}
if (inv.find(baseObj) == inv.end()) {
g_cellStorage->AddObjectToContainer(baseObj, nullptr, 1, nullptr);
}
@ -390,11 +380,18 @@ namespace ArtifactTracker
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_listNew, item);
ListRemoveItem(g_listStored, item);
g_listFound->AddForm(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);
}
}
}
}