-
Notifications
You must be signed in to change notification settings - Fork 0
/
AchievementInfoApplication.lua
195 lines (158 loc) · 6.79 KB
/
AchievementInfoApplication.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
--[[
AchievementInfo
@author Asto, @Astarax
]]
-- Do the magic
function AchievementInfo.onAchievementUpdated(_, achId)
local output = ""
-- addOn enabled?
if AchievementInfo.settingGet("genEnabled") == false then
if AchievementInfo.settingGet("devDebug") == false then
return
else
output = output .. "DEBUG (AddOn Disabled): "
end
end
--
local categoryId = AchievementInfo.getCorrectAchievementCategoryId(achId)
-- ignore unwanted achievements ...
if categoryId == false then
if AchievementInfo.settingGet("devDebug") == false then
return
else
output = output .. "DEBUG (Not Next): "
end
end
--
-- achievement category enabled?
if categoryId ~= false and AchievementInfo.settingGet("cat"..categoryId) == false then
if AchievementInfo.settingGet("devDebug") == false then
return
else
output = output .. "DEBUG (Category Off): "
end
end
--
-- okay continue with the message
local detailOutput = {}
local detailOutputCount = 1
local percentageCmpSum = 0
local percentageReqSum = 0
local percentageStep = false
local percentageStepSize = AchievementInfo.settingGet("genShowUpdateSteps")
local link = GetAchievementLink(achId, LINK_STYLE_BRACKETS)
local catName = "/"
if categoryId ~= false then
catName = GetAchievementCategoryInfo(categoryId)
end
output = output .. "" .. link .. " (" .. catName .. ")"
local numCriteria = GetAchievementNumCriteria(achId)
for i = 1, numCriteria, 1 do
local description, numCompleted, numRequired = GetAchievementCriterion(achId, i)
local tmpOutput = ""
if i > 1 and AchievementInfo.settingGet("genOnePerLine") == false then
tmpOutput = tmpOutput .. ", "
end
tmpOutput = tmpOutput .. zo_strformat("<<1>>", description) .. " "
tmpOutput = tmpOutput .. AchievementInfo.calcCriteriaColor(numCompleted, numRequired) .. numCompleted .. "|r"
tmpOutput = tmpOutput .. AchievementInfo.clrDefault .. "/" .. "|r"
tmpOutput = tmpOutput .. AchievementInfo.clrCriteriaComplete .. numRequired .. "|r"
tmpOutput = tmpOutput .. AchievementInfo.clrDefault
if AchievementInfo.settingGet("genShowOpenDetailsOnly") == true then
if numCompleted ~= numRequired then
detailOutput[detailOutputCount] = tmpOutput
detailOutputCount = detailOutputCount + 1
end
else
detailOutput[detailOutputCount] = tmpOutput
detailOutputCount = detailOutputCount + 1
end
-- show the achievement on every special achievement because it's a rare event
if numRequired == 1 and numCompleted == 1 then
percentageStep = true
-- collect the numbers to calculate the correct percentage
else
percentageReqSum = percentageReqSum + numRequired
percentageCmpSum = percentageCmpSum + numCompleted
end
end
if percentageStep == false then
-- show at percent value
local percentage = 100 / percentageReqSum * percentageCmpSum
local percentageNext = 100 / percentageReqSum * (percentageCmpSum + 1)
-- if percentage of percentageStepSize is hit or the value is next to it and the next value will be higher
if --[[percentage > 0 and]] percentage % percentageStepSize == 0 or (percentage % percentageStepSize > percentageNext % percentageStepSize and percentageNext % percentageStepSize ~= 0) then
percentageStep = true
-- show if this is the first numCompleted value
elseif percentageCmpSum == 1 then
percentageStep = true
end
end
-- show details?
local detailsCount = AchievementInfo.tableLength(detailOutput)
if AchievementInfo.settingGet("genShowDetails") == true and detailsCount > 0 and AchievementInfo.settingGet("genOnePerLine") == false then
output = output .. " - "
for i = 1, detailsCount, 1 do
output = output .. detailOutput[i]
end
else
output = output .. "."
end
--
-- output on every step OR when its a defined percentage step
if AchievementInfo.settingGet("genShowEveryUpdate") == false and percentageStep == false then
if AchievementInfo.settingGet("devDebug") == false then
return
else
output = "DEBUG (" .. AchievementInfo.settingGet("genShowUpdateSteps") .. "% Rule): " .. output
end
end
--
--
if percentageReqSum == percentageCmpSum then
output = LANG.Completed .. ": " .. output
else
output = LANG.Updated .. ": " .. output
end
--
AchievementInfo.echo(output)
-- output the details line by line - start @2 because the normal output happend before (achievement name)
if AchievementInfo.settingGet("genShowDetails") == true and AchievementInfo.settingGet("genOnePerLine") == true then
for i = 1, AchievementInfo.tableLength(detailOutput), 1 do
AchievementInfo.echo(detailOutput[i])
end
end
end
-- Check if the category of an achievement is valid (reverse check)
function AchievementInfo.checkForValidCategory(achId)
local categoryTopLevelIndex, categoryIndex, achievementIndex = GetCategoryInfoFromAchievementId(achId)
local reverseAchievementId = GetAchievementId(categoryTopLevelIndex, categoryIndex, achievementIndex)
if achId == reverseAchievementId then
return true
end
return false
end
-- Get the correct achievement category
function AchievementInfo.getCorrectAchievementCategoryId(achId)
local previousAchievementId = GetPreviousAchievementInLine(achId)
if AchievementInfo.checkForValidCategory(achId) == false and previousAchievementId ~= 0 then
return AchievementInfo.getCorrectAchievementCategoryId(previousAchievementId)
elseif AchievementInfo.checkForValidCategory(achId) then
return GetCategoryInfoFromAchievementId(achId)
else
return false
end
end
-- Calculates the percentage of the achievement completition to define the color
function AchievementInfo.calcCriteriaColor(completed, required)
local percentage = 100 / required * completed
if completed == required then
return AchievementInfo.clrCriteriaComplete
elseif percentage <= 33 then
return AchievementInfo.clrCriteriaFar
elseif percentage <= 66 then
return AchievementInfo.clrCriteriaMedi
else
return AchievementInfo.clrCriteriaClose
end
end