Fetch items by workbench keywords
This commit is contained in:
parent
52b2ab878d
commit
635e37657c
Binary file not shown.
@ -65,9 +65,21 @@ inline const std::map<std::string, bool> GetSettings(bool bInit = false)
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline RE::TESObjectREFR* GetChest()
|
||||||
|
{
|
||||||
|
return RE::TESForm::LookupByID<RE::TESObjectREFR>(0x5C132);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void NotifyFetching(const char* a_notification)
|
||||||
|
{
|
||||||
|
if (GetSettings().at("ShowFetchingNotification")) {
|
||||||
|
RE::DebugNotification(a_notification);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void FetchSuppliesByType(RE::FormType formType)
|
inline void FetchSuppliesByType(RE::FormType formType)
|
||||||
{
|
{
|
||||||
const auto chest = RE::TESForm::LookupByID(0x5C132)->As<RE::TESObjectREFR>();
|
const auto chest = GetChest();
|
||||||
const auto targetRef = RE::PlayerCharacter::GetSingleton();
|
const auto targetRef = RE::PlayerCharacter::GetSingleton();
|
||||||
|
|
||||||
const auto inv = chest->GetInventory([formType](RE::TESBoundObject& a_form) {
|
const auto inv = chest->GetInventory([formType](RE::TESBoundObject& a_form) {
|
||||||
@ -93,6 +105,37 @@ inline void FetchSuppliesByType(RE::FormType formType)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void FetchByWorkbenchKeyword(RE::BGSKeyword* keyword)
|
||||||
|
{
|
||||||
|
if (!keyword) {
|
||||||
|
logger::warn("Invalid keyword argument in FetchByWorkbenchKeyword");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unordered_set<RE::FormID> checkedItems;
|
||||||
|
|
||||||
|
const auto chest = GetChest();
|
||||||
|
const auto playerRef = RE::PlayerCharacter::GetSingleton();
|
||||||
|
const auto inv = chest->GetInventory();
|
||||||
|
RE::ITEM_REMOVE_REASON iReason = RE::ITEM_REMOVE_REASON::kStoreInContainer;
|
||||||
|
|
||||||
|
for (const auto& recipe : RE::TESDataHandler::GetSingleton()->GetFormArray<RE::BGSConstructibleObject>()) {
|
||||||
|
if (recipe->benchKeyword == keyword && recipe->requiredItems.numContainerObjects > 0) {
|
||||||
|
for (int i = 0; i < recipe->requiredItems.numContainerObjects; i++) {
|
||||||
|
const auto component = recipe->requiredItems.GetContainerObjectAt(i).value();
|
||||||
|
const auto formID = (component && component->obj) ? component->obj->formID : NULL;
|
||||||
|
if (formID && !checkedItems.contains(formID)) {
|
||||||
|
checkedItems.insert(formID);
|
||||||
|
const auto it = inv.find(component->obj);
|
||||||
|
if (it != inv.end()) {
|
||||||
|
supplyCount.insert({ it->first, it->second.first });
|
||||||
|
chest->RemoveItem(it->first, it->second.first, iReason, nullptr, playerRef, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void FetchSuppliesByForm(RE::TESForm* a_form)
|
inline void FetchSuppliesByForm(RE::TESForm* a_form)
|
||||||
{
|
{
|
||||||
@ -100,7 +143,7 @@ inline void FetchSuppliesByForm(RE::TESForm* a_form)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto chest = RE::TESForm::LookupByID(0x5C132)->As<RE::TESObjectREFR>();
|
const auto chest = GetChest();
|
||||||
const auto targetRef = RE::PlayerCharacter::GetSingleton();
|
const auto targetRef = RE::PlayerCharacter::GetSingleton();
|
||||||
|
|
||||||
const auto inv = chest->GetInventory([&](RE::TESBoundObject& a_xform) {
|
const auto inv = chest->GetInventory([&](RE::TESBoundObject& a_xform) {
|
||||||
@ -130,7 +173,7 @@ inline void ReturnSupplies()
|
|||||||
RE::DebugNotification("Returning supplies...");
|
RE::DebugNotification("Returning supplies...");
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto chest = RE::TESForm::LookupByID(0x5C132)->As<RE::TESObjectREFR>();
|
const auto chest = GetChest();
|
||||||
const auto playerRef = RE::PlayerCharacter::GetSingleton();
|
const auto playerRef = RE::PlayerCharacter::GetSingleton();
|
||||||
RE::ITEM_REMOVE_REASON iReason = RE::ITEM_REMOVE_REASON::kStoreInContainer;
|
RE::ITEM_REMOVE_REASON iReason = RE::ITEM_REMOVE_REASON::kStoreInContainer;
|
||||||
|
|
||||||
@ -234,37 +277,51 @@ inline void FetchSupplies(RE::TESFurniture* a_furn)
|
|||||||
bool bNotify = GetSettings().at("ShowFetchingNotification");
|
bool bNotify = GetSettings().at("ShowFetchingNotification");
|
||||||
|
|
||||||
switch (a_furn->workBenchData.benchType.underlying()) {
|
switch (a_furn->workBenchData.benchType.underlying()) {
|
||||||
|
|
||||||
case (int)RE::TESFurniture::WorkBenchData::BenchType::kAlchemy:
|
case (int)RE::TESFurniture::WorkBenchData::BenchType::kAlchemy:
|
||||||
case (int)RE::TESFurniture::WorkBenchData::BenchType::kAlchemyExperiment:
|
case (int)RE::TESFurniture::WorkBenchData::BenchType::kAlchemyExperiment:
|
||||||
if (bNotify) {
|
NotifyFetching("Fetching alchemy ingredients...");
|
||||||
RE::DebugNotification("Fetching ingredients...");
|
|
||||||
}
|
|
||||||
FetchSuppliesByType(RE::FormType::Ingredient);
|
FetchSuppliesByType(RE::FormType::Ingredient);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case (int)RE::TESFurniture::WorkBenchData::BenchType::kEnchanting:
|
case (int)RE::TESFurniture::WorkBenchData::BenchType::kEnchanting:
|
||||||
case (int)RE::TESFurniture::WorkBenchData::BenchType::kEnchantingExperiment:
|
case (int)RE::TESFurniture::WorkBenchData::BenchType::kEnchantingExperiment:
|
||||||
if (bNotify) {
|
NotifyFetching("Fetching soul gems...");
|
||||||
RE::DebugNotification("Fetching soul gems...");
|
|
||||||
}
|
|
||||||
FetchSuppliesByType(RE::FormType::SoulGem);
|
FetchSuppliesByType(RE::FormType::SoulGem);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (a_furn->As<RE::BGSKeywordForm>()->HasKeywordString("CraftingCookpot")) {
|
if (a_furn->As<RE::BGSKeywordForm>()->HasKeywordString("CraftingCookpot")) {
|
||||||
if (bNotify) {
|
NotifyFetching("Fetching cooking ingredients...");
|
||||||
RE::DebugNotification("Fetching cooking ingredients...");
|
FetchByWorkbenchKeyword(RE::TESForm::LookupByID<RE::BGSKeyword>(0xA5CB3)); // CraftingCookpot
|
||||||
}
|
|
||||||
FetchSuppliesByType(RE::FormType::Ingredient);
|
} else if (a_furn->As<RE::BGSKeywordForm>()->HasKeywordString("CraftingSmelter")) {
|
||||||
FetchSuppliesByType(RE::FormType::AlchemyItem);
|
NotifyFetching("Fetching smelting supplies...");
|
||||||
|
FetchByWorkbenchKeyword(RE::TESForm::LookupByID<RE::BGSKeyword>(0xA5CCE)); // CraftingSmelter
|
||||||
|
|
||||||
|
} else if (a_furn->As<RE::BGSKeywordForm>()->HasKeywordString("CraftingTanningRack")) {
|
||||||
|
NotifyFetching("Fetching tanning supplies...");
|
||||||
|
FetchByWorkbenchKeyword(RE::TESForm::LookupByID<RE::BGSKeyword>(0x7866A)); // CraftingTanningRack
|
||||||
|
|
||||||
|
} else if (a_furn->As<RE::BGSKeywordForm>()->HasKeywordString("CraftingSmithingSharpeningWheel")) {
|
||||||
|
NotifyFetching("Fetching crafting supplies...");
|
||||||
|
FetchByWorkbenchKeyword(RE::TESForm::LookupByID<RE::BGSKeyword>(0x88108)); // CraftingSmithingSharpeningWheel
|
||||||
|
|
||||||
|
} else if (a_furn->As<RE::BGSKeywordForm>()->HasKeywordString("CraftingSmithingForge")) {
|
||||||
|
NotifyFetching("Fetching crafting supplies...");
|
||||||
|
FetchByWorkbenchKeyword(RE::TESForm::LookupByID<RE::BGSKeyword>(0x88105)); // CraftingSmithingForge
|
||||||
|
|
||||||
|
} else if (a_furn->As<RE::BGSKeywordForm>()->HasKeywordString("CraftingSmithingArmorTable")) {
|
||||||
|
NotifyFetching("Fetching crafting supplies...");
|
||||||
|
FetchByWorkbenchKeyword(RE::TESForm::LookupByID<RE::BGSKeyword>(0xADB78)); // CraftingSmithingArmorTable
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (bNotify) {
|
NotifyFetching("Fetching crafting supplies...");
|
||||||
RE::DebugNotification("Fetching crafting supplies...");
|
|
||||||
}
|
|
||||||
FetchSuppliesByType(RE::FormType::Misc);
|
FetchSuppliesByType(RE::FormType::Misc);
|
||||||
FetchSuppliesByType(RE::FormType::Ingredient);
|
FetchSuppliesByType(RE::FormType::Ingredient);
|
||||||
FetchSuppliesByType(RE::FormType::SoulGem);
|
FetchSuppliesByType(RE::FormType::SoulGem);
|
||||||
FetchSuppliesByType(RE::FormType::AlchemyItem);
|
FetchSuppliesByType(RE::FormType::AlchemyItem);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).detach();
|
}).detach();
|
||||||
|
Loading…
Reference in New Issue
Block a user