aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-11-15 19:07:50 +0100
committerOvahlord <dreadkiller@gmx.de>2024-11-15 19:10:22 +0100
commit4762ed8f8cd0be1454b76055e79b3c65eea8a570 (patch)
treefc14c9628078373d38b3f26ff6a2957229805d5b /src
parent2d91df0dafb3c33dbad210dbfd4edfab3b4ef1fd (diff)
Core/DataStores: Rewrite DB2Manager::GetDefaultMapDifficulty to only return entries that point to valid Difficulty.db2 rows
(cherry picked from commit 441d7e5dc1522680d52fde03e0f3cbe751350f3b)
Diffstat (limited to 'src')
-rw-r--r--src/server/game/DataStores/DB2Stores.cpp36
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