From 9b2001114d84164528ca59959e9e5f54e47c005e Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Thu, 21 May 2026 03:20:13 -0500 Subject: [PATCH] dedup shot-haste loops behind libcast.ApplyShotHaste The three customcast handlers (Aimed Shot, Multi-Shot, Steady Shot) each iterated 1..32 UnitBuff slots checking the same four icon paths for haste-providing buffs. Lifted into libcast.ApplyShotHaste which iterates the populated auras once via C_UnitAuras.GetUnitAuras and reads from a single SHOT_HASTE lookup table. Three loop copies collapse to one helper. Kept texture-keyed matching (rather than spellID) because the Naxx trinket and Quick Shots procs have spell-ID variants across server flavors but stable icons. --- libs/libcast.lua | 61 +++++++++++++++++++----------------------- modules/turtle-wow.lua | 19 +------------ 2 files changed, 28 insertions(+), 52 deletions(-) diff --git a/libs/libcast.lua b/libs/libcast.lua index 2912df07..2b22026e 100644 --- a/libs/libcast.lua +++ b/libs/libcast.lua @@ -438,26 +438,35 @@ end) local aimedshot = L["customcast"]["AIMEDSHOT"] local multishot = L["customcast"]["MULTISHOT"] +-- Shot-timer haste lookup. Keyed by icon path because some of these buffs have +-- spell-ID variants across server flavors but stable icons. Berserking is the +-- variable Troll-racial calculation (more haste at lower HP); other entries are +-- flat duration multipliers. +local SHOT_HASTE = { + ["Interface\\Icons\\Racial_Troll_Berserk"] = "berserking", + ["Interface\\Icons\\Ability_Hunter_RunningShot"] = 1.4, + ["Interface\\Icons\\Ability_Warrior_InnerRage"] = 1.3, + ["Interface\\Icons\\Inv_Trinket_Naxxramas04"] = 1.2, +} + +function libcast.ApplyShotHaste(duration) + for _, a in ipairs(C_UnitAuras.GetUnitAuras("player", "HELPFUL")) do + local mult = SHOT_HASTE[a.icon] + if mult == "berserking" then + local hp = UnitHealth("player") / UnitHealthMax("player") + local berserk = hp >= 0.40 and (1.30 - hp) / 3 or 0.3 + duration = duration / (1 + berserk) + elseif mult then + duration = duration / mult + end + end + return duration +end + libcast.customcast = {} libcast.customcast[strlower(aimedshot)] = function(begin, duration) if begin then - local duration = duration or 3000 - - for i=1,32 do - if UnitBuff("player", i) == "Interface\\Icons\\Racial_Troll_Berserk" then - local berserk = 0.3 - if((UnitHealth("player")/UnitHealthMax("player")) >= 0.40) then - berserk = (1.30 - (UnitHealth("player") / UnitHealthMax("player"))) / 3 - end - duration = duration / (1 + berserk) - elseif UnitBuff("player", i) == "Interface\\Icons\\Ability_Hunter_RunningShot" then - duration = duration / 1.4 - elseif UnitBuff("player", i) == "Interface\\Icons\\Ability_Warrior_InnerRage" then - duration = duration / 1.3 - elseif UnitBuff("player", i) == "Interface\\Icons\\Inv_Trinket_Naxxramas04" then - duration = duration / 1.2 - end - end + local duration = libcast.ApplyShotHaste(duration or 3000) local _,_, lag = GetNetStats() local start = GetTime() + lag/1000 @@ -482,23 +491,7 @@ end libcast.customcast[strlower(multishot)] = function(begin, duration) if begin then - local duration = duration or 500 - - for i=1,32 do - if UnitBuff("player", i) == "Interface\\Icons\\Racial_Troll_Berserk" then - local berserk = 0.3 - if((UnitHealth("player")/UnitHealthMax("player")) >= 0.40) then - berserk = (1.30 - (UnitHealth("player") / UnitHealthMax("player"))) / 3 - end - duration = duration / (1 + berserk) - elseif UnitBuff("player", i) == "Interface\\Icons\\Ability_Hunter_RunningShot" then - duration = duration / 1.4 - elseif UnitBuff("player", i) == "Interface\\Icons\\Ability_Warrior_InnerRage" then - duration = duration / 1.3 - elseif UnitBuff("player", i) == "Interface\\Icons\\Inv_Trinket_Naxxramas04" then - duration = duration / 1.2 - end - end + local duration = libcast.ApplyShotHaste(duration or 500) local _,_, lag = GetNetStats() local start = GetTime() + lag/1000 diff --git a/modules/turtle-wow.lua b/modules/turtle-wow.lua index c592b8cb..ce45b789 100644 --- a/modules/turtle-wow.lua +++ b/modules/turtle-wow.lua @@ -331,24 +331,7 @@ pfUI:RegisterModule("turtle-wow", "vanilla", function () libcast.customcast[strlower(trueshot)] = function(begin, duration) if begin then -- cast time is 1sec, however it takes 1.4sec to fire in average - local duration = duration or 1400 - - for i=1,32 do - if UnitBuff("player", i) == "Interface\\Icons\\Racial_Troll_Berserk" then - local berserk = 0.3 - if((UnitHealth("player")/UnitHealthMax("player")) >= 0.40) then - berserk = (1.30 - (UnitHealth("player") / UnitHealthMax("player"))) / 3 - end - - duration = duration / (1 + berserk) - elseif UnitBuff("player", i) == "Interface\\Icons\\Ability_Hunter_RunningShot" then - duration = duration / 1.4 - elseif UnitBuff("player", i) == "Interface\\Icons\\Ability_Warrior_InnerRage" then - duration = duration / 1.3 - elseif UnitBuff("player", i) == "Interface\\Icons\\Inv_Trinket_Naxxramas04" then - duration = duration / 1.2 - end - end + local duration = libcast.ApplyShotHaste(duration or 1400) local _,_, lag = GetNetStats() local start = GetTime() + lag/1000