TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AchievementMgr< T > Singleton Reference

#include <AchievementMgr.h>

Public Member Functions

 AchievementMgr (T *owner)
 
 ~AchievementMgr ()
 
void Reset ()
 
void LoadFromDB (PreparedQueryResult achievementResult, PreparedQueryResult criteriaResult)
 
void SaveToDB (SQLTransaction &trans)
 
void ResetAchievementCriteria (AchievementCriteriaTypes type, uint64 miscValue1=0, uint64 miscValue2=0, bool evenIfCriteriaComplete=false)
 
void UpdateAchievementCriteria (AchievementCriteriaTypes type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, Unit const *unit=NULL, Player *referencePlayer=NULL)
 
void CompletedAchievement (AchievementEntry const *entry, Player *referencePlayer)
 
void CheckAllAchievementCriteria (Player *referencePlayer)
 
void SendAllAchievementData (Player *receiver) const
 
void SendAllTrackedCriterias (Player *receiver, std::set< uint32 > const &trackedCriterias) const
 
void SendAchievementInfo (Player *receiver, uint32 achievementId=0) const
 
bool HasAchieved (uint32 achievementId) const
 
T * GetOwner () const
 
void UpdateTimedAchievements (uint32 timeDiff)
 
void StartTimedAchievement (AchievementCriteriaTimedTypes type, uint32 entry, uint32 timeLost=0)
 
void RemoveTimedAchievement (AchievementCriteriaTimedTypes type, uint32 entry)
 
uint32 GetAchievementPoints () const
 
template<>
void SaveToDB (SQLTransaction &trans)
 
template<>
void LoadFromDB (PreparedQueryResult achievementResult, PreparedQueryResult criteriaResult)
 
template<>
void Reset ()
 
template<>
void StartTimedAchievement (AchievementCriteriaTimedTypes type, uint32 entry, uint32 timeLost)
 
template<>
void CompletedAchievement (AchievementEntry const *achievement, Player *referencePlayer)
 
template<>
void SendAchievementInfo (Player *receiver, uint32) const
 

Private Types

typedef std::map< uint32, uint32TimedAchievementMap
 

Private Member Functions

void SendAchievementEarned (AchievementEntry const *achievement) const
 
void SendCriteriaUpdate (AchievementCriteria const *entry, CriteriaProgress const *progress, uint32 timeElapsed, bool timedCompleted) const
 
CriteriaProgressGetCriteriaProgress (AchievementCriteria const *entry)
 
void SetCriteriaProgress (AchievementCriteria const *entry, uint64 changeValue, Player *referencePlayer, ProgressType ptype=PROGRESS_SET)
 
void RemoveCriteriaProgress (AchievementCriteria const *entry)
 
void CompletedCriteriaFor (AchievementEntry const *achievement, Player *referencePlayer)
 
bool IsCompletedCriteriaTree (AchievementCriteriaTree const *tree)
 
bool IsCompletedCriteria (AchievementCriteria const *achievementCriteria, uint64 requiredAmount)
 
bool IsCompletedAchievement (AchievementEntry const *entry)
 
bool CanUpdateCriteria (AchievementCriteria const *criteria, AchievementCriteriaTreeList const *trees, uint64 miscValue1, uint64 miscValue2, uint64 miscValue3, Unit const *unit, Player *referencePlayer)
 
void SendPacket (WorldPacket const *data) const
 
bool ConditionsSatisfied (AchievementCriteria const *criteria, Player *referencePlayer) const
 
bool RequirementsSatisfied (AchievementCriteria const *criteria, uint64 miscValue1, uint64 miscValue2, uint64 miscValue3, Unit const *unit, Player *referencePlayer) const
 
bool AdditionalRequirementsSatisfied (ModifierTreeNode const *parent, uint64 miscValue1, uint64 miscValue2, Unit const *unit, Player *referencePlayer) const
 
template<>
void SendPacket (WorldPacket const *data) const
 
template<>
void SendCriteriaUpdate (AchievementCriteria const *criteria, CriteriaProgress const *progress, uint32 timeElapsed, bool timedCompleted) const
 

Private Attributes

T * _owner
 
CriteriaProgressMap m_criteriaProgress
 
CompletedAchievementMap m_completedAchievements
 
TimedAchievementMap m_timedAchievements
 
uint32 _achievementPoints
 

Member Typedef Documentation

template<class T>
typedef std::map<uint32, uint32> AchievementMgr< T >::TimedAchievementMap
private

Constructor & Destructor Documentation

template<class T>
AchievementMgr< T >::AchievementMgr ( T *  owner)
396 : _owner(owner), _achievementPoints(0) { }
T * _owner
Definition: AchievementMgr.h:357
uint32 _achievementPoints
Definition: AchievementMgr.h:362
template<class T >
AchievementMgr< T >::~AchievementMgr ( )
399 { }

Member Function Documentation

template<class T >
bool AchievementMgr< T >::AdditionalRequirementsSatisfied ( ModifierTreeNode const parent,
uint64  miscValue1,
uint64  miscValue2,
Unit const unit,
Player referencePlayer 
) const
private
2394 {
2395  for (ModifierTreeNode const* node : tree->Children)
2396  if (!AdditionalRequirementsSatisfied(node, miscValue1, miscValue2, unit, referencePlayer))
2397  return false;
2398 
2399  uint32 reqType = tree->Entry->Type;
2400  if (!reqType)
2401  return true;
2402 
2403  uint32 reqValue = tree->Entry->Asset[0];
2404 
2405  switch (AchievementCriteriaAdditionalCondition(reqType))
2406  {
2408  if (!unit || unit->GetEntry() != reqValue)
2409  return false;
2410  break;
2412  if (!unit || unit->GetTypeId() != TYPEID_PLAYER)
2413  return false;
2414  break;
2416  if (!unit || unit->IsAlive())
2417  return false;
2418  break;
2420  if (!unit || !referencePlayer->IsHostileTo(unit))
2421  return false;
2422  break;
2424  if (!referencePlayer->HasAura(reqValue))
2425  return false;
2426  break;
2428  if (!unit || !unit->HasAura(reqValue))
2429  return false;
2431  if (!unit || !unit->HasAuraType(AuraType(reqValue)))
2432  return false;
2433  break;
2435  {
2436  // miscValue1 is itemid
2437  ItemTemplate const* const item = sObjectMgr->GetItemTemplate(uint32(miscValue1));
2438  if (!item || item->GetQuality() < reqValue)
2439  return false;
2440  break;
2441  }
2443  {
2444  // miscValue1 is itemid
2445  ItemTemplate const* const item = sObjectMgr->GetItemTemplate(uint32(miscValue1));
2446  if (!item || item->GetQuality() != reqValue)
2447  return false;
2448  break;
2449  }
2451  {
2452  uint32 zoneId, areaId;
2453  referencePlayer->GetZoneAndAreaId(zoneId, areaId);
2454  if (zoneId != reqValue && areaId != reqValue)
2455  return false;
2456  break;
2457  }
2459  {
2460  if (!unit)
2461  return false;
2462  uint32 zoneId, areaId;
2463  unit->GetZoneAndAreaId(zoneId, areaId);
2464  if (zoneId != reqValue && areaId != reqValue)
2465  return false;
2466  break;
2467  }
2469  if (uint32(referencePlayer->GetMap()->GetDifficultyID()) != reqValue)
2470  return false;
2471  break;
2473  {
2474  Battleground* bg = referencePlayer->GetBattleground();
2475  if (!bg || !bg->isArena() || bg->GetArenaType() != reqValue)
2476  return false;
2477  break;
2478  }
2480  if (referencePlayer->getRace() != reqValue)
2481  return false;
2482  break;
2484  if (referencePlayer->getClass() != reqValue)
2485  return false;
2486  break;
2488  if (!unit || unit->GetTypeId() != TYPEID_PLAYER || unit->getRace() != reqValue)
2489  return false;
2490  break;
2492  if (!unit || unit->GetTypeId() != TYPEID_PLAYER || unit->getClass() != reqValue)
2493  return false;
2494  break;
2496  if (referencePlayer->GetGroup() && referencePlayer->GetGroup()->GetMembersCount() >= reqValue)
2497  return false;
2498  break;
2500  {
2501  if (!unit)
2502  return false;
2503  Creature const* const creature = unit->ToCreature();
2504  if (!creature || creature->GetCreatureType() != reqValue)
2505  return false;
2506  break;
2507  }
2509  if (referencePlayer->GetMapId() != reqValue)
2510  return false;
2511  break;
2513  // miscValue1 is title's bit index
2514  if (miscValue1 != reqValue)
2515  return false;
2516  break;
2518  if (referencePlayer->getLevel() != reqValue)
2519  return false;
2520  break;
2522  if (!unit || unit->getLevel() != reqValue)
2523  return false;
2524  break;
2526  if (!unit || unit->GetZoneId() != reqValue)
2527  return false;
2528  break;
2530  if (!unit || unit->GetHealthPct() >= reqValue)
2531  return false;
2532  break;
2534  if (miscValue1 != reqValue)
2535  return false;
2536  break;
2538  {
2539  if (!referencePlayer)
2540  return false;
2541  Garrison* garrison = referencePlayer->GetGarrison();
2542  if (!garrison)
2543  return false;
2544  Garrison::Follower const* follower = garrison->GetFollower(miscValue1);
2545  if (!follower || follower->PacketInfo.Quality != reqValue)
2546  return false;
2547 
2548  break;
2549  }
2551  {
2552  if (!referencePlayer)
2553  return false;
2554  Garrison* garrison = referencePlayer->GetGarrison();
2555  if (!garrison)
2556  return false;
2557  Garrison::Follower const* follower = garrison->GetFollower(miscValue1);
2558  if (!follower || follower->PacketInfo.FollowerLevel < reqValue)
2559  return false;
2560 
2561  break;
2562  }
2564  {
2565  if (!referencePlayer)
2566  return false;
2567  Garrison* garrison = referencePlayer->GetGarrison();
2568  if (!garrison)
2569  return false;
2570  Garrison::Follower const* follower = garrison->GetFollower(miscValue1);
2571  if (!follower || follower->GetItemLevel() < reqValue)
2572  return false;
2573  break;
2574  }
2575  default:
2576  break;
2577  }
2578  return true;
2579 }
AuraType
Definition: SpellAuraDefines.h:58
Definition: AchievementMgr.h:36
std::vector< ModifierTreeNode const * > Children
Definition: AchievementMgr.h:39
WorldPackets::Garrison::GarrisonFollower PacketInfo
Definition: Garrison.h:112
Definition: Garrison.h:83
Definition: Creature.h:467
uint32 GetCreatureType() const
Definition: Unit.cpp:11248
#define sObjectMgr
Definition: ObjectMgr.h:1567
uint32 GetItemLevel() const
Definition: Garrison.cpp:829
bool isArena() const
Definition: Battleground.h:326
uint8 GetArenaType() const
Definition: Battleground.h:281
bool AdditionalRequirementsSatisfied(ModifierTreeNode const *parent, uint64 miscValue1, uint64 miscValue2, Unit const *unit, Player *referencePlayer) const
Definition: AchievementMgr.cpp:2393
Follower const * GetFollower(uint64 dbId) const
Definition: Garrison.cpp:517
uint32 Quality
Definition: GarrisonPackets.h:82
uint32_t uint32
Definition: Define.h:150
Definition: Garrison.h:108
uint32 FollowerLevel
Definition: GarrisonPackets.h:83
Definition: ObjectGuid.h:33
Definition: ItemTemplate.h:647
AchievementCriteriaAdditionalCondition
Definition: DBCEnums.h:117
Creature * ToCreature()
Definition: Object.h:194
Definition: Battleground.h:235
uint32_t uint32
Definition: g3dmath.h:168
uint32 GetQuality() const
Definition: ItemTemplate.h:655

+ Here is the call graph for this function:

template<class T >
bool AchievementMgr< T >::CanUpdateCriteria ( AchievementCriteria const criteria,
AchievementCriteriaTreeList const trees,
uint64  miscValue1,
uint64  miscValue2,
uint64  miscValue3,
Unit const unit,
Player referencePlayer 
)
private
2011 {
2013  {
2014  TC_LOG_TRACE("achievement", "CanUpdateCriteria: (Id: %u Type %s) Disabled",
2015  criteria->ID, AchievementGlobalMgr::GetCriteriaTypeString(criteria->Entry->Type));
2016  return false;
2017  }
2018 
2019  bool treeRequirementPassed = false;
2020  for (AchievementCriteriaTree const* tree : *trees)
2021  {
2022  if (HasAchieved(tree->Achievement->ID))
2023  {
2024  TC_LOG_TRACE("achievement", "CanUpdateCriteria: (Id: %u Type %s Achievement %u) Achievement already earned",
2025  criteria->ID, AchievementGlobalMgr::GetCriteriaTypeString(criteria->Entry->Type), tree->Achievement->ID);
2026  continue;
2027  }
2028 
2029  if (tree->Achievement->MapID != -1 && referencePlayer->GetMapId() != uint32(tree->Achievement->MapID))
2030  {
2031  TC_LOG_TRACE("achievement", "CanUpdateCriteria: (Id: %u Type %s Achievement %u) Wrong map",
2032  criteria->ID, AchievementGlobalMgr::GetCriteriaTypeString(criteria->Entry->Type), tree->Achievement->ID);
2033  continue;
2034  }
2035 
2036  if ((tree->Achievement->Faction == ACHIEVEMENT_FACTION_HORDE && referencePlayer->GetTeam() != HORDE) ||
2037  (tree->Achievement->Faction == ACHIEVEMENT_FACTION_ALLIANCE && referencePlayer->GetTeam() != ALLIANCE))
2038  {
2039  TC_LOG_TRACE("achievement", "CanUpdateCriteria: (Id: %u Type %s Achievement %u) Wrong faction",
2040  criteria->ID, AchievementGlobalMgr::GetCriteriaTypeString(criteria->Entry->Type), tree->Achievement->ID);
2041  continue;
2042  }
2043 
2044  treeRequirementPassed = true;
2045  break;
2046  }
2047 
2048  if (!treeRequirementPassed)
2049  return false;
2050 
2051  if (!RequirementsSatisfied(criteria, miscValue1, miscValue2, miscValue3, unit, referencePlayer))
2052  {
2053  TC_LOG_TRACE("achievement", "CanUpdateCriteria: (Id: %u Type %s) Requirements not satisfied",
2054  criteria->ID, AchievementGlobalMgr::GetCriteriaTypeString(criteria->Entry->Type));
2055  return false;
2056  }
2057 
2058  if (criteria->Modifier && !AdditionalRequirementsSatisfied(criteria->Modifier, miscValue1, miscValue2, unit, referencePlayer))
2059  {
2060  TC_LOG_TRACE("achievement", "CanUpdateCriteria: (Id: %u Type %s) Additional requirements not satisfied",
2061  criteria->ID, AchievementGlobalMgr::GetCriteriaTypeString(criteria->Entry->Type));
2062  return false;
2063  }
2064 
2065  if (!ConditionsSatisfied(criteria, referencePlayer))
2066  {
2067  TC_LOG_TRACE("achievement", "CanUpdateCriteria: (Id: %u Type %s) Conditions not satisfied",
2068  criteria->ID, AchievementGlobalMgr::GetCriteriaTypeString(criteria->Entry->Type));
2069  return false;
2070  }
2071 
2072  return true;
2073 }
bool IsDisabledFor(DisableType type, uint32 entry, Unit const *unit, uint8 flags)
Definition: DisableMgr.cpp:277
Definition: AchievementMgr.h:62
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: DBCEnums.h:77
static char const * GetCriteriaTypeString(AchievementCriteriaTypes type)
Definition: AchievementMgr.cpp:2589
Definition: SharedDefines.h:1000
Definition: DBCEnums.h:76
bool AdditionalRequirementsSatisfied(ModifierTreeNode const *parent, uint64 miscValue1, uint64 miscValue2, Unit const *unit, Player *referencePlayer) const
Definition: AchievementMgr.cpp:2393
#define TC_LOG_TRACE(filterType__,...)
Definition: Log.h:195
bool RequirementsSatisfied(AchievementCriteria const *criteria, uint64 miscValue1, uint64 miscValue2, uint64 miscValue3, Unit const *unit, Player *referencePlayer) const
Definition: AchievementMgr.cpp:2099
bool HasAchieved(uint32 achievementId) const
Definition: AchievementMgr.cpp:2004
Definition: SharedDefines.h:999
Definition: DisableMgr.h:33
uint32_t uint32
Definition: g3dmath.h:168
bool ConditionsSatisfied(AchievementCriteria const *criteria, Player *referencePlayer) const
Definition: AchievementMgr.cpp:2076

+ Here is the call graph for this function:

template<class T >
void AchievementMgr< T >::CheckAllAchievementCriteria ( Player referencePlayer)

called at player login. The player might have fulfilled some achievements when the achievement system wasn't working yet

955 {
956  // suppress sending packets
957  for (uint32 i = 0; i < ACHIEVEMENT_CRITERIA_TYPE_TOTAL; ++i)
958  UpdateAchievementCriteria(AchievementCriteriaTypes(i), 0, 0, 0, NULL, referencePlayer);
959 }
#define ACHIEVEMENT_CRITERIA_TYPE_TOTAL
Definition: DBCEnums.h:360
arena_t NULL
Definition: jemalloc_internal.h:624
AchievementCriteriaTypes
Definition: DBCEnums.h:196
uint32_t uint32
Definition: Define.h:150
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, Unit const *unit=NULL, Player *referencePlayer=NULL)
Definition: AchievementMgr.cpp:969
template<class T>
void AchievementMgr< T >::CompletedAchievement ( AchievementEntry const entry,
Player referencePlayer 
)
template<>
void AchievementMgr< Player >::CompletedAchievement ( AchievementEntry const achievement,
Player referencePlayer 
)

Currently there's only one achievement that deals with gender-specific titles. Since no common attributes were found, (not even in titleRewardFlags field) we explicitly check by ID. Maybe in the future we could move the achievement_reward condition fields to the condition system.

1730 {
1731  // disable for gamemasters with GM-mode enabled
1732  if (GetOwner()->IsGameMaster())
1733  return;
1734 
1735  if (achievement->Flags & ACHIEVEMENT_FLAG_COUNTER || HasAchieved(achievement->ID))
1736  return;
1737 
1738  if (achievement->Flags & ACHIEVEMENT_FLAG_SHOW_IN_GUILD_NEWS)
1739  if (Guild* guild = referencePlayer->GetGuild())
1740  guild->AddGuildNews(GUILD_NEWS_PLAYER_ACHIEVEMENT, referencePlayer->GetGUID(), achievement->Flags & ACHIEVEMENT_FLAG_SHOW_IN_GUILD_HEADER, achievement->ID);
1741 
1742  if (!GetOwner()->GetSession()->PlayerLoading())
1743  SendAchievementEarned(achievement);
1744 
1745  TC_LOG_DEBUG("achievement", "AchievementMgr::CompletedAchievement(%u). %s %s",
1746  achievement->ID, GetOwner()->GetGUID().ToString().c_str(), GetOwner()->GetName().c_str());
1747 
1748  CompletedAchievementData& ca = m_completedAchievements[achievement->ID];
1749  ca.date = time(NULL);
1750  ca.changed = true;
1751 
1752  sAchievementMgr->SetRealmCompleted(achievement, GetOwner()->GetInstanceId());
1753 
1754  _achievementPoints += achievement->Points;
1755 
1757  UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_ACHIEVEMENT_POINTS, achievement->Points, 0, 0, NULL, referencePlayer);
1758 
1759  // reward items and titles if any
1760  AchievementReward const* reward = sAchievementMgr->GetAchievementReward(achievement);
1761 
1762  // no rewards
1763  if (!reward)
1764  return;
1765 
1766  // titles
1771  if (uint32 titleId = reward->titleId[achievement->ID == 1793 ? GetOwner()->GetByteValue(PLAYER_BYTES_3, PLAYER_BYTES_3_OFFSET_GENDER) : (GetOwner()->GetTeam() == ALLIANCE ? 0 : 1)])
1772  if (CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(titleId))
1773  GetOwner()->SetTitle(titleEntry);
1774 
1775  // mail
1776  if (reward->sender)
1777  {
1778  MailDraft draft(reward->mailTemplate);
1779 
1780  if (!reward->mailTemplate)
1781  {
1782  // subject and text
1783  std::string subject = reward->subject;
1784  std::string text = reward->text;
1785 
1786  LocaleConstant localeConstant = GetOwner()->GetSession()->GetSessionDbLocaleIndex();
1787  if (localeConstant >= LOCALE_enUS)
1788  {
1789  if (AchievementRewardLocale const* loc = sAchievementMgr->GetAchievementRewardLocale(achievement))
1790  {
1791  ObjectMgr::GetLocaleString(loc->subject, localeConstant, subject);
1792  ObjectMgr::GetLocaleString(loc->text, localeConstant, text);
1793  }
1794  }
1795 
1796  draft = MailDraft(subject, text);
1797  }
1798 
1800 
1801  Item* item = reward->itemId ? Item::CreateItem(reward->itemId, 1, GetOwner()) : NULL;
1802  if (item)
1803  {
1804  // save new item before send
1805  item->SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted
1806 
1807  // item
1808  draft.AddItem(item);
1809  }
1810 
1811  draft.SendMailTo(trans, GetOwner(), MailSender(MAIL_CREATURE, uint64(reward->sender)));
1813  }
1814 }
Definition: Player.h:587
uint32 sender
Definition: AchievementMgr.h:255
CompletedAchievementMap m_completedAchievements
Definition: AchievementMgr.h:359
bool changed
Definition: AchievementMgr.h:275
uint32 mailTemplate
Definition: AchievementMgr.h:258
Definition: DBCStructure.h:162
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
std::string subject
Definition: AchievementMgr.h:256
Definition: DBCEnums.h:95
arena_t NULL
Definition: jemalloc_internal.h:624
uint32 titleId[2]
Definition: AchievementMgr.h:253
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint64_t uint64
Definition: g3dmath.h:170
uint32 _achievementPoints
Definition: AchievementMgr.h:362
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesfmt)
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
Definition: SharedDefines.h:1000
Definition: UpdateFields.h:198
virtual void SaveToDB(SQLTransaction &trans)
Definition: Item.cpp:311
Definition: Mail.h:118
Definition: AchievementMgr.h:263
Definition: Guild.h:235
time_t date
Definition: AchievementMgr.h:273
string ToString(int i)
Definition: strutil.h:491
Definition: DBCEnums.h:96
LocaleConstant
Definition: Common.h:115
Definition: Item.h:259
uint32_t uint32
Definition: Define.h:150
uint32 itemId
Definition: AchievementMgr.h:254
static Item * CreateItem(uint32 itemEntry, uint32 count, Player const *player=NULL)
Definition: Item.cpp:1068
TC_GAME_API bool GetName(uint32 accountId, std::string &name)
Definition: BattlenetAccountMgr.cpp:138
bool HasAchieved(uint32 achievementId) const
Definition: AchievementMgr.cpp:2004
std::string text
Definition: AchievementMgr.h:257
Definition: DBCEnums.h:83
Definition: Common.h:117
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, Unit const *unit=NULL, Player *referencePlayer=NULL)
Definition: AchievementMgr.cpp:969
void SendAchievementEarned(AchievementEntry const *achievement) const
Definition: AchievementMgr.cpp:813
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
static void GetLocaleString(StringVector const &data, LocaleConstant localeConstant, std::string &value)
Definition: ObjectMgr.h:1345
static uint32 GetInstanceId(T *)
Definition: AchievementMgr.cpp:1326
Definition: Guild.h:320
T * GetOwner() const
Definition: AchievementMgr.h:333
Definition: AchievementMgr.h:271
Definition: Mail.h:40
Definition: AchievementMgr.h:251
#define sAchievementMgr
Definition: AchievementMgr.h:501
Definition: Mail.h:83
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

template<class T >
void AchievementMgr< T >::CompletedCriteriaFor ( AchievementEntry const achievement,
Player referencePlayer 
)
private
1499 {
1500  // counter can never complete
1501  if (achievement->Flags & ACHIEVEMENT_FLAG_COUNTER)
1502  return;
1503 
1504  // already completed and stored
1505  if (HasAchieved(achievement->ID))
1506  return;
1507 
1508  if (IsCompletedAchievement(achievement))
1509  CompletedAchievement(achievement, referencePlayer);
1510 }
void CompletedAchievement(AchievementEntry const *entry, Player *referencePlayer)
bool HasAchieved(uint32 achievementId) const
Definition: AchievementMgr.cpp:2004
Definition: DBCEnums.h:83
bool IsCompletedAchievement(AchievementEntry const *entry)
Definition: AchievementMgr.cpp:1513
template<class T >
bool AchievementMgr< T >::ConditionsSatisfied ( AchievementCriteria const criteria,
Player referencePlayer 
) const
private
2077 {
2078  if (!criteria->Entry->FailEvent)
2079  return true;
2080 
2081  switch (criteria->Entry->FailEvent)
2082  {
2084  if (!referencePlayer->InBattleground())
2085  return false;
2086  break;
2088  if (referencePlayer->GetGroup())
2089  return false;
2090  break;
2091  default:
2092  break;
2093  }
2094 
2095  return true;
2096 }
Definition: DBCEnums.h:108
template<class T>
uint32 AchievementMgr< T >::GetAchievementPoints ( ) const
inline
339 { return _achievementPoints; }
uint32 _achievementPoints
Definition: AchievementMgr.h:362

+ Here is the caller graph for this function:

template<class T >
CriteriaProgress * AchievementMgr< T >::GetCriteriaProgress ( AchievementCriteria const entry)
private
1542 {
1543  CriteriaProgressMap::iterator iter = m_criteriaProgress.find(entry->ID);
1544 
1545  if (iter == m_criteriaProgress.end())
1546  return NULL;
1547 
1548  return &(iter->second);
1549 }
arena_t NULL
Definition: jemalloc_internal.h:624
CriteriaProgressMap m_criteriaProgress
Definition: AchievementMgr.h:358
template<class T>
T* AchievementMgr< T >::GetOwner ( ) const
inline
333 { return _owner; }
T * _owner
Definition: AchievementMgr.h:357

+ Here is the caller graph for this function:

template<class T >
bool AchievementMgr< T >::HasAchieved ( uint32  achievementId) const
2005 {
2006  return m_completedAchievements.find(achievementId) != m_completedAchievements.end();
2007 }
CompletedAchievementMap m_completedAchievements
Definition: AchievementMgr.h:359

+ Here is the caller graph for this function:

template<class T >
bool AchievementMgr< T >::IsCompletedAchievement ( AchievementEntry const entry)
private
1514 {
1515  // counter can never complete
1516  if (entry->Flags & ACHIEVEMENT_FLAG_COUNTER)
1517  return false;
1518 
1519  AchievementCriteriaTree const* tree = sAchievementMgr->GetAchievementCriteriaTree(entry->CriteriaTree);
1520  if (!tree)
1521  return false;
1522 
1523  // For SUMM achievements, we have to count the progress of each criteria of the achievement.
1524  // Oddly, the target count is NOT contained in the achievement, but in each individual criteria
1525  if (entry->Flags & ACHIEVEMENT_FLAG_SUMM)
1526  {
1527  uint64 progress = 0;
1528  sAchievementMgr->WalkCriteriaTree(tree, [this, &progress](AchievementCriteriaTree const* criteriaTree)
1529  {
1530  if (criteriaTree->Criteria)
1531  if (CriteriaProgress const* criteriaProgress = this->GetCriteriaProgress(criteriaTree->Criteria))
1532  progress += criteriaProgress->counter;
1533  });
1534  return progress >= tree->Entry->Amount;
1535  }
1536 
1537  return IsCompletedCriteriaTree(tree);
1538 }
CriteriaTreeEntry const * Entry
Definition: AchievementMgr.h:65
AchievementCriteria const * Criteria
Definition: AchievementMgr.h:67
Definition: AchievementMgr.h:62
uint64 Amount
Definition: DB2Structure.h:322
bool IsCompletedCriteriaTree(AchievementCriteriaTree const *tree)
Definition: AchievementMgr.cpp:1332
CriteriaProgress * GetCriteriaProgress(AchievementCriteria const *entry)
Definition: AchievementMgr.cpp:1541
uint64_t uint64
Definition: Define.h:149
Definition: DBCEnums.h:86
Definition: AchievementMgr.h:78
Definition: DBCEnums.h:83
#define sAchievementMgr
Definition: AchievementMgr.h:501
template<class T >
bool AchievementMgr< T >::IsCompletedCriteria ( AchievementCriteria const achievementCriteria,
uint64  requiredAmount 
)
private
1385 {
1386  CriteriaProgress const* progress = GetCriteriaProgress(achievementCriteria);
1387  if (!progress)
1388  return false;
1389 
1390  switch (AchievementCriteriaTypes(achievementCriteria->Entry->Type))
1391  {
1442  return progress->counter >= requiredAmount;
1449  return progress->counter >= 1;
1451  return progress->counter >= (requiredAmount * 75);
1453  return progress->counter >= 9000;
1455  return requiredAmount && progress->counter >= requiredAmount;
1457  return true;
1458  // handle all statistic-only criteria here
1490  default:
1491  break;
1492  }
1493 
1494  return false;
1495 }
Definition: DBCEnums.h:207
Definition: DBCEnums.h:265
Definition: DBCEnums.h:234
Definition: DBCEnums.h:221
Definition: DBCEnums.h:208
Definition: DBCEnums.h:263
Definition: DBCEnums.h:199
Definition: DBCEnums.h:271
Definition: DBCEnums.h:198
Definition: DBCEnums.h:249
Definition: DBCEnums.h:224
Definition: DBCEnums.h:212
Definition: DBCEnums.h:235
Definition: DBCEnums.h:246
Definition: DBCEnums.h:237
Definition: DBCEnums.h:244
Definition: DBCEnums.h:218
AchievementCriteriaTypes
Definition: DBCEnums.h:196
Definition: DBCEnums.h:279
CriteriaProgress * GetCriteriaProgress(AchievementCriteria const *entry)
Definition: AchievementMgr.cpp:1541
Definition: DBCEnums.h:245
Definition: DBCEnums.h:266
Definition: AchievementMgr.h:78
Definition: DBCEnums.h:233
Definition: DBCEnums.h:201
Definition: DBCEnums.h:247
Definition: DBCEnums.h:257
Definition: DBCEnums.h:226
Definition: DBCEnums.h:280
Definition: DBCEnums.h:290
Definition: DBCEnums.h:289
uint64 counter
Definition: AchievementMgr.h:80
Definition: DBCEnums.h:228
Definition: DBCEnums.h:211
template<class T >
bool AchievementMgr< T >::IsCompletedCriteriaTree ( AchievementCriteriaTree const tree)
private
1333 {
1334  AchievementEntry const* achievement = tree->Achievement;
1335  if (!achievement)
1336  return false;
1337 
1338  // counter can never complete
1339  if (achievement->Flags & ACHIEVEMENT_FLAG_COUNTER)
1340  return false;
1341 
1343  {
1344  // someone on this realm has already completed that achievement
1345  if (sAchievementMgr->IsRealmCompleted(achievement, GetInstanceId(GetOwner())))
1346  return false;
1347  }
1348 
1349  uint64 requiredCount = tree->Entry->Amount;
1350  uint64 completedCount = 0;
1351  uint32 op = tree->Entry->Operator;
1352  bool hasAll = true;
1353 
1354  // Check criteria we depend on first
1355  for (AchievementCriteriaTree const* node : tree->Children)
1356  {
1357  if (IsCompletedCriteriaTree(node))
1358  ++completedCount;
1359  else
1360  hasAll = false;
1361 
1362  if (op & ACHIEVEMENT_CRITERIA_TREE_OPERATOR_ANY && completedCount >= requiredCount)
1363  {
1364  if (!tree->Criteria)
1365  return true;
1366 
1367  break;
1368  }
1369  }
1370 
1371  if (op & ACHIEVEMENT_CRITERIA_TREE_OPERATOR_ANY && completedCount < requiredCount)
1372  return false;
1373 
1374  if (op & ACHIEVEMENT_CRITERIA_TREE_OPERATOR_ALL && !hasAll)
1375  return false;
1376 
1377  if (!tree->Criteria)
1378  return true;
1379 
1380  return IsCompletedCriteria(tree->Criteria, requiredCount);
1381 }
bool IsCompletedCriteria(AchievementCriteria const *achievementCriteria, uint64 requiredAmount)
Definition: AchievementMgr.cpp:1384
Definition: DBCEnums.h:91
Definition: DBCEnums.h:364
Definition: DBCEnums.h:365
uint32 Flags
Definition: DB2Structure.h:38
Definition: AchievementMgr.h:62
std::vector< AchievementCriteriaTree const * > Children
Definition: AchievementMgr.h:68
bool IsCompletedCriteriaTree(AchievementCriteriaTree const *tree)
Definition: AchievementMgr.cpp:1332
Definition: DB2Structure.h:27
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
Definition: DBCEnums.h:83
Definition: DBCEnums.h:92
static uint32 GetInstanceId(T *)
Definition: AchievementMgr.cpp:1326
T * GetOwner() const
Definition: AchievementMgr.h:333
#define sAchievementMgr
Definition: AchievementMgr.h:501

+ Here is the call graph for this function:

template<class T >
void AchievementMgr< T >::LoadFromDB ( PreparedQueryResult  achievementResult,
PreparedQueryResult  criteriaResult 
)
627 {
628 }
template<>
void AchievementMgr< Player >::LoadFromDB ( PreparedQueryResult  achievementResult,
PreparedQueryResult  criteriaResult 
)
632 {
633  if (achievementResult)
634  {
635  do
636  {
637  Field* fields = achievementResult->Fetch();
638  uint32 achievementid = fields[0].GetUInt16();
639 
640  // must not happen: cleanup at server startup in sAchievementMgr->LoadCompletedAchievements()
641  AchievementEntry const* achievement = sAchievementMgr->GetAchievement(achievementid);
642  if (!achievement)
643  continue;
644 
646  ca.date = time_t(fields[1].GetUInt32());
647  ca.changed = false;
648 
649  _achievementPoints += achievement->Points;
650 
651  // title achievement rewards are retroactive
652  if (AchievementReward const* reward = sAchievementMgr->GetAchievementReward(achievement))
653  if (uint32 titleId = reward->titleId[Player::TeamForRace(GetOwner()->getRace()) == ALLIANCE ? 0 : 1])
654  if (CharTitlesEntry const* titleEntry = sCharTitlesStore.LookupEntry(titleId))
655  GetOwner()->SetTitle(titleEntry);
656 
657  }
658  while (achievementResult->NextRow());
659  }
660 
661  if (criteriaResult)
662  {
663  time_t now = time(NULL);
664  do
665  {
666  Field* fields = criteriaResult->Fetch();
667  uint32 id = fields[0].GetUInt32();
668  uint64 counter = fields[1].GetUInt64();
669  time_t date = time_t(fields[2].GetUInt32());
670 
671  AchievementCriteria const* criteria = sAchievementMgr->GetAchievementCriteria(id);
672  if (!criteria)
673  {
674  // we will remove not existed criteria for all characters
675  TC_LOG_ERROR("achievement", "Non-existing achievement criteria %u data removed from table `character_achievement_progress`.", id);
676 
678  stmt->setUInt32(0, uint16(id));
680 
681  continue;
682  }
683 
684  if (criteria->Entry->StartTimer && time_t(date + criteria->Entry->StartTimer) < now)
685  continue;
686 
687  CriteriaProgress& progress = m_criteriaProgress[id];
688  progress.counter = counter;
689  progress.date = date;
690  progress.changed = false;
691  }
692  while (criteriaResult->NextRow());
693  }
694 }
uint32 StartTimer
Definition: DB2Structure.h:309
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
uint64 GetUInt64() const
Definition: Field.h:184
bool changed
Definition: AchievementMgr.h:83
CompletedAchievementMap m_completedAchievements
Definition: AchievementMgr.h:359
bool changed
Definition: AchievementMgr.h:275
Definition: DBCStructure.h:162
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 Points
Definition: DB2Structure.h:36
arena_t NULL
Definition: jemalloc_internal.h:624
uint32 _achievementPoints
Definition: AchievementMgr.h:362
uint16_t uint16
Definition: g3dmath.h:166
Definition: PreparedStatement.h:74
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesfmt)
Definition: SharedDefines.h:1000
CriteriaProgressMap m_criteriaProgress
Definition: AchievementMgr.h:358
time_t date
Definition: AchievementMgr.h:273
Definition: DB2Structure.h:27
Definition: CharacterDatabase.h:346
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
uint16 GetUInt16() const
Definition: Field.h:108
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
Definition: AchievementMgr.h:78
CriteriaEntry const * Entry
Definition: AchievementMgr.h:54
uint32 GetUInt32() const
Definition: Field.h:146
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint64 counter
Definition: AchievementMgr.h:80
T * GetOwner() const
Definition: AchievementMgr.h:333
Definition: AchievementMgr.h:271
Definition: AchievementMgr.h:51
Definition: AchievementMgr.h:251
time_t date
Definition: AchievementMgr.h:81
#define sAchievementMgr
Definition: AchievementMgr.h:501

+ Here is the call graph for this function:

template<class T >
void AchievementMgr< T >::RemoveCriteriaProgress ( AchievementCriteria const entry)
private
418 {
419  if (!entry)
420  return;
421 
422  CriteriaProgressMap::iterator criteriaProgress = m_criteriaProgress.find(entry->ID);
423  if (criteriaProgress == m_criteriaProgress.end())
424  return;
425 
427  criteriaDeleted.CriteriaID = entry->ID;
428  SendPacket(criteriaDeleted.Write());
429 
430  m_criteriaProgress.erase(criteriaProgress);
431 }
WorldPacket const * Write() override
Definition: AchievementPackets.cpp:81
Definition: AchievementPackets.h:91
uint32 CriteriaID
Definition: AchievementPackets.h:98
CriteriaProgressMap m_criteriaProgress
Definition: AchievementMgr.h:358
void SendPacket(WorldPacket const *data) const
Definition: AchievementMgr.cpp:402

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T >
void AchievementMgr< T >::RemoveTimedAchievement ( AchievementCriteriaTimedTypes  type,
uint32  entry 
)
1711 {
1712  AchievementCriteriaList const& achievementCriteriaList = sAchievementMgr->GetTimedAchievementCriteriaByType(type);
1713  for (AchievementCriteria const* criteria : achievementCriteriaList)
1714  {
1715  if (criteria->Entry->StartAsset != entry)
1716  continue;
1717 
1718  AchievementCriteriaTreeList const* trees = sAchievementMgr->GetAchievementCriteriaTreesByCriteria(criteria->ID);
1719  // Remove the timer from all trees
1720  for (AchievementCriteriaTree const* tree : *trees)
1721  m_timedAchievements.erase(tree->ID);
1722 
1723  // remove progress
1724  RemoveCriteriaProgress(criteria);
1725  }
1726 }
TimedAchievementMap m_timedAchievements
Definition: AchievementMgr.h:361
Definition: AchievementMgr.h:62
void RemoveCriteriaProgress(AchievementCriteria const *entry)
Definition: AchievementMgr.cpp:417
std::vector< AchievementCriteriaTree const * > AchievementCriteriaTreeList
Definition: AchievementMgr.h:72
std::vector< AchievementCriteria const * > AchievementCriteriaList
Definition: AchievementMgr.h:59
Definition: AchievementMgr.h:51
#define sAchievementMgr
Definition: AchievementMgr.h:501
template<class T >
bool AchievementMgr< T >::RequirementsSatisfied ( AchievementCriteria const criteria,
uint64  miscValue1,
uint64  miscValue2,
uint64  miscValue3,
Unit const unit,
Player referencePlayer 
) const
private
2100 {
2101  switch (AchievementCriteriaTypes(achievementCriteria->Entry->Type))
2102  {
2138  if (!miscValue1)
2139  return false;
2140  break;
2153  break;
2155  if (m_completedAchievements.find(achievementCriteria->Entry->Asset.AchievementID) == m_completedAchievements.end())
2156  return false;
2157  break;
2159  if (!miscValue1 || achievementCriteria->Entry->Asset.MapID != referencePlayer->GetMapId())
2160  return false;
2161  break;
2163  if (!miscValue1 || achievementCriteria->Entry->Asset.CreatureID != miscValue1)
2164  return false;
2165  break;
2168  // update at loading or specific skill update
2169  if (miscValue1 && miscValue1 != achievementCriteria->Entry->Asset.SkillID)
2170  return false;
2171  break;
2173  if (miscValue1 && miscValue1 != achievementCriteria->Entry->Asset.ZoneID)
2174  return false;
2175  break;
2178  if (!miscValue1 || referencePlayer->GetMapId() != achievementCriteria->Entry->Asset.MapID)
2179  return false;
2180  break;
2182  {
2183  if (!miscValue1)
2184  return false;
2185  break;
2186  }
2188  {
2189  if (!miscValue1)
2190  return false;
2191 
2192  Map const* map = referencePlayer->IsInWorld() ? referencePlayer->GetMap() : sMapMgr->FindMap(referencePlayer->GetMapId(), referencePlayer->GetInstanceId());
2193  if (!map || !map->IsDungeon())
2194  return false;
2195 
2196  //FIXME: work only for instances where max == min for players
2197  if (map->ToInstanceMap()->GetMaxPlayers() != achievementCriteria->Entry->Asset.GroupSize)
2198  return false;
2199  break;
2200  }
2202  if (!miscValue1 || miscValue1 != achievementCriteria->Entry->Asset.CreatureID)
2203  return false;
2204  break;
2206  if (!miscValue1 || !unit || unit->GetTypeId() != TYPEID_PLAYER)
2207  return false;
2208  break;
2210  if (!miscValue1 || miscValue2 != achievementCriteria->Entry->Asset.DamageType)
2211  return false;
2212  break;
2214  {
2215  // if miscValues != 0, it contains the questID.
2216  if (miscValue1)
2217  {
2218  if (miscValue1 != achievementCriteria->Entry->Asset.QuestID)
2219  return false;
2220  }
2221  else
2222  {
2223  // login case.
2224  if (!referencePlayer->GetQuestRewardStatus(achievementCriteria->Entry->Asset.QuestID))
2225  return false;
2226  }
2227 
2228  if (AchievementCriteriaDataSet const* data = sAchievementMgr->GetCriteriaDataSet(achievementCriteria))
2229  if (!data->Meets(referencePlayer, unit))
2230  return false;
2231  break;
2232  }
2237  if (!miscValue1 || miscValue1 != achievementCriteria->Entry->Asset.SpellID)
2238  return false;
2239  break;
2241  if (miscValue1 && miscValue1 != achievementCriteria->Entry->Asset.SpellID)
2242  return false;
2243 
2244  if (!referencePlayer->HasSpell(achievementCriteria->Entry->Asset.SpellID))
2245  return false;
2246  break;
2248  // miscValue1 = itemId - miscValue2 = count of item loot
2249  // miscValue3 = loot_type (note: 0 = LOOT_CORPSE and then it ignored)
2250  if (!miscValue1 || !miscValue2 || !miscValue3 || miscValue3 != achievementCriteria->Entry->Asset.LootType)
2251  return false;
2252  break;
2254  if (miscValue1 && achievementCriteria->Entry->Asset.ItemID != miscValue1)
2255  return false;
2256  break;
2260  if (!miscValue1 || achievementCriteria->Entry->Asset.ItemID != miscValue1)
2261  return false;
2262  break;
2264  {
2265  WorldMapOverlayEntry const* worldOverlayEntry = sWorldMapOverlayStore.LookupEntry(achievementCriteria->Entry->Asset.WorldMapOverlayID);
2266  if (!worldOverlayEntry)
2267  break;
2268 
2269  bool matchFound = false;
2270  for (int j = 0; j < MAX_WORLD_MAP_OVERLAY_AREA_IDX; ++j)
2271  {
2272  AreaTableEntry const* area = sAreaTableStore.LookupEntry(worldOverlayEntry->AreaID[j]);
2273  if (!area)
2274  break;
2275 
2276  if (area->AreaBit < 0)
2277  continue;
2278 
2279  uint32 playerIndexOffset = uint32(area->AreaBit) / 32;
2280  if (playerIndexOffset >= PLAYER_EXPLORED_ZONES_SIZE)
2281  continue;
2282 
2283  uint32 mask = 1 << (uint32(area->AreaBit) % 32);
2284  if (referencePlayer->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + playerIndexOffset) & mask)
2285  {
2286  matchFound = true;
2287  break;
2288  }
2289  }
2290 
2291  if (!matchFound)
2292  return false;
2293  break;
2294  }
2296  if (miscValue1 && miscValue1 != achievementCriteria->Entry->Asset.FactionID)
2297  return false;
2298  break;
2300  // miscValue1 = itemid miscValue2 = itemSlot
2301  if (!miscValue1 || miscValue2 != achievementCriteria->Entry->Asset.ItemSlot)
2302  return false;
2303  break;
2306  {
2307  // miscValue1 = itemid miscValue2 = diced value
2308  if (!miscValue1 || miscValue2 != achievementCriteria->Entry->Asset.RollValue)
2309  return false;
2310 
2311  ItemTemplate const* proto = sObjectMgr->GetItemTemplate(uint32(miscValue1));
2312  if (!proto)
2313  return false;
2314  break;
2315  }
2317  if (!miscValue1 || miscValue1 != achievementCriteria->Entry->Asset.EmoteID)
2318  return false;
2319  break;
2322  if (!miscValue1)
2323  return false;
2324 
2325  if (achievementCriteria->Entry->FailEvent == ACHIEVEMENT_CRITERIA_CONDITION_BG_MAP)
2326  {
2327  if (!referencePlayer->InBattleground())
2328  return false;
2329 
2330  // map specific case (BG in fact) expected player targeted damage/heal
2331  if (!unit || unit->GetTypeId() != TYPEID_PLAYER)
2332  return false;
2333  }
2334  break;
2337  if (!miscValue1 || miscValue1 != achievementCriteria->Entry->Asset.GameObjectID)
2338  return false;
2339  break;
2342  if (miscValue1 && miscValue1 != achievementCriteria->Entry->Asset.SkillID)
2343  return false;
2344  break;
2347  {
2348  if (!miscValue1)
2349  return false;
2350  ItemTemplate const* proto = sObjectMgr->GetItemTemplate(uint32(miscValue1));
2351  if (!proto || proto->GetQuality() < ITEM_QUALITY_EPIC)
2352  return false;
2353  break;
2354  }
2356  if (!miscValue1 || miscValue1 != achievementCriteria->Entry->Asset.ClassID)
2357  return false;
2358  break;
2360  if (!miscValue1 || miscValue1 != achievementCriteria->Entry->Asset.RaceID)
2361  return false;
2362  break;
2364  if (!miscValue1 || miscValue1 != achievementCriteria->Entry->Asset.ObjectiveId)
2365  return false;
2366  break;
2368  if (!miscValue1 || miscValue1 != achievementCriteria->Entry->Asset.AreaID)
2369  return false;
2370  break;
2372  if (!miscValue1 || !miscValue2 || int64(miscValue2) < 0
2373  || miscValue1 != achievementCriteria->Entry->Asset.CurrencyID)
2374  return false;
2375  break;
2377  if (miscValue1 != achievementCriteria->Entry->Asset.MapID)
2378  return false;
2379  break;
2381  return false;
2383  if (miscValue1 != achievementCriteria->Entry->Asset.GarrBuildingID)
2384  return false;
2385  break;
2386  default:
2387  break;
2388  }
2389  return true;
2390 }
Definition: DBCEnums.h:207
Definition: DBCEnums.h:265
Definition: DBCStructure.h:37
Definition: DBCEnums.h:234
Definition: DBCEnums.h:221
CompletedAchievementMap m_completedAchievements
Definition: AchievementMgr.h:359
Definition: DBCEnums.h:208
Definition: DBCEnums.h:108
Definition: DBCEnums.h:263
Definition: DBCEnums.h:199
Definition: DBCEnums.h:271
Definition: DBCEnums.h:198
bool IsDungeon() const
Definition: Map.h:395
#define PLAYER_EXPLORED_ZONES_SIZE
Definition: Player.h:72
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: DBCEnums.h:249
Definition: AchievementMgr.h:237
Definition: DBCEnums.h:224
Definition: DBCEnums.h:235
Definition: DBCEnums.h:212
Definition: DBCEnums.h:246
DBCStorage< AreaTableEntry > sAreaTableStore(AreaTablefmt)
Definition: DBCEnums.h:237
Definition: DBCEnums.h:244
Definition: DBCEnums.h:218
AchievementCriteriaTypes
Definition: DBCEnums.h:196
Definition: DBCEnums.h:279
InstanceMap * ToInstanceMap()
Definition: Map.h:495
uint32_t uint32
Definition: Define.h:150
Definition: DBCEnums.h:245
Definition: DBCEnums.h:266
Definition: Map.h:259
int64_t int64
Definition: g3dmath.h:169
Definition: DBCEnums.h:233
uint32 AreaID[MAX_WORLD_MAP_OVERLAY_AREA_IDX]
Definition: DB2Structure.h:1422
#define MAX_WORLD_MAP_OVERLAY_AREA_IDX
Definition: DB2Structure.h:1416
Definition: DBCEnums.h:201
Definition: DBCEnums.h:247
Definition: ObjectGuid.h:33
Definition: ItemTemplate.h:647
int32 AreaBit
Definition: DBCStructure.h:42
Definition: DBCEnums.h:257
#define sMapMgr
Definition: MapManager.h:194
Definition: DBCEnums.h:226
Definition: DBCEnums.h:280
Definition: DBCEnums.h:290
Definition: DB2Structure.h:1418
Definition: DBCEnums.h:289
uint32_t uint32
Definition: g3dmath.h:168
uint32 GetMaxPlayers() const
Definition: Map.cpp:3434
Definition: DBCEnums.h:228
Definition: SharedDefines.h:324
Definition: UpdateFields.h:249
#define sAchievementMgr
Definition: AchievementMgr.h:501
Definition: DBCEnums.h:211
DB2Storage< WorldMapOverlayEntry > sWorldMapOverlayStore("WorldMapOverlay.db2", WorldMapOverlayFormat, HOTFIX_SEL_WORLD_MAP_OVERLAY)
uint32 GetQuality() const
Definition: ItemTemplate.h:655

+ Here is the call graph for this function:

template<class T >
void AchievementMgr< T >::Reset ( )
761 {
762 }
template<>
void AchievementMgr< Player >::Reset ( )
766 {
767  for (CompletedAchievementMap::const_iterator iter = m_completedAchievements.begin(); iter != m_completedAchievements.end(); ++iter)
768  {
770  achievementDeleted.AchievementID = iter->first;
771  SendPacket(achievementDeleted.Write());
772  }
773 
774  for (CriteriaProgressMap::const_iterator iter = m_criteriaProgress.begin(); iter != m_criteriaProgress.end(); ++iter)
775  {
777  criteriaDeleted.CriteriaID = iter->first;
778  SendPacket(criteriaDeleted.Write());
779  }
780 
781  m_completedAchievements.clear();
782  _achievementPoints = 0;
783  m_criteriaProgress.clear();
784  DeleteFromDB(GetOwner()->GetGUID());
785 
786  // re-fill data
788 }
WorldPacket const * Write() override
Definition: AchievementPackets.cpp:81
CompletedAchievementMap m_completedAchievements
Definition: AchievementMgr.h:359
Definition: AchievementPackets.h:91
uint32 _achievementPoints
Definition: AchievementMgr.h:362
uint32 CriteriaID
Definition: AchievementPackets.h:98
CriteriaProgressMap m_criteriaProgress
Definition: AchievementMgr.h:358
uint32 AchievementID
Definition: AchievementPackets.h:108
WorldPacket const * Write() override
Definition: AchievementPackets.cpp:88
void SendPacket(WorldPacket const *data) const
Definition: AchievementMgr.cpp:402
void CheckAllAchievementCriteria(Player *referencePlayer)
Definition: AchievementMgr.cpp:954
T * GetOwner() const
Definition: AchievementMgr.h:333
Definition: AchievementPackets.h:101

+ Here is the call graph for this function:

template<class T >
void AchievementMgr< T >::ResetAchievementCriteria ( AchievementCriteriaTypes  type,
uint64  miscValue1 = 0,
uint64  miscValue2 = 0,
bool  evenIfCriteriaComplete = false 
)
453 {
454  TC_LOG_DEBUG("achievement", "ResetAchievementCriteria(%u, " UI64FMTD ", " UI64FMTD ")", type, miscValue1, miscValue2);
455 
456  // disable for gamemasters with GM-mode enabled
457  if (GetOwner()->IsGameMaster())
458  return;
459 
460  AchievementCriteriaList const& achievementCriteriaList = sAchievementMgr->GetAchievementCriteriaByType(type);
461  for (AchievementCriteria const* achievementCriteria : achievementCriteriaList)
462  {
463  if (achievementCriteria->Entry->FailEvent != miscValue1 || (achievementCriteria->Entry->FailAsset && achievementCriteria->Entry->FailAsset != miscValue2))
464  continue;
465 
466  AchievementCriteriaTreeList const* trees = sAchievementMgr->GetAchievementCriteriaTreesByCriteria(achievementCriteria->ID);
467  bool allComplete = true;
468  for (AchievementCriteriaTree const* tree : *trees)
469  {
470  // don't update already completed criteria if not forced or achievement already complete
471  if (!(IsCompletedCriteriaTree(tree) && !evenIfCriteriaComplete) || !HasAchieved(tree->Achievement->ID))
472  {
473  allComplete = false;
474  break;
475  }
476  }
477 
478  if (allComplete)
479  continue;
480 
481  RemoveCriteriaProgress(achievementCriteria);
482  }
483 }
Definition: AchievementMgr.h:62
void RemoveCriteriaProgress(AchievementCriteria const *entry)
Definition: AchievementMgr.cpp:417
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
std::vector< AchievementCriteriaTree const * > AchievementCriteriaTreeList
Definition: AchievementMgr.h:72
bool IsCompletedCriteriaTree(AchievementCriteriaTree const *tree)
Definition: AchievementMgr.cpp:1332
#define UI64FMTD
Definition: Define.h:137
bool HasAchieved(uint32 achievementId) const
Definition: AchievementMgr.cpp:2004
std::vector< AchievementCriteria const * > AchievementCriteriaList
Definition: AchievementMgr.h:59
T * GetOwner() const
Definition: AchievementMgr.h:333
Definition: AchievementMgr.h:51
#define sAchievementMgr
Definition: AchievementMgr.h:501
template<class T >
void AchievementMgr< T >::SaveToDB ( SQLTransaction trans)
523 {
524 }

+ Here is the caller graph for this function:

template<>
void AchievementMgr< Player >::SaveToDB ( SQLTransaction trans)
528 {
529  if (!m_completedAchievements.empty())
530  {
531  for (CompletedAchievementMap::iterator iter = m_completedAchievements.begin(); iter != m_completedAchievements.end(); ++iter)
532  {
533  if (!iter->second.changed)
534  continue;
535 
537  stmt->setUInt16(0, iter->first);
538  stmt->setUInt64(1, GetOwner()->GetGUID().GetCounter());
539  trans->Append(stmt);
540 
542  stmt->setUInt64(0, GetOwner()->GetGUID().GetCounter());
543  stmt->setUInt16(1, iter->first);
544  stmt->setUInt32(2, uint32(iter->second.date));
545  trans->Append(stmt);
546 
547  iter->second.changed = false;
548  }
549  }
550 
551  if (!m_criteriaProgress.empty())
552  {
553  for (CriteriaProgressMap::iterator iter = m_criteriaProgress.begin(); iter != m_criteriaProgress.end(); ++iter)
554  {
555  if (!iter->second.changed)
556  continue;
557 
559  stmt->setUInt64(0, GetOwner()->GetGUID().GetCounter());
560  stmt->setUInt32(1, iter->first);
561  trans->Append(stmt);
562 
563  if (iter->second.counter)
564  {
566  stmt->setUInt64(0, GetOwner()->GetGUID().GetCounter());
567  stmt->setUInt32(1, iter->first);
568  stmt->setUInt32(2, iter->second.counter);
569  stmt->setUInt32(3, uint32(iter->second.date));
570  trans->Append(stmt);
571  }
572 
573  iter->second.changed = false;
574  }
575  }
576 }
Definition: CharacterDatabase.h:411
Definition: CharacterDatabase.h:440
CompletedAchievementMap m_completedAchievements
Definition: AchievementMgr.h:359
Definition: CharacterDatabase.h:410
Definition: CharacterDatabase.h:409
Definition: PreparedStatement.h:74
CriteriaProgressMap m_criteriaProgress
Definition: AchievementMgr.h:358
void setUInt16(const uint8 index, const uint16 value)
Definition: PreparedStatement.cpp:106
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
uint32_t uint32
Definition: g3dmath.h:168
T * GetOwner() const
Definition: AchievementMgr.h:333

+ Here is the call graph for this function:

template<class T >
void AchievementMgr< T >::SendAchievementEarned ( AchievementEntry const achievement) const
private
814 {
815  // Don't send for achievements with ACHIEVEMENT_FLAG_HIDDEN
816  if (achievement->Flags & ACHIEVEMENT_FLAG_HIDDEN)
817  return;
818 
819  TC_LOG_DEBUG("achievement", "AchievementMgr::SendAchievementEarned(%u)", achievement->ID);
820 
821  if (Guild* guild = sGuildMgr->GetGuildById(GetOwner()->GetGuildId()))
822  {
825  guild->BroadcastWorker(_localizer, GetOwner());
826  }
827 
829  {
830  // broadcast realm first reached
832  serverFirstAchievement.Name = GetOwner()->GetName();
833  serverFirstAchievement.PlayerGUID = GetOwner()->GetGUID();
834  serverFirstAchievement.AchievementID = achievement->ID;
835  sWorld->SendGlobalMessage(serverFirstAchievement.Write());
836  }
837  // if player is in world he can tell his friends about new achievement
838  else if (GetOwner()->IsInWorld())
839  {
843  GetOwner()->VisitNearbyWorldObject(sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY), _worker);
844  }
845 
847  achievementEarned.Sender = GetOwner()->GetGUID();
848  achievementEarned.Earner = GetOwner()->GetGUID();
849  achievementEarned.EarnerNativeRealm = achievementEarned.EarnerVirtualRealm = GetVirtualRealmAddress();
850  achievementEarned.AchievementID = achievement->ID;
851  achievementEarned.Time = time(NULL);
852  GetOwner()->SendMessageToSetInRange(achievementEarned.Write(), sWorld->getFloatConfig(CONFIG_LISTEN_RANGE_SAY), true);
853 }
uint32 AchievementID
Definition: AchievementPackets.h:122
ObjectGuid PlayerGUID
Definition: AchievementPackets.h:135
std::string Name
Definition: AchievementPackets.h:136
Definition: GridNotifiers.h:560
#define sGuildMgr
Definition: GuildMgr.h:61
Definition: DBCEnums.h:91
Definition: World.h:190
arena_t NULL
Definition: jemalloc_internal.h:624
ObjectGuid Earner
Definition: AchievementPackets.h:119
Definition: GridNotifiers.h:1400
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
#define sWorld
Definition: World.h:887
Definition: SharedDefines.h:4277
time_t Time
Definition: AchievementPackets.h:123
uint32 EarnerNativeRealm
Definition: AchievementPackets.h:120
WorldPacket const * Write() override
Definition: AchievementPackets.cpp:96
Definition: ChatTextBuilder.h:27
Definition: SharedDefines.h:4278
Definition: Language.h:24
ObjectGuid Sender
Definition: AchievementPackets.h:125
uint32 GetVirtualRealmAddress()
Definition: World.cpp:3487
Definition: DBCEnums.h:92
uint32 EarnerVirtualRealm
Definition: AchievementPackets.h:121
Definition: Guild.h:320
T * GetOwner() const
Definition: AchievementMgr.h:333
Definition: DBCEnums.h:84
uint32 AchievementID
Definition: AchievementPackets.h:137
Definition: AchievementPackets.h:112
Definition: AchievementPackets.h:128
WorldPacket const * Write() override
Definition: AchievementPackets.cpp:110

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T>
void AchievementMgr< T >::SendAchievementInfo ( Player receiver,
uint32  achievementId = 0 
) const
template<>
void AchievementMgr< Player >::SendAchievementInfo ( Player receiver,
uint32   
) const
1929 {
1930  VisibleAchievementCheck filterInvisible;
1932  inspectedAchievements.Player = GetOwner()->GetGUID();
1933  inspectedAchievements.Data.Earned.reserve(m_completedAchievements.size());
1934  inspectedAchievements.Data.Progress.reserve(m_criteriaProgress.size());
1935 
1936  for (auto itr = m_completedAchievements.begin(); itr != m_completedAchievements.end(); ++itr)
1937  {
1938  AchievementEntry const* achievement = filterInvisible(*itr);
1939  if (!achievement)
1940  continue;
1941 
1943  earned.Id = itr->first;
1944  earned.Date = itr->second.date;
1945  if (!(achievement->Flags & ACHIEVEMENT_FLAG_ACCOUNT))
1946  {
1947  earned.Owner = GetOwner()->GetGUID();
1949  }
1950  inspectedAchievements.Data.Earned.push_back(earned);
1951  }
1952 
1953  for (auto itr = m_criteriaProgress.begin(); itr != m_criteriaProgress.end(); ++itr)
1954  {
1956  progress.Id = itr->first;
1957  progress.Quantity = itr->second.counter;
1958  progress.Player = itr->second.PlayerGUID;
1959  progress.Flags = 0;
1960  progress.Date = itr->second.date;
1961  progress.TimeFromStart = 0;
1962  progress.TimeFromCreate = 0;
1963  inspectedAchievements.Data.Progress.push_back(progress);
1964  }
1965 
1966  receiver->GetSession()->SendPacket(inspectedAchievements.Write());
1967 }
uint32 TimeFromCreate
Definition: AchievementPackets.h:45
AllAchievements Data
Definition: AchievementPackets.h:72
CompletedAchievementMap m_completedAchievements
Definition: AchievementMgr.h:359
uint32 Flags
Definition: DB2Structure.h:38
ObjectGuid Player
Definition: AchievementPackets.h:71
Definition: AchievementPackets.h:37
Definition: AchievementPackets.h:28
uint32 Flags
Definition: AchievementPackets.h:42
std::vector< CriteriaProgress > Progress
Definition: AchievementPackets.h:51
time_t Date
Definition: AchievementPackets.h:43
WorldPacket const * Write() override
Definition: AchievementPackets.cpp:60
CriteriaProgressMap m_criteriaProgress
Definition: AchievementMgr.h:358
ObjectGuid Owner
Definition: AchievementPackets.h:32
uint32 TimeFromStart
Definition: AchievementPackets.h:44
Definition: DB2Structure.h:27
uint64 Quantity
Definition: AchievementPackets.h:40
Definition: DBCEnums.h:100
time_t Date
Definition: AchievementPackets.h:31
Definition: AchievementMgr.cpp:1853
std::vector< EarnedAchievement > Earned
Definition: AchievementPackets.h:50
uint32 Id
Definition: AchievementPackets.h:39
uint32 VirtualRealmAddress
Definition: AchievementPackets.h:33
uint32 Id
Definition: AchievementPackets.h:30
uint32 GetVirtualRealmAddress()
Definition: World.cpp:3487
T * GetOwner() const
Definition: AchievementMgr.h:333
ObjectGuid Player
Definition: AchievementPackets.h:41
uint32 NativeRealmAddress
Definition: AchievementPackets.h:34

+ Here is the call graph for this function:

template<class T >
void AchievementMgr< T >::SendAllAchievementData ( Player receiver) const
1866 {
1867  VisibleAchievementCheck filterInvisible;
1869  achievementData.Data.Earned.reserve(m_completedAchievements.size());
1870  achievementData.Data.Progress.reserve(m_criteriaProgress.size());
1871 
1872  for (auto itr = m_completedAchievements.begin(); itr != m_completedAchievements.end(); ++itr)
1873  {
1874  AchievementEntry const* achievement = filterInvisible(*itr);
1875  if (!achievement)
1876  continue;
1877 
1879  earned.Id = itr->first;
1880  earned.Date = itr->second.date;
1881  if (!(achievement->Flags & ACHIEVEMENT_FLAG_ACCOUNT))
1882  {
1883  earned.Owner = GetOwner()->GetGUID();
1885  }
1886  achievementData.Data.Earned.push_back(earned);
1887  }
1888 
1889  for (auto itr = m_criteriaProgress.begin(); itr != m_criteriaProgress.end(); ++itr)
1890  {
1892  progress.Id = itr->first;
1893  progress.Quantity = itr->second.counter;
1894  progress.Player = itr->second.PlayerGUID;
1895  progress.Flags = 0;
1896  progress.Date = itr->second.date;
1897  progress.TimeFromStart = 0;
1898  progress.TimeFromCreate = 0;
1899  achievementData.Data.Progress.push_back(progress);
1900  }
1901 
1902  SendPacket(achievementData.Write());
1903 }
uint32 TimeFromCreate
Definition: AchievementPackets.h:45
CompletedAchievementMap m_completedAchievements
Definition: AchievementMgr.h:359
WorldPacket const * Write() override
Definition: AchievementPackets.cpp:53
uint32 Flags
Definition: DB2Structure.h:38
Definition: AchievementPackets.h:37
Definition: AchievementPackets.h:28
uint32 Flags
Definition: AchievementPackets.h:42
std::vector< CriteriaProgress > Progress
Definition: AchievementPackets.h:51
time_t Date
Definition: AchievementPackets.h:43
CriteriaProgressMap m_criteriaProgress
Definition: AchievementMgr.h:358
AllAchievements Data
Definition: AchievementPackets.h:61
ObjectGuid Owner
Definition: AchievementPackets.h:32
uint32 TimeFromStart
Definition: AchievementPackets.h:44
Definition: DB2Structure.h:27
uint64 Quantity
Definition: AchievementPackets.h:40
Definition: DBCEnums.h:100
time_t Date
Definition: AchievementPackets.h:31
Definition: AchievementMgr.cpp:1853
std::vector< EarnedAchievement > Earned
Definition: AchievementPackets.h:50
uint32 Id
Definition: AchievementPackets.h:39
uint32 VirtualRealmAddress
Definition: AchievementPackets.h:33
void SendPacket(WorldPacket const *data) const
Definition: AchievementMgr.cpp:402
uint32 Id
Definition: AchievementPackets.h:30
uint32 GetVirtualRealmAddress()
Definition: World.cpp:3487
Definition: AchievementPackets.h:54
T * GetOwner() const
Definition: AchievementMgr.h:333
ObjectGuid Player
Definition: AchievementPackets.h:41
uint32 NativeRealmAddress
Definition: AchievementPackets.h:34

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T >
void AchievementMgr< T >::SendAllTrackedCriterias ( Player receiver,
std::set< uint32 > const trackedCriterias 
) const
920 {
921 }

+ Here is the caller graph for this function:

template<class T >
void AchievementMgr< T >::SendCriteriaUpdate ( AchievementCriteria const entry,
CriteriaProgress const progress,
uint32  timeElapsed,
bool  timedCompleted 
) const
private
878 {
879 }
template<>
void AchievementMgr< Player >::SendCriteriaUpdate ( AchievementCriteria const criteria,
CriteriaProgress const progress,
uint32  timeElapsed,
bool  timedCompleted 
) const
private
883 {
885 
886  criteriaUpdate.CriteriaID = criteria->ID;
887  criteriaUpdate.Quantity = progress->counter;
888  criteriaUpdate.PlayerGUID = GetOwner()->GetGUID();
889  if (criteria->Entry->StartTimer)
890  criteriaUpdate.Flags = timedCompleted ? 1 : 0; // 1 is for keeping the counter at 0 in client
891 
892  criteriaUpdate.Flags = 0;
893  criteriaUpdate.CurrentTime = progress->date;
894  criteriaUpdate.ElapsedTime = timeElapsed;
895  criteriaUpdate.CreationTime = 0;
896 
897  SendPacket(criteriaUpdate.Write());
898 }
time_t CurrentTime
Definition: AchievementPackets.h:86
WorldPacket const * Write() override
Definition: AchievementPackets.cpp:68
uint32 CriteriaID
Definition: AchievementPackets.h:82
uint32 ElapsedTime
Definition: AchievementPackets.h:87
uint32 Flags
Definition: AchievementPackets.h:85
uint32 CreationTime
Definition: AchievementPackets.h:88
uint64 Quantity
Definition: AchievementPackets.h:83
Definition: AchievementPackets.h:75
void SendPacket(WorldPacket const *data) const
Definition: AchievementMgr.cpp:402
ObjectGuid PlayerGUID
Definition: AchievementPackets.h:84
T * GetOwner() const
Definition: AchievementMgr.h:333

+ Here is the call graph for this function:

template<class T >
void AchievementMgr< T >::SendPacket ( WorldPacket const data) const
private
402 { }

+ Here is the caller graph for this function:

template<>
void AchievementMgr< Player >::SendPacket ( WorldPacket const data) const
private
412 {
413  GetOwner()->GetSession()->SendPacket(data);
414 }
T * GetOwner() const
Definition: AchievementMgr.h:333
template<class T >
void AchievementMgr< T >::SetCriteriaProgress ( AchievementCriteria const entry,
uint64  changeValue,
Player referencePlayer,
ProgressType  ptype = PROGRESS_SET 
)
private
1553 {
1554  // Don't allow to cheat - doing timed achievements without timer active
1555  AchievementCriteriaTreeList const* trees = nullptr;
1556  if (criteria->Entry->StartTimer)
1557  {
1558  trees = sAchievementMgr->GetAchievementCriteriaTreesByCriteria(criteria->ID);
1559  if (!trees)
1560  return;
1561 
1562  bool hasTreeForTimed = false;
1563  for (AchievementCriteriaTree const* tree : *trees)
1564  {
1565  auto timedIter = m_timedAchievements.find(tree->ID);
1566  if (timedIter != m_timedAchievements.end())
1567  {
1568  hasTreeForTimed = true;
1569  break;
1570  }
1571 
1572  }
1573 
1574  if (!hasTreeForTimed)
1575  return;
1576  }
1577 
1578  TC_LOG_DEBUG("achievement", "SetCriteriaProgress(%u, " UI64FMTD ") for (%s)",
1579  criteria->ID, changeValue, GetOwner()->GetGUID().ToString().c_str());
1580 
1581  CriteriaProgress* progress = GetCriteriaProgress(criteria);
1582  if (!progress)
1583  {
1584  // not create record for 0 counter but allow it for timed achievements
1585  // we will need to send 0 progress to client to start the timer
1586  if (changeValue == 0 && !criteria->Entry->StartTimer)
1587  return;
1588 
1589  progress = &m_criteriaProgress[criteria->ID];
1590  progress->counter = changeValue;
1591  }
1592  else
1593  {
1594  uint64 newValue = 0;
1595  switch (ptype)
1596  {
1597  case PROGRESS_SET:
1598  newValue = changeValue;
1599  break;
1600  case PROGRESS_ACCUMULATE:
1601  {
1602  // avoid overflow
1604  newValue = max_value - progress->counter > changeValue ? progress->counter + changeValue : max_value;
1605  break;
1606  }
1607  case PROGRESS_HIGHEST:
1608  newValue = progress->counter < changeValue ? changeValue : progress->counter;
1609  break;
1610  }
1611 
1612  // not update (not mark as changed) if counter will have same value
1613  if (progress->counter == newValue && !criteria->Entry->StartTimer)
1614  return;
1615 
1616  progress->counter = newValue;
1617  }
1618 
1619  progress->changed = true;
1620  progress->date = time(NULL); // set the date to the latest update.
1621  progress->PlayerGUID = referencePlayer->GetGUID();
1622 
1623  uint32 timeElapsed = 0;
1624 
1625  if (criteria->Entry->StartTimer)
1626  {
1627  ASSERT(trees);
1628 
1629  for (AchievementCriteriaTree const* tree : *trees)
1630  {
1631  auto timedIter = m_timedAchievements.find(tree->ID);
1632  if (timedIter != m_timedAchievements.end())
1633  {
1634  // Client expects this in packet
1635  timeElapsed = criteria->Entry->StartTimer - (timedIter->second / IN_MILLISECONDS);
1636 
1637  // Remove the timer, we wont need it anymore
1638  if (IsCompletedCriteriaTree(tree))
1639  m_timedAchievements.erase(timedIter);
1640  }
1641  }
1642  }
1643 
1644  SendCriteriaUpdate(criteria, progress, timeElapsed, true);
1645 }
TimedAchievementMap m_timedAchievements
Definition: AchievementMgr.h:361
bool changed
Definition: AchievementMgr.h:83
Definition: AchievementMgr.h:62
arena_t NULL
Definition: jemalloc_internal.h:624
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
T max(const T &x, const T &y)
Definition: g3dmath.h:320
CriteriaProgressMap m_criteriaProgress
Definition: AchievementMgr.h:358
Definition: AchievementMgr.h:283
string ToString(int i)
Definition: strutil.h:491
std::vector< AchievementCriteriaTree const * > AchievementCriteriaTreeList
Definition: AchievementMgr.h:72
bool IsCompletedCriteriaTree(AchievementCriteriaTree const *tree)
Definition: AchievementMgr.cpp:1332
#define UI64FMTD
Definition: Define.h:137
Definition: AchievementMgr.h:285
CriteriaProgress * GetCriteriaProgress(AchievementCriteria const *entry)
Definition: AchievementMgr.cpp:1541
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
Definition: AchievementMgr.h:284
Definition: AchievementMgr.h:78
Definition: Common.h:103
#define ASSERT
Definition: Errors.h:55
void SendCriteriaUpdate(AchievementCriteria const *entry, CriteriaProgress const *progress, uint32 timeElapsed, bool timedCompleted) const
Definition: AchievementMgr.cpp:877
uint64 counter
Definition: AchievementMgr.h:80
ObjectGuid PlayerGUID
Definition: AchievementMgr.h:82
T * GetOwner() const
Definition: AchievementMgr.h:333
time_t date
Definition: AchievementMgr.h:81
#define sAchievementMgr
Definition: AchievementMgr.h:501

+ Here is the call graph for this function:

template<class T >
void AchievementMgr< T >::StartTimedAchievement ( AchievementCriteriaTimedTypes  type,
uint32  entry,
uint32  timeLost = 0 
)
1674 {
1675 }
template<>
void AchievementMgr< Player >::StartTimedAchievement ( AchievementCriteriaTimedTypes  type,
uint32  entry,
uint32  timeLost 
)
1679 {
1680  AchievementCriteriaList const& achievementCriteriaList = sAchievementMgr->GetTimedAchievementCriteriaByType(type);
1681  for (AchievementCriteria const* criteria : achievementCriteriaList)
1682  {
1683  if (criteria->Entry->StartAsset != entry)
1684  continue;
1685 
1686  AchievementCriteriaTreeList const* trees = sAchievementMgr->GetAchievementCriteriaTreesByCriteria(criteria->ID);
1687  bool canStart = false;
1688  for (AchievementCriteriaTree const* tree : *trees)
1689  {
1690  if (m_timedAchievements.find(tree->ID) == m_timedAchievements.end() && !IsCompletedCriteriaTree(tree))
1691  {
1692  // Start the timer
1693  if (criteria->Entry->StartTimer * IN_MILLISECONDS > timeLost)
1694  {
1695  m_timedAchievements[tree->ID] = criteria->Entry->StartTimer * IN_MILLISECONDS - timeLost;
1696  canStart = true;
1697  }
1698  }
1699  }
1700 
1701  if (!canStart)
1702  continue;
1703 
1704  // and at client too
1705  SetCriteriaProgress(criteria, 0, GetOwner(), PROGRESS_SET);
1706  }
1707 }
TimedAchievementMap m_timedAchievements
Definition: AchievementMgr.h:361
void SetCriteriaProgress(AchievementCriteria const *entry, uint64 changeValue, Player *referencePlayer, ProgressType ptype=PROGRESS_SET)
Definition: AchievementMgr.cpp:1552
Definition: AchievementMgr.h:62
Definition: AchievementMgr.h:283
std::vector< AchievementCriteriaTree const * > AchievementCriteriaTreeList
Definition: AchievementMgr.h:72
bool IsCompletedCriteriaTree(AchievementCriteriaTree const *tree)
Definition: AchievementMgr.cpp:1332
Definition: Common.h:103
std::vector< AchievementCriteria const * > AchievementCriteriaList
Definition: AchievementMgr.h:59
T * GetOwner() const
Definition: AchievementMgr.h:333
Definition: AchievementMgr.h:51
#define sAchievementMgr
Definition: AchievementMgr.h:501
template<class T >
void AchievementMgr< T >::UpdateAchievementCriteria ( AchievementCriteriaTypes  type,
uint64  miscValue1 = 0,
uint64  miscValue2 = 0,
uint64  miscValue3 = 0,
Unit const unit = NULL,
Player referencePlayer = NULL 
)

this function will be called whenever the user might have done a criteria relevant action

970 {
972  {
973  TC_LOG_DEBUG("achievement", "UpdateAchievementCriteria: Wrong criteria type %u", type);
974  return;
975  }
976 
977  if (!referencePlayer)
978  {
979  TC_LOG_DEBUG("achievement", "UpdateAchievementCriteria: Player is NULL! Cant update criteria");
980  return;
981  }
982 
983  // disable for gamemasters with GM-mode enabled
984  if (referencePlayer->IsGameMaster())
985  {
986  TC_LOG_DEBUG("achievement", "UpdateAchievementCriteria: [Player %s GM mode on] %s, %s (%u), " UI64FMTD ", " UI64FMTD ", " UI64FMTD
987  , referencePlayer->GetName().c_str(), GetOwner()->GetGUID().ToString().c_str(), AchievementGlobalMgr::GetCriteriaTypeString(type), type, miscValue1, miscValue2, miscValue3);
988  return;
989  }
990 
991  TC_LOG_DEBUG("achievement", "UpdateAchievementCriteria: %s, %s (%u), " UI64FMTD ", " UI64FMTD ", " UI64FMTD
992  , GetOwner()->GetGUID().ToString().c_str(), AchievementGlobalMgr::GetCriteriaTypeString(type), type, miscValue1, miscValue2, miscValue3);
993 
994  // Lua_GetGuildLevelEnabled() is checked in achievement UI to display guild tab
995  //if (IsGuild<T>() && !sWorld->getBoolConfig(CONFIG_GUILD_LEVELING_ENABLED))
996  // return;
997 
998  AchievementCriteriaList const& achievementCriteriaList = sAchievementMgr->GetAchievementCriteriaByType(type, IsGuild<T>());
999  for (AchievementCriteria const* achievementCriteria : achievementCriteriaList)
1000  {
1001  AchievementCriteriaTreeList const* trees = sAchievementMgr->GetAchievementCriteriaTreesByCriteria(achievementCriteria->ID);
1002 
1003  if (!CanUpdateCriteria(achievementCriteria, trees, miscValue1, miscValue2, miscValue3, unit, referencePlayer))
1004  continue;
1005 
1006  // requirements not found in the dbc
1007  if (AchievementCriteriaDataSet const* data = sAchievementMgr->GetCriteriaDataSet(achievementCriteria))
1008  if (!data->Meets(referencePlayer, unit, miscValue1))
1009  continue;
1010 
1011  switch (type)
1012  {
1013  // std. case: increment at 1
1017  case ACHIEVEMENT_CRITERIA_TYPE_WON_AUCTIONS: /* FIXME: for online player only currently */
1051  case ACHIEVEMENT_CRITERIA_TYPE_WIN_ARENA: // This also behaves like ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA
1055  SetCriteriaProgress(achievementCriteria, 1, referencePlayer, PROGRESS_ACCUMULATE);
1056  break;
1057  // std case: increment at miscValue1
1065  case ACHIEVEMENT_CRITERIA_TYPE_GOLD_EARNED_BY_AUCTIONS:/* FIXME: for online player only currently */
1073  SetCriteriaProgress(achievementCriteria, miscValue1, referencePlayer, PROGRESS_ACCUMULATE);
1074  break;
1081  SetCriteriaProgress(achievementCriteria, miscValue2, referencePlayer, PROGRESS_ACCUMULATE);
1082  break;
1083  // std case: high value at miscValue1
1085  case ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_SOLD: /* FIXME: for online player only currently */
1090  SetCriteriaProgress(achievementCriteria, miscValue1, referencePlayer, PROGRESS_HIGHEST);
1091  break;
1093  SetCriteriaProgress(achievementCriteria, referencePlayer->getLevel(), referencePlayer);
1094  break;
1096  if (uint32 skillvalue = referencePlayer->GetBaseSkillValue(achievementCriteria->Entry->Asset.SkillID))
1097  SetCriteriaProgress(achievementCriteria, skillvalue, referencePlayer);
1098  break;
1100  if (uint32 maxSkillvalue = referencePlayer->GetPureMaxSkillValue(achievementCriteria->Entry->Asset.SkillID))
1101  SetCriteriaProgress(achievementCriteria, maxSkillvalue, referencePlayer);
1102  break;
1104  SetCriteriaProgress(achievementCriteria, referencePlayer->GetRewardedQuestCount(), referencePlayer);
1105  break;
1107  {
1108  time_t nextDailyResetTime = sWorld->GetNextDailyQuestsResetTime();
1109  CriteriaProgress *progress = GetCriteriaProgress(achievementCriteria);
1110 
1111  if (!miscValue1) // Login case.
1112  {
1113  // reset if player missed one day.
1114  if (progress && progress->date < (nextDailyResetTime - 2 * DAY))
1115  SetCriteriaProgress(achievementCriteria, 0, referencePlayer, PROGRESS_SET);
1116  continue;
1117  }
1118 
1119  ProgressType progressType;
1120  if (!progress)
1121  // 1st time. Start count.
1122  progressType = PROGRESS_SET;
1123  else if (progress->date < (nextDailyResetTime - 2 * DAY))
1124  // last progress is older than 2 days. Player missed 1 day => Restart count.
1125  progressType = PROGRESS_SET;
1126  else if (progress->date < (nextDailyResetTime - DAY))
1127  // last progress is between 1 and 2 days. => 1st time of the day.
1128  progressType = PROGRESS_ACCUMULATE;
1129  else
1130  // last progress is within the day before the reset => Already counted today.
1131  continue;
1132 
1133  SetCriteriaProgress(achievementCriteria, 1, referencePlayer, progressType);
1134  break;
1135  }
1137  {
1138  uint32 counter = 0;
1139 
1140  const RewardedQuestSet &rewQuests = referencePlayer->getRewardedQuests();
1141  for (RewardedQuestSet::const_iterator itr = rewQuests.begin(); itr != rewQuests.end(); ++itr)
1142  {
1143  Quest const* quest = sObjectMgr->GetQuestTemplate(*itr);
1144  if (quest && quest->GetZoneOrSort() >= 0 && uint32(quest->GetZoneOrSort()) == achievementCriteria->Entry->Asset.ZoneID)
1145  ++counter;
1146  }
1147  SetCriteriaProgress(achievementCriteria, counter, referencePlayer);
1148  break;
1149  }
1151  // miscValue1 is the ingame fallheight*100 as stored in dbc
1152  SetCriteriaProgress(achievementCriteria, miscValue1, referencePlayer);
1153  break;
1163  SetCriteriaProgress(achievementCriteria, 1, referencePlayer);
1164  break;
1166  SetCriteriaProgress(achievementCriteria, referencePlayer->GetBankBagSlotCount(), referencePlayer);
1167  break;
1169  {
1170  int32 reputation = referencePlayer->GetReputationMgr().GetReputation(achievementCriteria->Entry->Asset.FactionID);
1171  if (reputation > 0)
1172  SetCriteriaProgress(achievementCriteria, reputation, referencePlayer);
1173  break;
1174  }
1176  SetCriteriaProgress(achievementCriteria, referencePlayer->GetReputationMgr().GetExaltedFactionCount(), referencePlayer);
1177  break;
1180  {
1181  uint32 spellCount = 0;
1182  for (PlayerSpellMap::const_iterator spellIter = referencePlayer->GetSpellMap().begin();
1183  spellIter != referencePlayer->GetSpellMap().end();
1184  ++spellIter)
1185  {
1186  SkillLineAbilityMapBounds bounds = sSpellMgr->GetSkillLineAbilityMapBounds(spellIter->first);
1187  for (SkillLineAbilityMap::const_iterator skillIter = bounds.first; skillIter != bounds.second; ++skillIter)
1188  {
1189  if (skillIter->second->SkillLine == achievementCriteria->Entry->Asset.SkillID)
1190  spellCount++;
1191  }
1192  }
1193  SetCriteriaProgress(achievementCriteria, spellCount, referencePlayer);
1194  break;
1195  }
1197  SetCriteriaProgress(achievementCriteria, referencePlayer->GetReputationMgr().GetReveredFactionCount(), referencePlayer);
1198  break;
1200  SetCriteriaProgress(achievementCriteria, referencePlayer->GetReputationMgr().GetHonoredFactionCount(), referencePlayer);
1201  break;
1203  SetCriteriaProgress(achievementCriteria, referencePlayer->GetReputationMgr().GetVisibleFactionCount(), referencePlayer);
1204  break;
1206  SetCriteriaProgress(achievementCriteria, referencePlayer->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS), referencePlayer);
1207  break;
1209  SetCriteriaProgress(achievementCriteria, referencePlayer->GetMoney(), referencePlayer, PROGRESS_HIGHEST);
1210  break;
1212  if (!miscValue1)
1213  SetCriteriaProgress(achievementCriteria, _achievementPoints, referencePlayer, PROGRESS_SET);
1214  else
1215  SetCriteriaProgress(achievementCriteria, miscValue1, referencePlayer, PROGRESS_ACCUMULATE);
1216  break;
1218  {
1219  uint32 reqTeamType = achievementCriteria->Entry->Asset.TeamType;
1220 
1221  if (miscValue1)
1222  {
1223  if (miscValue2 != reqTeamType)
1224  continue;
1225 
1226  SetCriteriaProgress(achievementCriteria, miscValue1, referencePlayer, PROGRESS_HIGHEST);
1227  }
1228  else // login case
1229  {
1230  for (uint32 arena_slot = 0; arena_slot < MAX_ARENA_SLOT; ++arena_slot)
1231  {
1232  uint32 teamId = referencePlayer->GetArenaTeamId(arena_slot);
1233  if (!teamId)
1234  continue;
1235 
1236  ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(teamId);
1237  if (!team || team->GetType() != reqTeamType)
1238  continue;
1239 
1240  if (ArenaTeamMember const* member = team->GetMember(referencePlayer->GetGUID()))
1241  {
1242  SetCriteriaProgress(achievementCriteria, member->PersonalRating, referencePlayer, PROGRESS_HIGHEST);
1243  break;
1244  }
1245  }
1246  }
1247  break;
1248  }
1250  SetCriteriaProgress(achievementCriteria, miscValue1, referencePlayer);
1251  break;
1252  // FIXME: not triggered in code as result, need to implement
1301  break; // Not implemented yet :(
1302  }
1303 
1304  for (AchievementCriteriaTree const* tree : *trees)
1305  {
1306  if (IsCompletedCriteriaTree(tree))
1307  CompletedCriteriaFor(tree->Achievement, referencePlayer);
1308 
1309  // check again the completeness for SUMM and REQ COUNT achievements,
1310  // as they don't depend on the completed criteria but on the sum of the progress of each individual criteria
1311  if (tree->Achievement->Flags & ACHIEVEMENT_FLAG_SUMM)
1312  if (IsCompletedAchievement(tree->Achievement))
1313  CompletedAchievement(tree->Achievement, referencePlayer);
1314 
1315  if (AchievementEntryList const* achRefList = sAchievementMgr->GetAchievementByReferencedId(tree->Achievement->ID))
1316  for (AchievementEntry const* refAchievement : *achRefList)
1317  if (IsCompletedAchievement(refAchievement))
1318  CompletedAchievement(refAchievement, referencePlayer);
1319  }
1320  }
1321 }
Definition: DBCEnums.h:207
Definition: DBCEnums.h:265
Definition: DBCEnums.h:236
Definition: QuestDef.h:279
Definition: DBCEnums.h:234
#define ACHIEVEMENT_CRITERIA_TYPE_TOTAL
Definition: DBCEnums.h:360
Definition: DBCEnums.h:221
Definition: DBCEnums.h:208
uint32 GetType() const
Definition: ArenaTeam.h:125
int32 GetZoneOrSort() const
Definition: QuestDef.h:307
void SetCriteriaProgress(AchievementCriteria const *entry, uint64 changeValue, Player *referencePlayer, ProgressType ptype=PROGRESS_SET)
Definition: AchievementMgr.cpp:1552
void CompletedAchievement(AchievementEntry const *entry, Player *referencePlayer)
Definition: DBCEnums.h:263
Definition: AchievementMgr.h:62
Definition: DBCEnums.h:199
Definition: DBCEnums.h:271
Definition: DBCEnums.h:198
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
#define sWorld
Definition: World.h:887
static char const * GetCriteriaTypeString(AchievementCriteriaTypes type)
Definition: AchievementMgr.cpp:2589
uint32 _achievementPoints
Definition: AchievementMgr.h:362
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: DBCEnums.h:249
Definition: AchievementMgr.h:237
Definition: DBCEnums.h:224
Definition: DBCEnums.h:235
Definition: DBCEnums.h:212
Definition: DBCEnums.h:246
std::pair< SkillLineAbilityMap::const_iterator, SkillLineAbilityMap::const_iterator > SkillLineAbilityMapBounds
Definition: SpellMgr.h:549
void CompletedCriteriaFor(AchievementEntry const *achievement, Player *referencePlayer)
Definition: AchievementMgr.cpp:1498
Definition: AchievementMgr.h:283
Definition: DBCEnums.h:237
Definition: DBCEnums.h:354
string ToString(int i)
Definition: strutil.h:491
std::vector< AchievementCriteriaTree const * > AchievementCriteriaTreeList
Definition: AchievementMgr.h:72
bool IsCompletedCriteriaTree(AchievementCriteriaTree const *tree)
Definition: AchievementMgr.cpp:1332
Definition: DB2Structure.h:27
bool CanUpdateCriteria(AchievementCriteria const *criteria, AchievementCriteriaTreeList const *trees, uint64 miscValue1, uint64 miscValue2, uint64 miscValue3, Unit const *unit, Player *referencePlayer)
Definition: AchievementMgr.cpp:2010
Definition: DBCEnums.h:244
Definition: DBCEnums.h:218
Definition: Common.h:99
#define UI64FMTD
Definition: Define.h:137
Definition: DBCEnums.h:357
Definition: AchievementMgr.h:285
#define sSpellMgr
Definition: SpellMgr.h:756
Definition: DBCEnums.h:279
CriteriaProgress * GetCriteriaProgress(AchievementCriteria const *entry)
Definition: AchievementMgr.cpp:1541
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
Definition: DBCEnums.h:245
Definition: DBCEnums.h:266
Definition: AchievementMgr.h:284
Definition: DBCEnums.h:86
Definition: UpdateFields.h:273
Definition: DBCEnums.h:316
Definition: AchievementMgr.h:78
Definition: DBCEnums.h:233
ArenaTeamMember * GetMember(ObjectGuid guid)
Definition: ArenaTeam.cpp:800
Definition: DBCEnums.h:201
Definition: DBCEnums.h:247
Definition: ArenaTeam.h:112
ProgressType
Definition: AchievementMgr.h:281
Definition: DBCEnums.h:257
std::vector< AchievementEntry const * > AchievementEntryList
Definition: AchievementMgr.h:73
Definition: DBCEnums.h:355
std::vector< AchievementCriteria const * > AchievementCriteriaList
Definition: AchievementMgr.h:59
Definition: DBCEnums.h:226
Definition: DBCEnums.h:280
Definition: DBCEnums.h:290
Definition: DBCEnums.h:333
bool IsCompletedAchievement(AchievementEntry const *entry)
Definition: AchievementMgr.cpp:1513
#define sArenaTeamMgr
Definition: ArenaTeamMgr.h:53
Definition: DBCEnums.h:289
uint32_t uint32
Definition: g3dmath.h:168
Definition: DBCEnums.h:228
Definition: DBCEnums.h:334
T * GetOwner() const
Definition: AchievementMgr.h:333
Definition: AchievementMgr.h:51
time_t date
Definition: AchievementMgr.h:81
#define sAchievementMgr
Definition: AchievementMgr.h:501
Definition: DBCEnums.h:211
Definition: DBCEnums.h:225
Definition: DBCEnums.h:214
#define MAX_ARENA_SLOT
Definition: ArenaTeam.h:110
Definition: ArenaTeam.h:84

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<class T >
void AchievementMgr< T >::UpdateTimedAchievements ( uint32  timeDiff)
1649 {
1650  if (!m_timedAchievements.empty())
1651  {
1652  for (TimedAchievementMap::iterator itr = m_timedAchievements.begin(); itr != m_timedAchievements.end();)
1653  {
1654  // Time is up, remove timer and reset progress
1655  if (itr->second <= timeDiff)
1656  {
1657  AchievementCriteriaTree const* criteriaTree = sAchievementMgr->GetAchievementCriteriaTree(itr->first);
1658  if (criteriaTree->Criteria)
1659  RemoveCriteriaProgress(criteriaTree->Criteria);
1660 
1661  m_timedAchievements.erase(itr++);
1662  }
1663  else
1664  {
1665  itr->second -= timeDiff;
1666  ++itr;
1667  }
1668  }
1669  }
1670 }
TimedAchievementMap m_timedAchievements
Definition: AchievementMgr.h:361
AchievementCriteria const * Criteria
Definition: AchievementMgr.h:67
Definition: AchievementMgr.h:62
void RemoveCriteriaProgress(AchievementCriteria const *entry)
Definition: AchievementMgr.cpp:417
#define sAchievementMgr
Definition: AchievementMgr.h:501

Member Data Documentation

template<class T>
uint32 AchievementMgr< T >::_achievementPoints
private
template<class T>
T* AchievementMgr< T >::_owner
private
template<class T>
CompletedAchievementMap AchievementMgr< T >::m_completedAchievements
private
template<class T>
CriteriaProgressMap AchievementMgr< T >::m_criteriaProgress
private
template<class T>
TimedAchievementMap AchievementMgr< T >::m_timedAchievements
private

The documentation for this singleton was generated from the following files: