fix: suppress duplicate "Upgraded to X" message on trainer rank-up

When buying a higher spell rank from a trainer, SMSG_TRAINER_BUY_SUCCEEDED
already announces "You have learned X", and SMSG_SUPERCEDED_SPELLS would
then also print "Upgraded to X" — two messages for one action.

Fix: check if the new spell ID was already in knownSpells before inserting
it in handleSupercededSpell. If so, the trainer handler already announced
it and we skip the redundant "Upgraded to" message. Non-trainer supersedes
(quest rewards, etc.) where the spell wasn't pre-inserted still show it.
This commit is contained in:
Kelsi 2026-03-13 06:00:39 -07:00
parent dfe091473c
commit b9c16e9be5

View file

@ -16576,6 +16576,11 @@ void GameHandler::handleSupercededSpell(network::Packet& packet) {
// Remove old spell
knownSpells.erase(oldSpellId);
// Track whether the new spell was already announced via SMSG_TRAINER_BUY_SUCCEEDED.
// If it was pre-inserted there, that handler already showed "You have learned X" so
// we should skip the "Upgraded to X" message to avoid a duplicate.
const bool newSpellAlreadyAnnounced = knownSpells.count(newSpellId) > 0;
// Add new spell
knownSpells.insert(newSpellId);
@ -16596,9 +16601,14 @@ void GameHandler::handleSupercededSpell(network::Packet& packet) {
}
if (barChanged) saveCharacterConfig();
const std::string& newName = getSpellName(newSpellId);
if (!newName.empty()) {
addSystemChatMessage("Upgraded to " + newName);
// Show "Upgraded to X" only when the new spell wasn't already announced by the
// trainer-buy handler. For non-trainer supersedes (e.g. quest rewards), the new
// spell won't be pre-inserted so we still show the message.
if (!newSpellAlreadyAnnounced) {
const std::string& newName = getSpellName(newSpellId);
if (!newName.empty()) {
addSystemChatMessage("Upgraded to " + newName);
}
}
}