hate underachiever forever
[QuestHelper.git] / collect_achievement.lua
blob832f337a03a301107d669537912bb3facf7d8633
1 QuestHelper_File["collect_achievement.lua"] = "Development Version"
2 QuestHelper_Loadtime["collect_achievement.lua"] = GetTime()
4 local QHCA
6 local GetLoc
7 local Merger
9 local cloc
11 local function ScanAchievements(oldADB, newADB)
12 --QuestHelper:TextOut("scanach")
13 local changes = 0
14 for k, v in pairs(newADB.achievements) do
15 if v.complete ~= oldADB.achievements[k].complete then
16 changes = changes + 1
17 end
18 end
19 for k, v in pairs(newADB.criteria) do
20 if v.complete and not oldADB.criteria[k].complete then
21 changes = changes + 1
22 end
23 end
25 if changes < 10 then -- if someone gets 10 criteria at once, well, I guess that's just what happens
26 for k, v in pairs(newADB.achievements) do
27 if v.complete ~= oldADB.achievements[k].complete then
28 QuestHelper: Assert(v.complete and not oldADB.achievements[k].complete)
29 if not QHCA[k] then QHCA[k] = {} end
30 QHCA[k].achieved = (QHCA[k].achieved or "") .. cloc
32 --QuestHelper:TextOut(string.format("Achievement complete, %s", select(2, GetAchievementInfo(k))))
33 end
34 end
36 for k, v in pairs(newADB.criteria) do
37 if v.complete and not oldADB.criteria[k].complete then -- Note that it's possible for objectives to be "uncompleted" when it's things like "do a bunch of shit in one run of this battleground" (see: isle of conquest)
38 --QuestHelper:TextOut(string.format("Criteria complete, %d", k))
39 --QuestHelper:TextOut(string.format("Criteria complete, %s", select(1, GetAchievementCriteriaInfo(k))))
40 if not QHCA[v.parent] then QHCA[v.parent] = {} end
41 QHCA[v.parent][k] = (QHCA[v.parent][k] or "") .. cloc
42 elseif v.progress > oldADB.criteria[k].progress then
43 --QuestHelper:TextOut(string.format("Criteria progress, %d", k))
44 --QuestHelper:TextOut(string.format("Criteria progress, %s", select(1, GetAchievementCriteriaInfo(k))))
45 end
46 end
47 end
48 end
50 function SetCloc()
51 cloc = GetLoc() -- yoink
52 end
54 function QH_Collect_Achievement_Init(QHCData, API)
55 if not QHCData.achievement then QHCData.achievement = {} end
56 QHCA = QHCData.achievement
58 GetLoc = API.Callback_LocationBolusCurrent
59 QuestHelper: Assert(GetLoc)
61 Merger = API.Utility_Merger
62 QuestHelper: Assert(Merger)
64 QH_AchievementManagerRegister(ScanAchievements)
65 QH_AchievementManagerRegister_Prescan(SetCloc)
67 QH_AchievementManager_Init()
68 end