diff options
Diffstat (limited to 'src/server/game/Spells/SpellMgr.cpp')
-rw-r--r-- | src/server/game/Spells/SpellMgr.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index 20ab87f8188..a91d73be4e1 100644 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -809,8 +809,69 @@ void SpellMgr::UnloadSpellInfoChains() mSpellChains.clear(); } +void SpellMgr::LoadSpellTalentRanks() +{ + // cleanup core data before reload - remove reference to ChainNode from SpellInfo + UnloadSpellInfoChains(); + + for (TalentEntry const* talentInfo : sTalentStore) + { + SpellInfo const* lastSpell = nullptr; + for (uint8 rank = talentInfo->SpellRank.size() - 1; rank > 0; --rank) + { + if (talentInfo->SpellRank[rank]) + { + lastSpell = GetSpellInfo(talentInfo->SpellRank[rank], DIFFICULTY_NONE); + break; + } + } + + if (!lastSpell) + continue; + + SpellInfo const* firstSpell = GetSpellInfo(talentInfo->SpellRank[0], DIFFICULTY_NONE); + if (!firstSpell) + { + TC_LOG_ERROR("spells", "SpellMgr::LoadSpellTalentRanks: First Rank Spell {} for TalentEntry {} does not exist.", talentInfo->SpellRank[0], talentInfo->ID); + continue; + } + + SpellInfo const* prevSpell = nullptr; + for (uint8 rank = 0; rank < talentInfo->SpellRank.size(); ++rank) + { + uint32 spellId = talentInfo->SpellRank[rank]; + if (!spellId) + break; + + SpellInfo const* currentSpell = GetSpellInfo(spellId, DIFFICULTY_NONE); + if (!currentSpell) + { + TC_LOG_ERROR("spells", "SpellMgr::LoadSpellTalentRanks: Spell {} (Rank: {}) for TalentEntry {} does not exist.", spellId, rank + 1, talentInfo->ID); + break; + } + + SpellChainNode node; + node.first = firstSpell; + node.last = lastSpell; + node.rank = rank + 1; + + node.prev = prevSpell; + node.next = node.rank < MAX_TALENT_RANK ? GetSpellInfo(talentInfo->SpellRank[node.rank], DIFFICULTY_NONE) : nullptr; + + mSpellChains[spellId] = node; + for (SpellInfo const& difficultyInfo : _GetSpellInfo(spellId)) + const_cast<SpellInfo&>(difficultyInfo).ChainEntry = &mSpellChains[spellId]; + + prevSpell = currentSpell; + } + } +} + void SpellMgr::LoadSpellRanks() { + // cleanup data and load spell ranks for talents from dbc + LoadSpellTalentRanks(); + uint32 oldMSTime = getMSTime(); std::map<uint32 /*spell*/, uint32 /*next*/> chains; |