Repository navigation
Expand file tree
/
Copy pathUtils_Achievement.lua
More file actions
123 lines (107 loc) · 4.2 KB
/
Copy pathUtils_Achievement.lua
File metadata and controls
123 lines (107 loc) · 4.2 KB
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
local name = ...
--- @class LazyCurve
local LazyCurve = LibStub('AceAddon-3.0'):GetAddon(name)
if not LazyCurve then return end
local AchiementUtil = {}
LazyCurve.utils.achievement = AchiementUtil
AchiementUtil.achievementKeywordMap = {}
function AchiementUtil:IsAchievementEarned(achievementID)
if LazyCurve.DB.enableSimulation and LazyCurve.DB.simulatedAchievements[achievementID] then
return true
end
local _, _, _, completed, _ = GetAchievementInfo(achievementID);
return completed or false
end
function AchiementUtil:GetHighestEarnedAchievement(activityTable, applyMythicThreshold)
local ret = {}
if self:IsAchievementEarned(activityTable.achievements.edge) then
return {activityTable.achievements.edge}
end
if self:IsAchievementEarned(activityTable.achievements.curve) then
table.insert(ret, activityTable.achievements.curve)
end
local earnedMythic = self:GetHighestEarnedMythicAchievement(activityTable, applyMythicThreshold)
if earnedMythic then
table.insert(ret, earnedMythic)
end
if #ret == 0 then
if self:IsAchievementEarned(activityTable.achievements.normal) then
ret = {activityTable.achievements.normal}
end
end
return ret
end
--- @param activityTable LazyCurveActivityTable
--- @param applyMythicThreshold true?
--- @return number?
function AchiementUtil:GetHighestEarnedMythicAchievement(activityTable, applyMythicThreshold)
local earnedMythic
local threshold = -1
if applyMythicThreshold then
threshold = LazyCurve.DB.mythicThreshold
if threshold == 0 then threshold = 999 end
end
for i, achievementID in ipairs(activityTable.achievements.mythic) do
if i >= threshold and self:IsAchievementEarned(achievementID) then
earnedMythic = achievementID
end
end
return earnedMythic
end
function AchiementUtil:BuildAchievementKeywordMap()
local map = {}
for _, module in LazyCurve:IterateModules() do
local infoTable = LazyCurve.utils.module:GetModuleInfoTable(module)
local count = #infoTable
for i, activityTable in ipairs(infoTable) do
if activityTable.isLatest then
map.curve = activityTable.achievements.curve
map.edge = activityTable.achievements.edge
end
local activityNames = {
activityTable.shortName,
activityTable.alternativeKeyword,
module.shortName and (module.shortName .. (count - i + 1)) or nil,
}
for _, activityName in ipairs(activityNames) do
map[activityName .. 'normal'] = activityTable.achievements.normal
map[activityName .. 'curve'] = activityTable.achievements.curve
map[activityName .. 'edge'] = activityTable.achievements.edge
map[activityName .. 'mythic'] = self:GetHighestEarnedMythicAchievement(activityTable) or activityTable.achievements.edge
end
end
end
self.achievementKeywordMap = map
end
--- @return table<string, number> # [keyword] = achievementID
function AchiementUtil:GetAchievementKeywordMap()
if not self.achievementKeywordMap then
self:BuildAchievementKeywordMap()
end
return self.achievementKeywordMap
end
--- @param message string
--- @param keyword string
--- @return boolean
local function findKeywordInMessage(message, keyword)
return (message == keyword)
or (not not message:find('^' .. keyword .. '[^%w]'))
or (not not message:find('[^%w]' .. keyword .. '[^%w]'))
or (not not message:find('[^%w]' .. keyword .. '$'))
end
--- @param message string
--- @param keyword string
--- @param achievementID number
--- @return string
function AchiementUtil:ReplaceKeywordWithAchievementLink(message, keyword, achievementID)
if not GetAchievementLink(achievementID) then return message end
keyword = strupper(keyword)
if message:find(keyword) then
local found = findKeywordInMessage(message, keyword)
while (found) do
message = message:gsub(keyword, GetAchievementLink(achievementID))
found = findKeywordInMessage(message, keyword)
end
end
return message
end