From 9f9eae960c80f07eb3faad9c951dcf273083308a Mon Sep 17 00:00:00 2001 From: Pedro Henrique Alves Cruz Date: Sun, 22 Sep 2024 22:12:35 -0300 Subject: [PATCH] fix: items description --- src/items/item.cpp | 43 +++++++++++++------- src/server/network/protocol/protocolgame.cpp | 15 ++++--- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/items/item.cpp b/src/items/item.cpp index b7281da584f..95153bb812e 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -1182,12 +1182,17 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr item /*= nullptr } descriptions.emplace_back("Attack", ss.str()); } else if (!it.isRanged()) { + std::string attackDescription; if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0) { - ss.str(""); - ss << attack << " physical +" << it.abilities->elementDamage << ' ' << getCombatName(it.abilities->elementType); - descriptions.emplace_back("Attack", ss.str()); - } else if (it.attack != 0) { - descriptions.emplace_back("Attack", std::to_string(attack)); + attackDescription = fmt::format("{} {}", it.abilities->elementDamage, getCombatName(it.abilities->elementType)); + } + + if (it.attack != 0) { + attackDescription = fmt::format("{} physical + {}", attack, attackDescription); + } + + if (!attackDescription.empty()) { + descriptions.emplace_back("Attack", attackDescription); } } @@ -1595,12 +1600,17 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr item /*= nullptr } descriptions.emplace_back("Attack", ss.str()); } else if (!it.isRanged()) { + std::string attackDescription; if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0) { - ss.str(""); - ss << attack << " physical +" << it.abilities->elementDamage << ' ' << getCombatName(it.abilities->elementType); - descriptions.emplace_back("Attack", ss.str()); - } else if (it.attack != 0) { - descriptions.emplace_back("Attack", std::to_string(attack)); + attackDescription = fmt::format("{} {}", it.abilities->elementDamage, getCombatName(it.abilities->elementType)); + } + + if (it.attack != 0) { + attackDescription = fmt::format("{} physical + {}", attack, attackDescription); + } + + if (!attackDescription.empty()) { + descriptions.emplace_back("Attack", attackDescription); } } @@ -2642,14 +2652,19 @@ std::string Item::getDescription(const ItemType &it, int32_t lookDistance, std:: s << "Vol:" << volume; } } - if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0) { - begin = false; - s << " (Atk:" << attack << " physical + " << it.abilities->elementDamage << ' ' << getCombatName(it.abilities->elementType); - } else if (attack != 0) { + + if (attack != 0) { begin = false; s << " (Atk:" << attack; } + if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0 && !begin) { + s << " physical + " << it.abilities->elementDamage << ' ' << getCombatName(it.abilities->elementType); + } else if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0 && begin) { + begin = false; + s << " (" << it.abilities->elementDamage << ' ' << getCombatName(it.abilities->elementType); + } + if (defense != 0 || extraDefense != 0 || it.isMissile()) { if (begin) { begin = false; diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index a02c2fcc851..d2d31d4206d 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -5741,12 +5741,17 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { } msg.addString(ss.str(), "ProtocolGame::sendMarketDetail - ss.str()"); } else if (!it.isRanged()) { + std::string attackDescription; if (it.abilities && it.abilities->elementType != COMBAT_NONE && it.abilities->elementDamage != 0) { - std::ostringstream ss; - ss << it.attack << " physical +" << it.abilities->elementDamage << ' ' << getCombatName(it.abilities->elementType); - msg.addString(ss.str(), "ProtocolGame::sendMarketDetail - ss.str()"); - } else if (it.attack != 0) { - msg.addString(std::to_string(it.attack), "ProtocolGame::sendMarketDetail - std::to_string(it.attack)"); + attackDescription = fmt::format("{} {}", it.abilities->elementDamage, getCombatName(it.abilities->elementType)); + } + + if (it.attack != 0) { + attackDescription = fmt::format("{} physical + {}", it.attack, attackDescription); + } + + if (!attackDescription.empty()) { + msg.addString(attackDescription, "ProtocolGame::sendMarketDetail - attackDescription"); } } else { msg.add(0x00);