Guest User

Untitled

a guest
Oct 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.90 KB | None | 0 0
  1. -- don't load if class is wrong
  2. local _, class = UnitClass("player")
  3. if class ~= "MONK" then return end
  4.  
  5. local GetTime = GetTime
  6. local debug = clcInfo.debug
  7.  
  8. local version = 5000002
  9.  
  10. local modName = "__ww"
  11. local mod = clcInfo:RegisterClassModule(modName)
  12. local emod = clcInfo.env
  13.  
  14. local ef = CreateFrame("Frame")
  15. ef:Hide()
  16.  
  17. local defaults = {
  18.     version = version,
  19.     rangePerSkill = true,
  20. }
  21.  
  22. -- @defines
  23. --------------------------------------------------------------------------------
  24. local gcdId                 = 115693    -- jab for gcd
  25. -- list of spellId
  26. local tpId                  = 100787        -- tiger palm
  27. local bokId             = 100784        -- blackout kick
  28. local rskId             = 107428        -- rising sun kick
  29. local fofId             = 113656        -- fists of fury
  30. local jabId                 = 115693        -- jab
  31. local todId                 = 115080        -- touch of death
  32. local ebrewId           = 115288        -- energizing brew
  33. local ehId              = 115072        -- expel harm
  34. local fbId              = 115203        -- fortifying brew
  35. -- status
  36. local s_ctime, s_otime, s_gcd, chi, energy
  37. -- buffs & procs
  38. local cmbBok            = "Combo Breaker: Blackout Kick" -- ComboBreaker BOK
  39. local cmbTP                 = "Combo Breaker: Tiger Palm" -- ComboBreaker TP
  40. local buffTP            = "Tiger Power"  -- Tiger Power
  41. local buffToD           = "Death Note"  -- Death Note (Touch of Death ok)
  42. local cmbBokDur
  43. local cmbTpDur
  44. local todOK
  45. local useFB
  46. -- debuffs
  47. local debuffRsk         = "Rising Sun Kick" -- RSK debuff
  48.  
  49. -- status vars
  50. local s1, s2
  51. local s_ctime, s_otime, s_gcd, s_chi, s_tp, s_rsk, s_energy, s_tsStack
  52. local s_chi_previous = 0
  53. local s_effectife_chi = 0
  54. local s_health_per
  55. local s_player_health
  56. local s_target_health
  57. local s_player_health_FB
  58. local PSTimer
  59. local PS_talented = false
  60.  
  61. local expelHarmOK = true
  62.  
  63. -- the queue
  64. local qn = {}       -- normal queue
  65. -- local qz = {}    -- zeal queue
  66. local q                     -- working var
  67.  
  68. local prio = "fb tod rsk tp fof cbbok cbtp bok ebrew eh jab"
  69. local tpRefresh = 4.0
  70. local rskRefresh = 4.0
  71.  
  72. local function GetCooldown(id)
  73.     local start, duration = GetSpellCooldown(id)
  74.     local cd = start + duration - s_ctime - s_gcd
  75.     if cd < 0 then return 0 end
  76.     return cd
  77. end
  78.  
  79.  
  80. -- actions ---------------------------------------------------------------------
  81. local actions = {
  82.     fb = {
  83.         id = fbId,
  84.         GetCD = function()
  85.             if useFB and GetCooldown(fbId) == 0.0 then
  86.                 return 0
  87.             end
  88.             return 100 -- lazy stuff
  89.         end,
  90.         UpdateStatus = function()
  91.             s_ctime = s_ctime + 1
  92.         end,
  93.         info = "Fortifying Brew",
  94.     tod = {
  95.         id = todId,
  96.         GetCD = function()
  97.             if s_chi >= 3 and GetCooldown(todId) <= 1  then
  98.                 if todOK then  
  99.                     return 0
  100.                 else
  101.                     return 100
  102.                 end
  103.             end
  104.             return 100
  105.         end,
  106.         UpdateStatus = function()
  107.             s_ctime = s_ctime + s_gcd + 1
  108.             s_chi = max(0, s_chi - 3)
  109.         end,
  110.         info = "Touch of Death"
  111.     },
  112.     rsk = {
  113.         id = rskId,
  114.         GetCD = function()
  115.             if s_chi >= 2 and GetCooldown(rskId) <= 1 and s_rsk < 100 then
  116.                 if todOK and GetCooldown(todId) <= 1  then
  117.                     return 100
  118.                 end
  119.                 if s_tp == 0.0 or s_tp >= tpRefresh then
  120.                     return 0
  121.                 else
  122.                     return 100
  123.                 end
  124.             end
  125.             return 100
  126.         end,
  127.         UpdateStatus = function()
  128.             s_ctime = s_ctime + s_gcd + 1
  129.             s_rsk = 100 -- make sure it's not shown as next skill
  130.             s_chi = max(0, s_chi - 2)
  131.         end,
  132.         info = "apply RSK"
  133.     },
  134.     tp = {
  135.         id = tpId,
  136.         GetCD = function()
  137.             if s_chi >= 1 and (s_tp <= tpRefresh or s_tpStack < 3) then
  138.                 if todOK and GetCooldown(todId) <= 1  then
  139.                     return 100
  140.                 end
  141.                 if s_tp == 0.0 and GetCooldown(rskId) <= 1 then
  142.                     return 100
  143.                 else
  144.                     return 0
  145.                 end
  146.             end
  147.             return 100
  148.         end,
  149.         UpdateStatus = function()
  150.             s_ctime = s_ctime + s_gcd + 1
  151.             s_chi = max(0, s_chi - 1)
  152.             s_tpStack = min(3, s_tpStack + 1)
  153.             s_tp = 20
  154.         end,
  155.         info = "Tiger Palm"
  156.     },
  157.     fof = {
  158.         id = fofId,
  159.         GetCD = function()
  160.             if s_chi >= 3 and GetCooldown(fofId) <= 1  then
  161.                 if todOK and GetCooldown(todId) <= 1  then
  162.                     return 100
  163.                 end
  164.                 if s_tp >= (tpRefresh + 3) then -- +3 seconds to prevent TP from falling off
  165.                     return 0
  166.                 else
  167.                     return 100
  168.                 end
  169.             end
  170.             return 100
  171.         end,
  172.         UpdateStatus = function()
  173.             s_ctime = s_ctime + s_gcd + 4
  174.             s_chi = max(0, s_chi - 3)
  175.         end,
  176.         info = "Fists of Fury"
  177.     },
  178.     cbbok = {
  179.         id = bokId,
  180.         GetCD = function()
  181.             if todOK and GetCooldown(todId) <= 1  then
  182.                     return 100
  183.             end
  184.             if cmbBokDur >= 1 then
  185.                 return 0
  186.             end
  187.             return 100
  188.         end,
  189.         UpdateStatus = function()
  190.             s_ctime = s_ctime + s_gcd + 1
  191.             cmbBokDur = 0.0
  192.         end,
  193.         info = "Combo Breaker Blackout Kick"
  194.     },
  195.     cbtp = {
  196.         id = tpId,
  197.         GetCD = function()
  198.             if todOK and GetCooldown(todId) <= 1  then
  199.                     return 100
  200.             end
  201.             if cmbTpDur >= 1 then
  202.                 return 0
  203.             end
  204.             return 100
  205.         end,
  206.         UpdateStatus = function()
  207.             s_ctime = s_ctime + s_gcd + 1
  208.             cmbTpDur = 0.0
  209.         end,
  210.         info = "Combo Breaker Tiger Palm"
  211.     },
  212.     bok = {
  213.         id = bokId,
  214.         GetCD = function()
  215.             if todOK and GetCooldown(todId) <= 1  then
  216.                     return 100
  217.             end
  218.             if s_chi >= 2 and GetCooldown(fofId) >= 3 then
  219.                 return 0
  220.             end
  221.             return 100
  222.         end,
  223.         UpdateStatus = function()
  224.             s_ctime = s_ctime + s_gcd + 1
  225.             s_chi = max(0, s_chi - 2)
  226.         end,
  227.         info = "Blackout Kick"
  228.     },
  229.     ebrew = {
  230.         id = ebrewId,
  231.         GetCD = function()
  232.             if s_energy < 30 and GetCooldown(ebrewId) == 0.0 then
  233.                 return 0
  234.             end
  235.             return 100 -- lazy stuff
  236.         end,
  237.         UpdateStatus = function()
  238.             s_ctime = s_ctime + 1
  239.             s_energy = 30
  240.         end,
  241.         info = "Energizing Brew",
  242.     },
  243.     eh = {
  244.         id = ehId,
  245.         GetCD = function()
  246.             if s_health_per < 30 and GetCooldown(ehId) == 0.0 then
  247.                 return 0
  248.             end
  249.             return 100 -- lazy stuff
  250.         end,
  251.         UpdateStatus = function()
  252.             s_ctime = s_ctime + s_gcd + 1
  253.             s_chi = min(4, s_chi + 2)
  254.             s_health_per = 30
  255.         end,
  256.         info = "Energizing Brew",
  257.     },
  258.     jab = {
  259.         id = jabId,
  260.         GetCD = function()
  261.             if s_chi < 4 then
  262.                 return 0
  263.             end
  264.             return 100 -- lazy stuff
  265.         end,
  266.         UpdateStatus = function()
  267.             s_ctime = s_ctime + s_gcd + 1
  268.             if PS_talented then
  269.                 if PSTimer == 0 or PSTimer == nil then
  270.                     s_chi = min(4, s_chi + 3)
  271.                 else
  272.                     s_chi = min(4, s_chi + 2)
  273.                 end
  274.             else
  275.                 s_chi = min(4, s_chi + 2)
  276.             end
  277.         end,
  278.         info = "Jab",
  279.     },
  280. }
  281.  
  282. mod.actions = actions
  283.  
  284. --------------------------------------------------------------------------------
  285.  
  286. local function UpdateTimers()
  287.     local cTime = GetTime()
  288.     local t
  289.  
  290.     -- Power Strikes
  291.     if PSTimer then
  292.         t = PSTimer - cTime
  293.         debug:AddBoth("timer", t)
  294.         if (t <= 0) then
  295.             PSTimer = nil
  296.         end
  297.     end
  298. end
  299.  
  300. -- reads all the interesting data
  301. local function GetStatus()
  302.     -- current time
  303.     s_ctime = GetTime()
  304.  
  305.     debug:Clear()
  306.     s_player_health = UnitHealth("player")
  307.     s_player_health_max = UnitHealthMax("player")
  308.     s_health_per = (s_player_health / s_player_health_max) * 100
  309.     debug:AddBoth("s_health_per", s_health_per)
  310.     -- gcd value
  311.     local start, duration = GetSpellCooldown(gcdId)
  312.     s_gcd = start + duration - s_ctime
  313.     if s_gcd < 0 then s_gcd = 0 end
  314.    
  315.        
  316.     debug:AddBoth("s_chi_previous", s_chi_previous)
  317.     debug:AddBoth("s_effectife_chi", s_effectife_chi)
  318.         -- client chi and energy
  319.     s_energy = UnitPower("player")
  320.    
  321.     if PS_talented then
  322.        
  323.         UpdateTimers()
  324.        
  325.         if s_effectife_chi ~= nil then
  326.             s_chi_previous = s_effectife_chi
  327.         end
  328.        
  329.         s_chi = UnitPower("player", 12)
  330.         s_effectife_chi = UnitPower("player", 12)
  331.        
  332.         if s_effectife_chi == s_chi_previous + 3 then
  333.             PSTimer = (s_ctime + 20)
  334.             debug:AddBoth("PSTimer", PSTimer)
  335.         end
  336.     else
  337.         s_chi = UnitPower("player", 12)
  338.     end
  339.  
  340.    
  341.    
  342.     qn = {}
  343.     for v in string.gmatch(prio, "[^ ]+") do
  344.         if actions[v] then
  345.             table.insert(qn, v)
  346.         else
  347.             print("clcInfo", modName, "invalid action:", v)
  348.         end
  349.     end
  350. end
  351.  
  352. local function GetNextAction()
  353.     q = qn
  354.  
  355.     local n = #q
  356.     --debug:AddBoth("n", n)
  357.    
  358.     -- parse once, get cooldowns, return first 0
  359.     for i = 1, n do
  360.         local action = actions[q[i]]
  361.         local cd = action.GetCD()
  362.         if debug.enabled then
  363.             --debug:AddBoth(q[i], cd)
  364.         end
  365.         if cd == 0 then
  366.             return action.id, q[i]
  367.         end
  368.         action.cd = cd
  369.     end
  370.    
  371.     -- parse again, return min cooldown
  372.     local minQ = 1
  373.     local minCd = actions[q[1]].cd
  374.     for i = 2, n do
  375.         local action = actions[q[i]]
  376.         if minCd > action.cd then
  377.             minCd = action.cd
  378.             minQ = i
  379.         end
  380.     end
  381.     return actions[q[minQ]].id, q[minQ]
  382.  
  383. end
  384.  
  385. local function WWRotation()
  386.     s1 = nil
  387.    
  388.     _, talent = GetTalentRowSelectionInfo(3)
  389.     if talent == 7 then
  390.         PS_talented = true
  391.     end
  392.    
  393.     GetStatus()
  394.     if debug.enabled then
  395.    
  396.         --debug:AddBoth("ctime", s_ctime)
  397.         --debug:AddBoth("gcd", s_gcd)
  398.         debug:AddBoth("chi variable", s_chi)
  399.         --debug:AddBoth("tp", s_tp)
  400.         --debug:AddBoth("rsk debuff ", s_rsk)
  401.         --debug:AddBoth("energy", s_energy)
  402.         --debug:AddBoth("prio", prio)
  403.         debug:AddBoth("talent", talent)
  404.     end
  405.    
  406.     -- the buffs
  407.     -- get tiger power duration & stack
  408.     local _, _, _, cntTP, _, _, expTP = UnitBuff("player", buffTP)
  409.     if expTP ~= nil then
  410.         s_tp = expTP - s_ctime
  411.         s_tpStack = cntTP
  412.     else
  413.         s_tp = 0.0
  414.         s_tpStack = 0
  415.     end
  416.    
  417.     -- is Touch of Death usable ?
  418.     s_target_health = UnitHealth("target")
  419.     s_player_health_FB = UnitHealth("player") * 1.2
  420.     if  s_player_health_FB >= s_target_health and UnitHealth("player") < s_target_health then
  421.         todOk = true
  422.         useFB = true
  423.     end
  424.     if ~= tokOK then
  425.         local name = UnitBuff("player", buffToD)
  426.         if name ~= nil then
  427.             todOK = true
  428.         else
  429.             todOK = false
  430.         end
  431.     end
  432.    
  433.     -- get RSK debuff on target's duration
  434.     local _, _, _, _, _, _, expRSK = UnitDebuff("target", "Rising Sun Kick")
  435.     if expRSK ~= nil then
  436.         s_rsk = expRSK - s_ctime
  437.     else
  438.         s_rsk = 0.0
  439.     end
  440.    
  441.     -- get mastery procs' duration : BoK
  442.     local _, _, _, _, _, _, expCBBoK = UnitBuff("player", cmbBok)
  443.     if expCBBoK ~= nil then
  444.         cmbBokDur = expCBBoK - s_ctime
  445.     else
  446.         cmbBokDur = 0.0
  447.     end
  448.  
  449.     -- get mastery procs' duration : TP
  450.     local _, _, _, _, _, _, expCBTP = UnitBuff("player", cmbTP)
  451.     if expCBTP ~= nil then
  452.         cmbTpDur = expCBTP - s_ctime
  453.     else
  454.         cmbTpDur = 0.0
  455.     end
  456.  
  457.    
  458.     local action
  459.     s1, action = GetNextAction()
  460.     if debug.enabled then
  461.         debug:AddBoth("s1", action)
  462.     end
  463.     --
  464.     s_otime = s_ctime -- save it so we adjust buffs for next
  465.     actions[action].UpdateStatus()
  466.     debug:AddBoth("chi variable a la fin", s_chi)
  467.     debug:AddBoth("chi effectif a la fin", s_effectife_chi)
  468.    
  469.     s2, action = GetNextAction()
  470.     if debug.enabled then
  471.         debug:AddBoth("s2", action)
  472.     end
  473. end
  474.  
  475.  
  476. -- plug in
  477. --------------------------------------------------------------------------------
  478. local secondarySkill
  479.  
  480. function emod.IconWW1(...)
  481.     WWRotation(...)
  482.     if secondarySkill then secondarySkill:DoUpdate() end
  483.     return emod.IconSpell(s1, rangePerSkill)
  484. end
  485.  
  486. local function SecondaryExec()
  487.     return emod.IconSpell(s2, rangePerSkill)
  488. end
  489.  
  490. local function ExecCleanup2()
  491.     secondarySkill = nil
  492. end
  493.  
  494. function emod.IconWW2(...)
  495.     secondarySkill = emod.___e
  496.     secondarySkill:SetScript("OnUpdate", nil)
  497.     secondarySkill.exec = SecondaryExec
  498.     secondarySkill.ExecCleanup = ExecCleanup2
  499. end
Add Comment
Please, Sign In to add comment