-
Notifications
You must be signed in to change notification settings - Fork 2
/
AheadOfTheCurve.lua
287 lines (244 loc) · 9.94 KB
/
AheadOfTheCurve.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
local AheadOfTheCurve = LibStub('AceAddon-3.0'):NewAddon('AheadOfTheCurve', 'AceConsole-3.0', 'AceHook-3.0', 'AceEvent-3.0')
local AceConfigRegistry = LibStub('AceConfigRegistry-3.0')
local keyStoneLink
local defaults = {
global = {
enable = {
addon = true,
override = false,
whispers = {
achievement = false,
keystone = false
}
},
minimap = {
hide = true
}
}
}
function AheadOfTheCurve:OnInitialize()
self.db = LibStub('AceDB-3.0'):New('AheadOfTheCurveDB', defaults)
self.achievementSearchList = {}
local id = self.db.global.overrideAchievement
if id then
local _, name = GetAchievementInfo(id)
self.achievementSearchList[id] = name
else
self.achievementSearchList[1] = 'Please search and then select an achievement from the list'
end
self.instances = {
{
ids = {691, 695, 699, 703, 705, 709, 713, 717},
name = 'Mythic Plus (Shadowlands)',
achievements = {14662, 14532, 14531},
highestCompleted = nil,
},
{
ids = {720, 722, 721},
name = 'Castle Nathria',
achievements = {14461, 14365, 14460, 14715},
highestCompleted = nil,
}
}
end
function AheadOfTheCurve:OnEnable()
self:SecureHookScript(LFGListFrame.CategorySelection.FindGroupButton, 'OnClick', 'GetLFGCategory')
self:HookScript(LFGListFrame.SearchPanel.SignUpButton, 'OnClick', 'GetLFGInstance')
self:HookScript(LFGListApplicationDialog.SignUpButton, 'OnClick', 'SendWhisper')
self:RegisterEvent('ACHIEVEMENT_SEARCH_UPDATED')
self:RegisterEvent('ACHIEVEMENT_EARNED')
self:GetHighestDefaultAchievement()
if not self.container then
self.container = CreateFrame('Frame', 'AheadOfTheCurveDialog', LFGListApplicationDialog, BackdropTemplateMixin and "BackdropTemplate");
self.container:SetSize(306, 50)
self.container:SetPoint('BOTTOM', 0, -55)
self.container:SetBackdrop({
bgFile = 'Interface\\DialogFrame\\UI-DialogBox-Background',
edgeFile = 'Interface\\DialogFrame\\UI-DialogBox-Border',
tile = true, tileSize = 32, edgeSize = 32,
insets = {left = 8, right = 8, top = 8, bottom = 8}
})
end
if not self.checkButtonAchievement then
self.checkButtonAchievement = CreateFrame('CheckButton', 'AheadOfTheCurveCheckBoxAchievement', self.container, 'UICheckButtonTemplate')
self.checkButtonAchievement:SetSize(24, 24)
self.checkButtonAchievement:SetPoint('CENTER', -85, 0)
self.checkButtonAchievement:SetChecked(self.db.global.enable.whispers.achievement)
end
if not self.checkButtonKeystone then
self.checkButtonKeystone = CreateFrame('CheckButton', 'AheadOfTheCurveCheckBoxKeystone', self.container, 'UICheckButtonTemplate')
self.checkButtonKeystone:SetSize(24, 24)
self.checkButtonKeystone:SetPoint('CENTER', -85, -11)
self.checkButtonKeystone:SetChecked(self.db.global.enable.whispers.keystone)
self.checkButtonKeystone.text:SetText('Send Mythic Plus Keystone')
self.checkButtonKeystone.text:SetWidth(145)
end
self.container:Show()
self.checkButtonAchievement:Show()
self.checkButtonKeystone:Hide()
end
function AheadOfTheCurve:OnDisable()
self:UnhookAll()
self:UnregisterEvent('ACHIEVEMENT_SEARCH_UPDATED')
self:UnregisterEvent('ACHIEVEMENT_EARNED')
self.container:Hide()
self.checkButtonAchievement:Hide()
end
function AheadOfTheCurve:ACHIEVEMENT_SEARCH_UPDATED()
local numFiltered = GetNumFilteredAchievements();
if numFiltered < 500 then
for index in pairs(self.achievementSearchList) do
self.achievementSearchList[index] = nil
end
for index = 1, numFiltered do
local achievementId = GetFilteredAchievementID(index)
local _, name, _, completed = GetAchievementInfo(achievementId)
if completed then
self.achievementSearchList[achievementId] = name
end
end
end
AceConfigRegistry:NotifyChange('AheadOfTheCurve')
end
function AheadOfTheCurve:ACHIEVEMENT_EARNED()
self:GetHighestDefaultAchievement()
AceConfigRegistry:NotifyChange('AheadOfTheCurve')
end
function AheadOfTheCurve:GetHighestDefaultAchievement()
for index, instance in pairs(self.instances) do
for _, id in pairs(instance.achievements) do
local _, _, _, completed = GetAchievementInfo(id)
if completed then
self.instances[index].highestCompleted = id
break
end
end
end
end
function AheadOfTheCurve:DisplayHighestDefaultAchievement(index)
if self.instances[index].highestCompleted then
local _, name, _, _, _, _, _, _, _, iconPath = GetAchievementInfo(self.instances[index].highestCompleted)
return name, iconPath
else
return nil, nil
end
end
function AheadOfTheCurve:GetLFGCategory(findAGroupButton)
local category = findAGroupButton:GetParent().selectedCategory;
if category ~= 2 or category ~= 3 then
self.container:Hide()
self.checkButtonAchievement:Hide()
else
self.container:Show()
self.checkButtonAchievement:Show()
end
if category == 2 then
self:ScanBagsForKeystone()
end
end
function AheadOfTheCurve:GetLFGInstance(signUpButton)
local searchResultInfo = C_LFGList.GetSearchResultInfo(signUpButton:GetParent().selectedResult)
local highestCompleted = self:GetLFGAchievement(searchResultInfo.activityID)
local isMythicDungeon = self:IsMythicDungeon(searchResultInfo.activityID)
local checkButtonAchievementText, checkButtonAchievementWidth, checkButtonAchievementPoint = self:GetCheckButtonAchievementData(isMythicDungeon)
if not highestCompleted and not self.db.global.enable.override or not self.db.global.enable.override then
self.container:Hide()
self.checkButtonAchievement:Hide()
else
self.container:Show()
self.checkButtonAchievement:Show()
self.checkButtonAchievement:SetChecked(self.db.global.enable.whispers.achievement)
self.checkButtonAchievement.text:SetText(checkButtonAchievementText)
self.checkButtonAchievement.text:SetWidth(checkButtonAchievementWidth)
self.checkButtonAchievement:SetPoint('CENTER', checkButtonAchievementPoint, 0)
end
if isMythicDungeon and keyStoneLink then
self:ShowMythicPlusOption(highestCompleted)
else
self.container:SetPoint('BOTTOM', 0, -55)
self.container:SetSize(306, 50)
self.checkButtonAchievement:SetPoint('CENTER', checkButtonAchievementPoint, 0)
self.checkButtonKeystone:Hide()
self.checkButtonKeystone:SetChecked(false)
end
end
function AheadOfTheCurve:GetCheckButtonAchievementData(isMythicDungeon)
if self.db.global.enable.override then
return 'Send Override Achievement', 158, -85
end
if isMythicDungeon then
return 'Send Mythic Plus Achievement', 170, -85
end
return 'Send Ahead of the Curve Achievement', 205, -100
end
function AheadOfTheCurve:GetLFGAchievement(instanceId)
for _, instance in pairs(self.instances) do
for _, id in pairs(instance.ids) do
if id == instanceId then
return instance.highestCompleted
end
end
end
end
function AheadOfTheCurve:SendWhisper(signUpButton)
local searchResultInfo = C_LFGList.GetSearchResultInfo(signUpButton:GetParent().resultID)
if self.checkButtonAchievement:GetChecked() or self.checkButtonKeystone:GetChecked() then
local achievementId
if self.db.global.enable.override and self.db.global.overrideAchievement then
achievementId = self.db.global.overrideAchievement
else
achievementId = self:GetLFGAchievement(searchResultInfo.activityID)
end
if achievementId then
local success = pcall(SendChatMessage, self:BuildWhisper(achievementId), 'WHISPER', nil, searchResultInfo.leaderName)
if not success then
self:Print('There was an error sending your whisper.')
end
end
end
end
function AheadOfTheCurve:BuildWhisper(achievementId)
if self.checkButtonAchievement:GetChecked() and (self.checkButtonKeystone:GetChecked() and keyStoneLink) then
return GetAchievementLink(achievementId) .. keyStoneLink
end
if self.checkButtonAchievement:GetChecked() then
return GetAchievementLink(achievementId)
end
if self.checkButtonKeystone:GetChecked() and keyStoneLink then
return keyStoneLink
end
end
function AheadOfTheCurve:ScanBagsForKeystone()
for bag = 0, 4 do
local numSlots = GetContainerNumSlots(bag)
for slot = 1, numSlots do
local _, _, _, _, _, _, link, _, _, itemId = GetContainerItemInfo(bag, slot)
if itemId == 138019 then
keyStoneLink = link
break
end
end
end
end
function AheadOfTheCurve:IsMythicDungeon(instanceId)
for _, id in pairs(self.instances[1].ids) do
if id == instanceId then
return true
end
end
end
function AheadOfTheCurve:ShowMythicPlusOption(highestCompleted)
if not highestCompleted and not self.db.global.enable.override then
self.checkButtonAchievement:Hide()
self.container:SetPoint('BOTTOM', 0, -55)
self.container:SetSize(306, 50)
self.checkButtonKeystone:SetPoint('CENTER', -75, 0)
self.container:Show()
else
self.container:SetPoint('BOTTOM', 0, -75)
self.container:SetSize(306, 70)
self.checkButtonAchievement:SetPoint('CENTER', -85, 9)
end
self.checkButtonKeystone:SetChecked(self.db.global.enable.whispers.keystone)
self.checkButtonKeystone:Show()
end