diff --git a/src/server/game/DataStores/DBCStores.cpp b/src/server/game/DataStores/DBCStores.cpp index 9f6699118..33cb2ace1 100644 --- a/src/server/game/DataStores/DBCStores.cpp +++ b/src/server/game/DataStores/DBCStores.cpp @@ -139,6 +139,7 @@ DBCStorage sScalingStatValuesStore(ScalingStatValuesfmt DBCStorage sSkillLineStore(SkillLinefmt); DBCStorage sSkillLineAbilityStore(SkillLineAbilityfmt); +SkillLineAbilityIndexBySkillLine sSkillLineAbilityIndexBySkillLine; DBCStorage sSkillRaceClassInfoStore(SkillRaceClassInfofmt); SkillRaceClassInfoMap SkillRaceClassInfoBySkill; DBCStorage sSkillTiersStore(SkillTiersfmt); @@ -454,6 +455,9 @@ void LoadDBCStores(const std::string& dataPath) } } + for (SkillLineAbilityEntry const* skillLine : sSkillLineAbilityStore) + sSkillLineAbilityIndexBySkillLine[skillLine->SkillLine].push_back(skillLine); + // Create Spelldifficulty searcher for (SpellDifficultyEntry const* spellDiff : sSpellDifficultyStore) { @@ -908,3 +912,14 @@ SkillRaceClassInfoEntry const* GetSkillRaceClassInfo(uint32 skill, uint8 race, u return nullptr; } + +const std::vector& GetSkillLineAbilitiesBySkillLine(uint32 skillLine) +{ + auto it = sSkillLineAbilityIndexBySkillLine.find(skillLine); + if (it == sSkillLineAbilityIndexBySkillLine.end()) + { + static const std::vector emptyVector; + return emptyVector; + } + return it->second; +} diff --git a/src/server/game/DataStores/DBCStores.h b/src/server/game/DataStores/DBCStores.h index da147e61d..9bc8090e2 100644 --- a/src/server/game/DataStores/DBCStores.h +++ b/src/server/game/DataStores/DBCStores.h @@ -72,6 +72,9 @@ typedef std::unordered_multimap SkillRac typedef std::pair SkillRaceClassInfoBounds; SkillRaceClassInfoEntry const* GetSkillRaceClassInfo(uint32 skill, uint8 race, uint8 class_); +typedef std::unordered_map > SkillLineAbilityIndexBySkillLine; +const std::vector& GetSkillLineAbilitiesBySkillLine(uint32 skillLine); + extern DBCStorage sAchievementStore; extern DBCStorage sAchievementCriteriaStore; extern DBCStorage sAchievementCategoryStore; @@ -151,6 +154,7 @@ extern DBCStorage sScalingStatDistributionStore; extern DBCStorage sScalingStatValuesStore; extern DBCStorage sSkillLineStore; extern DBCStorage sSkillLineAbilityStore; +extern SkillLineAbilityIndexBySkillLine sSkillLineAbilityIndexBySkillLine; extern DBCStorage sSkillTiersStore; extern DBCStorage sSoundEntriesStore; extern DBCStorage sSpellCastTimesStore; diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 19fff250e..fd173a16b 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -5313,10 +5313,8 @@ void Player::SetSkill(uint16 id, uint16 step, uint16 newVal, uint16 maxVal) mSkillStatus.erase(itr); // remove all spells that related to this skill - for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) - if (SkillLineAbilityEntry const* pAbility = sSkillLineAbilityStore.LookupEntry(j)) - if (pAbility->SkillLine == id) - removeSpell(sSpellMgr->GetFirstSpellInChain(pAbility->Spell), SPEC_MASK_ALL, false); + for (SkillLineAbilityEntry const* pAbility : GetSkillLineAbilitiesBySkillLine(id)) + removeSpell(sSpellMgr->GetFirstSpellInChain(pAbility->Spell), SPEC_MASK_ALL, false); } } else if (newVal) //add @@ -11935,14 +11933,8 @@ void Player::learnSkillRewardedSpells(uint32 skill_id, uint32 skill_value) { uint32 raceMask = getRaceMask(); uint32 classMask = getClassMask(); - for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) + for (SkillLineAbilityEntry const* pAbility : GetSkillLineAbilitiesBySkillLine(skill_id)) { - SkillLineAbilityEntry const* pAbility = sSkillLineAbilityStore.LookupEntry(j); - if (!pAbility || pAbility->SkillLine != skill_id) - { - continue; - } - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(pAbility->Spell); if (!spellInfo) { diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index 0e29e95d8..1bd906594 100644 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -2323,19 +2323,8 @@ void SpellMgr::LoadPetLevelupSpellMap() if (!creatureFamily->skillLine[j]) continue; - for (uint32 k = 0; k < sSkillLineAbilityStore.GetNumRows(); ++k) + for (SkillLineAbilityEntry const* skillLine : GetSkillLineAbilitiesBySkillLine(creatureFamily->skillLine[j])) { - SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(k); - if (!skillLine) - continue; - - //if (skillLine->skillId != creatureFamily->skillLine[0] && - // (!creatureFamily->skillLine[1] || skillLine->skillId != creatureFamily->skillLine[1])) - // continue; - - if (skillLine->SkillLine != creatureFamily->skillLine[j]) - continue; - if (skillLine->AcquireMethod != SKILL_LINE_ABILITY_LEARNED_ON_SKILL_LEARN) continue; diff --git a/src/server/scripts/Commands/cs_learn.cpp b/src/server/scripts/Commands/cs_learn.cpp index efe99283f..6664a294d 100644 --- a/src/server/scripts/Commands/cs_learn.cpp +++ b/src/server/scripts/Commands/cs_learn.cpp @@ -390,16 +390,8 @@ public: { uint32 classmask = player->getClassMask(); - for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) + for (SkillLineAbilityEntry const* skillLine : GetSkillLineAbilitiesBySkillLine(skillId)) { - SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(j); - if (!skillLine) - continue; - - // wrong skill - if (skillLine->SkillLine != skillId) - continue; - // not high rank if (skillLine->SupercededBySpell) continue;