You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.0 KiB
78 lines
2.0 KiB
#pragma once
|
|
|
|
namespace Papyrus::ObjectReference
|
|
{
|
|
inline std::uint32_t GetItemCountInList(RE::StaticFunctionTag*,
|
|
RE::BGSListForm* a_containerList,
|
|
RE::TESBoundObject* a_form)
|
|
{
|
|
if (!a_containerList || !a_form) {
|
|
return 0;
|
|
}
|
|
|
|
std::uint32_t iResult = 0;
|
|
|
|
a_containerList->ForEachForm([&](RE::TESForm& a_container) {
|
|
const auto refrItem = a_container.As<RE::TESObjectREFR>();
|
|
if (refrItem) {
|
|
const auto inv = refrItem->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 true;
|
|
});
|
|
|
|
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)
|
|
{
|
|
BIND(GetItemCountInList);
|
|
logger::info("Registered GetItemCountInList"sv);
|
|
BIND(GetItemCountInActors);
|
|
logger::info("Registered GetItemCountInActors"sv);
|
|
BIND(GetPlayerFollowers);
|
|
logger::info("Registered GetPlayerFollowers"sv);
|
|
}
|
|
}
|
|
|