/Tukui/modules/datatext/avoidance.lua

http://github.com/Asphyxia/Tukui · Lua · 85 lines · 72 code · 9 blank · 4 comment · 12 complexity · a8630cefc30ac9e187ed3c55cecaa8b9 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. --------------------------------------------------------------------
  3. -- Player Avoidance
  4. --------------------------------------------------------------------
  5. if C["datatext"].avd and C["datatext"].avd > 0 then
  6. local Stat = CreateFrame("Frame")
  7. Stat:EnableMouse(true)
  8. Stat:SetFrameStrata("HIGH")
  9. Stat:SetFrameLevel(3)
  10. local Text = TukuiInfoLeft:CreateFontString(nil, "OVERLAY")
  11. Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  12. T.PP(C["datatext"].avd, Text)
  13. local targetlv
  14. local playerlv
  15. local function Update(self)
  16. local format = string.format
  17. targetlv, playerlv = UnitLevel("target"), UnitLevel("player")
  18. if targetlv == -1 then
  19. basemisschance = (5 - (3*.2)) --Boss Value
  20. leveldifference = 3
  21. elseif targetlv > playerlv then
  22. basemisschance = (5 - ((targetlv - playerlv)*.2)) --Mobs above player level
  23. leveldifference = (targetlv - playerlv)
  24. elseif targetlv < playerlv and targetlv > 0 then
  25. basemisschance = (5 + ((playerlv - targetlv)*.2)) --Mobs below player level
  26. leveldifference = (targetlv - playerlv)
  27. else
  28. basemisschance = 5 --Sets miss chance of attacker level if no target exists, lv80=5, 81=4.2, 82=3.4, 83=2.6
  29. leveldifference = 0
  30. end
  31. if leveldifference >= 0 then
  32. dodge = (GetDodgeChance()-leveldifference*.2)
  33. parry = (GetParryChance()-leveldifference*.2)
  34. block = (GetBlockChance()-leveldifference*.2)
  35. MissChance = (basemisschance + 1/(0.0625 + 0.956/(GetCombatRating(CR_DEFENSE_SKILL)/4.91850*0.04)))
  36. avoidance = (dodge+parry+block+MissChance)
  37. Text:SetText(L.datatext_playeravd..T.datacolor..format("%.2f", avoidance))
  38. else
  39. dodge = (GetDodgeChance()+abs(leveldifference*.2))
  40. parry = (GetParryChance()+abs(leveldifference*.2))
  41. block = (GetBlockChance()+abs(leveldifference*.2))
  42. MissChance = (basemisschance + 1/(0.0625 + 0.956/(GetCombatRating(CR_DEFENSE_SKILL)/4.91850*0.04)))
  43. avoidance = (dodge+parry+block+MissChance)
  44. Text:SetText(L.datatext_playeravd..T.datacolor..format("%.2f", avoidance))
  45. end
  46. --Setup Avoidance Tooltip
  47. self:SetAllPoints(Text)
  48. end
  49. Stat:RegisterEvent("UNIT_AURA")
  50. Stat:RegisterEvent("UNIT_INVENTORY_CHANGED")
  51. Stat:RegisterEvent("PLAYER_TARGET_CHANGED")
  52. Stat:RegisterEvent("PLAYER_ENTERING_WORLD")
  53. Stat:SetScript("OnEvent", Update)
  54. Stat:SetScript("OnEnter", function(self)
  55. if not InCombatLockdown() then
  56. local anchor, yoff = T.DataTextTooltipAnchor(Text)
  57. GameTooltip:SetOwner(self, anchor, 0, yoff)
  58. GameTooltip:ClearAllPoints()
  59. GameTooltip:SetPoint("BOTTOM", self, "TOP", 0, T.mult)
  60. GameTooltip:ClearLines()
  61. if targetlv > 1 then
  62. GameTooltip:AddDoubleLine(L.datatext_avoidancebreakdown.." ("..L.datatext_lvl.." "..targetlv..")")
  63. elseif targetlv == -1 then
  64. GameTooltip:AddDoubleLine(L.datatext_avoidancebreakdown.." ("..L.datatext_boss..")")
  65. else
  66. GameTooltip:AddDoubleLine(L.datatext_avoidancebreakdown.." ("..L.datatext_lvl.." "..targetlv..")")
  67. end
  68. GameTooltip:AddDoubleLine(L.datatext_miss,format("%.2f",MissChance) .. "%",1,1,1, 1,1,1)
  69. GameTooltip:AddDoubleLine(L.datatext_dodge,format("%.2f",dodge) .. "%",1,1,1, 1,1,1)
  70. GameTooltip:AddDoubleLine(L.datatext_parry,format("%.2f",parry) .. "%",1,1,1, 1,1,1)
  71. GameTooltip:AddDoubleLine(L.datatext_block,format("%.2f",block) .. "%",1,1,1, 1,1,1)
  72. GameTooltip:Show()
  73. end
  74. end)
  75. Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
  76. end