-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAscensionDraftHelper.lua
235 lines (203 loc) · 6.46 KB
/
AscensionDraftHelper.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
local addonName = 'ascensiondrafthelper';
SPELL_LIST = {};
AscensionDraftHelper = {
macroName = 'AscensionDraftHelper - Macro',
spellList = { 965202, 1130, 1978, 13165 },
windowHidden = false
};
local ROUND = 1;
FOUND_SPELLS = {};
NUMBER_OF_MATCHES = 3;
function AscensionDraftHelper:log(msg)
ChatFrame1:AddMessage("|cFFFFC107[DraftMan]: |r" .. msg)
end
function AscensionDraftHelper:CreateMacro()
AscensionDraftHelper:DeleteMacro()
DRAFT_MAN_MACRO_ID = CreateMacro(AscensionDraftHelper.macroName, 10, "#show\n/script AscensionDraftHelper:StartRoll()", nil)
AscensionDraftHelper:log("Macro created! Please put it on action bar 1.")
PickupMacro(AscensionDraftHelper.macroName)
end
function AscensionDraftHelper:DeleteMacro()
DeleteMacro(AscensionDraftHelper.macroName);
end
-- Gets spell card info
local function getCardSpellInfo(index)
local spells = {
[1] = Card1.sID,
[2] = Card2.sID,
[3] = Card3.sID
}
local name = GetSpellInfo(spells[index])
return spells[index], name
end
-- Learn spell card at position
local function learnSpellCardAt(index)
_G["Card" .. tostring(index)].button:Click()
end
local round = 1;
local enabled = false;
function AscensionDraftHelper:Roll()
CardExtraBar.button1:Click();
-- ActionButton1:Click();
end
function AscensionDraftHelper:StartAutoRoll()
enabled = not enabled;
if enabled then
AscensionDraftHelperFrame_AutoRollButton:SetText('Stop Auto roll');
FOUND_SPELLS = {};
AscensionDraftHelper:AutoRoll();
else
AscensionDraftHelperFrame_AutoRollButton:SetText('Start Auto roll')
end
end
function AscensionDraftHelper:AutoRoll()
if enabled then
AscensionDraftHelper:Wait(1.2, function ()
AscensionDraftHelper:SelectOrRoll();
AscensionDraftHelper:AutoRoll()
end)
end
end
function AscensionDraftHelper:StartRoll()
FOUND_SPELLS = {};
AscensionDraftHelper:SelectOrRoll();
end
function AscensionDraftHelper:SelectOrRoll()
if not (table.getn(FOUND_SPELLS) == table.getn(SPELL_LIST) or table.getn(FOUND_SPELLS) == NUMBER_OF_MATCHES) then
print('>>> Round ' .. round);
local found = AscensionDraftHelper:SelectCard();
if not found then
print('not found')
AscensionDraftHelper:Roll();
FOUND_SPELLS = {};
round = 1;
else
print('found')
found = false;
round = round + 1;
end
else
print('All spells found')
end
end
function AscensionDraftHelper:SelectCard()
local found = false;
for i = 1, 3 do
local id, name = getCardSpellInfo(i)
print(id .. " | " ..name)
for j = 1, table.getn(SPELL_LIST)+1 do
if SPELL_LIST[j] == id then
print('learning')
learnSpellCardAt(i)
print('Learned' .. ' | ' .. name)
FOUND_SPELLS[round] = name;
found = true;
break
end
end
end
return found;
-- AscensionDraftHelper:Wait(1.2, function ()
-- if not found then
-- print('not found')
-- CardExtraBar.button1:Click();
-- FOUND_SPELLS = {}
-- round = 1;
-- else
-- print('found')
-- found = false;
-- round = round + 1;
-- end
-- AscensionDraftHelper:SelectCardOrRoll();
-- end)
end
function AscensionDraftHelper:OnLoad()
this:RegisterEvent("VARIABLES_LOADED")
this:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
this:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN")
AscensionDraftHelper:log("Loaded v1")
end
function AscensionDraftHelper:OnEvent(event)
if event == "VARIABLES_LOADED" then
AscensionDraftHelper:OnInit()
end
end
function AscensionDraftHelper:OnInit()
-- Reroll bar state
AscensionDraftHelperFrame_UnlockFrames:Hide();
AscensionDraftHelper:SetFrameVisibility(AscensionDraftHelper.windowHidden);
_G["AscensionDraftHelperFrame_Input1"]:SetText(table.concat(SPELL_LIST,", "));
_G["AscensionDraftHelperFrame_NumberOfSpells"]:SetText(NUMBER_OF_MATCHES);
-- AscensionDraftHelper:SetFrameVisibility(true)
end
function AscensionDraftHelper:SetFrameVisibility(status)
if status then
AscensionDraftHelperFrame:Show();
-- AscensionDraftHelperFrame_RerollBar:Show();
else
AscensionDraftHelperFrame:Hide();
-- AscensionDraftHelperFrame_RerollBar:Hide();
end
AscensionDraftHelper.windowHidden = not status
end
function AscensionDraftHelper:OnInputEdit(input, editbox)
local text = editbox:GetText();
SPELL_LIST = AscensionDraftHelper:ParseSpells(text);
end
function AscensionDraftHelper:OnNumberOfSpellsEdit(editbox)
local text = editbox:GetText();
NUMBER_OF_MATCHES = tonumber(text);
end
function AscensionDraftHelper:ParseSpells(input)
local spells = {}
for spell in string.gmatch(input, '([^,]+)') do
-- Trim string
spell = spell:gsub("^%s*(.-)%s*$", "%1")
-- Remove non numerics
spell = spell:gsub("[^0-9]", "")
-- To number
spell = tonumber(spell)
table.insert(spells, spell)
end
return spells
end
local waitTable = {};
local waitFrame = nil;
function AscensionDraftHelper:Wait(delay, func, ...)
if(type(delay)~="number" or type(func)~="function") then
return false;
end
if(waitFrame == nil) then
waitFrame = CreateFrame("Frame","WaitFrame", UIParent);
waitFrame:SetScript("onUpdate",function (self,elapse)
local count = #waitTable;
local i = 1;
while(i<=count) do
local waitRecord = tremove(waitTable,i);
local d = tremove(waitRecord,1);
local f = tremove(waitRecord,1);
local p = tremove(waitRecord,1);
if(d>elapse) then
tinsert(waitTable,i,{d-elapse,f,p});
i = i + 1;
else
count = count - 1;
f(unpack(p));
end
end
end);
end
tinsert(waitTable,{delay,func,{...}});
return true;
end
--===[ Slash command ]===---
function AscensionDraftHelper_HandleSlashCommand(msg)
if msg == "show" then
AscensionDraftHelper:SetFrameVisibility(true)
elseif msg == "hide" then
AscensionDraftHelper:SetFrameVisibility(false)
end
end
SlashCmdList["ASCENSIONDRAFTHELPER"] = AscensionDraftHelper_HandleSlashCommand;
SLASH_ASCENSIONDRAFTHELPER1 = "/" .. addonName
SLASH_ASCENSIONDRAFTHELPER2 = "/adh"