Revert "fixed swing timer vanishing"

This reverts commit b422a01039.
This commit is contained in:
Meow
2026-02-19 17:53:26 +01:00
parent b422a01039
commit 9e25bf6d2b
+25 -32
View File
@@ -166,35 +166,23 @@ pfUI:RegisterModule("swingtimer", "vanilla:tbc", function ()
UpdateMovable(pfUI.swingtimer.mainhand)
-- inventoryType 13 = INVTYPE_WEAPON (one-hand), 22 = INVTYPE_WEAPONOFFHAND
-- Shields, held-in-offhand, ranged etc. do NOT produce OH swings.
-- Uses GetItemStatsField() (DBC lookup) instead of GetItemInfo() (item cache)
-- so it works correctly on first login before the item cache is populated.
local OH_SWINGABLE = { [13] = true, [22] = true }
local function HasOffhandWeapon()
if not GetEquippedItem or not GetItemStatsField then return false end
local item = GetEquippedItem("player", 17)
if not item or not item.itemId or item.itemId == 0 then return false end
local invType = GetItemStatsField(item.itemId, "inventoryType")
return OH_SWINGABLE[invType] == true
end
-- VERSION B TEST: HasOffhandWeapon() removed.
-- The original used GetItemInfo() to detect OH weapon type, but GetItemInfo()
-- returns nil on first login before the item cache is populated, causing
-- offhand.speed to stay 0. Now we just read offhandAttackTime directly,
-- same as the old working version.
local function UpdateWeaponSpeeds()
if not GetUnitField then return end
local mhSpeed = GetUnitField("player", "baseAttackTime")
local ohSpeed = GetUnitField("player", "offhandAttackTime")
if mhSpeed and mhSpeed > 0 then
swingState.mainhand.speed = mhSpeed / 1000
end
if HasOffhandWeapon() then
local ohSpeed = GetUnitField("player", "offhandAttackTime")
if ohSpeed and ohSpeed > 0 then
swingState.offhand.speed = ohSpeed / 1000
else
swingState.offhand.speed = 0
end
if ohSpeed and ohSpeed > 0 then
swingState.offhand.speed = ohSpeed / 1000
else
swingState.offhand.speed = 0
end
@@ -203,8 +191,11 @@ pfUI:RegisterModule("swingtimer", "vanilla:tbc", function ()
local function StartSwing(isOffhand)
local now = GetTime()
-- always refresh speeds to catch haste buffs/debuffs
UpdateWeaponSpeeds()
-- dual-wield guard: if MH swing just started (<100ms ago) and this isn't
-- flagged as offhand, it's likely an OH event with missing flag
if not isOffhand and swingState.offhand.speed > 0 then
local mhAge = now - (swingState.mainhand.nextSwing - swingState.mainhand.speed)
if swingState.mainhand.swinging and mhAge > 0 and mhAge < 0.1 then
@@ -244,9 +235,7 @@ pfUI:RegisterModule("swingtimer", "vanilla:tbc", function ()
if remaining <= 0 then
swingState.mainhand.swinging = false
if not UnitExists("target") then
pfUI.swingtimer.mainhand:Hide()
end
pfUI.swingtimer.mainhand:Hide()
else
local progress = 1 - (remaining / swingState.mainhand.speed)
pfUI.swingtimer.mainhand:SetValue(progress)
@@ -263,9 +252,7 @@ pfUI:RegisterModule("swingtimer", "vanilla:tbc", function ()
if remaining <= 0 then
swingState.offhand.swinging = false
if not UnitExists("target") then
pfUI.swingtimer.offhand:Hide()
end
pfUI.swingtimer.offhand:Hide()
else
local progress = 1 - (remaining / swingState.offhand.speed)
pfUI.swingtimer.offhand:SetValue(progress)
@@ -290,6 +277,7 @@ pfUI:RegisterModule("swingtimer", "vanilla:tbc", function ()
events:RegisterEvent("UNIT_INVENTORY_CHANGED")
events:RegisterEvent("PLAYER_REGEN_DISABLED")
events:RegisterEvent("PLAYER_REGEN_ENABLED")
events:RegisterEvent("PLAYER_TARGET_CHANGED")
events:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
events:RegisterEvent("UNIT_DIED")
events:RegisterEvent("SPELL_QUEUE_EVENT")
@@ -302,12 +290,12 @@ pfUI:RegisterModule("swingtimer", "vanilla:tbc", function ()
pfUI.swingtimer:Hide()
end
-- Cache player GUID via UnitExists() which returns GUID on Turtle WoW
local playerGUID = UnitExists("player")
local playerGUID = nil
events:SetScript("OnEvent", function()
if event == "AUTO_ATTACK_SELF" then
local hitInfo = arg4 or 0
-- HITINFO_NOACTION: server did not advance the swing clock, ignore
if bit.band(hitInfo, HITINFO_NOACTION) ~= 0 then return end
local isOffhand = bit.band(hitInfo, HITINFO_LEFTSWING) ~= 0
StartSwing(isOffhand)
@@ -347,7 +335,7 @@ pfUI:RegisterModule("swingtimer", "vanilla:tbc", function ()
elseif event == "PLAYER_ENTERING_WORLD" then
local _, class = UnitClass("player")
isWarrior = (class == "WARRIOR")
playerGUID = UnitExists("player")
playerGUID = UnitGUID and UnitGUID("player") or nil
UpdateWeaponSpeeds()
RebuildQueueSlotCache()
@@ -370,11 +358,16 @@ pfUI:RegisterModule("swingtimer", "vanilla:tbc", function ()
hsQueued = false
cleaveQueued = false
elseif event == "PLAYER_TARGET_CHANGED" then
if not UnitExists("target") or UnitIsDead("target") then
ResetSwingTimers()
end
elseif event == "UNIT_DIED" then
-- Only reset if the player themselves died
local guid = arg1
if not guid then return end
if guid == playerGUID then
local targetGUID = UnitExists("target") and UnitGUID and UnitGUID("target") or nil
if guid == targetGUID or guid == playerGUID then
ResetSwingTimers()
end
end