grumble
[QuestHelper.git] / manager_achievement.lua
blob5b5c75914686a2a6c96a8691dce6ef09bac9a743
1 QuestHelper_File["manager_achievement.lua"] = "Development Version"
2 QuestHelper_Loadtime["manager_achievement.lua"] = GetTime()
4 local AchievementDB
6 --X 0 is a monster kill, asset is the monster ID
7 --X 1 is winning PvP objectives in a thorough manner (holding all bases, controlling all flags)
8 --X 7 is weapon skill, asset is probably a skill ID of some sort
9 --X 8 is another achievement, asset is achievement ID
10 --X 9 is completing quests globally
11 --X 10 is completing a daily quest every day
12 --X 11 is completing quests in specific areas
13 --X 14 is completing daily quests
14 --X 27 is a quest, asset is quest ID
15 --X 28 is getting a spell cast on you, asset is a spell ID
16 --X 29 is casting a spell (often crafting), asset is a spell ID
17 --X 30 is PvP objectives (flags, assaulting, defending)
18 --X 31 is PvP kills in battleground PvP locations
19 --X 32 is winning ranked arena matches in specific locations (asset is probably a location ID)
20 --X 34 is the Squashling (owning a specific pet?), asset is the spell ID
21 --X 35 is PvP kills while under the influence of something
22 --X 36 is acquiring items (soulbound), asset is an item ID
23 --X 37 is winning arenas
24 --X 41 is eating or drinking a specific item, asset is item ID
25 --X 42 is fishing things up, asset is item ID
26 --X 43 is exploration, asset is a location ID?
27 --X 45 is purchasing 7 bank slots
28 --X 46 is exalted rep, asset is presumably some kind of faction ID
29 --X 47 is 5 reputations to exalted
30 --X 49 is equipping items, asset is a slot ID (quality is presumably encoded into flags)
31 --X 52 is killing specific classes of player
32 --X 53 is kill-a-given-race, asset is race ID?
33 -- 54 is using emotes on targets, asset ID is likely the emote ID
34 --X 56 is being a wrecking ball in Alterac Valley
35 --X 62 is getting gold from quest rewards
36 --X 67 is looting gold
37 -- 68 is reading books
38 -- 70 is killing players in world PvP locations
39 -- 72 is fishing things from schools or wreckage
40 --X 73 is killing Mal'Ganis on Heroic. Why? Who can say.
41 --X 75 is obtaining mounts
42 -- 109 is fishing, either in general or in specific locations
43 -- 110 is casting spells on specific targets, asset ID is the spell ID
44 --X 112 is learning cooking recipes
45 --X 113 is honorable kills
46 local achievement_type_blacklist = {}
47 for _, v in pairs({0, 1, 7, 8, 9, 10, 11, 14, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 41, 42, 46, 47, 49, 52, 53, 56, 62, 67, 73, 75, 112, 113}) do
48 achievement_type_blacklist[v] = true
49 end
51 local achievement_list = {}
53 --local crittypes = {}
54 --QuestHelper_ZorbaForgotToRemoveThis = {}
56 local qhdinfo = false
57 local qhdinfodump = {}
58 local function qhadumpy()
59 for k, v in pairs(qhdinfodump) do
60 local ct = 0
61 local some
62 for tk, tv in pairs(v) do
63 ct = ct + 1
64 some = tk
65 end
66 QuestHelper:TextOut(string.format("%d: %d, %s", k, ct, some))
67 end
68 end
70 local function registerAchievement(id)
71 --if db.achievements[id] then return end
73 local _, title, _, complete = GetAchievementInfo(id)
74 --QuestHelper:TextOut(string.format("Registering %d (%s)", id, title))
75 local prev = GetPreviousAchievement(id)
76 local record = false
78 --[[
79 db.achievements[id] = {
80 previous = prev,
81 compete = complete,
82 name = title,
83 criterialist = {}
85 local dbi = db.achievements[id]
88 if prev then
89 registerAchievement(prev)
90 end
92 local critcount = GetAchievementNumCriteria(id)
93 if critcount == 0 then record = true end
95 for i = 1, critcount do
96 local crit_name, crit_type, crit_complete, crit_quantity, crit_reqquantity, _, _, crit_asset, _, crit_id = GetAchievementCriteriaInfo(id, i)
98 if qhdinfo and not achievement_type_blacklist[crit_type] then
99 if not qhdinfodump[crit_type] then qhdinfodump[crit_type] = {} end
100 qhdinfodump[crit_type][title .. " --- " .. crit_name] = true
103 --[[
104 table.insert(dbi.criterialist, crit_id)
105 ass ert (not db.criteria[crit_id])
106 crittypes[crit_type] = (crittypes[crit_type] or 0) + 1]]
108 if not achievement_type_blacklist[crit_type] then record = true end
110 --[[
111 db.criteria[crit_id] = {
112 name = crit_name,
113 type = crit_type,
114 complete = crit_complete,
115 progress = crit_quantity,
116 progress_total = crit_reqquantity,
117 asset = crit_asset,
121 if record then achievement_list[id] = true end
124 local function createAchievementList()
125 for _, catid in pairs(GetCategoryList()) do
126 for d = 1, GetCategoryNumAchievements(catid) do
127 registerAchievement(GetAchievementInfo(catid, d), db)
132 local achievement_stop_time = 0
134 local GetAchievementInfo = GetAchievementInfo
135 local GetAchievementNumCriteria = GetAchievementNumCriteria
136 local GetAchievementCriteriaInfo = GetAchievementCriteriaInfo
138 local function retrieveAchievement(id, db)
139 QH_Timeslice_Yield()
141 local _, _, _, complete = GetAchievementInfo(id)
142 --QuestHelper:TextOut(string.format("Registering %d (%s)", id, title))
144 db.achievements[id] = QuestHelper:CreateTable("collect_achievement achievement")
145 db.achievements[id].complete = complete
147 local dbi = db.achievements[id]
149 local critcount = GetAchievementNumCriteria(id)
151 --QuestHelper:TextOut(string.format("%d criteria", crit))
152 for i = 1, critcount do
153 QuestHelper: Assert(not db.criteria[crit_id])
154 local _, _, crit_complete, crit_quantity, crit_reqquantity, _, _, _, _, crit_id = GetAchievementCriteriaInfo(id, i)
156 db.criteria[crit_id] = QuestHelper:CreateTable("collect_achievement criteria")
157 db.criteria[crit_id].complete = crit_complete
158 db.criteria[crit_id].progress = crit_quantity
159 db.criteria[crit_id].parent = id
163 local function getAchievementDB()
164 local db = {}
165 db.achievements = {}
166 db.criteria = {}
168 local ct = 0
169 for k in pairs(achievement_list) do
170 retrieveAchievement(k, db)
171 ct = ct + 1
173 --QuestHelper: TextOut(tostring(ct))
175 return db
179 local registered = {}
180 local prescan = {}
182 function QH_AchievementManagerRegister(funky) -- I am imagining "funky" being said in the same tone of voice that "spicy" is in Puzzle Pirates
183 table.insert(registered, funky)
185 function QH_AchievementManagerRegister_Prescan(funky)
186 table.insert(prescan, funky)
189 local updating = false
190 local updating_continue = false
192 local function ScanAchievements()
193 while updating_continue do
194 updating_continue = false
196 for _, v in ipairs(prescan) do
200 local old = AchievementDB
201 local new = getAchievementDB()
203 for _, v in ipairs(registered) do
204 v(old, new)
207 AchievementDB = new
210 updating = false
213 local function OnEvent()
214 --print("oe", updating, AchievementDB)
215 if not updating and AchievementDB then
216 --print("cutea")
217 QH_Timeslice_Add(ScanAchievements, "criteria")
219 updating = true
220 updating_continue = true
222 --qhaach = OnEvent
224 QH_Event("CRITERIA_UPDATE", OnEvent)
225 QH_Event("ACHIEVEMENT_EARNED", OnEvent)
227 function QH_AchievementManagerRegister_Poke()
228 OnEvent()
231 createAchievementList()
233 local function prod_achievement()
234 OnEvent()
236 function QH_AchievementManager_Init()
237 AchievementDB = getAchievementDB() -- 'coz we're lazy
241 if QuestHelper_File["manager_achievement.lua"] == "Development Version" then
242 -- woop woop woop
243 -- runnin' around like a headless chicken
244 -- collidin' with walls
245 -- fallin' over backwards, waving arms wildly
246 -- little bit of drool
247 -- you know how it goes
249 local the_data
251 local function eatAchievement(id)
252 local _, title, _, complete = GetAchievementInfo(id)
253 --QuestHelper:TextOut(string.format("Registering %d (%s)", id, title))
254 local prev = GetPreviousAchievement(id)
255 local record = false
258 if prev then
259 registerAchievement(prev)
262 local critcount = GetAchievementNumCriteria(id)
264 the_data[id] = {name = title}
266 for i = 1, critcount do
267 local _, crit_type, _, _, _, _, _, crit_asset, _, crit_id = GetAchievementCriteriaInfo(id, i)
269 the_data[id]["crit_" .. crit_type] = (the_data["crit_" .. crit_type] or 0) + 1
271 if crit_type == 0 then
272 the_data[id]["monster_" .. crit_asset] = true
277 function dump_the_data_zorba_needs()
278 the_data = {}
279 QuestHelper_Errors.achievement_cruft = the_data
281 for _, catid in pairs(GetCategoryList()) do
282 for d = 1, GetCategoryNumAchievements(catid) do
283 eatAchievement(GetAchievementInfo(catid, d))