Eventmanager/classmagic/command emmy lua docs, move some stuff out of Unit

4n0n-patch-1
4n0n 2 years ago
parent 7d1b7560fa
commit c91a522b6b
  1. 108
      scripts/subtlety.lua
  2. 2
      src/ClassMagic/ClassMagic.lua
  3. 11
      src/Command/Command.lua
  4. 10
      src/EventManager/EventManager.lua
  5. 105
      src/Unit/Unit.lua

@ -1443,13 +1443,119 @@ BuildAPL:AddSpell(
):SetTarget(Target) ):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. -- # 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) -- 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( BuildAPL:AddVariable(
'anima_helper', 'anima_helper',
function() function()
return not EchoingReprimand:IsKnown() or ((not (DefaultAPL:GetVariable('is_next_cp_animacharged') and 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))) Player:GetPower() < 60)))
end end
) )

@ -2,6 +2,8 @@
local ClassMagic = {} local ClassMagic = {}
ClassMagic.__index = ClassMagic ClassMagic.__index = ClassMagic
---@param Class table
---@param key string
---@return any ---@return any
function ClassMagic:Resolve(Class, key) function ClassMagic:Resolve(Class, key)
if Class[key] or Class[key] == false then if Class[key] or Class[key] == false then

@ -3,10 +3,12 @@
local Command = {} local Command = {}
Command.__index = Command Command.__index = Command
---@return string
function Command:__tostring() function Command:__tostring()
return "Command(" .. self.command .. ")" return "Command(" .. self.command .. ")"
end end
---@param prefix string
function Command:New(prefix) function Command:New(prefix)
local self = setmetatable({}, Command) local self = setmetatable({}, Command)
@ -21,6 +23,10 @@ function Command:New(prefix)
return self return self
end end
---@param command string
---@param helpmsg string
---@param cb fun(args: table)
---@return nil
function Command:Register(command, helpmsg, cb) function Command:Register(command, helpmsg, cb)
self.commands[command] = { self.commands[command] = {
helpmsg = helpmsg, helpmsg = helpmsg,
@ -28,6 +34,8 @@ function Command:Register(command, helpmsg, cb)
} }
end end
---@param msg string
---@return table
function Command:Parse(msg) function Command:Parse(msg)
local args = {} local args = {}
for arg in msg:gmatch("%S+") do for arg in msg:gmatch("%S+") do
@ -37,6 +45,8 @@ function Command:Parse(msg)
return args return args
end end
---@param msg string
---@return nil
function Command:OnCommand(msg) function Command:OnCommand(msg)
local args = self:Parse(msg) local args = self:Parse(msg)
@ -51,6 +61,7 @@ function Command:OnCommand(msg)
end end
end end
---@return nil
function Command:PrintHelp() function Command:PrintHelp()
for k, v in pairs(self.commands) do for k, v in pairs(self.commands) do
print('/' .. self.prefix .. ' ' .. k .. " - " .. v.helpmsg) print('/' .. self.prefix .. ' ' .. k .. " - " .. v.helpmsg)

@ -10,6 +10,7 @@ local EventManager = {
EventManager.__index = EventManager EventManager.__index = EventManager
-- Constructor -- Constructor
---@return EventManager
function EventManager:New() function EventManager:New()
local self = setmetatable({}, EventManager) local self = setmetatable({}, EventManager)
self.events = {} self.events = {}
@ -31,6 +32,9 @@ function EventManager:New()
end end
-- Register an event -- Register an event
---@param event string
---@param handler fun(...)
---@return nil
function EventManager:RegisterEvent(event, handler) function EventManager:RegisterEvent(event, handler)
if not self.events[event] then if not self.events[event] then
self.events[event] = {} self.events[event] = {}
@ -40,6 +44,9 @@ function EventManager:RegisterEvent(event, handler)
end end
-- Register a wow event -- Register a wow event
---@param event string
---@param handler fun(...)
---@return nil
function EventManager:RegisterWoWEvent(event, handler) function EventManager:RegisterWoWEvent(event, handler)
if not self.wowEventHandlers[event] then if not self.wowEventHandlers[event] then
self.wowEventHandlers[event] = {} self.wowEventHandlers[event] = {}
@ -50,6 +57,9 @@ function EventManager:RegisterWoWEvent(event, handler)
end end
-- Trigger an event -- Trigger an event
---@param event string
---@param ... any
---@return nil
function EventManager:TriggerEvent(event, ...) function EventManager:TriggerEvent(event, ...)
if self.events[event] then if self.events[event] then
for _, handler in pairs(self.events[event]) do for _, handler in pairs(self.events[event]) do

@ -759,109 +759,4 @@ function Unit:WatchForSwings()
end) end)
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 return Unit

Loading…
Cancel
Save