-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathYaHT.lua
434 lines (388 loc) · 14.7 KB
/
YaHT.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
-- YaHT - Yet another Hunter Timer by Aviana
if select(2,UnitClass("player")) ~= "HUNTER" then return end
YaHT = select(2, ...)
local L = YaHT.L
local ACR = LibStub("AceConfigRegistry-3.0", true)
local SML = LibStub:GetLibrary("LibSharedMedia-3.0")
YaHT.version = 2140
local SWING_TIME = 0.65
local AimedDelay = 1
local movementDelay = 0
local AimedShot = GetSpellInfo(19434)
local MultiShot = GetSpellInfo(2643)
local backdrop = {insets = {}}
local mediaRequired
local defaultMedia = {
[SML.MediaType.STATUSBAR] = "Interface\\AddOns\\YaHT\\media\\Bar",
[SML.MediaType.BACKGROUND] = "Interface\\ChatFrame\\ChatFrameBackground",
[SML.MediaType.BORDER] = "Interface\\None",
}
local scanningTip = CreateFrame("GameTooltip", "YaHTScanningTooltip", nil, "GameTooltipTemplate")
scanningTip:SetOwner(UIParent, "ANCHOR_NONE")
local function GetRangedWeaponSpeed()
scanningTip:SetInventoryItem("player", 18)
for i=1, scanningTip:NumLines() do
local text = _G["YaHTScanningTooltipTextRight"..i]:GetText()
if (text ~= nil and text:sub(1, 6) == "Speed ") then
return tonumber(text:sub(7))
end
end
end
local function GetSpeedModifier()
local weaponSpeed = GetRangedWeaponSpeed()
if weaponSpeed == nil then
return 1
end
local playerSpeed = UnitRangedDamage("player")
return playerSpeed / weaponSpeed
end
local function OnUpdate(self, elapsed)
local config = YaHT.db.profile
if not config.lock then
self.mockTime = self.mockTime + elapsed
if self.mockTime > self.swingtime then
self.texture:SetVertexColor(config.drawcolor.r,config.drawcolor.g,config.drawcolor.b)
self.texture:SetWidth(self:GetWidth() * (1-(self.mockTime2/SWING_TIME)))
self.mockTime2 = self.mockTime2 + elapsed
if self.mockTime2 > SWING_TIME then
self.mockTime = 0
end
else
self.mockTime2 = 0
self.texture:SetVertexColor(config.timercolor.r,config.timercolor.g,config.timercolor.b)
self.texture:SetWidth(self:GetWidth() * self.mockTime/self.swingtime)
end
return
end
local curTime = GetTime()
if not self.SwingStart and (curTime - self.lastshot) >= self.swingtime then
--Start Swing timer
if self.shooting and not self.casting then
YaHT.mainFrame.texture:SetVertexColor(config.drawcolor.r,config.drawcolor.g,config.drawcolor.b)
self:SetAlpha(config.alpha)
self.SwingStart = curTime
else
if not self.shooting then
self:Hide()
end
end
elseif self.SwingStart then
if IsPlayerMoving() or IsFalling() then
self.SwingStart = curTime
self.texture:SetWidth(0.01)
self:SetAlpha(config.malpha)
local timeSinceReadyToFire = curTime - self.lastshot + self.swingtime
if timeSinceReadyToFire > 0 then
while timeSinceReadyToFire > 0.5 do
timeSinceReadyToFire = timeSinceReadyToFire - 0.5
end
movementDelay = 0.5 - timeSinceReadyToFire
end
else
self.texture:SetWidth(config.width * math.min(((curTime - self.SwingStart) / (SWING_TIME + movementDelay)),1))
self:SetAlpha(config.alpha)
end
else
self.texture:SetWidth(config.width * (1 - math.min(((curTime - self.lastshot) / self.swingtime),1)))
self:SetAlpha(config.alpha)
end
end
function YaHT:OnInitialize()
self:LoadDefaults()
-- Initialize DB
self.db = LibStub:GetLibrary("AceDB-3.0"):New("YaHTdb", self.defaults, true)
self.db.RegisterCallback(self, "OnProfileChanged", "ProfilesChanged")
self.db.RegisterCallback(self, "OnProfileCopied", "ProfilesChanged")
self.db.RegisterCallback(self, "OnProfileReset", "ProfileReset")
SML.RegisterCallback(self, "LibSharedMedia_Registered", "MediaRegistered")
SML:Register(SML.MediaType.STATUSBAR, "YaHT Bar", "Interface\\AddOns\\YaHT\\media\\Bar")
self:Load()
self:CreateConfig()
end
function YaHT:ProfilesChanged()
if( resetTimer ) then resetTimer:Hide() end
self.db:RegisterDefaults(self.defaults)
-- No active layout, register the default one
if( not self.db.profile.loadedLayout ) then
self:LoadDefaults()
end
self:ApplySettings()
end
local resetTimer
function YaHT:ProfileReset()
if( not resetTimer ) then
resetTimer = CreateFrame("Frame")
resetTimer:SetScript("OnUpdate", function(self)
YaHT:ProfilesChanged()
self:Hide()
end)
end
resetTimer:Show()
end
-- We might not have had a media we required at initial load, wait for it to load and then update everything when it does
function YaHT:MediaRegistered(event, mediaType, key)
if( mediaRequired and mediaRequired[mediaType] and mediaRequired[mediaType] == key ) then
mediaRequired[mediaType] = nil
self:ApplySettings()
end
end
function YaHT:GetMedia(type, mediaName)
local media = SML:Fetch(type, mediaName, true)
if not media then
mediaRequired = mediaRequired or {}
mediaRequired[type] = mediaName
return defaultMedia[type]
end
return media
end
function YaHT:ApplySettings()
local config = YaHT.db.profile
self.mainFrame:SetWidth(config.width)
self.mainFrame:SetHeight(config.height)
self.mainFrame:SetScale(config.scale)
self.mainFrame:ClearAllPoints()
if config.point then
self.mainFrame:SetPoint(config.point, UIParent, config.relativePoint, config.x, config.y)
else
self.mainFrame:SetPoint("CENTER", UIParent, "CENTER", 0, -350)
end
self.mainFrame:EnableMouse(not config.lock)
self.mainFrame:SetMovable(not config.lock)
backdrop.edgeFile = config.enableborder and self:GetMedia(SML.MediaType.BORDER, config.border)
backdrop.tile = true
backdrop.edgeSize = 10
backdrop.tileSize = 1
backdrop.insets.left = 3
backdrop.insets.right = 3
backdrop.insets.top = 3
backdrop.insets.bottom = 3
self.mainFrame.border:SetBackdrop(backdrop)
self.mainFrame.border:SetHeight(config.height + 6)
self.mainFrame.border:SetWidth(config.width + 6)
self.mainFrame.border:SetBackdropBorderColor(config.bordercolor.r, config.bordercolor.g, config.bordercolor.b)
if config.enablebackground then
self.mainFrame.background:Show()
else
self.mainFrame.background:Hide()
end
self.mainFrame.background:SetVertexColor(config.backgroundcolor.r, config.backgroundcolor.g, config.backgroundcolor.b, config.backgroundcolor.a)
self.mainFrame.background:SetTexture(self:GetMedia(SML.MediaType.BACKGROUND, config.background))
self.mainFrame.texture:ClearAllPoints()
if config.fill then
self.mainFrame.texture:SetPoint("CENTER", self.mainFrame, "CENTER")
else
self.mainFrame.texture:SetPoint("LEFT", self.mainFrame, "LEFT")
end
if YaHT.db.profile.lock and not self.mainFrame.shooting then
self.mainFrame:Hide()
else
self.mainFrame:Show()
self.mainFrame:SetAlpha(YaHT.db.profile.alpha)
if self.mainFrame.SwingStart then
self.mainFrame.texture:SetVertexColor(config.drawcolor.r,config.drawcolor.g,config.drawcolor.b)
else
self.mainFrame.texture:SetVertexColor(config.timercolor.r, config.timercolor.g,config.timercolor.b)
end
end
self.mainFrame.texture:SetTexture(self:GetMedia(SML.MediaType.STATUSBAR, config.statusbar))
self.mainFrame.texture:SetHeight(config.height)
end
function YaHT:Load()
self.mainFrame = CreateFrame("Frame", "YaHTMainFrame", UIParent)
self.mainFrame:SetFrameStrata("MEDIUM")
self.mainFrame:RegisterForDrag("LeftButton")
self.mainFrame:SetClampedToScreen(true)
self.mainFrame:SetScript("OnDragStart", function() YaHT.mainFrame:StartMoving() end)
self.mainFrame:SetScript("OnDragStop", function()
local config, meh = YaHT.db.profile
YaHT.mainFrame:StopMovingOrSizing()
config.point, meh , config.relativePoint, config.x, config.y = YaHT.mainFrame:GetPoint()
end)
self.mainFrame.mockTime = 0
self.mainFrame.time = 0
self.mainFrame.lastshot = GetTime()
self.mainFrame.swingtime = UnitRangedDamage("player") - SWING_TIME
self.mainFrame:SetScript("OnUpdate", OnUpdate)
self.mainFrame.background = self.mainFrame:CreateTexture("YaHTMainFrameBackground", "BACKGROUND")
self.mainFrame.background:SetAllPoints(self.mainFrame)
self.mainFrame.background:SetHorizTile(true)
self.mainFrame.background:SetVertTile(true)
self.mainFrame.texture = self.mainFrame:CreateTexture("YaHTMainFrameBar", "ARTWORK")
self.mainFrame.border = CreateFrame("Frame", "YaHTMainFrameBorder", self.mainFrame, BackdropTemplateMixin and "BackdropTemplate")
self.mainFrame.border:SetPoint("CENTER", self.mainFrame, "CENTER")
self:ApplySettings()
end
function YaHT:COMBAT_LOG_EVENT_UNFILTERED()
local _, event, _, casterID, _, _, _, targetID, targetName, _, _, spellID, name, _, extra_spell_id, _, _, resisted, blocked, absorbed = CombatLogGetCurrentEventInfo()
local _, rank, icon, castTime = GetSpellInfo(spellID)
local icon, castTime = select(3, GetSpellInfo(spellID))
if event == "SWING_DAMAGE" or event == "ENVIRONMENTAL_DAMAGE" or event == "RANGE_DAMAGE" or event == "SPELL_DAMAGE" then
if resisted or blocked or absorbed then return end
if targetID == UnitGUID("player") then
local maxValue
maxValue = 0
if CastingBarFrame.maxValue ~= nil then
maxValue = CastingBarFrame.maxValue
end
CastingBarFrame.maxValue = maxValue + math.min(CastingBarFrame:GetValue(),AimedDelay)
CastingBarFrame:SetMinMaxValues(0, CastingBarFrame.maxValue)
if AimedDelay > 0.2 then
AimedDelay = AimedDelay - 0.2
end
end
return
elseif event == "SPELL_CAST_SUCCESS" and name == GetSpellInfo(19801) and casterID == UnitGUID("player") then
if YaHT.db.profile.tranqannounce then
local num
if YaHT.db.profile.announcetype == "CHANNEL" then
num = GetChannelName(YaHT.db.profile.targetchannel)
end
SendChatMessage(string.format(YaHT.db.profile.announcemsg,targetName), YaHT.db.profile.announcetype, nil, num or YaHT.db.profile.targetchannel)
end
elseif event == "SPELL_MISSED" and name == GetSpellInfo(19801) and casterID == UnitGUID("player") then
if YaHT.db.profile.tranqannouncefail then
local num
if YaHT.db.profile.announcetype == "CHANNEL" then
num = GetChannelName(YaHT.db.profile.targetchannel)
end
SendChatMessage(string.format(YaHT.db.profile.announcefailmsg,targetName), YaHT.db.profile.announcetype, nil, num or YaHT.db.profile.targetchannel)
end
end
if (name ~= AimedShot and name ~= MultiShot) or (not YaHT.db.profile.showaimed and name == AimedShot) or (not YaHT.db.profile.showmulti and name == MultiShot) then return end
if event == "SPELL_CAST_START" and casterID == UnitGUID("player") then
self.mainFrame.casting = true
if name == AimedShot then
AimedDelay = 1
castTime = 3.5
else
castTime = 0.5
end
CastingBarFrame.Spark:Show()
local startColor = CastingBarFrame_GetEffectiveStartColor(CastingBarFrame, false, false)
CastingBarFrame:SetStatusBarColor(startColor:GetRGB())
if CastingBarFrame.flashColorSameAsStart then
CastingBarFrame.Flash:SetVertexColor(startColor:GetRGB())
else
CastingBarFrame.Flash:SetVertexColor(1, 1, 1)
end
CastingBarFrame.value = 0
CastingBarFrame.baseMaxValue = castTime
CastingBarFrame.maxValue = CastingBarFrame.baseMaxValue * GetSpeedModifier()
CastingBarFrame:SetMinMaxValues(0, CastingBarFrame.maxValue)
CastingBarFrame:SetValue(CastingBarFrame.value)
if ( CastingBarFrame.Text ) then
CastingBarFrame.Text:SetText(name)
end
if ( CastingBarFrame.Icon ) then
CastingBarFrame.Icon:SetTexture(icon)
if ( CastingBarFrame.iconWhenNoninterruptible ) then
CastingBarFrame.Icon:SetShown(true)
end
end
CastingBarFrame_ApplyAlpha(CastingBarFrame, 1.0)
CastingBarFrame.holdTime = 0
CastingBarFrame.casting = true
CastingBarFrame.castID = nil
CastingBarFrame.channeling = nil
CastingBarFrame.fadeOut = nil
CastingBarFrame:Show()
end
end
function YaHT:UNIT_SPELLCAST_INTERRUPTED(unit, castID, spellID)
if unit ~= "player" then return end
self.mainFrame.casting = nil
if GetSpellInfo(spellID) == AimedShot or GetSpellInfo(spellID) == MultiShot then
CastingBarFrame:SetValue(CastingBarFrame.maxValue)
CastingBarFrame:SetStatusBarColor(CastingBarFrame.failedCastColor:GetRGB())
if ( CastingBarFrame.Spark ) then
CastingBarFrame.Spark:Hide()
end
if ( CastingBarFrame.Text ) then
CastingBarFrame.Text:SetText(FAILED)
end
CastingBarFrame.casting = nil
CastingBarFrame.channeling = nil
CastingBarFrame.fadeOut = true
CastingBarFrame.holdTime = GetTime() + CASTING_BAR_HOLD_TIME
end
end
function YaHT:START_AUTOREPEAT_SPELL()
local config = YaHT.db.profile
local curTime = GetTime()
self.mainFrame.shooting = true
-- self.mainFrame.ignoregcd = self:GCDcheck()
if curTime - self.mainFrame.lastshot < self.mainFrame.swingtime then
self.mainFrame.texture:SetVertexColor(config.timercolor.r,config.timercolor.g,config.timercolor.b)
else
self.mainFrame.texture:SetVertexColor(config.drawcolor.r,config.drawcolor.g,config.drawcolor.b)
self.mainFrame.SwingStart = curTime
if IsPlayerMoving() then
self.mainFrame.lastshot = curTime - self.mainFrame.swingtime
end
end
self.mainFrame:SetAlpha(YaHT.db.profile.alpha)
self.mainFrame:Show()
end
function YaHT:STOP_AUTOREPEAT_SPELL()
self.mainFrame.shooting = nil
if YaHT.db.profile.lock and (GetTime() - self.mainFrame.lastshot) >= self.mainFrame.swingtime then
self.mainFrame:SetAlpha(0)
self.mainFrame:Hide()
end
end
function YaHT:UNIT_SPELLCAST_SUCCEEDED(unit, castGUID, spellID)
if unit ~= "player" then return end
local config = YaHT.db.profile
if self.mainFrame.casting then
self.mainFrame.casting = nil
return
end
if spellID == 75 then
if self.mainFrame.shooting then
self.mainFrame.lastshot = GetTime()
self.mainFrame.multishooting = nil
self.mainFrame.SwingStart = nil
self.mainFrame.ignoregcd = nil
if self.mainFrame.newswingtime then
self.mainFrame.swingtime = self.mainFrame.newswingtime
self.mainFrame.newswingtime = nil
end
self.mainFrame.texture:SetVertexColor(config.timercolor.r,config.timercolor.g,config.timercolor.b)
movementDelay = 0
end
end
end
function YaHT:UNIT_RANGEDDAMAGE()
local castingBarText = CastingBarFrame.Text:GetText()
if castingBarText and ( castingBarText == AimedShot or castingBarText == MultiShot ) then
CastingBarFrame.maxValue = min(CastingBarFrame.maxValue, CastingBarFrame.baseMaxValue * GetSpeedModifier())
CastingBarFrame:SetMinMaxValues(0, CastingBarFrame.maxValue)
end
self.mainFrame.newswingtime = UnitRangedDamage("player") - SWING_TIME
end
function YaHT:Print(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cFF2150C2YaHT|cFFFFFFFF: ".. msg)
end
SLASH_YAHT1 = "/yaht"
SLASH_YAHT2 = "/huntertimer"
SLASH_YAHT3 = "/yetanotherhuntertimer"
SlashCmdList["YAHT"] = function(msg)
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
AceConfigDialog:Open("YaHT")
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_LOGIN")
frame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
frame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED")
frame:RegisterEvent("START_AUTOREPEAT_SPELL")
frame:RegisterEvent("STOP_AUTOREPEAT_SPELL")
frame:RegisterEvent("UNIT_RANGEDDAMAGE")
frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
frame:SetScript("OnEvent", function(self, event, ...)
if( event == "PLAYER_LOGIN" ) then
YaHT:OnInitialize()
self:UnregisterEvent("PLAYER_LOGIN")
else
YaHT[event](YaHT, ...)
end
end)