Skip to content

Commit

Permalink
Fix parse item method to ignore game object links
Browse files Browse the repository at this point in the history
  • Loading branch information
davidonete committed May 16, 2024
1 parent 7a483bf commit 457beb8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
33 changes: 19 additions & 14 deletions playerbot/ChatHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,31 @@ uint32 ChatHelper::parseMoney(std::string& text)
return copper;
}

ItemIds ChatHelper::parseItems(const std::string& text, bool validate, bool parseItemNames)
ItemIds ChatHelper::parseItems(const std::string& text, bool validate)
{
std::vector<uint32> itemIDsUnordered = parseItemsUnordered(text, validate, parseItemNames);
std::vector<uint32> itemIDsUnordered = parseItemsUnordered(text, validate);
return ItemIds(itemIDsUnordered.begin(), itemIDsUnordered.end());
}

std::vector<uint32> ChatHelper::parseItemsUnordered(const std::string& text, bool validate, bool parseItemNames)
std::vector<uint32> ChatHelper::parseItemsUnordered(const std::string& text, bool validate)
{
// Replace all item links with item ids
std::string textCpy = text;

// Remove gameobject links
if (textCpy.find("Hfound:") != -1)
{
std::vector<std::string> goLinks = findSubstringsBetween(textCpy, "|c", "|r", true);
for (const std::string& goLink : goLinks)
{
std::vector<std::string> goIDs = findSubstringsBetween(goLink, "Hfound:", ":");
if (!goIDs.empty())
{
replaceSubstring(textCpy, goLink, "");
}
}
}

// Replace all item links with item ids
if (textCpy.find("Hitem:") != -1)
{
std::vector<std::string> itemLinks = findSubstringsBetween(textCpy, "|c", "|r", true);
Expand Down Expand Up @@ -323,16 +338,6 @@ std::vector<uint32> ChatHelper::parseItemsUnordered(const std::string& text, boo
itemIds.push_back(std::stoi(itemStr));
}
}
else if (parseItemNames)
{
std::string itemName = itemStr;
WorldDatabase.escape_string(itemName);
auto queryResult = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name LIKE '%s'", itemName.c_str());
if (queryResult)
{
itemIds.push_back(queryResult->Fetch()->GetUInt16());
}
}
}

return itemIds;
Expand Down
4 changes: 2 additions & 2 deletions playerbot/ChatHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace ai
static std::string formatItem(ItemPrototype const * proto, int count = 0, int total = 0);
static std::string formatItem(Item* item, int count = 0, int total = 0);
static std::string formatQItem(uint32 itemId);
static ItemIds parseItems(const std::string& text, bool validate = false, bool parseItemNames = false);
static std::vector<uint32> parseItemsUnordered(const std::string& text, bool validate = false, bool parseItemNames = false);
static ItemIds parseItems(const std::string& text, bool validate = false);
static std::vector<uint32> parseItemsUnordered(const std::string& text, bool validate = false);
static std::set<std::string> parseItemQualifiers(std::string& text);
static uint32 parseItemQuality(std::string text);
static bool parseItemClass(std::string text, uint32* itemClass, uint32* itemSubClass);
Expand Down
3 changes: 1 addition & 2 deletions playerbot/strategy/actions/UseItemAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ bool UseAction::Execute(Event& event)
}
else
{
std::vector<uint32> items = chat->parseItemsUnordered(name, false, true);

std::vector<uint32> items = chat->parseItemsUnordered(name, false);
if (items.empty())
{
std::list<Item*> inventoryItems = AI_VALUE2(std::list<Item*>, "inventory items", name);
Expand Down

0 comments on commit 457beb8

Please sign in to comment.