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.
164 lines
4.5 KiB
164 lines
4.5 KiB
#pragma once
|
|
|
|
#include "ArtifactTracker.h"
|
|
|
|
namespace Papyrus::PapyrusFunctions
|
|
{
|
|
inline std::int32_t AddAllFormsToList(RE::StaticFunctionTag*,
|
|
RE::BGSListForm* a_targetList,
|
|
short a_formType,
|
|
RE::BGSListForm* a_storedList,
|
|
RE::BGSListForm* a_foundList)
|
|
{
|
|
const auto formType = static_cast<RE::FormType>(a_formType);
|
|
|
|
switch (formType) {
|
|
|
|
case RE::FormType::Book:
|
|
for (auto const& item : ArtifactTracker::validBooks) {
|
|
if (!a_storedList->HasForm(item.second) && !a_foundList->HasForm(item.second)) {
|
|
a_targetList->AddForm(item.second);
|
|
}
|
|
}
|
|
break;
|
|
|
|
case RE::FormType::Misc:
|
|
for (auto const& item : ArtifactTracker::validMisc) {
|
|
if (!a_storedList->HasForm(item.second) && !a_foundList->HasForm(item.second)) {
|
|
a_targetList->AddForm(item.second);
|
|
}
|
|
}
|
|
break;
|
|
|
|
case RE::FormType::None:
|
|
break;
|
|
|
|
default:
|
|
const auto dataHandler = RE::TESDataHandler::GetSingleton();
|
|
|
|
if (!dataHandler) {
|
|
return a_targetList->forms.size();
|
|
}
|
|
|
|
for (const auto& form : dataHandler->GetFormArray(formType)) {
|
|
if (!form || !form->GetPlayable()) {
|
|
continue;
|
|
}
|
|
if (a_storedList->HasForm(form) || a_foundList->HasForm(form)) {
|
|
continue;
|
|
}
|
|
a_targetList->AddForm(form);
|
|
}
|
|
}
|
|
|
|
return a_targetList->forms.size();
|
|
}
|
|
|
|
inline std::int32_t AddArtifactsToList(VM* a_vm, StackID a_stackID, RE::StaticFunctionTag*,
|
|
RE::TESForm* a_refOrList,
|
|
RE::BGSListForm* a_targetList,
|
|
RE::BGSListForm* a_excludeList = NULL)
|
|
{
|
|
if (!a_refOrList) {
|
|
a_vm->TraceStack("a_refOrList in AddArtifactsToList is None", a_stackID);
|
|
return 0;
|
|
}
|
|
if (!a_targetList) {
|
|
a_vm->TraceStack("a_targetList in AddArtifactsToList is None", a_stackID);
|
|
return 0;
|
|
}
|
|
|
|
if (a_refOrList->Is(RE::FormType::FormList)) {
|
|
a_refOrList->As<RE::BGSListForm>()->ForEachForm([&](RE::TESForm& a_exform) {
|
|
const auto refrItem = a_exform.As<RE::TESObjectREFR>();
|
|
if (refrItem) {
|
|
AddArtifactsToList(a_vm, a_stackID, nullptr, refrItem, a_targetList, a_excludeList);
|
|
}
|
|
return true;
|
|
});
|
|
return a_targetList->forms.size();
|
|
}
|
|
|
|
const auto containerRef = a_refOrList->As<RE::TESObjectREFR>();
|
|
|
|
if (!containerRef) {
|
|
a_vm->TraceStack("containerRef in AddArtifactsToList is not a reference", a_stackID);
|
|
return 0;
|
|
}
|
|
|
|
const auto inv = containerRef->GetInventory([&](RE::TESBoundObject& a_exform) {
|
|
return ArtifactTracker::IsArtifact(&a_exform) && (!a_excludeList || !a_excludeList->HasForm(&a_exform));
|
|
});
|
|
|
|
for (const auto& item : inv) {
|
|
if (item.second.first > 0) {
|
|
a_targetList->AddForm(item.first);
|
|
}
|
|
}
|
|
|
|
return a_targetList->forms.size();
|
|
}
|
|
|
|
inline RE::TESObjectREFR* GetCellStorage(RE::StaticFunctionTag*,
|
|
RE::TESObjectREFR* a_ref,
|
|
RE::BGSListForm* a_refList,
|
|
RE::TESBoundObject* a_objectToCreate,
|
|
bool a_autoCreate = true)
|
|
{
|
|
return ArtifactTracker::GetCellStorage(a_ref, a_refList, a_objectToCreate, a_autoCreate);
|
|
}
|
|
|
|
inline void SyncCellStorage(RE::StaticFunctionTag*,
|
|
RE::TESObjectREFR* a_cellStorage,
|
|
RE::BGSListForm* a_excludeContainers)
|
|
{
|
|
ArtifactTracker::SyncCellStorage(a_cellStorage, a_excludeContainers);
|
|
}
|
|
|
|
inline std::int32_t AddArtifactsFromFollowersToList(RE::StaticFunctionTag*,
|
|
RE::BGSListForm* a_targetList,
|
|
RE::BGSListForm* a_excludeList = NULL)
|
|
{
|
|
if (const auto processLists = RE::ProcessLists::GetSingleton(); processLists) {
|
|
for (auto& actorHandle : processLists->highActorHandles) {
|
|
if (auto actor = actorHandle.get(); actor && actor->IsPlayerTeammate()) {
|
|
|
|
const auto inv = actor->GetInventory([&](RE::TESBoundObject& a_exform) {
|
|
return ArtifactTracker::IsArtifact(&a_exform) && (!a_excludeList || !a_excludeList->HasForm(&a_exform));
|
|
});
|
|
|
|
for (const auto& item : inv) {
|
|
if (item.second.first > 0) {
|
|
a_targetList->AddForm(item.first);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
return a_targetList->forms.size();
|
|
}
|
|
|
|
inline void OnItemPickup(RE::StaticFunctionTag*,
|
|
RE::TESBoundObject* a_item)
|
|
{
|
|
ArtifactTracker::OnItemPickup(a_item);
|
|
}
|
|
|
|
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(OnItemPickup);
|
|
logger::info("Registered OnItemPickup"sv);
|
|
}
|
|
}
|
|
|