2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #ifndef __MANGOS_ACHIEVEMENTMGR_H
19 #define __MANGOS_ACHIEVEMENTMGR_H
22 #include "Policies/Singleton.h"
23 #include "Database/DBCEnums.h"
24 #include "Database/DBCStores.h"
25 #include "Database/DatabaseEnv.h"
30 #define CRITERIA_CAST_SPELL_REQ_COUNT 46
31 #define ACHIEVEMENT_REWARD_COUNT 57
33 typedef std::list
<const AchievementCriteriaEntry
*> AchievementCriteriaEntryList
;
35 struct CriteriaProgress
42 struct CriteriaCastSpellRequirement
44 uint32 achievementCriteriaId
;
50 struct AchievementReward
59 typedef std::map
<uint32
,AchievementReward
> AchievementRewards
;
61 struct AchievementRewardLocale
63 std::vector
<std::string
> subject
;
64 std::vector
<std::string
> text
;
67 typedef std::map
<uint32
,AchievementRewardLocale
> AchievementRewardLocales
;
70 struct CompletedAchievementData
76 typedef UNORDERED_MAP
<uint32
, CriteriaProgress
> CriteriaProgressMap
;
77 typedef UNORDERED_MAP
<uint32
, CompletedAchievementData
> CompletedAchievementMap
;
83 enum AchievementCompletionState
85 ACHIEVEMENT_COMPLETED_NONE
,
86 ACHIEVEMENT_COMPLETED_COMPLETED_NOT_STORED
,
87 ACHIEVEMENT_COMPLETED_COMPLETED_STORED
,
93 AchievementMgr(Player
* pl
);
96 void LoadFromDB(QueryResult
*achievementResult
, QueryResult
*criteriaResult
);
98 void UpdateAchievementCriteria(AchievementCriteriaTypes type
, uint32 miscvalue1
=0, uint32 miscvalue2
=0, Unit
*unit
=NULL
, uint32 time
=0);
99 void CheckAllAchievementCriteria();
100 void SendAllAchievementData();
101 void SendRespondInspectAchievements(Player
* player
);
102 Player
* GetPlayer() { return m_player
;}
105 void SendAchievementEarned(AchievementEntry
const* achievement
);
106 void SendCriteriaUpdate(uint32 id
, CriteriaProgress
const* progress
);
107 void SetCriteriaProgress(AchievementCriteriaEntry
const* entry
, uint32 newValue
, bool relative
=false);
108 void CompletedCriteria(AchievementCriteriaEntry
const* entry
);
109 void CompletedAchievement(AchievementEntry
const* entry
);
110 bool IsCompletedCriteria(AchievementCriteriaEntry
const* entry
);
111 AchievementCompletionState
GetAchievementCompletionState(AchievementEntry
const* entry
);
112 void BuildAllDataPacket(WorldPacket
*data
);
115 CriteriaProgressMap m_criteriaProgress
;
116 CompletedAchievementMap m_completedAchievements
;
119 class AchievementGlobalMgr
122 AchievementCriteriaEntryList
const& GetAchievementCriteriaByType(AchievementCriteriaTypes type
);
124 AchievementReward
const* GetAchievementReward(AchievementEntry
const* achievement
) const
126 AchievementRewards::const_iterator iter
= m_achievementRewards
.find(achievement
->ID
);
127 return iter
!=m_achievementRewards
.end() ? &iter
->second
: NULL
;
130 AchievementRewardLocale
const* GetAchievementRewardLocale(AchievementEntry
const* achievement
) const
132 AchievementRewardLocales::const_iterator iter
= m_achievementRewardLocales
.find(achievement
->ID
);
133 return iter
!=m_achievementRewardLocales
.end() ? &iter
->second
: NULL
;
136 static CriteriaCastSpellRequirement
const * GetCriteriaCastSpellRequirement(AchievementCriteriaEntry
const *achievementCriteria
)
138 for (uint32 i
=0; i
< CRITERIA_CAST_SPELL_REQ_COUNT
; ++i
)
139 if (m_criteriaCastSpellRequirements
[i
].achievementCriteriaId
== achievementCriteria
->ID
)
140 return &m_criteriaCastSpellRequirements
[i
];
145 bool IsRealmCompleted(AchievementEntry
const* achievement
) const
147 return m_allCompletedAchievements
.find(achievement
->ID
) != m_allCompletedAchievements
.end();
150 void SetRealmCompleted(AchievementEntry
const* achievement
)
152 m_allCompletedAchievements
.insert(achievement
->ID
);
155 void LoadAchievementCriteriaList();
156 void LoadCompletedAchievements();
158 void LoadRewardLocales();
160 static const CriteriaCastSpellRequirement m_criteriaCastSpellRequirements
[];
162 // store achievement criterias by type to speed up lookup
163 AchievementCriteriaEntryList m_AchievementCriteriasByType
[ACHIEVEMENT_CRITERIA_TYPE_TOTAL
];
165 typedef std::set
<uint32
> AllCompletedAchievements
;
166 AllCompletedAchievements m_allCompletedAchievements
;
168 AchievementRewards m_achievementRewards
;
169 AchievementRewardLocales m_achievementRewardLocales
;
172 #define achievementmgr MaNGOS::Singleton<AchievementGlobalMgr>::Instance()