Skip to content

Commit a1fca43

Browse files
committed
Core/DataStores: Replace MapDifficulty structure with full MapDifficultyEntry and load all locales for that dbc, fixes sending SMSG_TRANSFER_ABORTED for missing achievement when not using enUS dbc files
(cherry picked from commit 5fed109)
1 parent 5d7e3e8 commit a1fca43

11 files changed

Lines changed: 53 additions & 68 deletions

File tree

src/server/game/DataStores/DBCStores.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
typedef std::map<uint16, uint32> AreaFlagByAreaID;
3737
typedef std::map<uint32, uint32> AreaFlagByMapID;
38-
38+
typedef std::map<std::pair<uint32, Difficulty>, MapDifficultyEntry const*> MapDifficultyMap;
3939
typedef std::tuple<int16, int8, int32> WMOAreaTableKey;
4040
typedef std::map<WMOAreaTableKey, WMOAreaTableEntry const*> WMOAreaInfoByTripple;
4141

@@ -132,7 +132,7 @@ DBCStorage <MapEntry> sMapStore(MapEntryfmt);
132132

133133
// DBC used only for initialization sMapDifficultyMap at startup.
134134
DBCStorage <MapDifficultyEntry> sMapDifficultyStore(MapDifficultyEntryfmt); // only for loading
135-
MapDifficultyMap sMapDifficultyMap;
135+
static MapDifficultyMap sMapDifficultyMap;
136136

137137
DBCStorage <MovieEntry> sMovieStore(MovieEntryfmt);
138138

@@ -437,7 +437,7 @@ void LoadDBCStores(const std::string& dataPath)
437437

438438
// fill data
439439
for (MapDifficultyEntry const* entry : sMapDifficultyStore)
440-
sMapDifficultyMap[MAKE_PAIR32(entry->MapID, entry->Difficulty)] = MapDifficulty(entry->RaidDuration, entry->MaxPlayers, entry->Message[0] != '\0');
440+
sMapDifficultyMap[{ entry->MapID, Difficulty(entry->Difficulty) }] = entry;
441441

442442
for (NamesProfanityEntry const* namesProfanity : sNamesProfanityStore)
443443
{
@@ -799,16 +799,15 @@ void Map2ZoneCoordinates(float& x, float& y, uint32 zone)
799799
std::swap(x, y); // client have map coords swapped
800800
}
801801

802-
MapDifficulty const* GetMapDifficultyData(uint32 mapId, Difficulty difficulty)
802+
MapDifficultyEntry const* GetMapDifficultyData(uint32 mapId, Difficulty difficulty)
803803
{
804-
MapDifficultyMap::const_iterator itr = sMapDifficultyMap.find(MAKE_PAIR32(mapId, difficulty));
805-
return itr != sMapDifficultyMap.end() ? &itr->second : nullptr;
804+
return Trinity::Containers::MapGetValuePtr(sMapDifficultyMap, { mapId, difficulty });
806805
}
807806

808-
MapDifficulty const* GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty)
807+
MapDifficultyEntry const* GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty)
809808
{
810809
uint32 tmpDiff = difficulty;
811-
MapDifficulty const* mapDiff = GetMapDifficultyData(mapId, Difficulty(tmpDiff));
810+
MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mapId, Difficulty(tmpDiff));
812811
if (!mapDiff)
813812
{
814813
if (tmpDiff > RAID_DIFFICULTY_25MAN_NORMAL) // heroic, downscale to normal

src/server/game/DataStores/DBCStores.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ TC_GAME_API bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint
6060
TC_GAME_API void Zone2MapCoordinates(float &x, float &y, uint32 zone);
6161
TC_GAME_API void Map2ZoneCoordinates(float &x, float &y, uint32 zone);
6262

63-
typedef std::map<uint32/*pair32(map, diff)*/, MapDifficulty> MapDifficultyMap;
64-
TC_GAME_API MapDifficulty const* GetMapDifficultyData(uint32 mapId, Difficulty difficulty);
65-
TC_GAME_API MapDifficulty const* GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty);
63+
TC_GAME_API MapDifficultyEntry const* GetMapDifficultyData(uint32 mapId, Difficulty difficulty);
64+
TC_GAME_API MapDifficultyEntry const* GetDownscaledMapDifficultyData(uint32 mapId, Difficulty &difficulty);
6665

6766
TC_GAME_API uint32 const* /*[MAX_TALENT_TABS]*/ GetTalentTabPages(uint8 cls);
6867

@@ -157,8 +156,7 @@ TC_GAME_API extern DBCStorage <LiquidTypeEntry> sLiquidTypeStore;
157156
TC_GAME_API extern DBCStorage <LockEntry> sLockStore;
158157
TC_GAME_API extern DBCStorage <MailTemplateEntry> sMailTemplateStore;
159158
TC_GAME_API extern DBCStorage <MapEntry> sMapStore;
160-
//TC_GAME_API extern DBCStorage <MapDifficultyEntry> sMapDifficultyStore; -- use GetMapDifficultyData insteed
161-
TC_GAME_API extern MapDifficultyMap sMapDifficultyMap;
159+
TC_GAME_API extern DBCStorage <MapDifficultyEntry> sMapDifficultyStore;
162160
TC_GAME_API extern DBCStorage <MovieEntry> sMovieStore;
163161
TC_GAME_API extern DBCStorage <OverrideSpellDataEntry> sOverrideSpellDataStore;
164162
TC_GAME_API extern DBCStorage <PowerDisplayEntry> sPowerDisplayStore;

src/server/game/Entities/Player/Player.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11621,29 +11621,29 @@ void Player::RemoveAmmo()
1162111621
}
1162211622

1162311623
// Return stored item (if stored to stack, it can diff. from pItem). And pItem ca be deleted in this case.
11624-
Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update, int32 randomPropertyId, GuidSet const& allowedLooters)
11624+
Item* Player::StoreNewItem(ItemPosCountVec const& pos, uint32 itemId, bool update, int32 randomPropertyId /*= 0*/, GuidSet const& allowedLooters /*= GuidSet()*/)
1162511625
{
1162611626
uint32 count = 0;
11627-
for (ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
11627+
for (ItemPosCountVec::const_iterator itr = pos.begin(); itr != pos.end(); ++itr)
1162811628
count += itr->count;
1162911629

11630-
Item* pItem = Item::CreateItem(item, count, this);
11631-
if (pItem)
11630+
Item* item = Item::CreateItem(itemId, count, this);
11631+
if (item)
1163211632
{
1163311633
if (randomPropertyId)
11634-
pItem->SetItemRandomProperties(randomPropertyId);
11634+
item->SetItemRandomProperties(randomPropertyId);
1163511635

11636-
pItem = StoreItem(dest, pItem, update);
11636+
item = StoreItem(pos, item, update);
1163711637

11638-
ItemAddedQuestCheck(item, count);
11639-
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, item, count);
11640-
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM, item, count);
11638+
ItemAddedQuestCheck(itemId, count);
11639+
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, itemId, count);
11640+
UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM, itemId, count);
1164111641

11642-
if (allowedLooters.size() > 1 && pItem->GetTemplate()->GetMaxStackSize() == 1 && pItem->IsSoulBound())
11642+
if (allowedLooters.size() > 1 && item->GetTemplate()->GetMaxStackSize() == 1 && item->IsSoulBound())
1164311643
{
11644-
pItem->SetSoulboundTradeable(allowedLooters);
11645-
pItem->SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, GetTotalPlayedTime());
11646-
AddTradeableItem(pItem);
11644+
item->SetSoulboundTradeable(allowedLooters);
11645+
item->SetUInt32Value(ITEM_FIELD_CREATE_PLAYED_TIME, GetTotalPlayedTime());
11646+
AddTradeableItem(item);
1164711647

1164811648
// save data
1164911649
std::ostringstream ss;
@@ -11653,12 +11653,12 @@ Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update
1165311653
ss << ' ' << itr->GetCounter();
1165411654

1165511655
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ITEM_BOP_TRADE);
11656-
stmt->setUInt32(0, pItem->GetGUID().GetCounter());
11656+
stmt->setUInt32(0, item->GetGUID().GetCounter());
1165711657
stmt->setString(1, ss.str());
1165811658
CharacterDatabase.Execute(stmt);
1165911659
}
1166011660
}
11661-
return pItem;
11661+
return item;
1166211662
}
1166311663

1166411664
Item* Player::StoreItem(ItemPosCountVec const& dest, Item* pItem, bool update)
@@ -18533,7 +18533,7 @@ void Player::_LoadBoundInstances(PreparedQueryResult result)
1853318533
}
1853418534
else
1853518535
{
18536-
MapDifficulty const* mapDiff = GetMapDifficultyData(mapId, Difficulty(difficulty));
18536+
MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mapId, Difficulty(difficulty));
1853718537
if (!mapDiff)
1853818538
{
1853918539
TC_LOG_ERROR("entities.player", "Player::_LoadBoundInstances: player '{}' ({}) has bind to not existed difficulty {} instance for map {} ({})",
@@ -18571,7 +18571,7 @@ void Player::_LoadBoundInstances(PreparedQueryResult result)
1857118571
InstancePlayerBind* Player::GetBoundInstance(uint32 mapid, Difficulty difficulty, bool withExpired)
1857218572
{
1857318573
// some instances only have one difficulty
18574-
MapDifficulty const* mapDiff = GetDownscaledMapDifficultyData(mapid, difficulty);
18574+
MapDifficultyEntry const* mapDiff = GetDownscaledMapDifficultyData(mapid, difficulty);
1857518575
if (!mapDiff)
1857618576
return nullptr;
1857718577

@@ -18842,14 +18842,14 @@ bool Player::Satisfy(AccessRequirement const* ar, uint32 target_map, bool report
1884218842
missingAchievement = ar->achievement;
1884318843

1884418844
Difficulty target_difficulty = group ? group->GetDifficultyID(mapEntry) : GetDifficultyID(mapEntry);
18845-
MapDifficulty const* mapDiff = GetDownscaledMapDifficultyData(target_map, target_difficulty);
18845+
MapDifficultyEntry const* mapDiff = GetDownscaledMapDifficultyData(target_map, target_difficulty);
1884618846
if (LevelMin || LevelMax || missingItem || missingQuest || missingAchievement)
1884718847
{
1884818848
if (report)
1884918849
{
1885018850
if (missingQuest && !ar->questFailedText.empty())
1885118851
ChatHandler(GetSession()).PSendSysMessage("%s", ar->questFailedText.c_str());
18852-
else if (mapDiff->hasErrorMessage) // if (missingAchievement) covered by this case
18852+
else if (mapDiff->Message[sWorld->GetDefaultDbcLocale()][0] != '\0') // if (missingAchievement) covered by this case
1885318853
SendTransferAborted(target_map, TRANSFER_ABORT_DIFFICULTY, target_difficulty);
1885418854
else if (missingItem)
1885518855
GetSession()->SendAreaTriggerMessage(GetSession()->GetTrinityString(LANG_LEVEL_MINREQUIRED_AND_ITEM), LevelMin, ASSERT_NOTNULL(sObjectMgr->GetItemTemplate(missingItem))->GetName(GetSession()->GetSessionDbLocaleIndex()).c_str());

src/server/game/Entities/Player/Player.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
11241124
InventoryResult CanUseItem(ItemTemplate const* pItem) const;
11251125
InventoryResult CanUseAmmo(uint32 item) const;
11261126
InventoryResult CanRollForItemInLFG(ItemTemplate const* item, WorldObject const* lootedObject) const;
1127-
Item* StoreNewItem(ItemPosCountVec const& pos, uint32 item, bool update, int32 randomPropertyId = 0, GuidSet const& allowedLooters = GuidSet());
1127+
Item* StoreNewItem(ItemPosCountVec const& pos, uint32 itemId, bool update, int32 randomPropertyId = 0, GuidSet const& allowedLooters = GuidSet());
11281128
Item* StoreItem(ItemPosCountVec const& pos, Item* pItem, bool update);
11291129
Item* EquipNewItem(uint16 pos, uint32 item, bool update);
11301130
Item* EquipItem(uint16 pos, Item* pItem, bool update);

src/server/game/Handlers/MovementHandler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,9 @@ void WorldSession::HandleMoveWorldportAck()
309309
{
310310
// check if this instance has a reset time and send it to player if so
311311
Difficulty diff = newMap->GetDifficultyID();
312-
if (MapDifficulty const* mapDiff = GetMapDifficultyData(mEntry->ID, diff))
312+
if (MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mEntry->ID, diff))
313313
{
314-
if (mapDiff->resetTime)
314+
if (mapDiff->RaidDuration)
315315
{
316316
if (time_t timeReset = sInstanceSaveMgr->GetResetTimeFor(mEntry->ID, diff))
317317
{

src/server/game/Instances/InstanceSaveMgr.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ void InstanceSaveManager::LoadResetTimes()
355355
Difficulty difficulty = Difficulty(fields[1].GetUInt8());
356356
uint64 oldresettime = fields[2].GetUInt64();
357357

358-
MapDifficulty const* mapDiff = GetMapDifficultyData(mapid, difficulty);
358+
MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mapid, difficulty);
359359
if (!mapDiff)
360360
{
361361
TC_LOG_ERROR("misc", "InstanceSaveManager::LoadResetTimes: invalid mapid({})/difficulty({}) pair in instance_reset!", mapid, static_cast<uint32>(difficulty));
@@ -384,17 +384,15 @@ void InstanceSaveManager::LoadResetTimes()
384384

385385
// calculate new global reset times for expired instances and those that have never been reset yet
386386
// add the global reset times to the priority queue
387-
for (MapDifficultyMap::const_iterator itr = sMapDifficultyMap.begin(); itr != sMapDifficultyMap.end(); ++itr)
387+
for (MapDifficultyEntry const* mapDiff : sMapDifficultyStore)
388388
{
389-
uint32 map_diff_pair = itr->first;
390-
uint32 mapid = PAIR32_LOPART(map_diff_pair);
391-
Difficulty difficulty = Difficulty(PAIR32_HIPART(map_diff_pair));
392-
MapDifficulty const* mapDiff = &itr->second;
393-
if (!mapDiff->resetTime)
389+
uint32 mapid = mapDiff->MapID;
390+
Difficulty difficulty = Difficulty(mapDiff->Difficulty);
391+
if (!mapDiff->RaidDuration)
394392
continue;
395393

396394
// the reset_delay must be at least one day
397-
uint32 period = uint32(((mapDiff->resetTime * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / float(DAY)) * float(DAY));
395+
uint32 period = uint32(((mapDiff->RaidDuration * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / float(DAY)) * float(DAY));
398396
if (period < DAY)
399397
period = DAY;
400398

@@ -435,23 +433,23 @@ void InstanceSaveManager::LoadResetTimes()
435433

436434
ScheduleReset(true, t - ResetTimeDelay[type-1], InstResetEvent(type, mapid, difficulty, 0));
437435

438-
ResetTimeMapDiffInstancesBounds range = mapDiffResetInstances.equal_range(map_diff_pair);
436+
ResetTimeMapDiffInstancesBounds range = mapDiffResetInstances.equal_range(MAKE_PAIR32(mapid, difficulty));
439437
for (; range.first != range.second; ++range.first)
440438
ScheduleReset(true, t - ResetTimeDelay[type-1], InstResetEvent(type, mapid, difficulty, range.first->second));
441439
}
442440
}
443441

444442
time_t InstanceSaveManager::GetSubsequentResetTime(uint32 mapid, Difficulty difficulty, time_t resetTime) const
445443
{
446-
MapDifficulty const* mapDiff = GetMapDifficultyData(mapid, difficulty);
447-
if (!mapDiff || !mapDiff->resetTime)
444+
MapDifficultyEntry const* mapDiff = GetMapDifficultyData(mapid, difficulty);
445+
if (!mapDiff || !mapDiff->RaidDuration)
448446
{
449447
TC_LOG_ERROR("misc", "InstanceSaveManager::GetSubsequentResetTime: not valid difficulty or no reset delay for map {}", mapid);
450448
return 0;
451449
}
452450

453451
time_t resetHour = sWorld->getIntConfig(CONFIG_INSTANCE_RESET_TIME_HOUR);
454-
time_t period = uint32(((mapDiff->resetTime * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / float(DAY)) * float(DAY));
452+
time_t period = uint32(((mapDiff->RaidDuration * sWorld->getRate(RATE_INSTANCE_RESET_TIME)) / float(DAY)) * float(DAY));
455453
if (period < DAY)
456454
period = DAY;
457455

src/server/game/Maps/Map.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4208,7 +4208,7 @@ void InstanceMap::SetResetSchedule(bool on)
42084208
}
42094209
}
42104210

4211-
MapDifficulty const* Map::GetMapDifficulty() const
4211+
MapDifficultyEntry const* Map::GetMapDifficulty() const
42124212
{
42134213
return GetMapDifficultyData(GetId(), GetDifficultyID());
42144214
}
@@ -4290,17 +4290,17 @@ bool InstanceMap::HasPermBoundPlayers() const
42904290

42914291
uint32 InstanceMap::GetMaxPlayers() const
42924292
{
4293-
MapDifficulty const* mapDiff = GetMapDifficulty();
4294-
if (mapDiff && mapDiff->maxPlayers)
4295-
return mapDiff->maxPlayers;
4293+
MapDifficultyEntry const* mapDiff = GetMapDifficulty();
4294+
if (mapDiff && mapDiff->MaxPlayers)
4295+
return mapDiff->MaxPlayers;
42964296

42974297
return GetEntry()->MaxPlayers;
42984298
}
42994299

43004300
uint32 InstanceMap::GetMaxResetDelay() const
43014301
{
4302-
MapDifficulty const* mapDiff = GetMapDifficulty();
4303-
return mapDiff ? mapDiff->resetTime : 0;
4302+
MapDifficultyEntry const* mapDiff = GetMapDifficulty();
4303+
return mapDiff ? mapDiff->RaidDuration : 0;
43044304
}
43054305

43064306
/* ******* Battleground Instance Maps ******* */

src/server/game/Maps/Map.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class Weather;
5757
class WorldObject;
5858
class WorldPacket;
5959
class WorldSession;
60-
struct MapDifficulty;
60+
struct MapDifficultyEntry;
6161
struct MapEntry;
6262
struct Position;
6363
struct ScriptAction;
@@ -431,7 +431,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
431431

432432
// have meaning only for instanced map (that have set real difficulty)
433433
Difficulty GetDifficultyID() const { return Difficulty(GetSpawnMode()); }
434-
MapDifficulty const* GetMapDifficulty() const;
434+
MapDifficultyEntry const* GetMapDifficulty() const;
435435

436436
bool Instanceable() const;
437437
bool IsWorldMap() const;

src/server/game/Maps/MapManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ Map::EnterState MapManager::PlayerCannotEnter(uint32 mapid, Player* player, bool
145145
Difficulty targetDifficulty, requestedDifficulty;
146146
targetDifficulty = requestedDifficulty = group ? group->GetDifficultyID(entry) : player->GetDifficultyID(entry);
147147
// Get the highest available difficulty if current setting is higher than the instance allows
148-
MapDifficulty const* mapDiff = GetDownscaledMapDifficultyData(entry->ID, targetDifficulty);
148+
MapDifficultyEntry const* mapDiff = GetDownscaledMapDifficultyData(entry->ID, targetDifficulty);
149149
if (!mapDiff)
150150
return Map::CANNOT_ENTER_DIFFICULTY_UNAVAILABLE;
151151

src/server/shared/DataStores/DBCStructure.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,7 +1118,7 @@ struct MapDifficultyEntry
11181118
//uint32 ID; // 0
11191119
uint32 MapID; // 1
11201120
uint32 Difficulty; // 2 (for arenas: arena slot)
1121-
char const* Message; // 3-18 text showed when transfer to map failed (missing requirements)
1121+
char const* Message[16]; // 3-18 text showed when transfer to map failed (missing requirements)
11221122
//uint32 Message_lang_mask; // 19
11231123
uint32 RaidDuration; // 20
11241124
uint32 MaxPlayers; // 21
@@ -1961,16 +1961,6 @@ struct WorldStateZoneSounds
19611961
#pragma pack(pop)
19621962

19631963
// Structures not used for casting to loaded DBC data and not required then packing
1964-
struct MapDifficulty
1965-
{
1966-
MapDifficulty() : resetTime(0), maxPlayers(0), hasErrorMessage(false) { }
1967-
MapDifficulty(uint32 _resetTime, uint32 _maxPlayers, bool _hasErrorMessage) : resetTime(_resetTime), maxPlayers(_maxPlayers), hasErrorMessage(_hasErrorMessage) { }
1968-
1969-
uint32 resetTime;
1970-
uint32 maxPlayers;
1971-
bool hasErrorMessage;
1972-
};
1973-
19741964
struct TalentSpellPos
19751965
{
19761966
TalentSpellPos() : talent_id(0), rank(0) { }

0 commit comments

Comments
 (0)