Skip to content

Commit

Permalink
[Fix] Non-unique item name registration (#390)
Browse files Browse the repository at this point in the history
Fix an issue related to items that have a non-unique name on the register. This problem was breaking some monster's loot.
  • Loading branch information
marcosvf132 authored May 27, 2022
1 parent 86e4a90 commit 63b30ca
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/items/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 63b30ca

Please sign in to comment.