AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
AchievementGlobalMgr Class Reference

#include "AchievementMgr.h"

Public Member Functions

bool IsStatisticCriteria (AchievementCriteriaEntry const *achievementCriteria) const
 
bool IsStatisticAchievement (AchievementEntry const *achievement) const
 
bool IsAverageCriteria (AchievementCriteriaEntry const *criteria) const
 
AchievementCriteriaEntryList const * GetAchievementCriteriaByType (AchievementCriteriaTypes type) const
 
AchievementCriteriaEntryList const * GetSpecialAchievementCriteriaByType (AchievementCriteriaTypes type, uint32 val)
 
AchievementCriteriaEntryList const * GetAchievementCriteriaByCondition (AchievementCriteriaCondition condition, uint32 val)
 
AchievementCriteriaEntryList const & GetTimedAchievementCriteriaByType (AchievementCriteriaTimedTypes type) const
 
AchievementCriteriaEntryList const * GetAchievementCriteriaByAchievement (uint32 id) const
 
AchievementEntryList const * GetAchievementByReferencedId (uint32 id) const
 
AchievementReward const * GetAchievementReward (AchievementEntry const *achievement) const
 
AchievementRewardLocale const * GetAchievementRewardLocale (AchievementEntry const *achievement) const
 
AchievementCriteriaDataSet const * GetCriteriaDataSet (AchievementCriteriaEntry const *achievementCriteria) const
 
bool IsRealmCompleted (AchievementEntry const *achievement) const
 
void SetRealmCompleted (AchievementEntry const *achievement)
 
void LoadAchievementCriteriaList ()
 
void LoadAchievementCriteriaData ()
 
void LoadAchievementReferenceList ()
 
void LoadCompletedAchievements ()
 
void LoadRewards ()
 
void LoadRewardLocales ()
 
AchievementEntry const * GetAchievement (uint32 achievementId) const
 
void CompletedAchievementForOfflinePlayer (ObjectGuid::LowType playerLowGuid, AchievementEntry const *entry)
 
void UpdateAchievementCriteriaForOfflinePlayer (ObjectGuid::LowType playerLowGuid, AchievementCriteriaTypes type, uint32 miscValue1=0, uint32 miscValue2=0)
 

Static Public Member Functions

static AchievementGlobalMgrinstance ()
 

Private Types

typedef std::unordered_map< uint32, SystemTimePointAllCompletedAchievements
 

Private Member Functions

 AchievementGlobalMgr ()=default
 
 ~AchievementGlobalMgr ()=default
 

Private Attributes

AchievementCriteriaDataMap _criteriaDataMap
 
AchievementCriteriaEntryList _achievementCriteriasByType [ACHIEVEMENT_CRITERIA_TYPE_TOTAL]
 
AchievementCriteriaEntryList _achievementCriteriasByTimedType [ACHIEVEMENT_TIMED_TYPE_MAX]
 
AchievementCriteriaListByAchievement _achievementCriteriaListByAchievement
 
AchievementListByReferencedId _achievementListByReferencedId
 
AllCompletedAchievements _allCompletedAchievements
 
AchievementRewards _achievementRewards
 
AchievementRewardLocales _achievementRewardLocales
 
std::map< uint32, AchievementCriteriaEntryList_specialList [ACHIEVEMENT_CRITERIA_TYPE_TOTAL]
 
std::map< uint32, AchievementCriteriaEntryList_achievementCriteriasByCondition [ACHIEVEMENT_CRITERIA_CONDITION_TOTAL]
 

Detailed Description

Member Typedef Documentation

◆ AllCompletedAchievements

Constructor & Destructor Documentation

◆ AchievementGlobalMgr()

AchievementGlobalMgr::AchievementGlobalMgr ( )
privatedefault

◆ ~AchievementGlobalMgr()

AchievementGlobalMgr::~AchievementGlobalMgr ( )
privatedefault

Member Function Documentation

◆ CompletedAchievementForOfflinePlayer()

void AchievementGlobalMgr::CompletedAchievementForOfflinePlayer ( ObjectGuid::LowType  playerLowGuid,
AchievementEntry const *  entry 
)
3142{
3144 stmt->SetData(0, playerLowGuid);
3146 stmt->SetData(2, entry->ID);
3147 stmt->SetData(3, 0);
3148 stmt->SetData(4, 0);
3149 CharacterDatabase.Execute(stmt);
3150}
@ ACHIEVEMENT_OFFLINE_PLAYER_UPDATE_TYPE_COMPLETE_ACHIEVEMENT
Definition: AchievementMgr.h:38
@ CHAR_INS_CHAR_ACHIEVEMENT_OFFLINE_UPDATES
Definition: CharacterDatabase.h:368
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Definition: PreparedStatement.h:158
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78

References ACHIEVEMENT_OFFLINE_PLAYER_UPDATE_TYPE_COMPLETE_ACHIEVEMENT, CHAR_INS_CHAR_ACHIEVEMENT_OFFLINE_UPDATES, CharacterDatabase, AchievementEntry::ID, and PreparedStatementBase::SetData().

◆ GetAchievement()

AchievementEntry const * AchievementGlobalMgr::GetAchievement ( uint32  achievementId) const
3137{
3138 return sAchievementStore.LookupEntry(achievementId);
3139}
DBCStorage< AchievementEntry > sAchievementStore(Achievementfmt)

References sAchievementStore.

Referenced by LoadAchievementCriteriaList().

◆ GetAchievementByReferencedId()

AchievementEntryList const * AchievementGlobalMgr::GetAchievementByReferencedId ( uint32  id) const
inline
393 {
394 AchievementListByReferencedId::const_iterator itr = _achievementListByReferencedId.find(id);
395 return itr != _achievementListByReferencedId.end() ? &itr->second : nullptr;
396 }
AchievementListByReferencedId _achievementListByReferencedId
Definition: AchievementMgr.h:439

References _achievementListByReferencedId.

Referenced by IsAverageCriteria().

◆ GetAchievementCriteriaByAchievement()

AchievementCriteriaEntryList const * AchievementGlobalMgr::GetAchievementCriteriaByAchievement ( uint32  id) const
inline
387 {
388 AchievementCriteriaListByAchievement::const_iterator itr = _achievementCriteriaListByAchievement.find(id);
389 return itr != _achievementCriteriaListByAchievement.end() ? &itr->second : nullptr;
390 }
AchievementCriteriaListByAchievement _achievementCriteriaListByAchievement
Definition: AchievementMgr.h:437

References _achievementCriteriaListByAchievement.

◆ GetAchievementCriteriaByCondition()

AchievementCriteriaEntryList const * AchievementGlobalMgr::GetAchievementCriteriaByCondition ( AchievementCriteriaCondition  condition,
uint32  val 
)
inline
375 {
376 if (_achievementCriteriasByCondition[condition].find(val) != _achievementCriteriasByCondition[condition].end())
377 return &_achievementCriteriasByCondition[condition][val];
378 return nullptr;
379 }
std::map< uint32, AchievementCriteriaEntryList > _achievementCriteriasByCondition[ACHIEVEMENT_CRITERIA_CONDITION_TOTAL]
Definition: AchievementMgr.h:449

References _achievementCriteriasByCondition.

◆ GetAchievementCriteriaByType()

AchievementCriteriaEntryList const * AchievementGlobalMgr::GetAchievementCriteriaByType ( AchievementCriteriaTypes  type) const
inline
363 {
364 return &_achievementCriteriasByType[type];
365 }
AchievementCriteriaEntryList _achievementCriteriasByType[ACHIEVEMENT_CRITERIA_TYPE_TOTAL]
Definition: AchievementMgr.h:434

References _achievementCriteriasByType.

◆ GetAchievementReward()

AchievementReward const * AchievementGlobalMgr::GetAchievementReward ( AchievementEntry const *  achievement) const
inline
399 {
400 AchievementRewards::const_iterator iter = _achievementRewards.find(achievement->ID);
401 return iter != _achievementRewards.end() ? &iter->second : nullptr;
402 }
AchievementRewards _achievementRewards
Definition: AchievementMgr.h:444

References _achievementRewards, and AchievementEntry::ID.

◆ GetAchievementRewardLocale()

AchievementRewardLocale const * AchievementGlobalMgr::GetAchievementRewardLocale ( AchievementEntry const *  achievement) const
inline
405 {
406 AchievementRewardLocales::const_iterator iter = _achievementRewardLocales.find(achievement->ID);
407 return iter != _achievementRewardLocales.end() ? &iter->second : nullptr;
408 }
AchievementRewardLocales _achievementRewardLocales
Definition: AchievementMgr.h:445

References _achievementRewardLocales, and AchievementEntry::ID.

◆ GetCriteriaDataSet()

AchievementCriteriaDataSet const * AchievementGlobalMgr::GetCriteriaDataSet ( AchievementCriteriaEntry const *  achievementCriteria) const
inline
411 {
412 AchievementCriteriaDataMap::const_iterator iter = _criteriaDataMap.find(achievementCriteria->ID);
413 return iter != _criteriaDataMap.end() ? &iter->second : nullptr;
414 }
AchievementCriteriaDataMap _criteriaDataMap
Definition: AchievementMgr.h:431

References _criteriaDataMap, and AchievementCriteriaEntry::ID.

Referenced by LoadAchievementCriteriaData().

◆ GetSpecialAchievementCriteriaByType()

AchievementCriteriaEntryList const * AchievementGlobalMgr::GetSpecialAchievementCriteriaByType ( AchievementCriteriaTypes  type,
uint32  val 
)
inline
368 {
369 if (_specialList[type].find(val) != _specialList[type].end())
370 return &_specialList[type][val];
371 return nullptr;
372 }
std::map< uint32, AchievementCriteriaEntryList > _specialList[ACHIEVEMENT_CRITERIA_TYPE_TOTAL]
Definition: AchievementMgr.h:448

References _specialList.

◆ GetTimedAchievementCriteriaByType()

AchievementCriteriaEntryList const & AchievementGlobalMgr::GetTimedAchievementCriteriaByType ( AchievementCriteriaTimedTypes  type) const
inline
382 {
384 }
AchievementCriteriaEntryList _achievementCriteriasByTimedType[ACHIEVEMENT_TIMED_TYPE_MAX]
Definition: AchievementMgr.h:435

References _achievementCriteriasByTimedType.

◆ instance()

AchievementGlobalMgr * AchievementGlobalMgr::instance ( )
static
2524{
2526 return &instance;
2527}
Definition: AchievementMgr.h:351
static AchievementGlobalMgr * instance()
Definition: AchievementMgr.cpp:2523

References instance().

Referenced by instance().

◆ IsAverageCriteria()

bool AchievementGlobalMgr::IsAverageCriteria ( AchievementCriteriaEntry const *  criteria) const
2558{
2559 auto referencedAchievement = sAchievementStore.LookupEntry(criteria->referredAchievement);
2560
2561 if (!referencedAchievement)
2562 return false;
2563
2564 if (referencedAchievement->flags & ACHIEVEMENT_FLAG_AVERAGE)
2565 return true;
2566
2567 if (AchievementEntryList const* achRefList = GetAchievementByReferencedId(referencedAchievement->ID))
2568 for (AchievementEntryList::const_iterator itr = achRefList->begin(); itr != achRefList->end(); ++itr)
2569 if ((*itr)->flags & ACHIEVEMENT_FLAG_AVERAGE)
2570 return true;
2571
2572 return false;
2573}
std::list< AchievementEntry const * > AchievementEntryList
Definition: AchievementMgr.h:31
@ ACHIEVEMENT_FLAG_AVERAGE
Definition: DBCEnums.h:77
AchievementEntryList const * GetAchievementByReferencedId(uint32 id) const
Definition: AchievementMgr.h:392

References ACHIEVEMENT_FLAG_AVERAGE, GetAchievementByReferencedId(), AchievementCriteriaEntry::referredAchievement, and sAchievementStore.

◆ IsRealmCompleted()

bool AchievementGlobalMgr::IsRealmCompleted ( AchievementEntry const *  achievement) const
2576{
2577 auto itr = _allCompletedAchievements.find(achievement->ID);
2578 if (itr == _allCompletedAchievements.end())
2579 return false;
2580
2581 if (itr->second == SystemTimePoint::min())
2582 return false;
2583
2584 if (!sScriptMgr->IsRealmCompleted(this, achievement, itr->second))
2585 return false;
2586
2587 if (itr->second == SystemTimePoint::max())
2588 return true;
2589
2590 // Allow completing the realm first kill for entire minute after first person did it
2591 // it may allow more than one group to achieve it (highly unlikely)
2592 // but apparently this is how blizz handles it as well
2593 if (achievement->flags & ACHIEVEMENT_FLAG_REALM_FIRST_KILL)
2594 return (GameTime::GetSystemTime() - itr->second) > 1min;
2595
2596 sScriptMgr->SetRealmCompleted(achievement);
2597
2598 return true;
2599}
#define sScriptMgr
Definition: ScriptMgr.h:708
@ ACHIEVEMENT_FLAG_REALM_FIRST_KILL
Definition: DBCEnums.h:80
SystemTimePoint GetSystemTime()
Current chrono system_clock time point.
Definition: GameTime.cpp:48
AllCompletedAchievements _allCompletedAchievements
Definition: AchievementMgr.h:442

References _allCompletedAchievements, ACHIEVEMENT_FLAG_REALM_FIRST_KILL, AchievementEntry::flags, GameTime::GetSystemTime(), AchievementEntry::ID, and sScriptMgr.

Referenced by SetRealmCompleted().

◆ IsStatisticAchievement()

bool AchievementGlobalMgr::IsStatisticAchievement ( AchievementEntry const *  achievement) const
2535{
2536 if (!achievement)
2537 return false;
2538
2539 AchievementCategoryEntry const* cat = sAchievementCategoryStore.LookupEntry(achievement->categoryId);
2540 do
2541 {
2542 switch (cat->ID)
2543 {
2545 return true;
2547 return false;
2548 default:
2549 cat = sAchievementCategoryStore.LookupEntry(cat->parentCategory);
2550 break;
2551 }
2552 } while (cat);
2553
2554 return false;
2555}
DBCStorage< AchievementCategoryEntry > sAchievementCategoryStore(AchievementCategoryfmt)
@ ACHIEVEMENT_CATEGORY_STATISTICS
Definition: AchievementMgr.h:92
@ ACHIEVEMENT_CATEOGRY_GENERAL
Definition: AchievementMgr.h:91
Definition: DBCStructure.h:61
int32 ID
Definition: DBCStructure.h:62
int32 parentCategory
Definition: DBCStructure.h:63

References ACHIEVEMENT_CATEGORY_STATISTICS, ACHIEVEMENT_CATEOGRY_GENERAL, AchievementEntry::categoryId, AchievementCategoryEntry::ID, AchievementCategoryEntry::parentCategory, and sAchievementCategoryStore.

Referenced by IsStatisticCriteria().

◆ IsStatisticCriteria()

bool AchievementGlobalMgr::IsStatisticCriteria ( AchievementCriteriaEntry const *  achievementCriteria) const
2530{
2531 return IsStatisticAchievement(sAchievementStore.LookupEntry(achievementCriteria->referredAchievement));
2532}
bool IsStatisticAchievement(AchievementEntry const *achievement) const
Definition: AchievementMgr.cpp:2534

References IsStatisticAchievement(), AchievementCriteriaEntry::referredAchievement, and sAchievementStore.

◆ LoadAchievementCriteriaData()

void AchievementGlobalMgr::LoadAchievementCriteriaData ( )
2793{
2794 uint32 oldMSTime = getMSTime();
2795
2796 _criteriaDataMap.clear(); // need for reload case
2797
2798 QueryResult result = WorldDatabase.Query("SELECT criteria_id, type, value1, value2, ScriptName FROM achievement_criteria_data");
2799
2800 if (!result)
2801 {
2802 LOG_WARN("server.loading", ">> Loaded 0 additional achievement criteria data. DB table `achievement_criteria_data` is empty.");
2803 LOG_INFO("server.loading", " ");
2804 return;
2805 }
2806
2807 uint32 count = 0;
2808
2809 do
2810 {
2811 Field* fields = result->Fetch();
2812 uint32 criteria_id = fields[0].Get<uint32>();
2813
2814 AchievementCriteriaEntry const* criteria = sAchievementCriteriaStore.LookupEntry(criteria_id);
2815
2816 if (!criteria)
2817 {
2818 LOG_ERROR("sql.sql", "Table `achievement_criteria_data` has data for non-existing criteria (Entry: {}), ignore.", criteria_id);
2819 continue;
2820 }
2821
2822 uint32 dataType = fields[1].Get<uint8>();
2823 std::string scriptName = fields[4].Get<std::string>();
2824 uint32 scriptId = 0;
2825 if (scriptName.length()) // not empty
2826 {
2828 LOG_ERROR("sql.sql", "Table `achievement_criteria_data` has ScriptName set for non-scripted data type (Entry: {}, type {}), useless data.", criteria_id, dataType);
2829 else
2830 scriptId = sObjectMgr->GetScriptId(scriptName);
2831 }
2832
2833 AchievementCriteriaData data(dataType, fields[2].Get<uint32>(), fields[3].Get<uint32>(), scriptId);
2834
2835 if (!data.IsValid(criteria))
2836 continue;
2837
2838 // this will allocate empty data set storage
2839 AchievementCriteriaDataSet& dataSet = _criteriaDataMap[criteria_id];
2840 dataSet.SetCriteriaId(criteria_id);
2841
2842 // add real data only for not NONE data types
2843 if (data.dataType != ACHIEVEMENT_CRITERIA_DATA_TYPE_NONE)
2844 dataSet.Add(data);
2845
2846 // counting data by and data types
2847 ++count;
2848 } while (result->NextRow());
2849
2850 // post loading checks
2851 for (uint32 entryId = 0; entryId < sAchievementCriteriaStore.GetNumRows(); ++entryId)
2852 {
2853 AchievementCriteriaEntry const* criteria = sAchievementCriteriaStore.LookupEntry(entryId);
2854 if (!criteria)
2855 continue;
2856
2857 switch (criteria->requiredType)
2858 {
2876 // achievement requires db data
2877 break;
2879 {
2880 AchievementEntry const* achievement = sAchievementStore.LookupEntry(criteria->referredAchievement);
2881 if (!achievement)
2882 continue;
2883
2884 // exist many achievements with this criteria, use at this moment hardcoded check to skil simple case
2885 if (achievement->ID == 1282)
2886 break;
2887
2888 continue;
2889 }
2890 case ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA: // need skip generic cases
2892 continue;
2893 break;
2894 case ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE: // need skip generic cases
2895 if (criteria->do_emote.count == 0)
2896 continue;
2897 break;
2898 case ACHIEVEMENT_CRITERIA_TYPE_WIN_DUEL: // skip statistics
2899 if (criteria->win_duel.duelCount == 0)
2900 continue;
2901 break;
2902 case ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE: // need skip generic cases
2903 if (criteria->loot_type.lootTypeCount != 1)
2904 continue;
2905 break;
2907 case ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM: // only Children's Week achievements
2908 {
2909 AchievementEntry const* achievement = sAchievementStore.LookupEntry(criteria->referredAchievement);
2910 if (!achievement)
2911 continue;
2912 if (achievement->categoryId != CATEGORY_CHILDRENS_WEEK)
2913 continue;
2914 break;
2915 }
2916 default: // type not use DB data, ignore
2917 continue;
2918 }
2919
2921 LOG_ERROR("sql.sql", "Table `achievement_criteria_data` does not have expected data for criteria (Entry: {} Type: {}) for achievement {}.", criteria->ID, criteria->requiredType, criteria->referredAchievement);
2922 }
2923
2924 LOG_INFO("server.loading", ">> Loaded {} additional achievement criteria data in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
2925 LOG_INFO("server.loading", " ");
2926}
#define LOG_INFO(filterType__,...)
Definition: Log.h:164
#define LOG_ERROR(filterType__,...)
Definition: Log.h:156
#define LOG_WARN(filterType__,...)
Definition: Log.h:160
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
@ DISABLE_TYPE_ACHIEVEMENT_CRITERIA
Definition: DisableMgr.h:33
#define sObjectMgr
Definition: ObjectMgr.h:1623
DBCStorage< AchievementCriteriaEntry > sAchievementCriteriaStore(AchievementCriteriafmt)
@ ACHIEVEMENT_CRITERIA_DATA_TYPE_SCRIPT
Definition: AchievementMgr.h:71
@ ACHIEVEMENT_CRITERIA_DATA_TYPE_NONE
Definition: AchievementMgr.h:60
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
@ ACHIEVEMENT_CRITERIA_CONDITION_NO_LOSE
Definition: DBCEnums.h:91
@ ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE
Definition: DBCEnums.h:216
@ ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2
Definition: DBCEnums.h:181
@ ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM
Definition: DBCEnums.h:155
@ ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET
Definition: DBCEnums.h:142
@ ACHIEVEMENT_CRITERIA_TYPE_FALL_WITHOUT_DYING
Definition: DBCEnums.h:139
@ ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL
Definition: DBCEnums.h:143
@ ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_DAILY_QUEST
Definition: DBCEnums.h:131
@ ACHIEVEMENT_CRITERIA_TYPE_OWN_RANK
Definition: DBCEnums.h:158
@ ACHIEVEMENT_CRITERIA_TYPE_ROLL_GREED_ON_LOOT
Definition: DBCEnums.h:165
@ ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE
Definition: DBCEnums.h:168
@ ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE_TYPE
Definition: DBCEnums.h:188
@ ACHIEVEMENT_CRITERIA_TYPE_HONORABLE_KILL
Definition: DBCEnums.h:149
@ ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2
Definition: DBCEnums.h:217
@ ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST
Definition: DBCEnums.h:141
@ ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA
Definition: DBCEnums.h:151
@ ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM
Definition: DBCEnums.h:163
@ ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE
Definition: DBCEnums.h:122
@ ACHIEVEMENT_CRITERIA_TYPE_WIN_DUEL
Definition: DBCEnums.h:186
@ ACHIEVEMENT_CRITERIA_TYPE_WIN_BG
Definition: DBCEnums.h:123
@ ACHIEVEMENT_CRITERIA_TYPE_SPECIAL_PVP_KILL
Definition: DBCEnums.h:182
@ ACHIEVEMENT_CRITERIA_TYPE_BG_OBJECTIVE_CAPTURE
Definition: DBCEnums.h:144
@ ACHIEVEMENT_CRITERIA_TYPE_GET_KILLING_BLOWS
Definition: DBCEnums.h:170
@ ACHIEVEMENT_CRITERIA_TYPE_ROLL_NEED_ON_LOOT
Definition: DBCEnums.h:164
@ ACHIEVEMENT_CRITERIA_TYPE_ON_LOGIN
Definition: DBCEnums.h:184
@ CATEGORY_CHILDRENS_WEEK
Definition: DBCEnums.h:229
bool IsDisabledFor(DisableType type, uint32 entry, Unit const *unit, uint8 flags)
Definition: DisableMgr.cpp:306
Class used to access individual fields of database query result.
Definition: Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
Definition: AchievementMgr.h:99
Definition: AchievementMgr.h:247
void Add(AchievementCriteriaData const &data)
Definition: AchievementMgr.h:250
void SetCriteriaId(uint32 id)
Definition: AchievementMgr.h:252
AchievementCriteriaDataSet const * GetCriteriaDataSet(AchievementCriteriaEntry const *achievementCriteria) const
Definition: AchievementMgr.h:410
Definition: DBCStructure.h:40
uint32 categoryId
Definition: DBCStructure.h:49
uint32 ID
Definition: DBCStructure.h:41
Definition: DBCStructure.h:70
struct AchievementCriteriaEntry::@307::@362 win_duel
uint32 lootTypeCount
Definition: DBCStructure.h:471
struct AchievementCriteriaEntry::@307::@367 loot_type
uint32 count
Definition: DBCStructure.h:223
uint32 duelCount
Definition: DBCStructure.h:440
struct AchievementCriteriaEntry::@309 additionalRequirements[MAX_CRITERIA_REQUIREMENTS]
uint32 ID
Definition: DBCStructure.h:71
uint32 requiredType
Definition: DBCStructure.h:73
uint32 additionalRequirement_type
Definition: DBCStructure.h:503
uint32 referredAchievement
Definition: DBCStructure.h:72
struct AchievementCriteriaEntry::@307::@352 do_emote

References _criteriaDataMap, ACHIEVEMENT_CRITERIA_CONDITION_NO_LOSE, ACHIEVEMENT_CRITERIA_DATA_TYPE_NONE, ACHIEVEMENT_CRITERIA_DATA_TYPE_SCRIPT, ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET, ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2, ACHIEVEMENT_CRITERIA_TYPE_BG_OBJECTIVE_CAPTURE, ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL, ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2, ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_DAILY_QUEST, ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST, ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE, ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM, ACHIEVEMENT_CRITERIA_TYPE_FALL_WITHOUT_DYING, ACHIEVEMENT_CRITERIA_TYPE_GET_KILLING_BLOWS, ACHIEVEMENT_CRITERIA_TYPE_HONORABLE_KILL, ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE, ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE_TYPE, ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE, ACHIEVEMENT_CRITERIA_TYPE_ON_LOGIN, ACHIEVEMENT_CRITERIA_TYPE_OWN_RANK, ACHIEVEMENT_CRITERIA_TYPE_ROLL_GREED_ON_LOOT, ACHIEVEMENT_CRITERIA_TYPE_ROLL_NEED_ON_LOOT, ACHIEVEMENT_CRITERIA_TYPE_SPECIAL_PVP_KILL, ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM, ACHIEVEMENT_CRITERIA_TYPE_WIN_BG, ACHIEVEMENT_CRITERIA_TYPE_WIN_DUEL, ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA, AchievementCriteriaDataSet::Add(), AchievementCriteriaEntry::additionalRequirement_type, AchievementCriteriaEntry::additionalRequirements, CATEGORY_CHILDRENS_WEEK, AchievementEntry::categoryId, AchievementCriteriaEntry::count, AchievementCriteriaData::dataType, DISABLE_TYPE_ACHIEVEMENT_CRITERIA, AchievementCriteriaEntry::do_emote, AchievementCriteriaEntry::duelCount, Field::Get(), GetCriteriaDataSet(), getMSTime(), GetMSTimeDiffToNow(), AchievementEntry::ID, AchievementCriteriaEntry::ID, DisableMgr::IsDisabledFor(), AchievementCriteriaData::IsValid(), LOG_ERROR, LOG_INFO, LOG_WARN, AchievementCriteriaEntry::loot_type, AchievementCriteriaEntry::lootTypeCount, AchievementCriteriaEntry::referredAchievement, AchievementCriteriaEntry::requiredType, sAchievementCriteriaStore, sAchievementStore, AchievementCriteriaDataSet::SetCriteriaId(), sObjectMgr, AchievementCriteriaEntry::win_duel, and WorldDatabase.

◆ LoadAchievementCriteriaList()

void AchievementGlobalMgr::LoadAchievementCriteriaList ( )
2611{
2612 uint32 oldMSTime = getMSTime();
2613
2614 if (sAchievementCriteriaStore.GetNumRows() == 0)
2615 {
2616 LOG_WARN("server.loading", ">> Loaded 0 achievement criteria.");
2617 LOG_INFO("server.loading", " ");
2618 return;
2619 }
2620
2621 uint32 loaded = 0;
2622 for (uint32 entryId = 0; entryId < sAchievementCriteriaStore.GetNumRows(); ++entryId)
2623 {
2624 AchievementCriteriaEntry const* criteria = sAchievementCriteriaStore.LookupEntry(entryId);
2625 if (!criteria)
2626 continue;
2627
2628 if (!GetAchievement(criteria->referredAchievement))
2629 {
2630 LOG_DEBUG("server.loading", "Achievement {} referenced by criteria {} doesn't exist, criteria not loaded.", criteria->referredAchievement, criteria->ID);
2631 continue;
2632 }
2633
2634 _achievementCriteriasByType[criteria->requiredType].push_back(criteria);
2635 _achievementCriteriaListByAchievement[criteria->referredAchievement].push_back(criteria);
2636
2642
2643 switch (criteria->requiredType)
2644 {
2646 _specialList[criteria->requiredType][criteria->kill_creature.creatureID].push_back(criteria);
2647 break;
2649 _specialList[criteria->requiredType][criteria->win_bg.bgMapID].push_back(criteria);
2650 break;
2652 _specialList[criteria->requiredType][criteria->reach_skill_level.skillID].push_back(criteria);
2653 break;
2655 _specialList[criteria->requiredType][criteria->complete_achievement.linkedAchievement].push_back(criteria);
2656 break;
2658 _specialList[criteria->requiredType][criteria->complete_quests_in_zone.zoneID].push_back(criteria);
2659 break;
2661 _specialList[criteria->requiredType][criteria->complete_battleground.mapID].push_back(criteria);
2662 break;
2664 _specialList[criteria->requiredType][criteria->killed_by_creature.creatureEntry].push_back(criteria);
2665 break;
2667 _specialList[criteria->requiredType][criteria->complete_quest.questID].push_back(criteria);
2668 break;
2670 _specialList[criteria->requiredType][criteria->be_spell_target.spellID].push_back(criteria);
2671 break;
2673 _specialList[criteria->requiredType][criteria->cast_spell.spellID].push_back(criteria);
2674 break;
2676 _specialList[criteria->requiredType][criteria->bg_objective.objectiveId].push_back(criteria);
2677 break;
2679 _specialList[criteria->requiredType][criteria->honorable_kill_at_area.areaID].push_back(criteria);
2680 break;
2682 _specialList[criteria->requiredType][criteria->learn_spell.spellID].push_back(criteria);
2683 break;
2685 _specialList[criteria->requiredType][criteria->own_item.itemID].push_back(criteria);
2686 break;
2688 _specialList[criteria->requiredType][criteria->learn_skill_level.skillID].push_back(criteria);
2689 break;
2691 _specialList[criteria->requiredType][criteria->use_item.itemID].push_back(criteria);
2692 break;
2694 _specialList[criteria->requiredType][criteria->own_item.itemID].push_back(criteria);
2695 break;
2697 {
2698 WorldMapOverlayEntry const* worldOverlayEntry = sWorldMapOverlayStore.LookupEntry(criteria->explore_area.areaReference);
2699 if (!worldOverlayEntry)
2700 break;
2701
2702 for (uint8 j = 0; j < MAX_WORLD_MAP_OVERLAY_AREA_IDX; ++j)
2703 if (worldOverlayEntry->areatableID[j])
2704 {
2705 bool valid = true;
2706 for (uint8 i = 0; i < j; ++i)
2707 if (worldOverlayEntry->areatableID[j] == worldOverlayEntry->areatableID[i])
2708 valid = false;
2709 if (valid)
2710 _specialList[criteria->requiredType][worldOverlayEntry->areatableID[j]].push_back(criteria);
2711 }
2712 }
2713 break;
2715 _specialList[criteria->requiredType][criteria->gain_reputation.factionID].push_back(criteria);
2716 break;
2718 _specialList[criteria->requiredType][criteria->equip_epic_item.itemSlot].push_back(criteria);
2719 break;
2721 _specialList[criteria->requiredType][criteria->hk_class.classID].push_back(criteria);
2722 break;
2724 _specialList[criteria->requiredType][criteria->hk_race.raceID].push_back(criteria);
2725 break;
2727 _specialList[criteria->requiredType][criteria->do_emote.emoteID].push_back(criteria);
2728 break;
2730 _specialList[criteria->requiredType][criteria->equip_item.itemID].push_back(criteria);
2731 break;
2733 _specialList[criteria->requiredType][criteria->use_gameobject.goEntry].push_back(criteria);
2734 break;
2736 _specialList[criteria->requiredType][criteria->be_spell_target.spellID].push_back(criteria);
2737 break;
2739 _specialList[criteria->requiredType][criteria->fish_in_gameobject.goEntry].push_back(criteria);
2740 break;
2742 _specialList[criteria->requiredType][criteria->learn_skillline_spell.skillLine].push_back(criteria);
2743 break;
2745 _specialList[criteria->requiredType][criteria->loot_type.lootType].push_back(criteria);
2746 break;
2748 _specialList[criteria->requiredType][criteria->cast_spell.spellID].push_back(criteria);
2749 break;
2751 _specialList[criteria->requiredType][criteria->learn_skill_line.skillLine].push_back(criteria);
2752 break;
2753 }
2754
2755 if (criteria->timeLimit)
2756 _achievementCriteriasByTimedType[criteria->timedType].push_back(criteria);
2757
2758 ++loaded;
2759 }
2760
2761 LOG_INFO("server.loading", ">> Loaded {} achievement criteria in {} ms", loaded, GetMSTimeDiffToNow(oldMSTime));
2762 LOG_INFO("server.loading", " ");
2763}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:168
DBCStorage< WorldMapOverlayEntry > sWorldMapOverlayStore(WorldMapOverlayEntryfmt)
#define MAX_WORLD_MAP_OVERLAY_AREA_IDX
Definition: DBCStructure.h:2162
@ ACHIEVEMENT_CRITERIA_CONDITION_NONE
Definition: DBCEnums.h:87
@ ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUESTS_IN_ZONE
Definition: DBCEnums.h:129
@ ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL
Definition: DBCEnums.h:125
@ ACHIEVEMENT_CRITERIA_TYPE_EQUIP_ITEM
Definition: DBCEnums.h:171
@ ACHIEVEMENT_CRITERIA_TYPE_FISH_IN_GAMEOBJECT
Definition: DBCEnums.h:183
@ ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM
Definition: DBCEnums.h:156
@ ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_BATTLEGROUND
Definition: DBCEnums.h:132
@ ACHIEVEMENT_CRITERIA_TYPE_USE_GAMEOBJECT
Definition: DBCEnums.h:180
@ ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM
Definition: DBCEnums.h:150
@ ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL
Definition: DBCEnums.h:148
@ ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS
Definition: DBCEnums.h:185
@ ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_ACHIEVEMENT
Definition: DBCEnums.h:126
@ ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION
Definition: DBCEnums.h:160
@ ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE
Definition: DBCEnums.h:218
@ ACHIEVEMENT_CRITERIA_TYPE_HK_RACE
Definition: DBCEnums.h:167
@ ACHIEVEMENT_CRITERIA_TYPE_EXPLORE_AREA
Definition: DBCEnums.h:157
@ ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LEVEL
Definition: DBCEnums.h:154
@ ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE
Definition: DBCEnums.h:137
@ ACHIEVEMENT_CRITERIA_TYPE_HONORABLE_KILL_AT_AREA
Definition: DBCEnums.h:145
@ ACHIEVEMENT_CRITERIA_TYPE_HK_CLASS
Definition: DBCEnums.h:166
AchievementEntry const * GetAchievement(uint32 achievementId) const
Definition: AchievementMgr.cpp:3136
struct AchievementCriteriaEntry::@307::@339 use_item
uint32 timeLimit
Definition: DBCStructure.h:514
struct AchievementCriteriaEntry::@307::@319 complete_battleground
struct AchievementCriteriaEntry::@307::@329 bg_objective
struct AchievementCriteriaEntry::@307::@326 complete_quest
uint32 areaReference
Definition: DBCStructure.h:290
uint32 creatureEntry
Definition: DBCStructure.h:166
struct AchievementCriteriaEntry::@307::@360 fish_in_gameobject
uint32 skillLine
Definition: DBCStructure.h:432
struct AchievementCriteriaEntry::@307::@311 win_bg
uint32 objectiveId
Definition: DBCStructure.h:208
uint32 timedType
Definition: DBCStructure.h:510
uint32 bgMapID
Definition: DBCStructure.h:87
struct AchievementCriteriaEntry::@307::@314 complete_achievement
struct AchievementCriteriaEntry::@307::@330 honorable_kill_at_area
uint32 zoneID
Definition: DBCStructure.h:128
uint32 itemID
Definition: DBCStructure.h:241
uint32 mapID
Definition: DBCStructure.h:142
struct AchievementCriteriaEntry::@307::@355 equip_item
uint32 spellID
Definition: DBCStructure.h:193
struct AchievementCriteriaEntry::@307::@317 complete_quests_in_zone
uint32 goEntry
Definition: DBCStructure.h:410
struct AchievementCriteriaEntry::@307::@361 learn_skillline_spell
struct AchievementCriteriaEntry::@307::@338 learn_skill_level
struct AchievementCriteriaEntry::@307::@327 be_spell_target
struct AchievementCriteriaEntry::@307::@368 learn_skill_line
uint32 emoteID
Definition: DBCStructure.h:367
uint32 skillID
Definition: DBCStructure.h:101
struct AchievementCriteriaEntry::@307::@323 killed_by_creature
struct AchievementCriteriaEntry::@307::@351 hk_race
uint32 classID
Definition: DBCStructure.h:352
uint32 lootType
Definition: DBCStructure.h:470
struct AchievementCriteriaEntry::@307::@328 cast_spell
uint32 itemSlot
Definition: DBCStructure.h:332
struct AchievementCriteriaEntry::@307::@334 own_item
struct AchievementCriteriaEntry::@307::@313 reach_skill_level
uint32 questID
Definition: DBCStructure.h:185
struct AchievementCriteriaEntry::@307::@344 gain_reputation
struct AchievementCriteriaEntry::@307::@341 explore_area
uint32 raceID
Definition: DBCStructure.h:359
struct AchievementCriteriaEntry::@307::@347 equip_epic_item
uint32 additionalRequirement_value
Definition: DBCStructure.h:504
uint32 linkedAchievement
Definition: DBCStructure.h:108
uint32 areaID
Definition: DBCStructure.h:215
uint32 creatureID
Definition: DBCStructure.h:80
struct AchievementCriteriaEntry::@307::@358 use_gameobject
struct AchievementCriteriaEntry::@307::@350 hk_class
struct AchievementCriteriaEntry::@307::@333 learn_spell
struct AchievementCriteriaEntry::@307::@310 kill_creature
uint32 factionID
Definition: DBCStructure.h:310
Definition: DBCStructure.h:2165
uint32 areatableID[MAX_WORLD_MAP_OVERLAY_AREA_IDX]
Definition: DBCStructure.h:2168

References _achievementCriteriaListByAchievement, _achievementCriteriasByCondition, _achievementCriteriasByTimedType, _achievementCriteriasByType, _specialList, ACHIEVEMENT_CRITERIA_CONDITION_NONE, ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET, ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2, ACHIEVEMENT_CRITERIA_TYPE_BG_OBJECTIVE_CAPTURE, ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL, ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2, ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_ACHIEVEMENT, ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_BATTLEGROUND, ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST, ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUESTS_IN_ZONE, ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE, ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM, ACHIEVEMENT_CRITERIA_TYPE_EQUIP_ITEM, ACHIEVEMENT_CRITERIA_TYPE_EXPLORE_AREA, ACHIEVEMENT_CRITERIA_TYPE_FISH_IN_GAMEOBJECT, ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION, ACHIEVEMENT_CRITERIA_TYPE_HK_CLASS, ACHIEVEMENT_CRITERIA_TYPE_HK_RACE, ACHIEVEMENT_CRITERIA_TYPE_HONORABLE_KILL_AT_AREA, ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE, ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE, ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LEVEL, ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE, ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS, ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL, ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM, ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE, ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM, ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL, ACHIEVEMENT_CRITERIA_TYPE_USE_GAMEOBJECT, ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM, ACHIEVEMENT_CRITERIA_TYPE_WIN_BG, AchievementCriteriaEntry::additionalRequirement_type, AchievementCriteriaEntry::additionalRequirement_value, AchievementCriteriaEntry::additionalRequirements, AchievementCriteriaEntry::areaID, AchievementCriteriaEntry::areaReference, WorldMapOverlayEntry::areatableID, AchievementCriteriaEntry::be_spell_target, AchievementCriteriaEntry::bg_objective, AchievementCriteriaEntry::bgMapID, AchievementCriteriaEntry::cast_spell, AchievementCriteriaEntry::classID, AchievementCriteriaEntry::complete_achievement, AchievementCriteriaEntry::complete_battleground, AchievementCriteriaEntry::complete_quest, AchievementCriteriaEntry::complete_quests_in_zone, AchievementCriteriaEntry::creatureEntry, AchievementCriteriaEntry::creatureID, AchievementCriteriaEntry::do_emote, AchievementCriteriaEntry::emoteID, AchievementCriteriaEntry::equip_epic_item, AchievementCriteriaEntry::equip_item, AchievementCriteriaEntry::explore_area, AchievementCriteriaEntry::factionID, AchievementCriteriaEntry::fish_in_gameobject, AchievementCriteriaEntry::gain_reputation, GetAchievement(), getMSTime(), GetMSTimeDiffToNow(), AchievementCriteriaEntry::goEntry, AchievementCriteriaEntry::hk_class, AchievementCriteriaEntry::hk_race, AchievementCriteriaEntry::honorable_kill_at_area, AchievementCriteriaEntry::ID, AchievementCriteriaEntry::itemID, AchievementCriteriaEntry::itemSlot, AchievementCriteriaEntry::kill_creature, AchievementCriteriaEntry::killed_by_creature, AchievementCriteriaEntry::learn_skill_level, AchievementCriteriaEntry::learn_skill_line, AchievementCriteriaEntry::learn_skillline_spell, AchievementCriteriaEntry::learn_spell, AchievementCriteriaEntry::linkedAchievement, LOG_DEBUG, LOG_INFO, LOG_WARN, AchievementCriteriaEntry::loot_type, AchievementCriteriaEntry::lootType, AchievementCriteriaEntry::mapID, MAX_WORLD_MAP_OVERLAY_AREA_IDX, AchievementCriteriaEntry::objectiveId, AchievementCriteriaEntry::own_item, AchievementCriteriaEntry::questID, AchievementCriteriaEntry::raceID, AchievementCriteriaEntry::reach_skill_level, AchievementCriteriaEntry::referredAchievement, AchievementCriteriaEntry::requiredType, sAchievementCriteriaStore, AchievementCriteriaEntry::skillID, AchievementCriteriaEntry::skillLine, AchievementCriteriaEntry::spellID, sWorldMapOverlayStore, AchievementCriteriaEntry::timedType, AchievementCriteriaEntry::timeLimit, AchievementCriteriaEntry::use_gameobject, AchievementCriteriaEntry::use_item, AchievementCriteriaEntry::win_bg, and AchievementCriteriaEntry::zoneID.

◆ LoadAchievementReferenceList()

void AchievementGlobalMgr::LoadAchievementReferenceList ( )
2766{
2767 uint32 oldMSTime = getMSTime();
2768
2769 if (sAchievementStore.GetNumRows() == 0)
2770 {
2771 LOG_WARN("server.loading", ">> Loaded 0 achievement references.");
2772 LOG_INFO("server.loading", " ");
2773 return;
2774 }
2775
2776 uint32 count = 0;
2777
2778 for (uint32 entryId = 0; entryId < sAchievementStore.GetNumRows(); ++entryId)
2779 {
2780 AchievementEntry const* achievement = sAchievementStore.LookupEntry(entryId);
2781 if (!achievement || !achievement->refAchievement)
2782 continue;
2783
2784 _achievementListByReferencedId[achievement->refAchievement].push_back(achievement);
2785 ++count;
2786 }
2787
2788 LOG_INFO("server.loading", ">> Loaded {} achievement references in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
2789 LOG_INFO("server.loading", " ");
2790}
uint32 refAchievement
Definition: DBCStructure.h:57

References _achievementListByReferencedId, getMSTime(), GetMSTimeDiffToNow(), LOG_INFO, LOG_WARN, AchievementEntry::refAchievement, and sAchievementStore.

◆ LoadCompletedAchievements()

void AchievementGlobalMgr::LoadCompletedAchievements ( )
2929{
2930 uint32 oldMSTime = getMSTime();
2931
2932 QueryResult result = CharacterDatabase.Query("SELECT achievement FROM character_achievement GROUP BY achievement");
2933
2934 // Populate _allCompletedAchievements with all realm first achievement ids to make multithreaded access safer
2935 // while it will not prevent races, it will prevent crashes that happen because std::unordered_map key was added
2936 // instead the only potential race will happen on value associated with the key
2937 for (uint32 i = 0; i < sAchievementStore.GetNumRows(); ++i)
2938 if (AchievementEntry const* achievement = sAchievementStore.LookupEntry(i))
2940 _allCompletedAchievements[achievement->ID] = SystemTimePoint::min();
2941
2942 if (!result)
2943 {
2944 LOG_WARN("server.loading", ">> Loaded 0 completed achievements. DB table `character_achievement` is empty.");
2945 LOG_INFO("server.loading", " ");
2946 return;
2947 }
2948
2949 do
2950 {
2951 Field* fields = result->Fetch();
2952
2953 uint16 achievementId = fields[0].Get<uint16>();
2954 const AchievementEntry* achievement = sAchievementStore.LookupEntry(achievementId);
2955 if (!achievement)
2956 {
2957 // Remove non existent achievements from all characters
2958 LOG_ERROR("achievement", "Non-existing achievement {} data removed from table `character_achievement`.", achievementId);
2959
2961
2962 stmt->SetData(0, uint16(achievementId));
2963 CharacterDatabase.Execute(stmt);
2964
2965 continue;
2966 }
2968 _allCompletedAchievements[achievementId] = SystemTimePoint::max();
2969 } while (result->NextRow());
2970
2971 LOG_INFO("server.loading", ">> Loaded {} completed achievements in {} ms", (unsigned long)_allCompletedAchievements.size(), GetMSTimeDiffToNow(oldMSTime));
2972 LOG_INFO("server.loading", " ");
2973}
std::uint16_t uint16
Definition: Define.h:108
@ CHAR_DEL_INVALID_ACHIEVMENT
Definition: CharacterDatabase.h:298
@ ACHIEVEMENT_FLAG_REALM_FIRST_REACH
Definition: DBCEnums.h:79

References _allCompletedAchievements, ACHIEVEMENT_FLAG_REALM_FIRST_KILL, ACHIEVEMENT_FLAG_REALM_FIRST_REACH, CHAR_DEL_INVALID_ACHIEVMENT, CharacterDatabase, Field::Get(), getMSTime(), GetMSTimeDiffToNow(), LOG_ERROR, LOG_INFO, LOG_WARN, sAchievementStore, and PreparedStatementBase::SetData().

◆ LoadRewardLocales()

void AchievementGlobalMgr::LoadRewardLocales ( )
3097{
3098 uint32 oldMSTime = getMSTime();
3099
3100 _achievementRewardLocales.clear(); // need for reload case
3101
3102 // 0 1 2 3
3103 QueryResult result = WorldDatabase.Query("SELECT ID, Locale, Subject, Text FROM achievement_reward_locale");
3104
3105 if (!result)
3106 {
3107 LOG_WARN("server.loading", ">> Loaded 0 achievement reward locale strings. DB table `achievement_reward_locale` is empty");
3108 LOG_INFO("server.loading", " ");
3109 return;
3110 }
3111
3112 do
3113 {
3114 Field* fields = result->Fetch();
3115
3116 uint32 ID = fields[0].Get<uint32>();
3117 if (_achievementRewards.find(ID) == _achievementRewards.end())
3118 {
3119 LOG_ERROR("sql.sql", "Table `achievement_reward_locale` (Entry: {}) has locale strings for non-existing achievement reward.", ID);
3120 continue;
3121 }
3122
3123 LocaleConstant locale = GetLocaleByName(fields[1].Get<std::string>());
3124 if (locale == LOCALE_enUS)
3125 continue;
3126
3128 ObjectMgr::AddLocaleString(fields[2].Get<std::string>(), locale, data.Subject);
3129 ObjectMgr::AddLocaleString(fields[3].Get<std::string>(), locale, data.Text);
3130 } while (result->NextRow());
3131
3132 LOG_INFO("server.loading", ">> Loaded {} Achievement Reward Locale Strings in {} ms", (unsigned long)_achievementRewardLocales.size(), GetMSTimeDiffToNow(oldMSTime));
3133 LOG_INFO("server.loading", " ");
3134}
LocaleConstant
Definition: Common.h:65
@ LOCALE_enUS
Definition: Common.h:66
LocaleConstant GetLocaleByName(const std::string &name)
Definition: Common.cpp:33
Definition: AchievementMgr.h:273
std::vector< std::string > Text
Definition: AchievementMgr.h:275
std::vector< std::string > Subject
Definition: AchievementMgr.h:274
static void AddLocaleString(std::string &&s, LocaleConstant locale, std::vector< std::string > &data)
Definition: ObjectMgr.cpp:380

References _achievementRewardLocales, _achievementRewards, ObjectMgr::AddLocaleString(), Field::Get(), GetLocaleByName(), getMSTime(), GetMSTimeDiffToNow(), LOCALE_enUS, LOG_ERROR, LOG_INFO, LOG_WARN, AchievementRewardLocale::Subject, AchievementRewardLocale::Text, and WorldDatabase.

◆ LoadRewards()

void AchievementGlobalMgr::LoadRewards ( )
2976{
2977 uint32 oldMSTime = getMSTime();
2978
2979 _achievementRewards.clear(); // need for reload case
2980
2981 // 0 1 2 3 4 5 6 7
2982 QueryResult result = WorldDatabase.Query("SELECT ID, TitleA, TitleH, ItemID, Sender, Subject, Body, MailTemplateID FROM achievement_reward");
2983
2984 if (!result)
2985 {
2986 LOG_WARN("server.loading", ">> Loaded 0 achievement rewards. DB table `achievement_reward` is empty.");
2987 LOG_INFO("server.loading", " ");
2988 return;
2989 }
2990
2991 uint32 count = 0;
2992
2993 do
2994 {
2995 Field* fields = result->Fetch();
2996 uint32 entry = fields[0].Get<uint32>();
2997 AchievementEntry const* achievement = sAchievementStore.LookupEntry(entry);
2998 if (!achievement)
2999 {
3000 LOG_ERROR("sql.sql", "Table `achievement_reward` has wrong achievement (Entry: {}). Ignoring.", entry);
3001 continue;
3002 }
3003
3004 AchievementReward reward;
3005 reward.titleId[0] = fields[1].Get<uint32>(); // Alliance title
3006 reward.titleId[1] = fields[2].Get<uint32>(); // Horde title
3007 reward.itemId = fields[3].Get<uint32>();
3008 reward.sender = fields[4].Get<uint32>(); // The sender of the mail (a creature from creature_template)
3009 reward.subject = fields[5].Get<std::string>();
3010 reward.text = fields[6].Get<std::string>(); // Body in DB
3011 reward.mailTemplate = fields[7].Get<uint32>();
3012
3013 // Must reward a title or send a mail else, skip it.
3014 if (!reward.titleId[0] && !reward.titleId[1] && !reward.sender)
3015 {
3016 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) does not have any title or item reward data. Ignoring.", entry);
3017 continue;
3018 }
3019
3020 if (achievement->requiredFaction == ACHIEVEMENT_FACTION_ANY && (!reward.titleId[0] ^ !reward.titleId[1]))
3021 LOG_DEBUG("achievement", "Table `achievement_reward` (Entry: {}) has title (A: {} H: {}) set for only one team.", entry, reward.titleId[0], reward.titleId[1]);
3022
3023 if (reward.titleId[0])
3024 {
3025 CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(reward.titleId[0]);
3026 if (!titleEntry)
3027 {
3028 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has invalid title id ({}) in `title_A`. Setting it to 0.", entry, reward.titleId[0]);
3029 reward.titleId[0] = 0;
3030 }
3031 }
3032
3033 if (reward.titleId[1])
3034 {
3035 CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(reward.titleId[1]);
3036 if (!titleEntry)
3037 {
3038 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has invalid title id ({}) in `title_H`. Setting it to 0.", entry, reward.titleId[1]);
3039 reward.titleId[1] = 0;
3040 }
3041 }
3042
3043 // Check mail data before item for report including wrong item case
3044 if (reward.sender)
3045 {
3046 if (!sObjectMgr->GetCreatureTemplate(reward.sender))
3047 {
3048 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has invalid creature_template entry {} as Sender. Will not send the mail reward.", entry, reward.sender);
3049 reward.sender = 0;
3050 }
3051 }
3052 else
3053 {
3054 if (reward.itemId)
3055 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has itemId reward set but does not have Sender data set. Item will not be sent.", entry);
3056
3057 if (!reward.subject.empty())
3058 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has mail Subject but does not have Sender data set.", entry); // Maybe add "Mail will not be sent." ?
3059
3060 if (!reward.text.empty())
3061 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has mail text (Body) set but does not have Sender data set.", entry); // Maybe add "Mail will not be sent." ?
3062
3063 if (reward.mailTemplate)
3064 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has mailTemplate set does not have Sender data set.", entry); // Maybe add "Mail will not be sent." ?
3065 }
3066
3067 if (reward.mailTemplate)
3068 {
3069 if (!sMailTemplateStore.LookupEntry(reward.mailTemplate))
3070 {
3071 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has invalid mailTemplate ({}) (check the DBC).", entry, reward.mailTemplate);
3072 reward.mailTemplate = 0;
3073 }
3074 else if (!reward.subject.empty() || !reward.text.empty())
3075 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has mailTemplate ({}) and mail Subject/Body. To use the column mailTemplate, Subject and Body must be empty.", entry, reward.mailTemplate);
3076 }
3077
3078 if (reward.itemId)
3079 {
3080 if (!sObjectMgr->GetItemTemplate(reward.itemId))
3081 {
3082 // Not sure it's an error, it's probably an outDebug instead, because we can simply send a mail with no reward, right?
3083 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has invalid item_template id {}. Reward mail will not contain any item.", entry, reward.itemId);
3084 reward.itemId = 0;
3085 }
3086 }
3087
3088 _achievementRewards[entry] = reward;
3089 ++count;
3090 } while (result->NextRow());
3091
3092 LOG_INFO("server.loading", ">> Loaded {} achievement rewards in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
3093 LOG_INFO("server.loading", " ");
3094}
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesEntryfmt)
DBCStorage< MailTemplateEntry > sMailTemplateStore(MailTemplateEntryfmt)
@ ACHIEVEMENT_FACTION_ANY
Definition: DBCEnums.h:66
Definition: AchievementMgr.h:261
std::string subject
Definition: AchievementMgr.h:265
std::string text
Definition: AchievementMgr.h:266
uint32 titleId[2]
Definition: AchievementMgr.h:262
uint32 sender
Definition: AchievementMgr.h:264
uint32 mailTemplate
Definition: AchievementMgr.h:267
uint32 itemId
Definition: AchievementMgr.h:263
Definition: DBCStructure.h:632

References _achievementRewards, ACHIEVEMENT_FACTION_ANY, Field::Get(), getMSTime(), GetMSTimeDiffToNow(), AchievementReward::itemId, LOG_DEBUG, LOG_ERROR, LOG_INFO, LOG_WARN, AchievementReward::mailTemplate, sAchievementStore, sCharTitlesStore, AchievementReward::sender, sMailTemplateStore, sObjectMgr, AchievementReward::subject, AchievementReward::text, AchievementReward::titleId, and WorldDatabase.

◆ SetRealmCompleted()

void AchievementGlobalMgr::SetRealmCompleted ( AchievementEntry const *  achievement)
2602{
2603 if (IsRealmCompleted(achievement))
2604 return;
2605
2607}
bool IsRealmCompleted(AchievementEntry const *achievement) const
Definition: AchievementMgr.cpp:2575

References _allCompletedAchievements, GameTime::GetSystemTime(), AchievementEntry::ID, and IsRealmCompleted().

◆ UpdateAchievementCriteriaForOfflinePlayer()

void AchievementGlobalMgr::UpdateAchievementCriteriaForOfflinePlayer ( ObjectGuid::LowType  playerLowGuid,
AchievementCriteriaTypes  type,
uint32  miscValue1 = 0,
uint32  miscValue2 = 0 
)
3153{
3155 stmt->SetData(0, playerLowGuid);
3157 stmt->SetData(2, type);
3158 stmt->SetData(3, miscValue1);
3159 stmt->SetData(4, miscValue2);
3160 CharacterDatabase.Execute(stmt);
3161}
@ ACHIEVEMENT_OFFLINE_PLAYER_UPDATE_TYPE_UPDATE_CRITERIA
Definition: AchievementMgr.h:39

References ACHIEVEMENT_OFFLINE_PLAYER_UPDATE_TYPE_UPDATE_CRITERIA, CHAR_INS_CHAR_ACHIEVEMENT_OFFLINE_UPDATES, CharacterDatabase, and PreparedStatementBase::SetData().

Member Data Documentation

◆ _achievementCriteriaListByAchievement

AchievementCriteriaListByAchievement AchievementGlobalMgr::_achievementCriteriaListByAchievement
private

◆ _achievementCriteriasByCondition

std::map<uint32, AchievementCriteriaEntryList> AchievementGlobalMgr::_achievementCriteriasByCondition[ACHIEVEMENT_CRITERIA_CONDITION_TOTAL]
private

◆ _achievementCriteriasByTimedType

AchievementCriteriaEntryList AchievementGlobalMgr::_achievementCriteriasByTimedType[ACHIEVEMENT_TIMED_TYPE_MAX]
private

◆ _achievementCriteriasByType

AchievementCriteriaEntryList AchievementGlobalMgr::_achievementCriteriasByType[ACHIEVEMENT_CRITERIA_TYPE_TOTAL]
private

◆ _achievementListByReferencedId

AchievementListByReferencedId AchievementGlobalMgr::_achievementListByReferencedId
private

◆ _achievementRewardLocales

AchievementRewardLocales AchievementGlobalMgr::_achievementRewardLocales
private

◆ _achievementRewards

AchievementRewards AchievementGlobalMgr::_achievementRewards
private

◆ _allCompletedAchievements

AllCompletedAchievements AchievementGlobalMgr::_allCompletedAchievements
private

◆ _criteriaDataMap

AchievementCriteriaDataMap AchievementGlobalMgr::_criteriaDataMap
private

◆ _specialList