From 20b1870c388784498b39bf87f96ca469725e1dd5 Mon Sep 17 00:00:00 2001 From: nooperation Date: Fri, 9 Feb 2024 14:01:47 -0500 Subject: [PATCH] Changed `.shopbot shop merchantname` to be `.shopbot shop item1 item2 item3 ...` to shop for specific items without having to play with the text files and to be more consistent with how other plugins work like gamble --- D2Hackit/Modules/shopbot/main.cpp | 21 +++++++++++++++++---- D2Hackit/Modules/shopbot/shopbot.cpp | 22 +++++++++++++++++----- D2Hackit/Modules/shopbot/shopbot.h | 2 +- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/D2Hackit/Modules/shopbot/main.cpp b/D2Hackit/Modules/shopbot/main.cpp index 70f196b..f431d07 100644 --- a/D2Hackit/Modules/shopbot/main.cpp +++ b/D2Hackit/Modules/shopbot/main.cpp @@ -7,15 +7,28 @@ std::vector customPath; BOOL PRIVATE Shop(char** argv, int argc) { - if(argc >= 3) + if (argc < 3) { - shopbot.Start(customPath, argv[2]); + return FALSE; } - else + + std::vector itemCodesToShopFor; + + for (int i = 2; i < argc; i++) { - shopbot.Start(customPath, ""); + if (strlen(argv[i]) == 3) + { + itemCodesToShopFor.push_back(argv[i]); + } + else + { + server->GameStringf("ÿc:Shopbotÿc0: Invalid item code %s (must be 3 characters)", argv[i]); + return FALSE; + } } + shopbot.Start(customPath, itemCodesToShopFor); + return TRUE; } diff --git a/D2Hackit/Modules/shopbot/shopbot.cpp b/D2Hackit/Modules/shopbot/shopbot.cpp index 419003a..5bb30d5 100644 --- a/D2Hackit/Modules/shopbot/shopbot.cpp +++ b/D2Hackit/Modules/shopbot/shopbot.cpp @@ -73,13 +73,14 @@ bool ShopBot::ReadConfig(const std::string &configPath, std::unordered_set return true; } -bool ShopBot::Start(const std::vector &customPath, const std::string &merchant) +bool ShopBot::Start(const std::vector &customPath, const std::vector &itemCodesToShopFor) { memset(&merchantNpc, 0, sizeof(GAMEUNIT)); - merchantName = merchant; + merchantName = ""; teleportPath = customPath; currentTeleportIndex = 1; ticksSinceLastTeleport = 0; + targetItems.clear(); while (!gambleQueue.empty()) { gambleQueue.pop(); @@ -119,9 +120,20 @@ bool ShopBot::Start(const std::vector &customPath, const std::string &me if(!ReadConfig(".\\plugin\\goodSuffix_shopbot.txt", goodSuffix)) return false; - if(!LoadItemMap(".\\plugin\\shopbot_items.txt", targetItems)) - return false; - + if (itemCodesToShopFor.empty()) + { + if (!LoadItemMap(".\\plugin\\shopbot_items.txt", targetItems)) + { + return false; + } + } + else + { + for (const auto& iter : itemCodesToShopFor) + { + targetItems[iter] = iter; + } + } minPrefix = GetPrivateProfileInt("ShopBot", "PrefixCount", 1, CONFIG_PATH); minSuffix = GetPrivateProfileInt("ShopBot", "SuffixCount", 0, CONFIG_PATH); diff --git a/D2Hackit/Modules/shopbot/shopbot.h b/D2Hackit/Modules/shopbot/shopbot.h index 30917f9..22f46de 100644 --- a/D2Hackit/Modules/shopbot/shopbot.h +++ b/D2Hackit/Modules/shopbot/shopbot.h @@ -26,7 +26,7 @@ class ShopBot { public: ShopBot(); - bool Start(const std::vector &customPath, const std::string &merchant); + bool Start(const std::vector& customPath, const std::vector& itemCodesToShopFor); void OnTick(); void OnMapBlink(); void OnNpcSession(int success);