fix: wrong checks and wrong quantities
This commit is contained in:
+20
-14
@@ -371,6 +371,7 @@ int main()
|
||||
|
||||
std::string currentItems = data.substr(pos, endPos - pos);
|
||||
std::unordered_set<std::string> seenIds;
|
||||
std::unordered_set<std::string> stackableSet(localStackable.begin(), localStackable.end());
|
||||
|
||||
size_t itemPos = 0;
|
||||
while ((itemPos = currentItems.find("\"itemId\":\"", itemPos)) != std::string::npos)
|
||||
@@ -382,25 +383,31 @@ int main()
|
||||
std::string id = currentItems.substr(idStart, idEnd - idStart);
|
||||
seenIds.insert(id);
|
||||
|
||||
int qty = 100;
|
||||
int qty = -1;
|
||||
if (perkSet.count(id))
|
||||
qty = 3;
|
||||
else if (uniqueSet.count(id))
|
||||
qty = 1;
|
||||
else if (stackableSet.count(id))
|
||||
qty = 100;
|
||||
|
||||
size_t objStart = currentItems.rfind("{", itemPos);
|
||||
size_t objEnd = currentItems.find("}", itemPos);
|
||||
if (objStart != std::string::npos && objEnd != std::string::npos && objStart < objEnd)
|
||||
if (qty != -1)
|
||||
{
|
||||
std::string objStr = currentItems.substr(objStart, objEnd - objStart + 1);
|
||||
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));
|
||||
size_t objStart = currentItems.rfind("{", itemPos);
|
||||
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);
|
||||
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);
|
||||
itemPos = objStart + objStr.length();
|
||||
currentItems.replace(objStart, objEnd - objStart + 1, objStr);
|
||||
itemPos = objStart + objStr.length();
|
||||
}
|
||||
else
|
||||
itemPos = idEnd;
|
||||
}
|
||||
else
|
||||
itemPos = idEnd;
|
||||
@@ -412,8 +419,7 @@ int main()
|
||||
if (seenIds.find(id) == seenIds.end())
|
||||
{
|
||||
if (!currentItems.empty() && currentItems.back() != ',') currentItems += ",";
|
||||
currentItems +=
|
||||
"{\"itemId\":\"" + id + "\",\"quantity\":" + std::to_string(qty) + "}";
|
||||
currentItems += "{\"itemId\":\"" + id + "\",\"quantity\":" + std::to_string(qty) + "}";
|
||||
seenIds.insert(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user