Skip to content

Commit 1c42f68

Browse files
committed
Rebuilt ranged haste calculation
1 parent 0c10567 commit 1c42f68

File tree

8 files changed

+87
-78
lines changed

8 files changed

+87
-78
lines changed

Lib/Aura.lua

Lines changed: 15 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,3 @@
1-
local resetTooltip = (function()
2-
local tooltip = nil
3-
local createTooltip = function()
4-
-- https://wowwiki-archive.fandom.com/wiki/UIOBJECT_GameTooltip
5-
tt = CreateFrame("GameTooltip", "QuiverAuraScanningTooltip", nil, "GameTooltipTemplate")
6-
tt:SetScript("OnHide", function() tt:SetOwner(WorldFrame, "ANCHOR_NONE") end)
7-
tt:Hide()
8-
tt:SetFrameStrata("Tooltip")
9-
return tt
10-
end
11-
return function()
12-
if not tooltip then tooltip = createTooltip() end
13-
tooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
14-
return tooltip
15-
end
16-
end)()
17-
18-
-- 10% at full hp, to a max of 30% at 40% hp
19-
-- That's a line with equation f(hp)= (130-hp) / 3, but capped at 30%
20-
local getTrollBerserkBonus = function()
21-
local percent = UnitHealth("player") / UnitHealthMax("player")
22-
return math.min(0.3, (1.30 - percent) / 3.0)
23-
end
24-
25-
--[[
26-
UnitBuff indexes from 1.
27-
GetPlayerBuffTexture indexes from 0.
28-
They also don't have the same iteration order.
29-
Haven't found a reason to use one over the other. ]]
30-
Quiver_Lib_Aura_GetRangedAttackSpeedMultiplier = function()
31-
local speed = 1.0
32-
for i=1,QUIVER.Buff_Cap do
33-
local texture = UnitBuff("player", i)
34-
if texture == QUIVER.Icon.CurseOfTongues then
35-
speed = speed * 0.5
36-
-- Unsure if it's safe to remove the wrong one. Maybe that would break other servers.
37-
elseif texture == QUIVER.Icon.NaxxTrinket
38-
or texture == QUIVER.Icon.NaxxTrinketWrong
39-
then
40-
speed = speed * 1.2
41-
elseif texture == QUIVER.Icon.Quickshots then
42-
speed = speed * 1.3
43-
elseif texture == QUIVER.Icon.RapidFire then
44-
speed = speed * 1.4
45-
elseif texture == QUIVER.Icon.TrollBerserk then
46-
speed = speed * (1.0 + getTrollBerserkBonus())
47-
end
48-
end
49-
return speed
50-
end
51-
521
-- This doesn't work for duplicate textures (ex. cheetah + zg mount).
532
-- For those you have to scan by name using the GameTooltip.
543
Quiver_Lib_Aura_GetIsActiveTimeLeftByTexture = function(targetTexture)
@@ -64,21 +13,24 @@ Quiver_Lib_Aura_GetIsActiveTimeLeftByTexture = function(targetTexture)
6413
return false, 0
6514
end
6615

67-
Quiver_Lib_Aura_GetIsBuffActive = function(buffname)
68-
local tooltip = resetTooltip()
69-
for i=0,QUIVER.Buff_Cap do
70-
local buffIndex, isCancellable = GetPlayerBuff(i, "HELPFUL|PASSIVE")
71-
if buffIndex >= 0 then
72-
tooltip:ClearLines()
73-
tooltip:SetPlayerBuff(buffIndex)
74-
local fs1 = _G["QuiverAuraScanningTooltipTextLeft1"]
75-
if fs1 and fs1:GetText() == buffname then
76-
return true
16+
Quiver_Lib_Aura_GetIsBuffActive = (function()
17+
local resetTooltip = Quiver_Lib_Tooltip_Factory("QuiverAuraScanningTooltip")
18+
return function(buffname)
19+
local tooltip = resetTooltip()
20+
for i=0,QUIVER.Buff_Cap do
21+
local buffIndex, isCancellable = GetPlayerBuff(i, "HELPFUL|PASSIVE")
22+
if buffIndex >= 0 then
23+
tooltip:ClearLines()
24+
tooltip:SetPlayerBuff(buffIndex)
25+
local fs1 = _G["QuiverAuraScanningTooltipTextLeft1"]
26+
if fs1 and fs1:GetText() == buffname then
27+
return true
28+
end
7729
end
7830
end
31+
return false
7932
end
80-
return false
81-
end
33+
end)()
8234

8335
-- This works great. Don't delete because I'm sure it will be useful in the future.
8436
--[[

Lib/Spellbook.lua

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
-- TODO parse spellbook in case a patch changes them, instead of hard-coding here
12
local HUNTER_CASTABLE_SHOTS = {
23
[QUIVER_T.Spellbook.Aimed_Shot] = 3.0,
3-
[QUIVER_T.Spellbook.Multi_Shot] = 0.5,
4-
[QUIVER_T.Spellbook.Trueshot] = 1.3,
4+
[QUIVER_T.Spellbook.Multi_Shot] = 0.0,
5+
[QUIVER_T.Spellbook.Trueshot] = 1.0,
56
}
67

78
local _HUNTER_INSTANT_SHOTS = {
@@ -14,6 +15,46 @@ local _HUNTER_INSTANT_SHOTS = {
1415
QUIVER_T.Spellbook.Wyvern_Sting,
1516
}
1617

18+
local calcRangedWeaponSpeedBase = (function()
19+
local resetTooltip = Quiver_Lib_Tooltip_Factory("QuiverRangedWeaponScanningTooltip")
20+
21+
-- Might be cachable. GetInventoryItemLink("Player", slot#) returns a link, ex. [name]
22+
-- Weapon name always appears at line TextLeft1
23+
return function()
24+
local tooltip = resetTooltip()
25+
tooltip:ClearLines()
26+
tooltip:SetInventoryItem("player", 18)-- ranged weapon slot
27+
28+
for i=1, tooltip:NumLines() do
29+
local fs = _G["QuiverRangedWeaponScanningTooltipTextRight"..i]
30+
local text = fs and fs:GetText()
31+
if text ~= nil then
32+
local _, _, speed = string.find(text, "Speed (%d+%.%d+)")
33+
if speed ~= nil then
34+
local parsed = tonumber(speed)
35+
if parsed ~= nil then
36+
return parsed
37+
end
38+
end
39+
end
40+
end
41+
end
42+
end)()
43+
44+
Quiver_Lib_Spellbook_CalcCastTime = function(spellName)
45+
local baseTime = HUNTER_CASTABLE_SHOTS[spellName]
46+
local _,_, msLatency = GetNetStats()
47+
local start = GetTime() + msLatency / 1000
48+
49+
local speedCurrent = UnitRangedDamage("player")
50+
local speedBase = calcRangedWeaponSpeedBase()
51+
local speedMultiplier = speedCurrent / speedBase
52+
53+
-- https://www.mmo-champion.com/content/2188-Patch-4-0-6-Feb-22-Hotfixes-Blue-Posts-Artworks-Comic
54+
local casttime = 0.5 + baseTime * speedMultiplier
55+
return casttime, start
56+
end
57+
1758
local GetIsSpellLearned = function(spellName)
1859
local i = 0
1960
while true do
@@ -66,14 +107,6 @@ Quiver_Lib_Spellbook_TryFindTexture = function(nameSeek)
66107
end
67108
end
68109

69-
Quiver_Lib_Spellbook_GetCastTime = function(spellName)
70-
local baseTime = HUNTER_CASTABLE_SHOTS[spellName]
71-
local _,_, msLatency = GetNetStats()
72-
local start = GetTime() + msLatency / 1000
73-
local casttime = baseTime / Quiver_Lib_Aura_GetRangedAttackSpeedMultiplier()
74-
return casttime, start
75-
end
76-
77110
Quiver_Lib_Spellbook_GetIsSpellCastableShot = function(spellName)
78111
for name, _castTime in HUNTER_CASTABLE_SHOTS do
79112
if spellName == name then return true end

Lib/Tooltip.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
local createTooltip = function(frameName)
2+
-- https://wowwiki-archive.fandom.com/wiki/UIOBJECT_GameTooltip
3+
local tt = CreateFrame("GameTooltip", frameName, nil, "GameTooltipTemplate")
4+
tt:SetScript("OnHide", function() tt:SetOwner(WorldFrame, "ANCHOR_NONE") end)
5+
tt:Hide()
6+
tt:SetFrameStrata("Tooltip")
7+
return tt
8+
end
9+
10+
--[[ [ Quiver_Lib_Tooltip_Factory ]
11+
@description Returns a function that clears the tooltip and gets a reference to it.
12+
@param frameName string name for tooltip element
13+
]]
14+
Quiver_Lib_Tooltip_Factory = function(frameName)
15+
local tooltip = nil
16+
return function()
17+
if not tooltip then tooltip = createTooltip(frameName) end
18+
tooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
19+
return tooltip
20+
end
21+
end

Modules/AutoShotTimer.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ local onSpellcast = function(spellName)
191191
if isShooting and (not isReloading) then
192192
timeStartShootOrReload = GetTime()
193193
end
194-
castTime, timeStartCast = Quiver_Lib_Spellbook_GetCastTime(spellName)
194+
castTime, timeStartCast = Quiver_Lib_Spellbook_CalcCastTime(spellName)
195195
end
196196

197197
local handleEvent = function()

Modules/Castbar.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ end
8383
-- ************ Custom Event Handlers ************
8484
local displayTime = function(current)
8585
if current < 0 then current = 0 end
86-
frame.SpellTime:SetText(string.format("%.1f / %.1f", current, castTime))
86+
frame.SpellTime:SetText(string.format("%.1f / %.2f", current, castTime))
8787
end
8888
local onSpellcast = function(spellName)
8989
if isCasting then return end
9090
isCasting = true
91-
castTime, timeStartCasting = Quiver_Lib_Spellbook_GetCastTime(spellName)
91+
castTime, timeStartCasting = Quiver_Lib_Spellbook_CalcCastTime(spellName)
9292
frame.SpellName:SetText(spellName)
9393
frame.Castbar:SetWidth(1)
9494
displayTime(0)

Modules/pfUIPlugins.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Quiver_Module_pfUITurtleTrueshot = function()
1717
-- Somehow player isn't defined, but all the other locals from pfUI work
1818
local player = UnitName("player")
1919
if begin then
20-
local castTime, start = Quiver_Lib_Spellbook_GetCastTime(QUIVER_T.Spellbook.Trueshot)
20+
local castTime, start = Quiver_Lib_Spellbook_CalcCastTime(QUIVER_T.Spellbook.Trueshot)
2121
local duration = duration or (castTime * 1000)
2222
-- add cast action to the database
2323
libcast.db[player].cast = trueshotName

Quiver.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ _G.Quiver_Modules = {
99
}
1010

1111
local savedVariablesRestore = function()
12+
-- If first time running Quiver, then savedVars are nil, so make defaults
1213
Quiver_Store.IsLockedFrames = Quiver_Store.IsLockedFrames == true
1314
Quiver_Store.ModuleEnabled = Quiver_Store.ModuleEnabled or {}
1415
Quiver_Store.ModuleStore = Quiver_Store.ModuleStore or {}
1516
for _k, v in _G.Quiver_Modules do
1617
Quiver_Store.ModuleEnabled[v.Id] = Quiver_Store.ModuleEnabled[v.Id] ~= false
1718
Quiver_Store.ModuleStore[v.Id] = Quiver_Store.ModuleStore[v.Id] or {}
19+
-- Loading saved variables into each module gives them a chance to set their own defaults.
1820
v.OnSavedVariablesRestore(Quiver_Store.ModuleStore[v.Id])
1921
end
2022
end

Quiver.toc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
## Title: Quiver - |cff00ff00Hunter
33
## Notes: A collection of hunter utilities.
44
## Author: SabineWren, 2022-2023
5-
## Version: 2.6.1
5+
## Version: 2.6.2
66
## SavedVariables: Quiver_Store
77

88
Lib\F.lua
99
Constants.lua
1010
Locale\enUS.lua
1111

12+
Lib\Tooltip.lua
1213
Lib\Aura.lua
1314
Lib\Print.lua
1415
Lib\Spellbook.lua

0 commit comments

Comments
 (0)