diff --git a/scripts/subtlety.lua b/scripts/subtlety.lua index b8a641e..770186c 100644 --- a/scripts/subtlety.lua +++ b/scripts/subtlety.lua @@ -1443,13 +1443,119 @@ BuildAPL:AddSpell( ):SetTarget(Target) ) + +-- GetTimeToShurikenTornado +--[[ + spec:RegisterStateTable( "time_to_sht", setmetatable( {}, { + __index = function( t, k ) + local n = tonumber( k ) + n = n - ( n % 1 ) + + if not n or n > 5 then return 3600 end + + if n <= swings_since_sht then return 0 end + + local mh_speed = swings.mainhand_speed + local mh_next = ( swings.mainhand > now - 3 ) and ( swings.mainhand + mh_speed ) or now + ( mh_speed * 0.5 ) + + local oh_speed = swings.offhand_speed + local oh_next = ( swings.offhand > now - 3 ) and ( swings.offhand + oh_speed ) or now + + table.wipe( sht ) + + if mh_speed and mh_speed > 0 then + for i = 1, 4 do + insert( sht, mh_next + ( i * mh_speed ) ) + end + end + + if oh_speed and oh_speed > 0 then + for i = 1, 4 do + insert( sht, oh_next + ( i * oh_speed ) ) + end + end + + local i = 1 + + while( sht[i] ) do + if sht[i] < last_shadow_techniques + 3 then + table.remove( sht, i ) + else + i = i + 1 + end + end + + if #sht > 0 and n - swings_since_sht < #sht then + table.sort( sht ) + return max( 0, sht[ n - swings_since_sht ] - query_time ) + else + return 3600 + end + end +} ) ) +]] +function GetTimeToShurikenTornado(unit, n) + local now = GetTime() + local sht = {} + local swings = unit:GetSwingTimers() + + if not unit.swings_since_sht then + unit.swings_since_sht = 0 + end + + if not unit.last_shadow_techniques then + unit.last_shadow_techniques = 0 + end + + if n <= unit.swings_since_sht then + return 0 + end + + local mh_speed = swings[1] + local mh_next = (unit.last_mh > now - 3) and (unit.last_mh + mh_speed) or now + (mh_speed * 0.5) + + local oh_speed = swings[2] + local oh_next = (unit.last_oh > now - 3) and (unit.last_oh + oh_speed) or now + + table.wipe(sht) + + if mh_speed and mh_speed > 0 then + for i = 1, 4 do + table.insert(sht, mh_next + (i * mh_speed)) + end + end + + if oh_speed and oh_speed > 0 then + for i = 1, 4 do + table.insert(sht, oh_next + (i * oh_speed)) + end + end + + local i = 1 + + while (sht[i]) do + if sht[i] < unit.last_shadow_techniques + 3 then + table.remove(sht, i) + else + i = i + 1 + end + end + + if #sht > 0 and n - unit.swings_since_sht < #sht then + table.sort(sht) + return math.max(0, sht[n - unit.swings_since_sht] - now) + else + return 3600 + end +end + -- # Build immediately unless the next CP is Animacharged and we won't cap energy waiting for it. -- actions.build+=/variable,name=anima_helper,value=!talent.echoing_reprimand.enabled|!(variable.is_next_cp_animacharged&(time_to_sht.3.plus<0.5|time_to_sht.4.plus<1)&energy<60) BuildAPL:AddVariable( 'anima_helper', function() return not EchoingReprimand:IsKnown() or ((not (DefaultAPL:GetVariable('is_next_cp_animacharged') and - (Player:GetTimeToShurikenTornado(3) < 0.5 or Player:GetTimeToShurikenTornado(4) < 1) and + (GetTimeToShurikenTornado(Player, 3) < 0.5 or GetTimeToShurikenTornado(Player, 4) < 1) and Player:GetPower() < 60))) end ) diff --git a/src/ClassMagic/ClassMagic.lua b/src/ClassMagic/ClassMagic.lua index 8b6f747..3a9ec61 100644 --- a/src/ClassMagic/ClassMagic.lua +++ b/src/ClassMagic/ClassMagic.lua @@ -2,6 +2,8 @@ local ClassMagic = {} ClassMagic.__index = ClassMagic +---@param Class table +---@param key string ---@return any function ClassMagic:Resolve(Class, key) if Class[key] or Class[key] == false then diff --git a/src/Command/Command.lua b/src/Command/Command.lua index f8c69fb..0e04436 100644 --- a/src/Command/Command.lua +++ b/src/Command/Command.lua @@ -3,10 +3,12 @@ local Command = {} Command.__index = Command +---@return string function Command:__tostring() return "Command(" .. self.command .. ")" end +---@param prefix string function Command:New(prefix) local self = setmetatable({}, Command) @@ -21,6 +23,10 @@ function Command:New(prefix) return self end +---@param command string +---@param helpmsg string +---@param cb fun(args: table) +---@return nil function Command:Register(command, helpmsg, cb) self.commands[command] = { helpmsg = helpmsg, @@ -28,6 +34,8 @@ function Command:Register(command, helpmsg, cb) } end +---@param msg string +---@return table function Command:Parse(msg) local args = {} for arg in msg:gmatch("%S+") do @@ -37,6 +45,8 @@ function Command:Parse(msg) return args end +---@param msg string +---@return nil function Command:OnCommand(msg) local args = self:Parse(msg) @@ -51,6 +61,7 @@ function Command:OnCommand(msg) end end +---@return nil function Command:PrintHelp() for k, v in pairs(self.commands) do print('/' .. self.prefix .. ' ' .. k .. " - " .. v.helpmsg) diff --git a/src/EventManager/EventManager.lua b/src/EventManager/EventManager.lua index b880614..409a445 100644 --- a/src/EventManager/EventManager.lua +++ b/src/EventManager/EventManager.lua @@ -10,6 +10,7 @@ local EventManager = { EventManager.__index = EventManager -- Constructor +---@return EventManager function EventManager:New() local self = setmetatable({}, EventManager) self.events = {} @@ -31,6 +32,9 @@ function EventManager:New() end -- Register an event +---@param event string +---@param handler fun(...) +---@return nil function EventManager:RegisterEvent(event, handler) if not self.events[event] then self.events[event] = {} @@ -40,6 +44,9 @@ function EventManager:RegisterEvent(event, handler) end -- Register a wow event +---@param event string +---@param handler fun(...) +---@return nil function EventManager:RegisterWoWEvent(event, handler) if not self.wowEventHandlers[event] then self.wowEventHandlers[event] = {} @@ -50,6 +57,9 @@ function EventManager:RegisterWoWEvent(event, handler) end -- Trigger an event +---@param event string +---@param ... any +---@return nil function EventManager:TriggerEvent(event, ...) if self.events[event] then for _, handler in pairs(self.events[event]) do diff --git a/src/Unit/Unit.lua b/src/Unit/Unit.lua index 71b7359..4815ad9 100644 --- a/src/Unit/Unit.lua +++ b/src/Unit/Unit.lua @@ -759,109 +759,4 @@ function Unit:WatchForSwings() end) end --- GetTimeToShurikenTornado ---[[ - spec:RegisterStateTable( "time_to_sht", setmetatable( {}, { - __index = function( t, k ) - local n = tonumber( k ) - n = n - ( n % 1 ) - - if not n or n > 5 then return 3600 end - - if n <= swings_since_sht then return 0 end - - local mh_speed = swings.mainhand_speed - local mh_next = ( swings.mainhand > now - 3 ) and ( swings.mainhand + mh_speed ) or now + ( mh_speed * 0.5 ) - - local oh_speed = swings.offhand_speed - local oh_next = ( swings.offhand > now - 3 ) and ( swings.offhand + oh_speed ) or now - - table.wipe( sht ) - - if mh_speed and mh_speed > 0 then - for i = 1, 4 do - insert( sht, mh_next + ( i * mh_speed ) ) - end - end - - if oh_speed and oh_speed > 0 then - for i = 1, 4 do - insert( sht, oh_next + ( i * oh_speed ) ) - end - end - - local i = 1 - - while( sht[i] ) do - if sht[i] < last_shadow_techniques + 3 then - table.remove( sht, i ) - else - i = i + 1 - end - end - - if #sht > 0 and n - swings_since_sht < #sht then - table.sort( sht ) - return max( 0, sht[ n - swings_since_sht ] - query_time ) - else - return 3600 - end - end -} ) ) -]] -function Unit:GetTimeToShurikenTornado(n) - local now = GetTime() - local sht = {} - local swings = self:GetSwingTimers() - - if not self.swings_since_sht then - self.swings_since_sht = 0 - end - - if not self.last_shadow_techniques then - self.last_shadow_techniques = 0 - end - - if n <= self.swings_since_sht then - return 0 - end - - local mh_speed = swings[1] - local mh_next = (self.last_mh > now - 3) and (self.last_mh + mh_speed) or now + (mh_speed * 0.5) - - local oh_speed = swings[2] - local oh_next = (self.last_oh > now - 3) and (self.last_oh + oh_speed) or now - - table.wipe(sht) - - if mh_speed and mh_speed > 0 then - for i = 1, 4 do - table.insert(sht, mh_next + (i * mh_speed)) - end - end - - if oh_speed and oh_speed > 0 then - for i = 1, 4 do - table.insert(sht, oh_next + (i * oh_speed)) - end - end - - local i = 1 - - while (sht[i]) do - if sht[i] < self.last_shadow_techniques + 3 then - table.remove(sht, i) - else - i = i + 1 - end - end - - if #sht > 0 and n - self.swings_since_sht < #sht then - table.sort(sht) - return math.max(0, sht[n - self.swings_since_sht] - now) - else - return 3600 - end -end - return Unit