fix: prefix SMSG_SPELL_FAILURE error message with spell name

Previously a spell failure like "Not in range" gave no context about
which spell failed. Now the message reads e.g. "Fireball: Not in range"
using the spell name from the DBC cache. Falls back to the bare reason
string if the spell name is not yet cached.
This commit is contained in:
Kelsi 2026-03-13 06:14:28 -07:00
parent c58fc3073f
commit 3b499d6871

View file

@ -2998,7 +2998,7 @@ void GameHandler::handlePacket(network::Packet& packet) {
const size_t remainingFields = isClassic ? 5u : 6u; // spellId(4)+reason(1) [+castCount(1)]
if (packet.getSize() - packet.getReadPos() >= remainingFields) {
if (!isClassic) /*uint8_t castCount =*/ packet.readUInt8();
/*uint32_t spellId =*/ packet.readUInt32();
uint32_t failSpellId = packet.readUInt32();
uint8_t rawFailReason = packet.readUInt8();
// Classic result enum starts at 0=AFFECTING_COMBAT; shift +1 for WotLK table
uint8_t failReason = isClassic ? static_cast<uint8_t>(rawFailReason + 1) : rawFailReason;
@ -3010,11 +3010,15 @@ void GameHandler::handlePacket(network::Packet& packet) {
pt = static_cast<int>(pu->getPowerType());
const char* reason = getSpellCastResultString(failReason, pt);
if (reason) {
addUIError(reason);
// Prefix with spell name for context, e.g. "Fireball: Not in range"
const std::string& sName = getSpellName(failSpellId);
std::string fullMsg = sName.empty() ? reason
: sName + ": " + reason;
addUIError(fullMsg);
MessageChatData emsg;
emsg.type = ChatType::SYSTEM;
emsg.language = ChatLanguage::UNIVERSAL;
emsg.message = reason;
emsg.message = std::move(fullMsg);
addLocalChatMessage(emsg);
}
}