fix: suppress duplicate chat message when learning trainer spell

SMSG_TRAINER_BUY_SUCCEEDED pre-inserts the spell into knownSpells and
shows "You have learned X." The subsequent SMSG_LEARNED_SPELL packet
would then show a second "You have learned a new spell: X." message.

Fix: check if the spell was already in knownSpells before inserting in
handleLearnedSpell. If it was pre-inserted by the trainer handler, skip
the chat notification to avoid the duplicate.
This commit is contained in:
Kelsi 2026-03-13 05:51:15 -07:00
parent 7dc12bb35e
commit b34df01331

View file

@ -16505,8 +16505,14 @@ void GameHandler::handleLearnedSpell(network::Packet& packet) {
const size_t minSz = classicSpellId ? 2u : 4u; const size_t minSz = classicSpellId ? 2u : 4u;
if (packet.getSize() - packet.getReadPos() < minSz) return; if (packet.getSize() - packet.getReadPos() < minSz) return;
uint32_t spellId = classicSpellId ? packet.readUInt16() : packet.readUInt32(); uint32_t spellId = classicSpellId ? packet.readUInt16() : packet.readUInt32();
// Track whether we already knew this spell before inserting.
// SMSG_TRAINER_BUY_SUCCEEDED pre-inserts the spell and shows its own "You have
// learned X" message, so when the accompanying SMSG_LEARNED_SPELL arrives we
// must not duplicate it.
const bool alreadyKnown = knownSpells.count(spellId) > 0;
knownSpells.insert(spellId); knownSpells.insert(spellId);
LOG_INFO("Learned spell: ", spellId); LOG_INFO("Learned spell: ", spellId, alreadyKnown ? " (already known, skipping chat)" : "");
// Check if this spell corresponds to a talent rank // Check if this spell corresponds to a talent rank
for (const auto& [talentId, talent] : talentCache_) { for (const auto& [talentId, talent] : talentCache_) {
@ -16522,12 +16528,15 @@ void GameHandler::handleLearnedSpell(network::Packet& packet) {
} }
} }
// Show chat message for non-talent spells // Show chat message for non-talent spells, but only if not already announced by
const std::string& name = getSpellName(spellId); // SMSG_TRAINER_BUY_SUCCEEDED (which pre-inserts into knownSpells).
if (!name.empty()) { if (!alreadyKnown) {
addSystemChatMessage("You have learned a new spell: " + name + "."); const std::string& name = getSpellName(spellId);
} else { if (!name.empty()) {
addSystemChatMessage("You have learned a new spell."); addSystemChatMessage("You have learned a new spell: " + name + ".");
} else {
addSystemChatMessage("You have learned a new spell.");
}
} }
} }