Ralgathor / LibClassicSwingTimerAPI

GNU General Public License v3.0
4 stars 5 forks source link

Swing timer inaccurate for druids casting spells that break form #44

Closed Korbrawr closed 1 year ago

Korbrawr commented 1 year ago

Expected behavior: When a druid casts a spell which resets the swing timer and takes them out of form, the next swing will occur with the timing of the attack speed of the weapon in caster form. For example, if a feral druid is in cat form with a 3.6 speed weapon equipped, and they cast gift of the wild, the next attack will occur 3.6 seconds (hasted) later. SWING_TIMER_START should provide 3.6 speed and expiration time of 3.6 + now.

Current behavior: When casting a spell which resets the swing timer and takes a druid out of cat form, SWING_TIMER_START provides a speed of 1.0 and an expiration time of 1 + now. Once the expected expiration time occurs, a SWING_TIMER_UPDATE event occurs with the correct weapon speed, but with the same expiration time originally provided (1 + the time of the cast which took them out of form), which is in the past.

Proposed solution: For druids, spell which take them out of form can send a SWING_TIMER_START event immediately after the event is resolved by using C_Timer.After() to schedule a unit:SwingStart. Adding the following two lines immediately before line 495 corrects the issue:

elseif unit.class == "DRUID" then
C_Timer.After(0, function() unit:SwingStart("mainhand", now, true) end)

This works as the C_Timer evaluates the frame after the spellcast event resolves, and the correct attack speed can be determined from UnitAttackSpeed().

Ralgathor commented 1 year ago

@Korbrawr Fixed by your proposed PR and released in version 2.0.2. Thanks for your contribution.