-
Notifications
You must be signed in to change notification settings - Fork 4
/
PullFrame.lua
211 lines (182 loc) · 7.64 KB
/
PullFrame.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
local addonVer = "1.0.3.2"
local me = UnitName('player')
function pfprint(a)
DEFAULT_CHAT_FRAME:AddMessage("|cff69ccf0[TWLC2c] |cffffffff" .. a)
end
function pfdebug(a)
wfprint('|cff0070de[PullFrame :' .. time() .. '] |cffffffff[' .. a .. ']')
end
local PullFrame = CreateFrame("Frame")
PullFrame:RegisterEvent("CHAT_MSG_ADDON")
PullFrame:RegisterEvent("CHAT_MSG_RAID")
PullFrame:RegisterEvent("CHAT_MSG_RAID_WARNING")
PullFrame:RegisterEvent("CHAT_MSG_RAID_LEADER")
PullFrame:RegisterEvent("ADDON_LOADED")
PullFrame:Hide()
PullFrame.started = false;
PullFrame:SetScript("OnEvent", function()
if (event) then
if (event == "ADDON_LOADED" and arg1 == 'TWLC2c') then
if TWLC_PULL == nil then
TWLC_PULL = true
end
if TWLC_PULL_SOUND == nil then
TWLC_PULL_SOUND = true
end
if TWLC_PULL then
wfprint('TWLC2c PullFrame (v' .. addonVer .. ') Loaded and Enabled. Type |cfffff569/tw|cff69ccf0pull |cffffffffto toggle pull frame.')
else
wfprint('TWLC2c PullFrame (v' .. addonVer .. ') Loaded and Disabled. Type |cfffff569/tw|cff69ccf0pull |cffffffffto toggle pull frame.')
end
if TWLC_PULL_SOUND then
wfprint('Pull Sound is Enabled. Type |cfffff569/tw|cff69ccf0pull|cfffff569sound |cffffffffto toggle pull sound on or off.')
else
wfprint('Pull Sound is Disabled. Type |cfffff569/tw|cff69ccf0win|cfffff569sound |cffffffffto toggle win sound on or off.')
end
end
if event == "CHAT_MSG_ADDON" then
if arg1 == 'BigWigs' and string.find(string.lower(arg2), 'pull') and TWLC_PULL then
if not PullFrame.started and pullframeIsAssistOrRL(arg4) then
local bwEx = string.split(arg2, ' ')
if tonumber(bwEx[2]) then
PullFrame.started = true
start_pull_countdown(tonumber(bwEx[2]))
end
end
end
end
if event == "CHAT_MSG_RAID" or event == "CHAT_MSG_RAID_WARNING" or event == "CHAT_MSG_RAID_LEADER" then
if string.find(string.lower(arg1), 'pulling in ') then
if TWLC_PULL then
if not PullFrame.started and pullframeIsAssistOrRL(arg2) then
local bwEx = string.split(arg1, ' ')
local exEx = string.split(bwEx[3], '!')
if tonumber(exEx[1]) then
PullFrame.started = true
start_pull_countdown(tonumber(exEx[1]))
end
end
end
--send message to collect raid buffs
if PullFrame:twlc2isRL(me) then
SendAddonMessage('TWLC2', 'scanConsumables=now', "RAID")
end
end
end
end
end)
PullFrame.countFrom = 6
PullFrame.start = 0
function start_pull_countdown(x)
PullFrame.bwTimerDuration = x
PullFrame.countFrom = x
getglobal('PullFrameNumbers'):SetTexture('Interface\\addons\\TWLC2c\\images\\pull\\5')
getglobal('PullFrameNumbersGlow'):SetTexture('Interface\\addons\\TWLC2c\\images\\pull\\5_glow')
PullFrame.start = GetTime()
PullFrame:Show();
end
PullFrame:SetScript("OnShow", function()
this.startTime = GetTime()
end)
PullFrame.lastNumer = 0
PullFrame.frameNr = 0
PullFrame:SetScript("OnUpdate", function()
local plus = 0.03
local gt = GetTime() * 1000 --22.123 -> 22123
local st = (this.startTime + plus) * 1000 -- (22.123 + 0.1) * 1000 = 22.223 * 1000 = 22223
if gt >= st then
PullFrame:Show()
PullFrame.countFrom = PullFrame.bwTimerDuration - (PullFrame.start - GetTime()) * -1
if (math.floor(PullFrame.countFrom) >= 0 and math.floor(PullFrame.countFrom) <= 5) then
getglobal('PullFrame'):Show()
PullFrame.frameNr = PullFrame.frameNr + 1
if PullFrame.frameNr >= 0 and PullFrame.frameNr <= 30 then
getglobal('PullFrameNumbers'):SetAlpha(1)
getglobal('PullFrame'):SetScale((0.3 + 0.7 * (PullFrame.frameNr / 30)) * 0.8)
getglobal('PullFrameNumbersGlow'):SetAlpha(1 - (PullFrame.frameNr / 30))
end
if PullFrame.frameNr > 85 then
getglobal('PullFrame'):SetScale( getglobal('PullFrame'):GetScale() + PullFrame.frameNr / 9000)
getglobal('PullFrameNumbers'):SetAlpha(getglobal('PullFrameNumbers'):GetAlpha() - PullFrame.frameNr / 9000)
end
if (math.floor(PullFrame.countFrom) >= 0 and math.floor(PullFrame.countFrom) <= (PullFrame.bwTimerDuration - 1)) then
getglobal('PullFrameNumbers'):SetTexture('Interface\\addons\\TWLC2c\\images\\pull\\' .. math.floor(PullFrame.countFrom))
getglobal('PullFrameNumbersGlow'):SetTexture('Interface\\addons\\TWLC2c\\images\\pull\\' .. math.floor(PullFrame.countFrom) .. '_glow')
if PullFrame.lastNumber ~= math.floor(PullFrame.countFrom) then
PullFrame.frameNr = 0
getglobal('PullFrame'):SetScale(0.3)
getglobal('PullFrameNumbers'):SetAlpha(1)
if TWLC_PULL_SOUND then
PlaySoundFile("Interface\\AddOns\\TWLC2c\\sound\\tick.ogg");
end
PullFrame.lastNumber = math.floor(PullFrame.countFrom)
end
else
PullFrame:Hide()
getglobal('PullFrame'):Hide()
end
end
end
if PullFrame.countFrom < 0 then
PullFrame:Hide()
getglobal('PullFrame'):Hide()
PullFrame.started = false
end
end)
SLASH_TWPULL1 = "/twpull"
SlashCmdList["TWPULL"] = function(cmd)
if (cmd) then
TWLC_PULL = not TWLC_PULL
if TWLC_PULL then
wfprint('TWLC2c PullFrame Enabled. Type |cfffff569/tw|cff69ccf0pull |cffffffffto toggle pull frame.')
else
wfprint('TWLC2c PullFrame Disabled. Type |cfffff569/tw|cff69ccf0pull |cffffffffto toggle pull frame.')
end
end
end
SLASH_TWPULLSOUND1 = "/twpullsound"
SlashCmdList["TWPULLSOUND"] = function(cmd)
if (cmd) then
TWLC_PULL_SOUND = not TWLC_PULL_SOUND
if TWLC_PULL_SOUND then
wfprint('Pull Sound is Enabled. Type |cfffff569/tw|cff69ccf0pull|cfffff569sound |cffffffffto toggle pull sound on or off.')
else
wfprint('Pull Sound is Disabled. Type |cfffff569/tw|cff69ccf0win|cfffff569sound |cffffffffto toggle win sound on or off.')
end
end
end
function pullframeIsAssistOrRL(name)
if not UnitInRaid('player') then return false end
for i = 0, GetNumRaidMembers() do
if GetRaidRosterInfo(i) then
local n, r = GetRaidRosterInfo(i);
if n == name and (r == 1 or r == 2) then
return true
end
end
end
return false
end
function string:split(delimiter)
local result = {}
local from = 1
local delim_from, delim_to = string.find(self, delimiter, from)
while delim_from do
table.insert(result, string.sub(self, from, delim_from - 1))
from = delim_to + 1
delim_from, delim_to = string.find(self, delimiter, from)
end
table.insert(result, string.sub(self, from))
return result
end
function PullFrame:twlc2isRL(name)
for i = 0, GetNumRaidMembers() do
if GetRaidRosterInfo(i) then
local n, r = GetRaidRosterInfo(i);
if n == name and r == 2 then
return true
end
end
end
return false
end