Automated update from: http://smariot.no-ip.org/translate
[QuestHelper.git] / manager_achievement.lua
blob0b9c48fa61885a4e72379218aa85f6dd156893dc
1 QuestHelper_File["manager_achievement.lua"] = "Development Version"
2 QuestHelper_Loadtime["manager_achievement.lua"] = GetTime()
4 local AchievementDB
6 -- 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 -- 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 -- 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({1, 7, 8, 9, 10, 11, 14, 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
72 QuestHelper: Assert(id)
73 if id < 0 then return end -- stupid underachiever
75 local _, title, _, complete = GetAchievementInfo(id)
76 --QuestHelper:TextOut(string.format("Registering %d (%s)", id, title))
77 local prev = GetPreviousAchievement(id)
78 local record = false
80 --[[
81 db.achievements[id] = {
82 previous = prev,
83 compete = complete,
84 name = title,
85 criterialist = {}
87 local dbi = db.achievements[id]
90 if prev then
91 registerAchievement(prev)
92 end
94 local critcount = GetAchievementNumCriteria(id)
95 if critcount == 0 then record = true end
97 for i = 1, critcount do
98 local crit_name, crit_type, crit_complete, crit_quantity, crit_reqquantity, _, _, crit_asset, _, crit_id = GetAchievementCriteriaInfo(id, i)
100 if qhdinfo and not achievement_type_blacklist[crit_type] then
101 if not qhdinfodump[crit_type] then qhdinfodump[crit_type] = {} end
102 qhdinfodump[crit_type][title .. " --- " .. crit_name] = true
105 --[[
106 table.insert(dbi.criterialist, crit_id)
107 ass ert (not db.criteria[crit_id])
108 crittypes[crit_type] = (crittypes[crit_type] or 0) + 1]]
110 if not achievement_type_blacklist[crit_type] then record = true end
112 --[[
113 db.criteria[crit_id] = {
114 name = crit_name,
115 type = crit_type,
116 complete = crit_complete,
117 progress = crit_quantity,
118 progress_total = crit_reqquantity,
119 asset = crit_asset,
123 if record then achievement_list[id] = true end
126 local function createAchievementList()
127 for _, catid in pairs(GetCategoryList()) do
128 for d = 1, GetCategoryNumAchievements(catid) do
129 --if GetAchievementInfo(catid, d) == 2557 then print("loading tffs") end
130 --if GetAchievementInfo(catid, d) == 1312 then print("loading otot") end
132 registerAchievement(GetAchievementInfo(catid, d), db)
133 --assert(AchievementDB.achievements[2557])
134 --assert(AchievementDB.achievements[1312]) -- what what
139 qh_cal = createAchievementList
141 local achievement_stop_time = 0
143 local GetAchievementInfo = GetAchievementInfo
144 local GetAchievementNumCriteria = GetAchievementNumCriteria
145 local GetAchievementCriteriaInfo = GetAchievementCriteriaInfo
147 local function retrieveAchievement(id, db)
148 QH_Timeslice_Yield()
150 local _, _, _, complete = GetAchievementInfo(id)
151 --QuestHelper:TextOut(string.format("Registering %d (%s)", id, title))
153 db.achievements[id] = QuestHelper:CreateTable("collect_achievement achievement")
154 db.achievements[id].complete = complete
156 local dbi = db.achievements[id]
158 local critcount = GetAchievementNumCriteria(id)
159 QuestHelper: Assert(critcount, "critcount nil " .. tostring(id))
161 --QuestHelper:TextOut(string.format("%d criteria", crit))
162 for i = 1, critcount do
163 QuestHelper: Assert(not db.criteria[crit_id])
164 local _, _, crit_complete, crit_quantity, crit_reqquantity, _, _, _, _, crit_id = GetAchievementCriteriaInfo(id, i)
166 db.criteria[crit_id] = QuestHelper:CreateTable("collect_achievement criteria")
167 db.criteria[crit_id].complete = crit_complete
168 db.criteria[crit_id].progress = crit_quantity
169 db.criteria[crit_id].parent = id
173 local function getAchievementDB()
174 local db = {}
175 db.achievements = {}
176 db.criteria = {}
178 local ct = 0
179 for k in pairs(achievement_list) do
180 retrieveAchievement(k, db)
181 ct = ct + 1
183 --QuestHelper: TextOut(tostring(ct))
185 return db
189 local registered = {}
190 local prescan = {}
192 function QH_AchievementManagerRegister(funky) -- I am imagining "funky" being said in the same tone of voice that "spicy" is in Puzzle Pirates
193 table.insert(registered, funky)
195 function QH_AchievementManagerRegister_Prescan(funky)
196 table.insert(prescan, funky)
199 local updating = false
200 local updating_continue = false
202 local function ScanAchievements()
203 while updating_continue do
204 updating_continue = false
206 for _, v in ipairs(prescan) do
210 local old = AchievementDB
211 local new = getAchievementDB()
213 for _, v in ipairs(registered) do
214 v(old, new)
217 AchievementDB = new
219 for k, v in pairs(old.achievements) do QuestHelper:ReleaseTable(v) end
220 for k, v in pairs(old.criteria) do QuestHelper:ReleaseTable(v) end
223 updating = false
226 local function OnEvent()
227 --print("oe", updating, AchievementDB)
228 if not updating and AchievementDB then
229 --print("cutea")
230 QH_Timeslice_Add(ScanAchievements, "criteria")
231 updating = true
233 updating_continue = true
235 --qhaach = OnEvent
237 QH_Event("CRITERIA_UPDATE", OnEvent)
238 QH_Event("ACHIEVEMENT_EARNED", OnEvent)
240 function QH_AchievementManagerRegister_Poke()
241 OnEvent()
244 function QH_AchievementManager_Init()
245 createAchievementList()
247 AchievementDB = getAchievementDB() -- 'coz we're lazy
248 --assert(AchievementDB.achievements[2556])
249 --assert(AchievementDB.achievements[2557])
250 --assert(AchievementDB.achievements[1312]) -- what what
252 for _, v in ipairs(registered) do -- basically initting everything linked to this
253 v(AchievementDB, AchievementDB)
258 if QuestHelper_File["manager_achievement.lua"] == "Development Version" then
259 -- woop woop woop
260 -- runnin' around like a headless chicken
261 -- collidin' with walls
262 -- fallin' over backwards, waving arms wildly
263 -- little bit of drool
264 -- you know how it goes
266 local the_data
268 local function eatAchievement(id)
269 local _, title, _, complete = GetAchievementInfo(id)
270 --QuestHelper:TextOut(string.format("Registering %d (%s)", id, title))
271 local prev = GetPreviousAchievement(id)
272 local record = false
275 if prev then
276 registerAchievement(prev)
279 local critcount = GetAchievementNumCriteria(id)
281 the_data[id] = {name = title}
283 for i = 1, critcount do
284 local _, crit_type, _, _, _, _, _, crit_asset, _, crit_id = GetAchievementCriteriaInfo(id, i)
285 table.insert(the_data[id], {cid = crit_id, type = crit_type, asset = crit_asset})
289 function dump_the_data_zorba_needs()
290 the_data = {}
291 QuestHelper_Errors.achievement_cruft = the_data
293 for _, catid in pairs(GetCategoryList()) do
294 for d = 1, GetCategoryNumAchievements(catid) do
295 eatAchievement(GetAchievementInfo(catid, d))
300 function dump_crits(id)
301 local critcount = GetAchievementNumCriteria(id)
302 print(string.format("%d criteria (%s)", critcount, tostring(achievement_list[id])))
304 for i = 1, critcount do
305 local _, crit_type = GetAchievementCriteriaInfo(id, i)
306 print(string.format("%d: %d", i, crit_type))