fix: wrong checks and wrong quantities

This commit is contained in:
2026-03-20 18:46:53 -03:00
parent 93900a56cb
commit 3231638ce7
+20 -14
View File
@@ -371,6 +371,7 @@ int main()
std::string currentItems = data.substr(pos, endPos - pos); std::string currentItems = data.substr(pos, endPos - pos);
std::unordered_set<std::string> seenIds; std::unordered_set<std::string> seenIds;
std::unordered_set<std::string> stackableSet(localStackable.begin(), localStackable.end());
size_t itemPos = 0; size_t itemPos = 0;
while ((itemPos = currentItems.find("\"itemId\":\"", itemPos)) != std::string::npos) while ((itemPos = currentItems.find("\"itemId\":\"", itemPos)) != std::string::npos)
@@ -382,25 +383,31 @@ int main()
std::string id = currentItems.substr(idStart, idEnd - idStart); std::string id = currentItems.substr(idStart, idEnd - idStart);
seenIds.insert(id); seenIds.insert(id);
int qty = 100; int qty = -1;
if (perkSet.count(id)) if (perkSet.count(id))
qty = 3; qty = 3;
else if (uniqueSet.count(id)) else if (uniqueSet.count(id))
qty = 1; qty = 1;
else if (stackableSet.count(id))
qty = 100;
size_t objStart = currentItems.rfind("{", itemPos); if (qty != -1)
size_t objEnd = currentItems.find("}", itemPos);
if (objStart != std::string::npos && objEnd != std::string::npos && objStart < objEnd)
{ {
std::string objStr = currentItems.substr(objStart, objEnd - objStart + 1); size_t objStart = currentItems.rfind("{", itemPos);
if (std::regex_search(objStr, qtyRegex)) size_t objEnd = currentItems.find("}", itemPos);
objStr = if (objStart != std::string::npos && objEnd != std::string::npos && objStart < objEnd)
std::regex_replace(objStr, qtyRegex, "\"quantity\":" + std::to_string(qty)); {
else std::string objStr = currentItems.substr(objStart, objEnd - objStart + 1);
objStr.insert(objStr.length() - 1, ",\"quantity\":" + std::to_string(qty)); if (std::regex_search(objStr, qtyRegex))
objStr = std::regex_replace(objStr, qtyRegex, "\"quantity\":" + std::to_string(qty));
else
objStr.insert(objStr.length() - 1, ",\"quantity\":" + std::to_string(qty));
currentItems.replace(objStart, objEnd - objStart + 1, objStr); currentItems.replace(objStart, objEnd - objStart + 1, objStr);
itemPos = objStart + objStr.length(); itemPos = objStart + objStr.length();
}
else
itemPos = idEnd;
} }
else else
itemPos = idEnd; itemPos = idEnd;
@@ -412,8 +419,7 @@ int main()
if (seenIds.find(id) == seenIds.end()) if (seenIds.find(id) == seenIds.end())
{ {
if (!currentItems.empty() && currentItems.back() != ',') currentItems += ","; if (!currentItems.empty() && currentItems.back() != ',') currentItems += ",";
currentItems += currentItems += "{\"itemId\":\"" + id + "\",\"quantity\":" + std::to_string(qty) + "}";
"{\"itemId\":\"" + id + "\",\"quantity\":" + std::to_string(qty) + "}";
seenIds.insert(id); seenIds.insert(id);
} }
} }