void Item::CalculateHash(const rapidjson::Value &json) { std::string unique_old(name_ + "~" + typeLine_ + "~"); std::string unique_new(std::string(json["name"].GetString()) + "~" + json["typeLine"].GetString() + "~"); std::string unique_common; if (json.HasMember("explicitMods")) for (auto &mod : json["explicitMods"]) unique_common += std::string(mod.GetString()) + "~"; if (json.HasMember("implicitMods")) for (auto &mod : json["implicitMods"]) unique_common += std::string(mod.GetString()) + "~"; unique_common += item_unique_properties(json, "properties") + "~"; unique_common += item_unique_properties(json, "additionalProperties") + "~"; if (json.HasMember("sockets")) for (auto &socket : json["sockets"]) unique_common += std::to_string(socket["group"].GetInt()) + "~" + socket["attr"].GetString() + "~"; unique_old += unique_common; unique_new += unique_common; old_hash_ = Util::Md5(unique_old); unique_new += "~" + location_.GetUniqueHash(); hash_ = Util::Md5(unique_new); }
Item::Item(const rapidjson::Value &json) : location_(ItemLocation(json)), name_(correct_name(json["name"].GetString())), typeLine_(correct_name(json["typeLine"].GetString())), corrupted_(json["corrupted"].GetBool()), w_(json["w"].GetInt()), h_(json["h"].GetInt()), frameType_(json["frameType"].GetInt()), icon_(json["icon"].GetString()), sockets_cnt_(0), links_cnt_(0), sockets_({ 0, 0, 0, 0 }), has_mtx_(false) { for (auto &mod_type : ITEM_MOD_TYPES) { text_mods_[mod_type] = std::vector<std::string>(); if (json.HasMember(mod_type.c_str())) { auto &mods = text_mods_[mod_type]; for (auto &mod : json[mod_type.c_str()]) mods.push_back(mod.GetString()); } } if (json.HasMember("properties")) { for (auto prop_it = json["properties"].Begin(); prop_it != json["properties"].End(); ++prop_it) { auto &prop = *prop_it; std::string name = prop["name"].GetString(); if (name == "Уровень карты") name = "Уровень"; if (name == "Урон от стихий") { for (auto value_it = prop["values"].Begin(); value_it != prop["values"].End(); ++value_it) elemental_damage_.push_back(std::make_pair((*value_it)[0].GetString(), (*value_it)[1].GetInt())); } else { if (prop["values"].Size()) properties_[name] = prop["values"][0][0].GetString(); } ItemProperty property; property.name = name; property.display_mode = prop["displayMode"].GetInt(); for (auto &value : prop["values"]) property.values.push_back(value[0].GetString()); text_properties_.push_back(property); } } if (json.HasMember("requirements")) { for (auto &req : json["requirements"]) { std::string name = req["name"].GetString(); std::string value = req["values"][0][0].GetString(); requirements_[name] = std::atoi(value.c_str()); text_requirements_.push_back({ name, value }); } } if (json.HasMember("sockets")) { ItemSocketGroup current_group = { 0, 0, 0, 0 }; sockets_cnt_ = json["sockets"].Size(); int counter = 0, prev_group = -1; for (auto &socket : json["sockets"]) { ItemSocket current_socket = { static_cast<unsigned char>(socket["group"].GetInt()), socket["attr"].GetString()[0] }; text_sockets_.push_back(current_socket); if (prev_group != current_socket.group) { counter = 0; socket_groups_.push_back(current_group); current_group = { 0, 0, 0, 0 }; } prev_group = current_socket.group; ++counter; links_cnt_ = std::max(links_cnt_, counter); switch (current_socket.attr) { case 'S': sockets_.r++; current_group.r++; break; case 'D': sockets_.g++; current_group.g++; break; case 'I': sockets_.b++; current_group.b++; break; case 'G': sockets_.w++; current_group.w++; break; } } socket_groups_.push_back(current_group); } std::string hashes[3]; for (int i = 0; i < 3; i++) { std::string unique(name_ + "~" + typeLine_ + "~"); if (i == 2) { // Strip off last "~" (a mistake from 0.3) unique = unique.substr(0, unique.length() - 1); } if (json.HasMember("explicitMods")) for (auto mod_it = json["explicitMods"].Begin(); mod_it != json["explicitMods"].End(); ++mod_it) unique += std::string(mod_it->GetString()) + "~"; if (json.HasMember("implicitMods")) for (auto mod_it = json["implicitMods"].Begin(); mod_it != json["implicitMods"].End(); ++mod_it) unique += std::string(mod_it->GetString()) + "~"; unique += item_unique_properties(json, "properties") + "~"; unique += item_unique_properties(json, "additionalProperties") + "~"; if (json.HasMember("sockets")) for (auto socket_it = json["sockets"].Begin(); socket_it != json["sockets"].End(); ++socket_it) unique += std::to_string((*socket_it)["group"].GetInt()) + "~" + (*socket_it)["attr"].GetString() + "~"; // This will only effect corrupted item's new hashes... if (i == 1 && corrupted()) unique += "corrupted"; hashes[i] = Util::Md5(unique); } old_hash_ = hashes[0]; hash_ = hashes[1]; broken_hash_ = hashes[2]; count_ = 1; if (properties_.find("Размер стопки") != properties_.end()) { std::string size = properties_["Размер стопки"]; if (size.find("/") != std::string::npos) { size = size.substr(0, size.find("/")); count_ = std::stoi(size); } } has_mtx_ = json.HasMember("cosmeticMods"); GenerateMods(json); }
Item::Item(const rapidjson::Value &json) : location_(ItemLocation(json)), name_(json["name"].GetString()), typeLine_(json["typeLine"].GetString()), corrupted_(json["corrupted"].GetBool()), w_(json["w"].GetInt()), h_(json["h"].GetInt()), frameType_(json["frameType"].GetInt()), icon_(json["icon"].GetString()), sockets_cnt_(0), links_cnt_(0), sockets_({ 0, 0, 0, 0 }), has_mtx_(false) { // Fix for 2.0.2 QString name = QString::fromStdString(name_); name.remove(QRegularExpression("<(.*)>")); name_ = name.toStdString(); QString typeLine = QString::fromStdString(typeLine_); typeLine.remove(QRegularExpression("<(.*)>")); typeLine_ = typeLine.toStdString(); for (auto &mod_type : ITEM_MOD_TYPES) { text_mods_[mod_type] = std::vector<std::string>(); if (json.HasMember(mod_type.c_str())) { auto &mods = text_mods_[mod_type]; for (auto &mod : json[mod_type.c_str()]) mods.push_back(mod.GetString()); } } if (json.HasMember("properties")) { for (auto prop_it = json["properties"].Begin(); prop_it != json["properties"].End(); ++prop_it) { auto &prop = *prop_it; std::string name = prop["name"].GetString(); if (name == "Map Level") name = "Level"; if (name == "Elemental Damage") { for (auto value_it = prop["values"].Begin(); value_it != prop["values"].End(); ++value_it) elemental_damage_.push_back(std::make_pair((*value_it)[0].GetString(), (*value_it)[1].GetInt())); } else { if (prop["values"].Size()) properties_[name] = prop["values"][0][0].GetString(); } ItemProperty property; property.name = name; property.display_mode = prop["displayMode"].GetInt(); for (auto &value : prop["values"]) property.values.push_back(value[0].GetString()); text_properties_.push_back(property); } } if (json.HasMember("requirements")) { for (auto &req : json["requirements"]) { std::string name = req["name"].GetString(); std::string value = req["values"][0][0].GetString(); requirements_[name] = std::atoi(value.c_str()); text_requirements_.push_back({ name, value }); } } if (json.HasMember("sockets")) { ItemSocketGroup current_group = { 0, 0, 0, 0 }; sockets_cnt_ = json["sockets"].Size(); int counter = 0, prev_group = -1; for (auto &socket : json["sockets"]) { ItemSocket current_socket = { static_cast<unsigned char>(socket["group"].GetInt()), socket["attr"].GetString()[0] }; text_sockets_.push_back(current_socket); if (prev_group != current_socket.group) { counter = 0; socket_groups_.push_back(current_group); current_group = { 0, 0, 0, 0 }; } prev_group = current_socket.group; ++counter; links_cnt_ = std::max(links_cnt_, counter); switch (current_socket.attr) { case 'S': sockets_.r++; current_group.r++; break; case 'D': sockets_.g++; current_group.g++; break; case 'I': sockets_.b++; current_group.b++; break; case 'G': sockets_.w++; current_group.w++; break; } } socket_groups_.push_back(current_group); } std::string unique(std::string(json["name"].GetString()) + "~" + json["typeLine"].GetString() + "~"); if (json.HasMember("explicitMods")) for (auto mod_it = json["explicitMods"].Begin(); mod_it != json["explicitMods"].End(); ++mod_it) unique += std::string(mod_it->GetString()) + "~"; if (json.HasMember("implicitMods")) for (auto mod_it = json["implicitMods"].Begin(); mod_it != json["implicitMods"].End(); ++mod_it) unique += std::string(mod_it->GetString()) + "~"; unique += item_unique_properties(json, "properties") + "~"; unique += item_unique_properties(json, "additionalProperties") + "~"; if (json.HasMember("sockets")) for (auto socket_it = json["sockets"].Begin(); socket_it != json["sockets"].End(); ++socket_it) unique += std::to_string((*socket_it)["group"].GetInt()) + "~" + (*socket_it)["attr"].GetString() + "~"; hash_ = Util::Md5(unique); count_ = 1; if (properties_.find("Stack Size") != properties_.end()) { std::string size = properties_["Stack Size"]; if (size.find("/") != std::string::npos) { size = size.substr(0, size.find("/")); count_ = std::stoi(size); } } has_mtx_ = json.HasMember("cosmeticMods"); GenerateMods(json); }