1 QuestHelper_File
["collect_achievement.lua"] = "Development Version"
3 local Collect_Achievement
= {}
5 --X 0 is a monster kill, asset is the monster ID
6 --X 1 is winning PvP objectives in a thorough manner (holding all bases, controlling all flags)
7 --X 7 is weapon skill, asset is probably a skill ID of some sort
8 --X 8 is another achievement, asset is achievement ID
9 --X 9 is completing quests globally
10 --X 10 is completing a daily quest every day
11 --X 11 is completing quests in specific areas
12 --X 14 is completing daily quests
13 --X 27 is a quest, asset is quest ID
14 --X 28 is getting a spell cast on you, asset is a spell ID
15 --X 29 is casting a spell (often crafting), asset is a spell ID
16 --X 30 is PvP objectives (flags, assaulting, defending)
17 --X 31 is PvP kills in battleground PvP locations
18 --X 32 is winning ranked arena matches in specific locations (asset is probably a location ID)
19 --X 34 is the Squashling (owning a specific pet?), asset is the spell ID
20 --X 35 is PvP kills while under the influence of something
21 --X 36 is acquiring items (soulbound), asset is an item ID
22 --X 37 is winning arenas
23 --X 41 is eating or drinking a specific item, asset is item ID
24 --X 42 is fishing things up, asset is item ID
25 --X 43 is exploration, asset is a location ID?
26 --X 45 is purchasing 7 bank slots
27 --X 46 is exalted rep, asset is presumably some kind of faction ID
28 --X 47 is 5 reputations to exalted
29 --X 49 is equipping items, asset is a slot ID (quality is presumably encoded into flags)
30 --X 52 is killing specific classes of player
31 --X 53 is kill-a-given-race, asset is race ID?
32 -- 54 is using emotes on targets, asset ID is likely the emote ID
33 --X 56 is being a wrecking ball in Alterac Valley
34 --X 62 is getting gold from quest rewards
35 --X 67 is looting gold
36 -- 68 is reading books
37 -- 70 is killing players in world PvP locations
38 -- 72 is fishing things from schools or wreckage
39 --X 73 is killing Mal'Ganis on Heroic. Why? Who can say.
40 --X 75 is obtaining mounts
41 -- 109 is fishing, either in general or in specific locations
42 -- 110 is casting spells on specific targets, asset ID is the spell ID
43 --X 112 is learning cooking recipes
44 --X 113 is honorable kills
45 local achievement_type_blacklist
= {}
46 for _
, v
in pairs({0, 1, 7, 8, 9, 10, 11, 14, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 41, 42, 43, 45, 46, 47, 49, 52, 53, 56, 62, 67, 73, 75, 112, 113}) do
47 achievement_type_blacklist
[v
] = true
50 local achievement_list
= {}
52 --local crittypes = {}
53 --QuestHelper_ZorbaForgotToRemoveThis = {}
55 local function registerAchievement(id
)
56 --if db.achievements[id] then return end
58 local _
, title
, _
, complete
= GetAchievementInfo(id
)
59 --QuestHelper:TextOut(string.format("Registering %d (%s)", id, title))
60 local prev
= GetPreviousAchievement(id
)
64 db.achievements[id] = {
70 local dbi = db.achievements[id]
74 registerAchievement(prev
)
77 local critcount
= GetAchievementNumCriteria(id
)
78 if critcount
== 0 then record
= true end
80 for i
= 1, critcount
do
81 local crit_name
, crit_type
, crit_complete
, crit_quantity
, crit_reqquantity
, _
, _
, crit_asset
, _
, crit_id
= GetAchievementCriteriaInfo(id
, i
)
83 --if not QuestHelper_ZorbaForgotToRemoveThis[string.format("%d", crit_type)] then QuestHelper_ZorbaForgotToRemoveThis[string.format("%d", crit_type)] = {} end
84 --QuestHelper_ZorbaForgotToRemoveThis[string.format("%d", crit_type)][title .. " --- " .. mega[1]] = crit_asset
87 table.insert(dbi.criterialist, crit_id)
88 ass ert (not db.criteria[crit_id])
89 crittypes[crit_type] = (crittypes[crit_type] or 0) + 1]]
91 if not achievement_type_blacklist
[crit_type
] then record
= true end
94 db.criteria[crit_id] = {
97 complete = crit_complete,
98 progress = crit_quantity,
99 progress_total = crit_reqquantity,
104 if record
then achievement_list
[id
] = true end
107 function createAchievementList()
108 for _
, catid
in pairs(GetCategoryList()) do
109 for d
= 1, GetCategoryNumAchievements(catid
) do
110 registerAchievement(GetAchievementInfo(catid
, d
), db
)
115 local achievement_stop_time
= 0
117 local function retrieveAchievement(id
, db
)
120 local _
, _
, _
, complete
= GetAchievementInfo(id
)
121 --QuestHelper:TextOut(string.format("Registering %d (%s)", id, title))
123 db
.achievements
[id
] = QuestHelper
:CreateTable("collect_achievement achievement")
124 db
.achievements
[id
].complete
= complete
126 local dbi
= db
.achievements
[id
]
128 local critcount
= GetAchievementNumCriteria(id
)
130 --QuestHelper:TextOut(string.format("%d criteria", crit))
131 for i
= 1, critcount
do
132 local _
, _
, crit_complete
, crit_quantity
, crit_reqquantity
, _
, _
, _
, _
, crit_id
= GetAchievementCriteriaInfo(id
, i
)
134 db
.criteria
[crit_id
] = QuestHelper
:CreateTable("collect_achievement criteria")
135 db
.criteria
[crit_id
].complete
= crit_complete
136 db
.criteria
[crit_id
].progress
= crit_quantity
140 local function getAchievementDB()
145 for k
in pairs(achievement_list
) do
146 retrieveAchievement(k
, db
)
152 local updating
= false
154 local function ScanAchievements()
155 local newADB
= getAchievementDB()
156 local oldADB
= Collect_Achievement
.AchievementDB
158 for k
, v
in pairs(newADB
.achievements
) do
159 if v
.complete
~= oldADB
.achievements
[k
].complete
then
160 assert(v
.complete
and not oldADB
.achievements
[k
].complete
)
161 --QuestHelper:TextOut(string.format("Achievement complete, %s", select(2, GetAchievementInfo(k))))
165 for k
, v
in pairs(newADB
.criteria
) do
166 if v
.complete
~= oldADB
.criteria
[k
].complete
then
167 assert(v
.complete
and not oldADB
.criteria
[k
].complete
)
168 --QuestHelper:TextOut(string.format("Criteria complete, %d", k))
169 --QuestHelper:TextOut(string.format("Criteria complete, %s", select(1, GetAchievementCriteriaInfo(k))))
170 elseif v
.progress
> oldADB
.criteria
[k
].progress
then
171 --QuestHelper:TextOut(string.format("Criteria progress, %d", k))
172 --QuestHelper:TextOut(string.format("Criteria progress, %s", select(1, GetAchievementCriteriaInfo(k))))
176 Collect_Achievement
.AchievementDB
= newADB
178 for k
, v
in pairs(oldADB
.achievements
) do QuestHelper
:ReleaseTable(v
) end
179 for k
, v
in pairs(oldADB
.criteria
) do QuestHelper
:ReleaseTable(v
) end
181 updating
= false -- This prevents error spam.
184 local function OnEvent()
185 if not updating
and Collect_Achievement
.AchievementDB
then
186 QH_Timeslice_Add(ScanAchievements
, "criteria")
191 function QH_Collect_Achievement_Init(_
, API
)
192 createAchievementList()
193 Collect_Achievement
.AchievementDB
= getAchievementDB() -- 'coz we're lazy
195 API
.Registrar_EventHook("CRITERIA_UPDATE", OnEvent
)
196 API
.Registrar_EventHook("ACHIEVEMENT_EARNED", OnEvent
)
198 OnEvent() -- kick it into its first update cycle