diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/DataStores/DB2Stores.cpp | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/server/game/DataStores/DB2Stores.cpp b/src/server/game/DataStores/DB2Stores.cpp index 734c0caa392..fe635b9ffd2 100644 --- a/src/server/game/DataStores/DB2Stores.cpp +++ b/src/server/game/DataStores/DB2Stores.cpp @@ -2094,32 +2094,34 @@ uint32 DB2Manager::GetLiquidFlags(uint32 liquidType) MapDifficultyEntry const* DB2Manager::GetDefaultMapDifficulty(uint32 mapId, Difficulty* difficulty /*= nullptr*/) const { - auto itr = _mapDifficulties.find(mapId); - if (itr == _mapDifficulties.end()) + std::unordered_map<uint32, MapDifficultyEntry const*>* difficultiesForMap = Trinity::Containers::MapGetValuePtr(_mapDifficulties, mapId); + if (!difficultiesForMap) return nullptr; - if (itr->second.empty()) - return nullptr; + auto difficultyEnd = difficultiesForMap->end(); - for (auto& p : itr->second) - { - DifficultyEntry const* difficultyEntry = sDifficultyStore.LookupEntry(p.first); - if (!difficultyEntry) - continue; + // first find any valid difficulty + auto foundDifficulty = std::ranges::find_if(difficultiesForMap->begin(), difficultyEnd, + [](std::pair<uint32 const, MapDifficultyEntry const*> const& p) { return sDifficultyStore.HasRecord(p.first); }); - if (difficultyEntry->Flags & DIFFICULTY_FLAG_DEFAULT) - { - if (difficulty) - *difficulty = Difficulty(p.first); + if (foundDifficulty == difficultyEnd) + return nullptr; // nothing valid was found - return p.second; - } + if (!(sDifficultyStore.AssertEntry(foundDifficulty->first)->Flags & DIFFICULTY_FLAG_DEFAULT)) + { + // first valid difficulty wasn't default, try finding one + auto defaultDifficulty = std::ranges::find_if(foundDifficulty, difficultyEnd, + [](DifficultyEntry const* difficultyEntry) { return difficultyEntry && (difficultyEntry->Flags & DIFFICULTY_FLAG_DEFAULT) != 0; }, + [](std::pair<uint32 const, MapDifficultyEntry const*> const& p) { return sDifficultyStore.LookupEntry(p.first); }); + + if (defaultDifficulty != difficultyEnd) + foundDifficulty = defaultDifficulty; // got a default } if (difficulty) - *difficulty = Difficulty(itr->second.begin()->first); + *difficulty = Difficulty(foundDifficulty->first); - return itr->second.begin()->second; + return foundDifficulty->second; } MapDifficultyEntry const* DB2Manager::GetMapDifficultyData(uint32 mapId, Difficulty difficulty) const |