mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-24 10:56:38 +01:00
Core/DataStores: Rewrite DB2Manager::GetDefaultMapDifficulty to only return entries that point to valid Difficulty.db2 rows
(cherry picked from commit 441d7e5dc1)
This commit is contained in:
@@ -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)
|
||||
// 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 (foundDifficulty == difficultyEnd)
|
||||
return nullptr; // nothing valid was found
|
||||
|
||||
if (!(sDifficultyStore.AssertEntry(foundDifficulty->first)->Flags & DIFFICULTY_FLAG_DEFAULT))
|
||||
{
|
||||
DifficultyEntry const* difficultyEntry = sDifficultyStore.LookupEntry(p.first);
|
||||
if (!difficultyEntry)
|
||||
continue;
|
||||
// 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 (difficultyEntry->Flags & DIFFICULTY_FLAG_DEFAULT)
|
||||
{
|
||||
if (difficulty)
|
||||
*difficulty = Difficulty(p.first);
|
||||
|
||||
return p.second;
|
||||
}
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user