1

Removed GetItemCountInActors, added FollowersHaveItem and AddArtifactsFromFollowersToList

This commit is contained in:
Eddoursul 2022-06-22 10:28:12 +02:00
parent e54adbd097
commit ed97ea6a69
11 changed files with 70 additions and 70 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -265,15 +265,74 @@ namespace Papyrus::ArtifactTracker
cellItems.clear(); cellItems.clear();
} }
// From po3's Papyrus Extender
inline std::vector<RE::Actor*> GetPlayerFollowers(RE::StaticFunctionTag*)
{
std::vector<RE::Actor*> 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) inline void Bind(VM& a_vm)
{ {
BIND(AddAllFormsToList); BIND(AddAllFormsToList);
logger::info("Registered AddAllFormsToList"sv); logger::info("Registered AddAllFormsToList"sv);
BIND(AddArtifactsToList); BIND(AddArtifactsToList);
logger::info("Registered AddArtifactsToList"sv); logger::info("Registered AddArtifactsToList"sv);
BIND(AddArtifactsFromFollowersToList);
logger::info("Registered AddArtifactsFromFollowersToList"sv);
BIND(GetCellStorage); BIND(GetCellStorage);
logger::info("Registered GetCellStorage"sv); logger::info("Registered GetCellStorage"sv);
BIND(SyncCellStorage); BIND(SyncCellStorage);
logger::info("Registered SyncCellStorage"sv); logger::info("Registered SyncCellStorage"sv);
BIND(FollowersHaveItem);
logger::info("Registered FollowersHaveItem"sv);
BIND(GetPlayerFollowers);
logger::info("Registered GetPlayerFollowers"sv);
} }
} }

View File

@ -27,52 +27,9 @@ namespace Papyrus::ObjectReference
return iResult; return iResult;
} }
inline std::uint32_t GetItemCountInActors(RE::StaticFunctionTag*,
std::vector<RE::Actor*> 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<RE::Actor*> GetPlayerFollowers(RE::StaticFunctionTag*)
{
std::vector<RE::Actor*> 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) inline void Bind(VM& a_vm)
{ {
BIND(GetItemCountInList); BIND(GetItemCountInList);
logger::info("Registered GetItemCountInList"sv); logger::info("Registered GetItemCountInList"sv);
BIND(GetItemCountInActors);
logger::info("Registered GetItemCountInActors"sv);
BIND(GetPlayerFollowers);
logger::info("Registered GetPlayerFollowers"sv);
} }
} }

View File

@ -6,10 +6,12 @@ int function AddArtifactsToList(Form refOrList, FormList targetList, Form exclud
int function GetItemCountInList(FormList refList, Form baseForm) native global int function GetItemCountInList(FormList refList, Form baseForm) native global
int function GetItemCountInActors(Actor[] refArray, Form baseForm) native global
Actor[] function GetPlayerFollowers() native global
ObjectReference function GetCellStorage(ObjectReference ref, FormList refList, Form refToCreate, bool autoCreate = true) 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 function SyncCellStorage(ObjectReference cellStorage, Form excludeForm = None) native global
Actor[] function GetPlayerFollowers() native global
bool function FollowersHaveItem(Form baseForm) native global
int function AddArtifactsFromFollowersToList(FormList targetList, Form excludeForm = None) native global

View File

@ -106,13 +106,7 @@ Event OnUpdate()
ETR_ItemsFound.Revert() ETR_ItemsFound.Revert()
ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored) ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored)
ETR_Functions.AddArtifactsFromFollowersToList(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
bBusy = false bBusy = false
@ -135,7 +129,7 @@ event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemRefe
bRescanHome = true bRescanHome = true
bRescanPersistent = false bRescanPersistent = false
RegisterForSingleUpdate(0.5) 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_ItemsFound.RemoveAddedForm(akBaseItem)
ETR_ItemsNew.AddForm(akBaseItem) ETR_ItemsNew.AddForm(akBaseItem)
endif endif
@ -143,7 +137,7 @@ event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemRefe
ETR_ItemsFound.RemoveAddedForm(akBaseItem) ETR_ItemsFound.RemoveAddedForm(akBaseItem)
ETR_ItemsStored.AddForm(akBaseItem) ETR_ItemsStored.AddForm(akBaseItem)
ETR_Functions.GetCellStorage(PlayerRef, ETR_PersistentStorageList, ETR_CellStorageContainer).AddItem(akBaseItem, 1, true) 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_ItemsFound.RemoveAddedForm(akBaseItem)
ETR_ItemsNew.AddForm(akBaseItem) ETR_ItemsNew.AddForm(akBaseItem)
endif endif

View File

@ -51,13 +51,7 @@ event OnPlayerLoadGame()
ETR_ItemsFound.Revert() ETR_ItemsFound.Revert()
ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored) ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored)
ETR_Functions.AddArtifactsFromFollowersToList(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_ItemsNew.Revert() ETR_ItemsNew.Revert()
ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 26, ETR_FoundAndStored) ETR_Functions.AddAllFormsToList(ETR_ItemsNew, 26, ETR_FoundAndStored)

View File

@ -95,13 +95,7 @@ Event OnUpdate()
ETR_ItemsFound.Revert() ETR_ItemsFound.Revert()
ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored) ETR_Functions.AddArtifactsToList(PlayerRef, ETR_ItemsFound, ETR_ItemsStored)
ETR_Functions.AddArtifactsFromFollowersToList(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
endif endif