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
 

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

◆ GetAchievement()

AchievementEntry const * AchievementGlobalMgr::GetAchievement ( uint32  achievementId) const
3049{
3050 return sAchievementStore.LookupEntry(achievementId);
3051}
DBCStorage< AchievementEntry > sAchievementStore(Achievementfmt)

References sAchievementStore.

Referenced by LoadAchievementCriteriaList().

◆ GetAchievementByReferencedId()

AchievementEntryList const * AchievementGlobalMgr::GetAchievementByReferencedId ( uint32  id) const
inline
366 {
367 AchievementListByReferencedId::const_iterator itr = _achievementListByReferencedId.find(id);
368 return itr != _achievementListByReferencedId.end() ? &itr->second : nullptr;
369 }
AchievementListByReferencedId _achievementListByReferencedId
Definition: AchievementMgr.h:410

References _achievementListByReferencedId.

Referenced by IsAverageCriteria().

◆ GetAchievementCriteriaByAchievement()

AchievementCriteriaEntryList const * AchievementGlobalMgr::GetAchievementCriteriaByAchievement ( uint32  id) const
inline
360 {
361 AchievementCriteriaListByAchievement::const_iterator itr = _achievementCriteriaListByAchievement.find(id);
362 return itr != _achievementCriteriaListByAchievement.end() ? &itr->second : nullptr;
363 }
AchievementCriteriaListByAchievement _achievementCriteriaListByAchievement
Definition: AchievementMgr.h:408

References _achievementCriteriaListByAchievement.

◆ GetAchievementCriteriaByCondition()

AchievementCriteriaEntryList const * AchievementGlobalMgr::GetAchievementCriteriaByCondition ( AchievementCriteriaCondition  condition,
uint32  val 
)
inline
348 {
349 if (_achievementCriteriasByCondition[condition].find(val) != _achievementCriteriasByCondition[condition].end())
350 return &_achievementCriteriasByCondition[condition][val];
351 return nullptr;
352 }
std::map< uint32, AchievementCriteriaEntryList > _achievementCriteriasByCondition[ACHIEVEMENT_CRITERIA_CONDITION_TOTAL]
Definition: AchievementMgr.h:420

References _achievementCriteriasByCondition.

◆ GetAchievementCriteriaByType()

AchievementCriteriaEntryList const * AchievementGlobalMgr::GetAchievementCriteriaByType ( AchievementCriteriaTypes  type) const
inline
336 {
337 return &_achievementCriteriasByType[type];
338 }
AchievementCriteriaEntryList _achievementCriteriasByType[ACHIEVEMENT_CRITERIA_TYPE_TOTAL]
Definition: AchievementMgr.h:405

References _achievementCriteriasByType.

◆ GetAchievementReward()

AchievementReward const * AchievementGlobalMgr::GetAchievementReward ( AchievementEntry const *  achievement) const
inline
372 {
373 AchievementRewards::const_iterator iter = _achievementRewards.find(achievement->ID);
374 return iter != _achievementRewards.end() ? &iter->second : nullptr;
375 }
AchievementRewards _achievementRewards
Definition: AchievementMgr.h:415

References _achievementRewards, and AchievementEntry::ID.

◆ GetAchievementRewardLocale()

AchievementRewardLocale const * AchievementGlobalMgr::GetAchievementRewardLocale ( AchievementEntry const *  achievement) const
inline
378 {
379 AchievementRewardLocales::const_iterator iter = _achievementRewardLocales.find(achievement->ID);
380 return iter != _achievementRewardLocales.end() ? &iter->second : nullptr;
381 }
AchievementRewardLocales _achievementRewardLocales
Definition: AchievementMgr.h:416

References _achievementRewardLocales, and AchievementEntry::ID.

◆ GetCriteriaDataSet()

AchievementCriteriaDataSet const * AchievementGlobalMgr::GetCriteriaDataSet ( AchievementCriteriaEntry const *  achievementCriteria) const
inline
384 {
385 AchievementCriteriaDataMap::const_iterator iter = _criteriaDataMap.find(achievementCriteria->ID);
386 return iter != _criteriaDataMap.end() ? &iter->second : nullptr;
387 }
AchievementCriteriaDataMap _criteriaDataMap
Definition: AchievementMgr.h:402

References _criteriaDataMap, and AchievementCriteriaEntry::ID.

Referenced by LoadAchievementCriteriaData().

◆ GetSpecialAchievementCriteriaByType()

AchievementCriteriaEntryList const * AchievementGlobalMgr::GetSpecialAchievementCriteriaByType ( AchievementCriteriaTypes  type,
uint32  val 
)
inline
341 {
342 if (_specialList[type].find(val) != _specialList[type].end())
343 return &_specialList[type][val];
344 return nullptr;
345 }
std::map< uint32, AchievementCriteriaEntryList > _specialList[ACHIEVEMENT_CRITERIA_TYPE_TOTAL]
Definition: AchievementMgr.h:419

References _specialList.

◆ GetTimedAchievementCriteriaByType()

AchievementCriteriaEntryList const & AchievementGlobalMgr::GetTimedAchievementCriteriaByType ( AchievementCriteriaTimedTypes  type) const
inline
355 {
357 }
AchievementCriteriaEntryList _achievementCriteriasByTimedType[ACHIEVEMENT_TIMED_TYPE_MAX]
Definition: AchievementMgr.h:406

References _achievementCriteriasByTimedType.

◆ instance()

AchievementGlobalMgr * AchievementGlobalMgr::instance ( )
static
2441{
2443 return &instance;
2444}
Definition: AchievementMgr.h:324
static AchievementGlobalMgr * instance()
Definition: AchievementMgr.cpp:2440

References instance().

Referenced by instance().

◆ IsAverageCriteria()

bool AchievementGlobalMgr::IsAverageCriteria ( AchievementCriteriaEntry const *  criteria) const
2475{
2476 if ((sAchievementStore.LookupEntry(criteria->referredAchievement))->flags & ACHIEVEMENT_FLAG_AVERAGE)
2477 return true;
2478
2479 if (AchievementEntryList const* achRefList = GetAchievementByReferencedId(criteria->referredAchievement))
2480 for (AchievementEntryList::const_iterator itr = achRefList->begin(); itr != achRefList->end(); ++itr)
2481 if ((*itr)->flags & ACHIEVEMENT_FLAG_AVERAGE)
2482 return true;
2483
2484 return false;
2485}
std::list< AchievementEntry const * > AchievementEntryList
Definition: AchievementMgr.h:31
@ ACHIEVEMENT_FLAG_AVERAGE
Definition: DBCEnums.h:85
AchievementEntryList const * GetAchievementByReferencedId(uint32 id) const
Definition: AchievementMgr.h:365

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

◆ IsRealmCompleted()

bool AchievementGlobalMgr::IsRealmCompleted ( AchievementEntry const *  achievement) const
2488{
2489 auto itr = _allCompletedAchievements.find(achievement->ID);
2490 if (itr == _allCompletedAchievements.end())
2491 return false;
2492
2493 if (itr->second == SystemTimePoint::min())
2494 return false;
2495
2496 if (!sScriptMgr->IsRealmCompleted(this, achievement, itr->second))
2497 return false;
2498
2499 if (itr->second == SystemTimePoint::max())
2500 return true;
2501
2502 // Allow completing the realm first kill for entire minute after first person did it
2503 // it may allow more than one group to achieve it (highly unlikely)
2504 // but apparently this is how blizz handles it as well
2505 if (achievement->flags & ACHIEVEMENT_FLAG_REALM_FIRST_KILL)
2506 return (GameTime::GetSystemTime() - itr->second) > 1min;
2507
2508 sScriptMgr->SetRealmCompleted(achievement);
2509
2510 return true;
2511}
#define sScriptMgr
Definition: ScriptMgr.h:698
@ ACHIEVEMENT_FLAG_REALM_FIRST_KILL
Definition: DBCEnums.h:88
SystemTimePoint GetSystemTime()
Current chrono system_clock time point.
Definition: GameTime.cpp:48
AllCompletedAchievements _allCompletedAchievements
Definition: AchievementMgr.h:413

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
2452{
2453 if (!achievement)
2454 return false;
2455
2456 AchievementCategoryEntry const* cat = sAchievementCategoryStore.LookupEntry(achievement->categoryId);
2457 do
2458 {
2459 switch(cat->ID)
2460 {
2462 return true;
2464 return false;
2465 default:
2466 cat = sAchievementCategoryStore.LookupEntry(cat->parentCategory);
2467 break;
2468 }
2469 } while (cat);
2470
2471 return false;
2472}
@ ACHIEVEMENT_CATEGORY_STATISTICS
Definition: AchievementMgr.h:78
@ ACHIEVEMENT_CATEOGRY_GENERAL
Definition: AchievementMgr.h:77
DBCStorage< AchievementCategoryEntry > sAchievementCategoryStore(AchievementCategoryfmt)
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
2447{
2448 return IsStatisticAchievement(sAchievementStore.LookupEntry(achievementCriteria->referredAchievement));
2449}
bool IsStatisticAchievement(AchievementEntry const *achievement) const
Definition: AchievementMgr.cpp:2451

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

◆ LoadAchievementCriteriaData()

void AchievementGlobalMgr::LoadAchievementCriteriaData ( )
2705{
2706 uint32 oldMSTime = getMSTime();
2707
2708 _criteriaDataMap.clear(); // need for reload case
2709
2710 QueryResult result = WorldDatabase.Query("SELECT criteria_id, type, value1, value2, ScriptName FROM achievement_criteria_data");
2711
2712 if (!result)
2713 {
2714 LOG_WARN("server.loading", ">> Loaded 0 additional achievement criteria data. DB table `achievement_criteria_data` is empty.");
2715 LOG_INFO("server.loading", " ");
2716 return;
2717 }
2718
2719 uint32 count = 0;
2720
2721 do
2722 {
2723 Field* fields = result->Fetch();
2724 uint32 criteria_id = fields[0].Get<uint32>();
2725
2726 AchievementCriteriaEntry const* criteria = sAchievementCriteriaStore.LookupEntry(criteria_id);
2727
2728 if (!criteria)
2729 {
2730 LOG_ERROR("sql.sql", "Table `achievement_criteria_data` has data for non-existing criteria (Entry: {}), ignore.", criteria_id);
2731 continue;
2732 }
2733
2734 uint32 dataType = fields[1].Get<uint8>();
2735 std::string scriptName = fields[4].Get<std::string>();
2736 uint32 scriptId = 0;
2737 if (scriptName.length()) // not empty
2738 {
2740 LOG_ERROR("sql.sql", "Table `achievement_criteria_data` has ScriptName set for non-scripted data type (Entry: {}, type {}), useless data.", criteria_id, dataType);
2741 else
2742 scriptId = sObjectMgr->GetScriptId(scriptName);
2743 }
2744
2745 AchievementCriteriaData data(dataType, fields[2].Get<uint32>(), fields[3].Get<uint32>(), scriptId);
2746
2747 if (!data.IsValid(criteria))
2748 continue;
2749
2750 // this will allocate empty data set storage
2751 AchievementCriteriaDataSet& dataSet = _criteriaDataMap[criteria_id];
2752 dataSet.SetCriteriaId(criteria_id);
2753
2754 // add real data only for not NONE data types
2755 if (data.dataType != ACHIEVEMENT_CRITERIA_DATA_TYPE_NONE)
2756 dataSet.Add(data);
2757
2758 // counting data by and data types
2759 ++count;
2760 } while (result->NextRow());
2761
2762 // post loading checks
2763 for (uint32 entryId = 0; entryId < sAchievementCriteriaStore.GetNumRows(); ++entryId)
2764 {
2765 AchievementCriteriaEntry const* criteria = sAchievementCriteriaStore.LookupEntry(entryId);
2766 if (!criteria)
2767 continue;
2768
2769 switch (criteria->requiredType)
2770 {
2788 // achievement requires db data
2789 break;
2791 {
2792 AchievementEntry const* achievement = sAchievementStore.LookupEntry(criteria->referredAchievement);
2793 if (!achievement)
2794 continue;
2795
2796 // exist many achievements with this criteria, use at this moment hardcoded check to skil simple case
2797 if (achievement->ID == 1282)
2798 break;
2799
2800 continue;
2801 }
2802 case ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA: // need skip generic cases
2804 continue;
2805 break;
2806 case ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE: // need skip generic cases
2807 if (criteria->do_emote.count == 0)
2808 continue;
2809 break;
2810 case ACHIEVEMENT_CRITERIA_TYPE_WIN_DUEL: // skip statistics
2811 if (criteria->win_duel.duelCount == 0)
2812 continue;
2813 break;
2814 case ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE: // need skip generic cases
2815 if (criteria->loot_type.lootTypeCount != 1)
2816 continue;
2817 break;
2819 case ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM: // only Children's Week achievements
2820 {
2821 AchievementEntry const* achievement = sAchievementStore.LookupEntry(criteria->referredAchievement);
2822 if (!achievement)
2823 continue;
2824 if (achievement->categoryId != CATEGORY_CHILDRENS_WEEK)
2825 continue;
2826 break;
2827 }
2828 default: // type not use DB data, ignore
2829 continue;
2830 }
2831
2833 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);
2834 }
2835
2836 LOG_INFO("server.loading", ">> Loaded {} additional achievement criteria data in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
2837 LOG_INFO("server.loading", " ");
2838}
std::uint8_t uint8
Definition: Define.h:110
std::uint32_t uint32
Definition: Define.h:108
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
#define LOG_WARN(filterType__,...)
Definition: Log.h:161
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
@ ACHIEVEMENT_CRITERIA_DATA_TYPE_SCRIPT
Definition: AchievementMgr.h:57
@ ACHIEVEMENT_CRITERIA_DATA_TYPE_NONE
Definition: AchievementMgr.h:46
@ DISABLE_TYPE_ACHIEVEMENT_CRITERIA
Definition: DisableMgr.h:33
DBCStorage< AchievementCriteriaEntry > sAchievementCriteriaStore(AchievementCriteriafmt)
#define sObjectMgr
Definition: ObjectMgr.h:1640
@ ACHIEVEMENT_CRITERIA_CONDITION_NO_LOSE
Definition: DBCEnums.h:99
@ ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE
Definition: DBCEnums.h:224
@ ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2
Definition: DBCEnums.h:189
@ ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM
Definition: DBCEnums.h:163
@ ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET
Definition: DBCEnums.h:150
@ ACHIEVEMENT_CRITERIA_TYPE_FALL_WITHOUT_DYING
Definition: DBCEnums.h:147
@ ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL
Definition: DBCEnums.h:151
@ ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_DAILY_QUEST
Definition: DBCEnums.h:139
@ ACHIEVEMENT_CRITERIA_TYPE_OWN_RANK
Definition: DBCEnums.h:166
@ ACHIEVEMENT_CRITERIA_TYPE_ROLL_GREED_ON_LOOT
Definition: DBCEnums.h:173
@ ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE
Definition: DBCEnums.h:176
@ ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE_TYPE
Definition: DBCEnums.h:196
@ ACHIEVEMENT_CRITERIA_TYPE_HONORABLE_KILL
Definition: DBCEnums.h:157
@ ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2
Definition: DBCEnums.h:225
@ ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST
Definition: DBCEnums.h:149
@ ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA
Definition: DBCEnums.h:159
@ ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM
Definition: DBCEnums.h:171
@ ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE
Definition: DBCEnums.h:130
@ ACHIEVEMENT_CRITERIA_TYPE_WIN_DUEL
Definition: DBCEnums.h:194
@ ACHIEVEMENT_CRITERIA_TYPE_WIN_BG
Definition: DBCEnums.h:131
@ ACHIEVEMENT_CRITERIA_TYPE_SPECIAL_PVP_KILL
Definition: DBCEnums.h:190
@ ACHIEVEMENT_CRITERIA_TYPE_BG_OBJECTIVE_CAPTURE
Definition: DBCEnums.h:152
@ ACHIEVEMENT_CRITERIA_TYPE_GET_KILLING_BLOWS
Definition: DBCEnums.h:178
@ ACHIEVEMENT_CRITERIA_TYPE_ROLL_NEED_ON_LOOT
Definition: DBCEnums.h:172
@ ACHIEVEMENT_CRITERIA_TYPE_ON_LOGIN
Definition: DBCEnums.h:192
@ CATEGORY_CHILDRENS_WEEK
Definition: DBCEnums.h:237
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:85
Definition: AchievementMgr.h:233
void Add(AchievementCriteriaData const &data)
Definition: AchievementMgr.h:236
void SetCriteriaId(uint32 id)
Definition: AchievementMgr.h:238
AchievementCriteriaDataSet const * GetCriteriaDataSet(AchievementCriteriaEntry const *achievementCriteria) const
Definition: AchievementMgr.h:383
Definition: DBCStructure.h:40
uint32 categoryId
Definition: DBCStructure.h:49
uint32 ID
Definition: DBCStructure.h:41
Definition: DBCStructure.h:70
struct AchievementCriteriaEntry::@301::@361 loot_type
uint32 lootTypeCount
Definition: DBCStructure.h:471
uint32 count
Definition: DBCStructure.h:223
struct AchievementCriteriaEntry::@301::@346 do_emote
uint32 duelCount
Definition: DBCStructure.h:440
struct AchievementCriteriaEntry::@303 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::@301::@356 win_duel

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 ( )
2523{
2524 uint32 oldMSTime = getMSTime();
2525
2526 if (sAchievementCriteriaStore.GetNumRows() == 0)
2527 {
2528 LOG_WARN("server.loading", ">> Loaded 0 achievement criteria.");
2529 LOG_INFO("server.loading", " ");
2530 return;
2531 }
2532
2533 uint32 loaded = 0;
2534 for (uint32 entryId = 0; entryId < sAchievementCriteriaStore.GetNumRows(); ++entryId)
2535 {
2536 AchievementCriteriaEntry const* criteria = sAchievementCriteriaStore.LookupEntry(entryId);
2537 if (!criteria)
2538 continue;
2539
2540 if (!GetAchievement(criteria->referredAchievement))
2541 {
2542 LOG_DEBUG("server.loading", "Achievement {} referenced by criteria {} doesn't exist, criteria not loaded.", criteria->referredAchievement, criteria->ID);
2543 continue;
2544 }
2545
2546 _achievementCriteriasByType[criteria->requiredType].push_back(criteria);
2547 _achievementCriteriaListByAchievement[criteria->referredAchievement].push_back(criteria);
2548
2554
2555 switch (criteria->requiredType)
2556 {
2558 _specialList[criteria->requiredType][criteria->kill_creature.creatureID].push_back(criteria);
2559 break;
2561 _specialList[criteria->requiredType][criteria->win_bg.bgMapID].push_back(criteria);
2562 break;
2564 _specialList[criteria->requiredType][criteria->reach_skill_level.skillID].push_back(criteria);
2565 break;
2567 _specialList[criteria->requiredType][criteria->complete_achievement.linkedAchievement].push_back(criteria);
2568 break;
2570 _specialList[criteria->requiredType][criteria->complete_quests_in_zone.zoneID].push_back(criteria);
2571 break;
2573 _specialList[criteria->requiredType][criteria->complete_battleground.mapID].push_back(criteria);
2574 break;
2576 _specialList[criteria->requiredType][criteria->killed_by_creature.creatureEntry].push_back(criteria);
2577 break;
2579 _specialList[criteria->requiredType][criteria->complete_quest.questID].push_back(criteria);
2580 break;
2582 _specialList[criteria->requiredType][criteria->be_spell_target.spellID].push_back(criteria);
2583 break;
2585 _specialList[criteria->requiredType][criteria->cast_spell.spellID].push_back(criteria);
2586 break;
2588 _specialList[criteria->requiredType][criteria->bg_objective.objectiveId].push_back(criteria);
2589 break;
2591 _specialList[criteria->requiredType][criteria->honorable_kill_at_area.areaID].push_back(criteria);
2592 break;
2594 _specialList[criteria->requiredType][criteria->learn_spell.spellID].push_back(criteria);
2595 break;
2597 _specialList[criteria->requiredType][criteria->own_item.itemID].push_back(criteria);
2598 break;
2600 _specialList[criteria->requiredType][criteria->learn_skill_level.skillID].push_back(criteria);
2601 break;
2603 _specialList[criteria->requiredType][criteria->use_item.itemID].push_back(criteria);
2604 break;
2606 _specialList[criteria->requiredType][criteria->own_item.itemID].push_back(criteria);
2607 break;
2609 {
2610 WorldMapOverlayEntry const* worldOverlayEntry = sWorldMapOverlayStore.LookupEntry(criteria->explore_area.areaReference);
2611 if (!worldOverlayEntry)
2612 break;
2613
2614 for (uint8 j = 0; j < MAX_WORLD_MAP_OVERLAY_AREA_IDX; ++j)
2615 if (worldOverlayEntry->areatableID[j])
2616 {
2617 bool valid = true;
2618 for (uint8 i = 0; i < j; ++i)
2619 if (worldOverlayEntry->areatableID[j] == worldOverlayEntry->areatableID[i])
2620 valid = false;
2621 if (valid)
2622 _specialList[criteria->requiredType][worldOverlayEntry->areatableID[j]].push_back(criteria);
2623 }
2624 }
2625 break;
2627 _specialList[criteria->requiredType][criteria->gain_reputation.factionID].push_back(criteria);
2628 break;
2630 _specialList[criteria->requiredType][criteria->equip_epic_item.itemSlot].push_back(criteria);
2631 break;
2633 _specialList[criteria->requiredType][criteria->hk_class.classID].push_back(criteria);
2634 break;
2636 _specialList[criteria->requiredType][criteria->hk_race.raceID].push_back(criteria);
2637 break;
2639 _specialList[criteria->requiredType][criteria->do_emote.emoteID].push_back(criteria);
2640 break;
2642 _specialList[criteria->requiredType][criteria->equip_item.itemID].push_back(criteria);
2643 break;
2645 _specialList[criteria->requiredType][criteria->use_gameobject.goEntry].push_back(criteria);
2646 break;
2648 _specialList[criteria->requiredType][criteria->be_spell_target.spellID].push_back(criteria);
2649 break;
2651 _specialList[criteria->requiredType][criteria->fish_in_gameobject.goEntry].push_back(criteria);
2652 break;
2654 _specialList[criteria->requiredType][criteria->learn_skillline_spell.skillLine].push_back(criteria);
2655 break;
2657 _specialList[criteria->requiredType][criteria->loot_type.lootType].push_back(criteria);
2658 break;
2660 _specialList[criteria->requiredType][criteria->cast_spell.spellID].push_back(criteria);
2661 break;
2663 _specialList[criteria->requiredType][criteria->learn_skill_line.skillLine].push_back(criteria);
2664 break;
2665 }
2666
2667 if (criteria->timeLimit)
2668 _achievementCriteriasByTimedType[criteria->timedType].push_back(criteria);
2669
2670 ++loaded;
2671 }
2672
2673 LOG_INFO("server.loading", ">> Loaded {} achievement criteria in {} ms", loaded, GetMSTimeDiffToNow(oldMSTime));
2674 LOG_INFO("server.loading", " ");
2675}
#define LOG_DEBUG(filterType__,...)
Definition: Log.h:169
DBCStorage< WorldMapOverlayEntry > sWorldMapOverlayStore(WorldMapOverlayEntryfmt)
@ ACHIEVEMENT_CRITERIA_CONDITION_NONE
Definition: DBCEnums.h:95
@ ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUESTS_IN_ZONE
Definition: DBCEnums.h:137
@ ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL
Definition: DBCEnums.h:133
@ ACHIEVEMENT_CRITERIA_TYPE_EQUIP_ITEM
Definition: DBCEnums.h:179
@ ACHIEVEMENT_CRITERIA_TYPE_FISH_IN_GAMEOBJECT
Definition: DBCEnums.h:191
@ ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM
Definition: DBCEnums.h:164
@ ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_BATTLEGROUND
Definition: DBCEnums.h:140
@ ACHIEVEMENT_CRITERIA_TYPE_USE_GAMEOBJECT
Definition: DBCEnums.h:188
@ ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM
Definition: DBCEnums.h:158
@ ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL
Definition: DBCEnums.h:156
@ ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS
Definition: DBCEnums.h:193
@ ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_ACHIEVEMENT
Definition: DBCEnums.h:134
@ ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION
Definition: DBCEnums.h:168
@ ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE
Definition: DBCEnums.h:226
@ ACHIEVEMENT_CRITERIA_TYPE_HK_RACE
Definition: DBCEnums.h:175
@ ACHIEVEMENT_CRITERIA_TYPE_EXPLORE_AREA
Definition: DBCEnums.h:165
@ ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LEVEL
Definition: DBCEnums.h:162
@ ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE
Definition: DBCEnums.h:145
@ ACHIEVEMENT_CRITERIA_TYPE_HONORABLE_KILL_AT_AREA
Definition: DBCEnums.h:153
@ ACHIEVEMENT_CRITERIA_TYPE_HK_CLASS
Definition: DBCEnums.h:174
#define MAX_WORLD_MAP_OVERLAY_AREA_IDX
Definition: DBCStructure.h:2163
AchievementEntry const * GetAchievement(uint32 achievementId) const
Definition: AchievementMgr.cpp:3048
struct AchievementCriteriaEntry::@301::@322 cast_spell
uint32 timeLimit
Definition: DBCStructure.h:514
struct AchievementCriteriaEntry::@301::@344 hk_class
struct AchievementCriteriaEntry::@301::@304 kill_creature
uint32 areaReference
Definition: DBCStructure.h:290
uint32 creatureEntry
Definition: DBCStructure.h:166
struct AchievementCriteriaEntry::@301::@338 gain_reputation
uint32 skillLine
Definition: DBCStructure.h:432
struct AchievementCriteriaEntry::@301::@311 complete_quests_in_zone
uint32 objectiveId
Definition: DBCStructure.h:208
struct AchievementCriteriaEntry::@301::@335 explore_area
uint32 timedType
Definition: DBCStructure.h:510
uint32 bgMapID
Definition: DBCStructure.h:87
struct AchievementCriteriaEntry::@301::@349 equip_item
struct AchievementCriteriaEntry::@301::@321 be_spell_target
struct AchievementCriteriaEntry::@301::@327 learn_spell
uint32 zoneID
Definition: DBCStructure.h:128
struct AchievementCriteriaEntry::@301::@317 killed_by_creature
uint32 itemID
Definition: DBCStructure.h:241
uint32 mapID
Definition: DBCStructure.h:142
uint32 spellID
Definition: DBCStructure.h:193
struct AchievementCriteriaEntry::@301::@307 reach_skill_level
uint32 goEntry
Definition: DBCStructure.h:410
uint32 emoteID
Definition: DBCStructure.h:367
struct AchievementCriteriaEntry::@301::@354 fish_in_gameobject
uint32 skillID
Definition: DBCStructure.h:101
uint32 classID
Definition: DBCStructure.h:352
struct AchievementCriteriaEntry::@301::@308 complete_achievement
struct AchievementCriteriaEntry::@301::@323 bg_objective
uint32 lootType
Definition: DBCStructure.h:470
uint32 itemSlot
Definition: DBCStructure.h:332
struct AchievementCriteriaEntry::@301::@305 win_bg
uint32 questID
Definition: DBCStructure.h:185
struct AchievementCriteriaEntry::@301::@313 complete_battleground
struct AchievementCriteriaEntry::@301::@352 use_gameobject
struct AchievementCriteriaEntry::@301::@345 hk_race
uint32 raceID
Definition: DBCStructure.h:359
struct AchievementCriteriaEntry::@301::@333 use_item
struct AchievementCriteriaEntry::@301::@355 learn_skillline_spell
uint32 additionalRequirement_value
Definition: DBCStructure.h:504
uint32 linkedAchievement
Definition: DBCStructure.h:108
struct AchievementCriteriaEntry::@301::@362 learn_skill_line
uint32 areaID
Definition: DBCStructure.h:215
uint32 creatureID
Definition: DBCStructure.h:80
struct AchievementCriteriaEntry::@301::@320 complete_quest
struct AchievementCriteriaEntry::@301::@332 learn_skill_level
struct AchievementCriteriaEntry::@301::@341 equip_epic_item
uint32 factionID
Definition: DBCStructure.h:310
struct AchievementCriteriaEntry::@301::@324 honorable_kill_at_area
struct AchievementCriteriaEntry::@301::@328 own_item
Definition: DBCStructure.h:2166
uint32 areatableID[MAX_WORLD_MAP_OVERLAY_AREA_IDX]
Definition: DBCStructure.h:2169

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 ( )
2678{
2679 uint32 oldMSTime = getMSTime();
2680
2681 if (sAchievementStore.GetNumRows() == 0)
2682 {
2683 LOG_WARN("server.loading", ">> Loaded 0 achievement references.");
2684 LOG_INFO("server.loading", " ");
2685 return;
2686 }
2687
2688 uint32 count = 0;
2689
2690 for (uint32 entryId = 0; entryId < sAchievementStore.GetNumRows(); ++entryId)
2691 {
2692 AchievementEntry const* achievement = sAchievementStore.LookupEntry(entryId);
2693 if (!achievement || !achievement->refAchievement)
2694 continue;
2695
2696 _achievementListByReferencedId[achievement->refAchievement].push_back(achievement);
2697 ++count;
2698 }
2699
2700 LOG_INFO("server.loading", ">> Loaded {} achievement references in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
2701 LOG_INFO("server.loading", " ");
2702}
uint32 refAchievement
Definition: DBCStructure.h:57

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

◆ LoadCompletedAchievements()

void AchievementGlobalMgr::LoadCompletedAchievements ( )
2841{
2842 uint32 oldMSTime = getMSTime();
2843
2844 QueryResult result = CharacterDatabase.Query("SELECT achievement FROM character_achievement GROUP BY achievement");
2845
2846 // Populate _allCompletedAchievements with all realm first achievement ids to make multithreaded access safer
2847 // while it will not prevent races, it will prevent crashes that happen because std::unordered_map key was added
2848 // instead the only potential race will happen on value associated with the key
2849 for (uint32 i = 0; i < sAchievementStore.GetNumRows(); ++i)
2850 if (AchievementEntry const* achievement = sAchievementStore.LookupEntry(i))
2852 _allCompletedAchievements[achievement->ID] = SystemTimePoint::min();
2853
2854 if (!result)
2855 {
2856 LOG_WARN("server.loading", ">> Loaded 0 completed achievements. DB table `character_achievement` is empty.");
2857 LOG_INFO("server.loading", " ");
2858 return;
2859 }
2860
2861 do
2862 {
2863 Field* fields = result->Fetch();
2864
2865 uint16 achievementId = fields[0].Get<uint16>();
2866 const AchievementEntry* achievement = sAchievementStore.LookupEntry(achievementId);
2867 if (!achievement)
2868 {
2869 // Remove non existent achievements from all characters
2870 LOG_ERROR("achievement", "Non-existing achievement {} data removed from table `character_achievement`.", achievementId);
2871
2873
2874 stmt->SetData(0, uint16(achievementId));
2875 CharacterDatabase.Execute(stmt);
2876
2877 continue;
2878 }
2880 _allCompletedAchievements[achievementId] = SystemTimePoint::max();
2881 } while (result->NextRow());
2882
2883 LOG_INFO("server.loading", ">> Loaded {} completed achievements in {} ms", (unsigned long)_allCompletedAchievements.size(), GetMSTimeDiffToNow(oldMSTime));
2884 LOG_INFO("server.loading", " ");
2885}
std::uint16_t uint16
Definition: Define.h:109
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
@ CHAR_DEL_INVALID_ACHIEVMENT
Definition: CharacterDatabase.h:298
@ ACHIEVEMENT_FLAG_REALM_FIRST_REACH
Definition: DBCEnums.h:87
Definition: PreparedStatement.h:158
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78

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 ( )
3009{
3010 uint32 oldMSTime = getMSTime();
3011
3012 _achievementRewardLocales.clear(); // need for reload case
3013
3014 // 0 1 2 3
3015 QueryResult result = WorldDatabase.Query("SELECT ID, Locale, Subject, Text FROM achievement_reward_locale");
3016
3017 if (!result)
3018 {
3019 LOG_WARN("server.loading", ">> Loaded 0 achievement reward locale strings. DB table `achievement_reward_locale` is empty");
3020 LOG_INFO("server.loading", " ");
3021 return;
3022 }
3023
3024 do
3025 {
3026 Field* fields = result->Fetch();
3027
3028 uint32 ID = fields[0].Get<uint32>();
3029 if (_achievementRewards.find(ID) == _achievementRewards.end())
3030 {
3031 LOG_ERROR("sql.sql", "Table `achievement_reward_locale` (Entry: {}) has locale strings for non-existing achievement reward.", ID);
3032 continue;
3033 }
3034
3035 LocaleConstant locale = GetLocaleByName(fields[1].Get<std::string>());
3036 if (locale == LOCALE_enUS)
3037 continue;
3038
3040 ObjectMgr::AddLocaleString(fields[2].Get<std::string>(), locale, data.Subject);
3041 ObjectMgr::AddLocaleString(fields[3].Get<std::string>(), locale, data.Text);
3042 } while (result->NextRow());
3043
3044 LOG_INFO("server.loading", ">> Loaded {} Achievement Reward Locale Strings in {} ms", (unsigned long)_achievementRewardLocales.size(), GetMSTimeDiffToNow(oldMSTime));
3045 LOG_INFO("server.loading", " ");
3046}
LocaleConstant GetLocaleByName(const std::string &name)
Definition: Common.cpp:33
LocaleConstant
Definition: Common.h:67
@ LOCALE_enUS
Definition: Common.h:68
Definition: AchievementMgr.h:259
std::vector< std::string > Text
Definition: AchievementMgr.h:261
std::vector< std::string > Subject
Definition: AchievementMgr.h:260
static void AddLocaleString(std::string &&s, LocaleConstant locale, std::vector< std::string > &data)
Definition: ObjectMgr.cpp:436

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 ( )
2888{
2889 uint32 oldMSTime = getMSTime();
2890
2891 _achievementRewards.clear(); // need for reload case
2892
2893 // 0 1 2 3 4 5 6 7
2894 QueryResult result = WorldDatabase.Query("SELECT ID, TitleA, TitleH, ItemID, Sender, Subject, Body, MailTemplateID FROM achievement_reward");
2895
2896 if (!result)
2897 {
2898 LOG_WARN("server.loading", ">> Loaded 0 achievement rewards. DB table `achievement_reward` is empty.");
2899 LOG_INFO("server.loading", " ");
2900 return;
2901 }
2902
2903 uint32 count = 0;
2904
2905 do
2906 {
2907 Field* fields = result->Fetch();
2908 uint32 entry = fields[0].Get<uint32>();
2909 AchievementEntry const* achievement = sAchievementStore.LookupEntry(entry);
2910 if (!achievement)
2911 {
2912 LOG_ERROR("sql.sql", "Table `achievement_reward` has wrong achievement (Entry: {}). Ignoring.", entry);
2913 continue;
2914 }
2915
2916 AchievementReward reward;
2917 reward.titleId[0] = fields[1].Get<uint32>(); // Alliance title
2918 reward.titleId[1] = fields[2].Get<uint32>(); // Horde title
2919 reward.itemId = fields[3].Get<uint32>();
2920 reward.sender = fields[4].Get<uint32>(); // The sender of the mail (a creature from creature_template)
2921 reward.subject = fields[5].Get<std::string>();
2922 reward.text = fields[6].Get<std::string>(); // Body in DB
2923 reward.mailTemplate = fields[7].Get<uint32>();
2924
2925 // Must reward a title or send a mail else, skip it.
2926 if (!reward.titleId[0] && !reward.titleId[1] && !reward.sender)
2927 {
2928 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) does not have any title or item reward data. Ignoring.", entry);
2929 continue;
2930 }
2931
2932 if (achievement->requiredFaction == ACHIEVEMENT_FACTION_ANY && (!reward.titleId[0] ^ !reward.titleId[1]))
2933 LOG_DEBUG("achievement", "Table `achievement_reward` (Entry: {}) has title (A: {} H: {}) set for only one team.", entry, reward.titleId[0], reward.titleId[1]);
2934
2935 if (reward.titleId[0])
2936 {
2937 CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(reward.titleId[0]);
2938 if (!titleEntry)
2939 {
2940 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has invalid title id ({}) in `title_A`. Setting it to 0.", entry, reward.titleId[0]);
2941 reward.titleId[0] = 0;
2942 }
2943 }
2944
2945 if (reward.titleId[1])
2946 {
2947 CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(reward.titleId[1]);
2948 if (!titleEntry)
2949 {
2950 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has invalid title id ({}) in `title_H`. Setting it to 0.", entry, reward.titleId[1]);
2951 reward.titleId[1] = 0;
2952 }
2953 }
2954
2955 // Check mail data before item for report including wrong item case
2956 if (reward.sender)
2957 {
2958 if (!sObjectMgr->GetCreatureTemplate(reward.sender))
2959 {
2960 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has invalid creature_template entry {} as Sender. Will not send the mail reward.", entry, reward.sender);
2961 reward.sender = 0;
2962 }
2963 }
2964 else
2965 {
2966 if (reward.itemId)
2967 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);
2968
2969 if (!reward.subject.empty())
2970 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." ?
2971
2972 if (!reward.text.empty())
2973 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." ?
2974
2975 if (reward.mailTemplate)
2976 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." ?
2977 }
2978
2979 if (reward.mailTemplate)
2980 {
2981 if (!sMailTemplateStore.LookupEntry(reward.mailTemplate))
2982 {
2983 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has invalid mailTemplate ({}) (check the DBC).", entry, reward.mailTemplate);
2984 reward.mailTemplate = 0;
2985 }
2986 else if (!reward.subject.empty() || !reward.text.empty())
2987 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);
2988 }
2989
2990 if (reward.itemId)
2991 {
2992 if (!sObjectMgr->GetItemTemplate(reward.itemId))
2993 {
2994 // Not sure it's an error, it's probably an outDebug instead, because we can simply send a mail with no reward, right?
2995 LOG_ERROR("sql.sql", "Table `achievement_reward` (Entry: {}) has invalid item_template id {}. Reward mail will not contain any item.", entry, reward.itemId);
2996 reward.itemId = 0;
2997 }
2998 }
2999
3000 _achievementRewards[entry] = reward;
3001 ++count;
3002 } while (result->NextRow());
3003
3004 LOG_INFO("server.loading", ">> Loaded {} achievement rewards in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
3005 LOG_INFO("server.loading", " ");
3006}
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesEntryfmt)
DBCStorage< MailTemplateEntry > sMailTemplateStore(MailTemplateEntryfmt)
@ ACHIEVEMENT_FACTION_ANY
Definition: DBCEnums.h:74
Definition: AchievementMgr.h:247
std::string subject
Definition: AchievementMgr.h:251
std::string text
Definition: AchievementMgr.h:252
uint32 titleId[2]
Definition: AchievementMgr.h:248
uint32 sender
Definition: AchievementMgr.h:250
uint32 mailTemplate
Definition: AchievementMgr.h:253
uint32 itemId
Definition: AchievementMgr.h:249
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)
2514{
2515 if (IsRealmCompleted(achievement))
2516 return;
2517
2519}
bool IsRealmCompleted(AchievementEntry const *achievement) const
Definition: AchievementMgr.cpp:2487

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

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