Skip to content

Commit

Permalink
Changed .shopbot shop merchantname to be `.shopbot shop item1 item2…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
nooperation committed Feb 9, 2024
1 parent 607847c commit 20b1870
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
21 changes: 17 additions & 4 deletions D2Hackit/Modules/shopbot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,28 @@ std::vector<MAPPOS> customPath;

BOOL PRIVATE Shop(char** argv, int argc)
{
if(argc >= 3)
if (argc < 3)
{
shopbot.Start(customPath, argv[2]);
return FALSE;
}
else

std::vector<std::string> 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;
}

Expand Down
22 changes: 17 additions & 5 deletions D2Hackit/Modules/shopbot/shopbot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ bool ShopBot::ReadConfig(const std::string &configPath, std::unordered_set<int>
return true;
}

bool ShopBot::Start(const std::vector<MAPPOS> &customPath, const std::string &merchant)
bool ShopBot::Start(const std::vector<MAPPOS> &customPath, const std::vector<std::string> &itemCodesToShopFor)
{
memset(&merchantNpc, 0, sizeof(GAMEUNIT));
merchantName = merchant;
merchantName = "";
teleportPath = customPath;
currentTeleportIndex = 1;
ticksSinceLastTeleport = 0;
targetItems.clear();

while (!gambleQueue.empty()) {
gambleQueue.pop();
Expand Down Expand Up @@ -119,9 +120,20 @@ bool ShopBot::Start(const std::vector<MAPPOS> &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);
Expand Down
2 changes: 1 addition & 1 deletion D2Hackit/Modules/shopbot/shopbot.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ShopBot
{
public:
ShopBot();
bool Start(const std::vector<MAPPOS> &customPath, const std::string &merchant);
bool Start(const std::vector<MAPPOS>& customPath, const std::vector<std::string>& itemCodesToShopFor);
void OnTick();
void OnMapBlink();
void OnNpcSession(int success);
Expand Down

0 comments on commit 20b1870

Please sign in to comment.