From 63b30ca9be725f1f6768c44d11cc57c0253b5cc0 Mon Sep 17 00:00:00 2001 From: Marcos <66353315+marcosvf132@users.noreply.github.com> Date: Fri, 27 May 2022 17:05:54 -0300 Subject: [PATCH] [Fix] Non-unique item name registration (#390) Fix an issue related to items that have a non-unique name on the register. This problem was breaking some monster's loot. --- src/items/items.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/items/items.cpp b/src/items/items.cpp index 5c9854c4caf..6b170d06b8d 100644 --- a/src/items/items.cpp +++ b/src/items/items.cpp @@ -266,25 +266,24 @@ void Items::parseItemNode(const pugi::xml_node & itemNode, uint16_t id) { return; } - bool isNameRegistered = !itemType.name.empty(); - if (isNameRegistered && itemType.name != itemNode.attribute("name").as_string()) { - if (auto result = nameToItems.find(asLowerCaseString(itemType.name)); - result != nameToItems.end()) { - nameToItems.erase(result); - isNameRegistered = false; + if (std::string xmlName = itemNode.attribute("name").as_string(); + !xmlName.empty() && itemType.name != xmlName) { + if (!itemType.name.empty()) { + if (auto it = std::find_if(nameToItems.begin(), nameToItems.end(), [id](const auto nameMapIt) { + return nameMapIt.second == id; + }); it != nameToItems.end()) { + nameToItems.erase(it); + } } - } - itemType.loaded = true; - itemType.name = itemNode.attribute("name").as_string(); - - if (!isNameRegistered) { + itemType.name = xmlName; nameToItems.insert({ asLowerCaseString(itemType.name), id }); } + itemType.loaded = true; pugi::xml_attribute articleAttribute = itemNode.attribute("article"); if (articleAttribute) { itemType.article = articleAttribute.as_string();