refactor(Script/Command): learn spell (#24319)

Co-authored-by: Treeston <14020072+Treeston@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Kitzunu
2026-03-21 13:28:24 +01:00
committed by GitHub
parent b90c917b49
commit e6054ec7ea
6 changed files with 71 additions and 43 deletions

View File

@@ -9719,6 +9719,7 @@ void ObjectMgr::LoadTrainers()
// For reload case
_trainers.clear();
_classTrainers.clear();
std::unordered_map<int32, std::vector<Trainer::Spell>> spellsByTrainer;
if (QueryResult trainerSpellsResult = WorldDatabase.Query("SELECT TrainerId, SpellId, MoneyCost, ReqSkillLine, ReqSkillRank, ReqAbility1, ReqAbility2, ReqAbility3, ReqLevel FROM trainer_spell"))
@@ -9795,7 +9796,18 @@ void ObjectMgr::LoadTrainers()
spellsByTrainer.erase(spellsItr);
}
_trainers.emplace(std::piecewise_construct, std::forward_as_tuple(trainerId), std::forward_as_tuple(trainerId, trainerType, requirement, std::move(greeting), std::move(spells)));
auto [it, isNew] = _trainers.emplace(std::piecewise_construct, std::forward_as_tuple(trainerId), std::forward_as_tuple(trainerId, trainerType, requirement, std::move(greeting), std::move(spells)));
ASSERT(isNew);
if (trainerType == Trainer::Type::Class)
{
if (!requirement || requirement >= MAX_CLASSES)
LOG_ERROR("sql.sql", "Table `trainer` has invalid class requirement for trainer {}, ignoring");
else
{
uint8 classId = static_cast<uint8>(requirement);
_classTrainers[classId].push_back(&it->second);
}
}
} while (trainersResult->NextRow());
}