diff --git a/SKSE/Plugins/ArtifactTrackerFunctions.dll b/SKSE/Plugins/ArtifactTrackerFunctions.dll index 3d98620..0c96306 100644 Binary files a/SKSE/Plugins/ArtifactTrackerFunctions.dll and b/SKSE/Plugins/ArtifactTrackerFunctions.dll differ diff --git a/Scripts/ETR_Functions.pex b/Scripts/ETR_Functions.pex index fe8a42a..d9138a3 100644 Binary files a/Scripts/ETR_Functions.pex and b/Scripts/ETR_Functions.pex differ diff --git a/Scripts/ETR_TrackFoundItems.pex b/Scripts/ETR_TrackFoundItems.pex index b2a1e83..3434ca1 100644 Binary files a/Scripts/ETR_TrackFoundItems.pex and b/Scripts/ETR_TrackFoundItems.pex differ diff --git a/Scripts/ETR_TrackNewItems.pex b/Scripts/ETR_TrackNewItems.pex index 66091b2..818c533 100644 Binary files a/Scripts/ETR_TrackNewItems.pex and b/Scripts/ETR_TrackNewItems.pex differ diff --git a/Scripts/ETR_TrackStoredItems.pex b/Scripts/ETR_TrackStoredItems.pex index d38026a..8d737cb 100644 Binary files a/Scripts/ETR_TrackStoredItems.pex and b/Scripts/ETR_TrackStoredItems.pex differ diff --git a/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h b/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h index cd5414a..317e91a 100644 --- a/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h +++ b/Source/ArtifactTrackerDLL/src/Functions/ArtifactTracker.h @@ -265,15 +265,74 @@ namespace Papyrus::ArtifactTracker cellItems.clear(); } + // From po3's Papyrus Extender + inline std::vector GetPlayerFollowers(RE::StaticFunctionTag*) + { + std::vector result; + + if (const auto processLists = RE::ProcessLists::GetSingleton(); processLists) { + for (auto& actorHandle : processLists->highActorHandles) { + if (auto actor = actorHandle.get(); actor && actor->IsPlayerTeammate()) { + result.push_back(actor.get()); + } + } + } + + return result; + } + + inline std::int32_t AddArtifactsFromFollowersToList(RE::StaticFunctionTag*, + RE::BGSListForm* a_targetList, + RE::TESForm* a_excludeForm = NULL) + { + for (const auto& actor : GetPlayerFollowers(nullptr)) { + auto inv = actor->GetInventory([&](RE::TESBoundObject& a_exform) { + return is_artifact(&a_exform) && !is_excluded(&a_exform, a_excludeForm); + }); + + for (const auto& item : inv) { + if (item.second.first > 0) { + a_targetList->AddForm(item.first); + } + } + } + + return a_targetList->forms.size(); + } + + inline bool FollowersHaveItem(RE::StaticFunctionTag*, + RE::TESBoundObject* a_form) + { + for (const auto& actor : GetPlayerFollowers(nullptr)) { + const auto inv = actor->GetInventory([&](RE::TESBoundObject& a_object) -> bool { + return a_form->formID == a_object.formID; + }); + const auto it = inv.find(a_form); + const auto iCount = it != inv.end() ? it->second.first : 0; + + if (iCount > 0) { + return true; + } + } + + return false; + } + inline void Bind(VM& a_vm) { BIND(AddAllFormsToList); logger::info("Registered AddAllFormsToList"sv); BIND(AddArtifactsToList); logger::info("Registered AddArtifactsToList"sv); + BIND(AddArtifactsFromFollowersToList); + logger::info("Registered AddArtifactsFromFollowersToList"sv); BIND(GetCellStorage); logger::info("Registered GetCellStorage"sv); BIND(SyncCellStorage); logger::info("Registered SyncCellStorage"sv); + BIND(FollowersHaveItem); + logger::info("Registered FollowersHaveItem"sv); + BIND(GetPlayerFollowers); + logger::info("Registered GetPlayerFollowers"sv); } } diff --git a/Source/ArtifactTrackerDLL/src/Functions/ObjectReference.h b/Source/ArtifactTrackerDLL/src/Functions/ObjectReference.h index ac7c919..271f880 100644 --- a/Source/ArtifactTrackerDLL/src/Functions/ObjectReference.h +++ b/Source/ArtifactTrackerDLL/src/Functions/ObjectReference.h @@ -27,52 +27,9 @@ namespace Papyrus::ObjectReference return iResult; } - inline std::uint32_t GetItemCountInActors(RE::StaticFunctionTag*, - std::vector a_refArray, // accepts ObjectReference[] and Actor[] - RE::TESBoundObject* a_form) - { - if (a_refArray.size() <= 0 || !a_form) { - return 0; - } - - std::uint32_t iResult = 0; - - for (RE::Actor* actorItem : a_refArray) { - if (actorItem) { - const auto inv = actorItem->GetInventory([&](RE::TESBoundObject& a_object) -> bool { - return a_form->formID == a_object.formID; - }); - const auto it = inv.find(a_form); - iResult += it != inv.end() ? it->second.first : 0; - } - } - - return iResult; - } - - // From po3's Papyrus Extender - inline std::vector GetPlayerFollowers(RE::StaticFunctionTag*) - { - std::vector result; - - if (const auto processLists = RE::ProcessLists::GetSingleton(); processLists) { - for (auto& actorHandle : processLists->highActorHandles) { - if (auto actor = actorHandle.get(); actor && actor->IsPlayerTeammate()) { - result.push_back(actor.get()); - } - } - } - - return result; - } - inline void Bind(VM& a_vm) { BIND(GetItemCountInList); logger::info("Registered GetItemCountInList"sv); - BIND(GetItemCountInActors); - logger::info("Registered GetItemCountInActors"sv); - BIND(GetPlayerFollowers); - logger::info("Registered GetPlayerFollowers"sv); } } diff --git a/Source/Scripts/ETR_Functions.psc b/Source/Scripts/ETR_Functions.psc index 3e4cc22..fd237fc 100644 --- a/Source/Scripts/ETR_Functions.psc +++ b/Source/Scripts/ETR_Functions.psc @@ -6,10 +6,12 @@ int function AddArtifactsToList(Form refOrList, FormList targetList, Form exclud int function GetItemCountInList(FormList refList, Form baseForm) native global -int function GetItemCountInActors(Actor[] refArray, Form baseForm) native global +ObjectReference function GetCellStorage(ObjectReference ref, FormList refList, Form refToCreate, bool autoCreate = true) native global + +function SyncCellStorage(ObjectReference cellStorage, Form excludeForm = None) native global Actor[] function GetPlayerFollowers() native global -ObjectReference function GetCellStorage(ObjectReference ref, FormList refList, Form refToCreate, bool autoCreate = true) native global +bool function FollowersHaveItem(Form baseForm) native global -function SyncCellStorage(ObjectReference cellStorage, Form excludeForm = None) native global +int function AddArtifactsFromFollowersToList(FormList targetList, Form excludeForm = None) native global diff --git a/Source/Scripts/ETR_TrackFoundItems.psc b/Source/Scripts/ETR_TrackFoundItems.psc index 84e2e78..35e7197 100644 --- a/Source/Scripts/ETR_TrackFoundItems.psc +++ b/Source/Scripts/ETR_TrackFoundItems.psc @@ -106,13 +106,7 @@ Event OnUpdate() ETR_ItemsFound.Revert() ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored) - - Actor[] aFollowers = ETR_Functions.GetPlayerFollowers() - int i = aFollowers.length - while i > 0 - i -= 1 - ETR_Functions.AddArtifactsToList(aFollowers[i], ETR_ItemsFound, ETR_ItemsStored) - endwhile + ETR_Functions.AddArtifactsFromFollowersToList(ETR_ItemsFound, ETR_ItemsStored) bBusy = false @@ -135,7 +129,7 @@ event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemRefe bRescanHome = true bRescanPersistent = false RegisterForSingleUpdate(0.5) - elseif PlayerRef.GetItemCount(akBaseItem) == 0 && ETR_Functions.GetItemCountInActors(ETR_Functions.GetPlayerFollowers(), akBaseItem) == 0 + elseif PlayerRef.GetItemCount(akBaseItem) == 0 && ! ETR_Functions.FollowersHaveItem(akBaseItem) ETR_ItemsFound.RemoveAddedForm(akBaseItem) ETR_ItemsNew.AddForm(akBaseItem) endif @@ -143,7 +137,7 @@ event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemRefe ETR_ItemsFound.RemoveAddedForm(akBaseItem) ETR_ItemsStored.AddForm(akBaseItem) ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer).AddItem(akBaseItem, 1, true) - elseif PlayerRef.GetItemCount(akBaseItem) == 0 && ETR_Functions.GetItemCountInActors(ETR_Functions.GetPlayerFollowers(), akBaseItem) == 0 + elseif PlayerRef.GetItemCount(akBaseItem) == 0 && ! ETR_Functions.FollowersHaveItem(akBaseItem) ETR_ItemsFound.RemoveAddedForm(akBaseItem) ETR_ItemsNew.AddForm(akBaseItem) endif diff --git a/Source/Scripts/ETR_TrackNewItems.psc b/Source/Scripts/ETR_TrackNewItems.psc index 6249c91..93f5d9e 100644 --- a/Source/Scripts/ETR_TrackNewItems.psc +++ b/Source/Scripts/ETR_TrackNewItems.psc @@ -51,13 +51,7 @@ event OnPlayerLoadGame() ETR_ItemsFound.Revert() ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored) - - Actor[] aFollowers = ETR_Functions.GetPlayerFollowers() - int i = aFollowers.length - while i > 0 - i -= 1 - ETR_Functions.AddArtifactsToList(aFollowers[i], ETR_ItemsFound, ETR_ItemsStored) - endwhile + ETR_Functions.AddArtifactsFromFollowersToList(ETR_ItemsFound, ETR_ItemsStored) ETR_ItemsNew.Revert() ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 26, ETR_FoundAndStored) diff --git a/Source/Scripts/ETR_TrackStoredItems.psc b/Source/Scripts/ETR_TrackStoredItems.psc index c70ece4..61f7b11 100644 --- a/Source/Scripts/ETR_TrackStoredItems.psc +++ b/Source/Scripts/ETR_TrackStoredItems.psc @@ -95,13 +95,7 @@ Event OnUpdate() ETR_ItemsFound.Revert() ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored) - - Actor[] aFollowers = ETR_Functions.GetPlayerFollowers() - int i = aFollowers.length - while i > 0 - i -= 1 - ETR_Functions.AddArtifactsToList(aFollowers[i], ETR_ItemsFound, ETR_ItemsStored) - endwhile + ETR_Functions.AddArtifactsFromFollowersToList(ETR_ItemsFound, ETR_ItemsStored) endif