Guest User

Untitled

a guest
Oct 18th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.87 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 = false
  45. local useFB = false
  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 PSTimer
  56. local PS_talented = false
  57.  
  58. local expelHarmOK = true
  59.  
  60. -- the queue
  61. local qn = {}       -- normal queue
  62. -- local qz = {}    -- zeal queue
  63. local q                     -- working var
  64.  
  65. local prio = "fb tod rsk tp fof cbbok cbtp bok ebrew eh jab"
  66. local tpRefresh = 4.0
  67. local rskRefresh = 4.0
  68.  
  69. local function GetCooldown(id)
  70.     local start, duration = GetSpellCooldown(id)
  71.     local cd = start + duration - s_ctime - s_gcd
  72.     if cd < 0 then return 0 end
  73.     return cd
  74. end
  75.  
  76.  
  77. -- actions ---------------------------------------------------------------------
  78. local actions = {
  79.     fb = {
  80.         id = fbId,
  81.         GetCD = function()
  82.             if useFB and GetCooldown(fbId) == 0.0 then
  83.                 if s_chi >= 3 and GetCooldown(todId) <= 1 then
  84.                     return 0
  85.                 end
  86.             end
  87.             return 100 -- lazy stuff
  88.         end,
  89.         UpdateStatus = function()
  90.                 s_ctime = s_ctime + 1
  91.         end,
  92.         info = "Fortifying Brew"
  93.     },
  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 + 3
  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 = "Expel Harm",
  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. local function getPlayerHealthPer()
  301.     player_health = UnitHealth("player")
  302.     player_health_max = UnitHealthMax("player")
  303.     return (player_health / player_health_max) * 100
  304. end
  305.  
  306. -- reads all the interesting data
  307. local function GetStatus()
  308.     -- current time
  309.     s_ctime = GetTime()
  310.  
  311.     debug:Clear()
  312.     s_health_per = getPlayerHealthPer()
  313.     debug:AddBoth("s_health_per", s_health_per)
  314.     -- gcd value
  315.     local start, duration = GetSpellCooldown(gcdId)
  316.     s_gcd = start + duration - s_ctime
  317.     if s_gcd < 0 then s_gcd = 0 end
  318.    
  319.        
  320.     debug:AddBoth("s_chi_previous", s_chi_previous)
  321.     debug:AddBoth("s_effectife_chi", s_effectife_chi)
  322.         -- client chi and energy
  323.     s_energy = UnitPower("player")
  324.    
  325.     if PS_talented then
  326.        
  327.         UpdateTimers()
  328.        
  329.         if s_effectife_chi ~= nil then
  330.             s_chi_previous = s_effectife_chi
  331.         end
  332.        
  333.         s_chi = UnitPower("player", 12)
  334.         s_effectife_chi = UnitPower("player", 12)
  335.        
  336.         if s_effectife_chi == s_chi_previous + 3 then
  337.             PSTimer = (s_ctime + 20)
  338.             debug:AddBoth("PSTimer", PSTimer)
  339.         end
  340.     else
  341.         s_chi = UnitPower("player", 12)
  342.     end
  343.  
  344.    
  345.    
  346.     qn = {}
  347.     for v in string.gmatch(prio, "[^ ]+") do
  348.         if actions[v] then
  349.             table.insert(qn, v)
  350.         else
  351.             print("clcInfo", modName, "invalid action:", v)
  352.         end
  353.     end
  354. end
  355.  
  356. local function GetNextAction()
  357.     q = qn
  358.  
  359.     local n = #q
  360.     --debug:AddBoth("n", n)
  361.    
  362.     -- parse once, get cooldowns, return first 0
  363.     for i = 1, n do
  364.         local action = actions[q[i]]
  365.         local cd = action.GetCD()
  366.         if debug.enabled then
  367.             --debug:AddBoth(q[i], cd)
  368.         end
  369.         if cd == 0 then
  370.             return action.id, q[i]
  371.         end
  372.         action.cd = cd
  373.     end
  374.    
  375.     -- parse again, return min cooldown
  376.     local minQ = 1
  377.     local minCd = actions[q[1]].cd
  378.     for i = 2, n do
  379.         local action = actions[q[i]]
  380.         if minCd > action.cd then
  381.             minCd = action.cd
  382.             minQ = i
  383.         end
  384.     end
  385.     return actions[q[minQ]].id, q[minQ]
  386.  
  387. end
  388.  
  389. local function WWRotation()
  390.     s1 = nil
  391.    
  392.     _, talent = GetTalentRowSelectionInfo(3)
  393.     if talent == 7 then
  394.         PS_talented = true
  395.     end
  396.    
  397.     GetStatus()
  398.     if debug.enabled then
  399.    
  400.         --debug:AddBoth("ctime", s_ctime)
  401.         --debug:AddBoth("gcd", s_gcd)
  402.         debug:AddBoth("chi variable", s_chi)
  403.         --debug:AddBoth("tp", s_tp)
  404.         --debug:AddBoth("rsk debuff ", s_rsk)
  405.         --debug:AddBoth("energy", s_energy)
  406.         --debug:AddBoth("prio", prio)
  407.         debug:AddBoth("talent", talent)
  408.     end
  409.    
  410.     -- the buffs
  411.     -- get tiger power duration & stack
  412.     local _, _, _, cntTP, _, _, expTP = UnitBuff("player", buffTP)
  413.     if expTP ~= nil then
  414.         s_tp = expTP - s_ctime
  415.         s_tpStack = cntTP
  416.     else
  417.         s_tp = 0.0
  418.         s_tpStack = 0
  419.     end
  420.    
  421.     -- is Touch of Death usable ?
  422.     pH = UnitHealth("player")
  423.     tH = UnitHealth("target")
  424.     if pH * 1.2 > tH and pH < tH then
  425.         useFB = true
  426.         toD = true
  427.     else
  428.         local name = UnitBuff("player", buffToD)
  429.         if name ~= nil then
  430.             todOK = true
  431.         else
  432.             todOK = false
  433.         end
  434.     end
  435.    
  436.     -- get RSK debuff on target's duration
  437.     local _, _, _, _, _, _, expRSK = UnitDebuff("target", "Rising Sun Kick")
  438.     if expRSK ~= nil then
  439.         s_rsk = expRSK - s_ctime
  440.     else
  441.         s_rsk = 0.0
  442.     end
  443.    
  444.     -- get mastery procs' duration : BoK
  445.     local _, _, _, _, _, _, expCBBoK = UnitBuff("player", cmbBok)
  446.     if expCBBoK ~= nil then
  447.         cmbBokDur = expCBBoK - s_ctime
  448.     else
  449.         cmbBokDur = 0.0
  450.     end
  451.  
  452.     -- get mastery procs' duration : TP
  453.     local _, _, _, _, _, _, expCBTP = UnitBuff("player", cmbTP)
  454.     if expCBTP ~= nil then
  455.         cmbTpDur = expCBTP - s_ctime
  456.     else
  457.         cmbTpDur = 0.0
  458.     end
  459.  
  460.    
  461.     local action
  462.     s1, action = GetNextAction()
  463.     if debug.enabled then
  464.         debug:AddBoth("s1", action)
  465.     end
  466.     --
  467.     s_otime = s_ctime -- save it so we adjust buffs for next
  468.     actions[action].UpdateStatus()
  469.     debug:AddBoth("chi variable a la fin", s_chi)
  470.     debug:AddBoth("chi effectif a la fin", s_effectife_chi)
  471.    
  472.     s2, action = GetNextAction()
  473.     if debug.enabled then
  474.         debug:AddBoth("s2", action)
  475.     end
  476. end
  477.  
  478.  
  479. -- plug in
  480. --------------------------------------------------------------------------------
  481. local secondarySkill
  482.  
  483. function emod.IconWW1(...)
  484.     WWRotation(...)
  485.     if secondarySkill then secondarySkill:DoUpdate() end
  486.     return emod.IconSpell(s1, rangePerSkill)
  487. end
  488.  
  489. local function SecondaryExec()
  490.     return emod.IconSpell(s2, rangePerSkill)
  491. end
  492.  
  493. local function ExecCleanup2()
  494.     secondarySkill = nil
  495. end
  496.  
  497. function emod.IconWW2(...)
  498.     secondarySkill = emod.___e
  499.     secondarySkill:SetScript("OnUpdate", nil)
  500.     secondarySkill.exec = SecondaryExec
  501.     secondarySkill.ExecCleanup = ExecCleanup2
  502. end
Add Comment
Please, Sign In to add comment