2022-06-30 10:31:01 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
inline void ListRemoveItem(RE::BGSListForm* a_List, RE::TESForm* a_form)
|
|
|
|
{
|
|
|
|
using func_t = decltype(&ListRemoveItem);
|
|
|
|
REL::Relocation<func_t> func{ REL::RelocationID(20471, 20914) };
|
|
|
|
return func(a_List, a_form);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void ListRevert(RE::BGSListForm* a_form)
|
|
|
|
{
|
|
|
|
using func_t = decltype(&ListRevert);
|
|
|
|
REL::Relocation<func_t> func{ REL::RelocationID(20469, 20912) };
|
|
|
|
return func(a_form);
|
|
|
|
}
|
|
|
|
|
2022-07-02 17:04:55 +00:00
|
|
|
inline std::int32_t GetItemCount(RE::TESObjectREFR* a_container, RE::TESForm* a_form)
|
|
|
|
{
|
|
|
|
std::int32_t iResult = 0;
|
|
|
|
|
|
|
|
auto invChanges = a_container->GetInventoryChanges();
|
|
|
|
if (invChanges && invChanges->entryList) {
|
|
|
|
for (auto& entry : *invChanges->entryList) {
|
|
|
|
if (entry && entry->object == a_form) {
|
|
|
|
if (entry->IsLeveled()) {
|
|
|
|
return entry->countDelta > 0 ? entry->countDelta : 0;
|
|
|
|
} else {
|
|
|
|
iResult = entry->countDelta;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto container = a_container->GetContainer();
|
|
|
|
if (container) {
|
|
|
|
container->ForEachContainerObject([&](RE::ContainerObject& a_entry) {
|
|
|
|
if (a_entry.obj == a_form) {
|
|
|
|
iResult += a_entry.count;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return iResult > 0 ? iResult : 0;
|
|
|
|
}
|
|
|
|
|
2022-07-02 13:57:34 +00:00
|
|
|
inline std::int32_t GetItemCount(RE::TESObjectREFR* a_container, RE::FormID a_formID)
|
|
|
|
{
|
|
|
|
std::int32_t iResult = 0;
|
|
|
|
|
|
|
|
auto invChanges = a_container->GetInventoryChanges();
|
|
|
|
if (invChanges && invChanges->entryList) {
|
|
|
|
for (auto& entry : *invChanges->entryList) {
|
|
|
|
if (entry && entry->object && entry->object->formID == a_formID) {
|
|
|
|
if (entry->IsLeveled()) {
|
|
|
|
return entry->countDelta > 0 ? entry->countDelta : 0;
|
|
|
|
} else {
|
|
|
|
iResult = entry->countDelta;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
auto container = a_container->GetContainer();
|
|
|
|
if (container) {
|
|
|
|
container->ForEachContainerObject([&](RE::ContainerObject& a_entry) {
|
2022-07-02 17:04:55 +00:00
|
|
|
if (a_entry.obj && a_entry.obj->formID == a_formID) {
|
2022-07-02 13:57:34 +00:00
|
|
|
iResult += a_entry.count;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return iResult > 0 ? iResult : 0;
|
|
|
|
}
|
|
|
|
|
2022-07-02 17:04:55 +00:00
|
|
|
inline bool RefListHasItem(RE::TESForm* a_refOrList, RE::FormID a_formID)
|
2022-06-30 10:31:01 +00:00
|
|
|
{
|
|
|
|
if (!a_refOrList || !a_formID) {
|
|
|
|
SKSE::log::warn("Invalid arguments in RefHasItem");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto refr = a_refOrList->As<RE::TESObjectREFR>();
|
|
|
|
|
|
|
|
if (refr) {
|
2022-07-02 13:57:34 +00:00
|
|
|
return GetItemCount(refr, a_formID) > 0;
|
2022-06-30 10:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto list = a_refOrList->As<RE::BGSListForm>();
|
|
|
|
|
|
|
|
if (list) {
|
2022-07-02 16:42:40 +00:00
|
|
|
bool bResult = false;
|
|
|
|
list->ForEachForm([&](RE::TESForm& a_form) {
|
2022-07-02 17:04:55 +00:00
|
|
|
if (&a_form && RefListHasItem(&a_form, a_formID)) {
|
2022-07-02 16:42:40 +00:00
|
|
|
bResult = true;
|
|
|
|
return false;
|
2022-06-30 10:31:01 +00:00
|
|
|
}
|
2022-07-02 16:42:40 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return bResult;
|
2022-06-30 10:31:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-07-02 17:04:55 +00:00
|
|
|
inline bool FollowersHaveItem(RE::TESForm* a_form)
|
2022-06-30 10:31:01 +00:00
|
|
|
{
|
|
|
|
if (const auto processLists = RE::ProcessLists::GetSingleton(); processLists) {
|
|
|
|
for (auto& actorHandle : processLists->highActorHandles) {
|
|
|
|
if (auto actor = actorHandle.get(); actor && actor->IsPlayerTeammate()) {
|
|
|
|
|
2022-07-02 17:04:55 +00:00
|
|
|
if (GetItemCount(actor->As<RE::TESObjectREFR>(), a_form) > 0) {
|
2022-07-02 16:37:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
2022-06-30 10:31:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-02 16:37:52 +00:00
|
|
|
return false;
|
2022-07-02 13:57:34 +00:00
|
|
|
}
|