Advertisement
Guest User

Statistics.lua

a guest
Oct 20th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1. local nData = LibStub("AceAddon-3.0"):GetAddon("nData")
  2.  
  3. ------------------------------------------------------------------------
  4. -- Statistics Plugin Functions
  5. ------------------------------------------------------------------------
  6. nData.pluginConstructors["stat1"] = function()
  7.  
  8. db = nData.db.profile
  9.  
  10. local plugin = CreateFrame('Frame', nil, Datapanel)
  11. plugin:RegisterEvent("PLAYER_ENTERING_WORLD")
  12. plugin:SetFrameStrata("BACKGROUND")
  13. plugin:SetFrameLevel(3)
  14. plugin:EnableMouse(true)
  15.  
  16. local Text = plugin:CreateFontString(nil, "OVERLAY")
  17. Text:SetFont(db.font, db.fontSize,'THINOUTLINE')
  18. nData:PlacePlugin(db.stat1, Text)
  19.  
  20. local playerClass, englishClass = UnitClass("player");
  21.  
  22. local function ShowTooltip(self)
  23. if InCombatLockdown() then return end
  24.  
  25. local anchor, panel, xoff, yoff = nData:DataTextTooltipAnchor(Text)
  26. GameTooltip:SetOwner(panel, anchor, xoff, yoff)
  27. GameTooltip:ClearLines()
  28. GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Statistics")
  29. GameTooltip:AddLine' '
  30. if UnitLevel("player") > 10 then
  31.  
  32. if playerRole == "Tank" then
  33. local Total_Dodge = GetDodgeChance()
  34. local Total_Parry = GetParryChance()
  35. local Total_Block = GetBlockChance()
  36.  
  37. GameTooltip:AddLine(STAT_CATEGORY_DEFENSE)
  38. GameTooltip:AddDoubleLine(DODGE_CHANCE, format("%.2f%%", Total_Dodge),1,1,1)
  39. GameTooltip:AddDoubleLine(PARRY_CHANCE, format("%.2f%%", Total_Parry),1,1,1)
  40. GameTooltip:AddDoubleLine(BLOCK_CHANCE, format("%.2f%%", Total_Block),1,1,1)
  41.  
  42. elseif playerRole == "Caster" then
  43. local SC = GetSpellCritChance("2")
  44. local Total_Spell_Haste = UnitSpellHaste("player")
  45. local base, casting = GetManaRegen()
  46. local manaRegenString = "%d / %d"
  47.  
  48. GameTooltip:AddLine(STAT_CATEGORY_SPELL)
  49. GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", SC), 1, 1, 1)
  50. GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Spell_Haste), 1, 1, 1)
  51. GameTooltip:AddDoubleLine(MANA_REGEN, format(manaRegenString, base * 5, casting * 5), 1, 1, 1)
  52.  
  53. elseif playerRole == "Melee" then
  54.  
  55. if englishClass == "HUNTER" then
  56. local Total_Range_Haste = GetRangedHaste("player")
  57. local Range_Armor_Pen = GetArmorPenetration();
  58. local Range_Crit = GetRangedCritChance("25")
  59. local speed = UnitRangedDamage("player")
  60. local Total_Range_Speed = speed
  61.  
  62. GameTooltip:AddLine(STAT_CATEGORY_RANGED)
  63. GameTooltip:AddDoubleLine("Armor Penetration", format("%.2f%%", Range_Armor_Pen), 1, 1, 1)
  64. GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Range_Crit), 1, 1, 1)
  65. GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Range_Haste), 1, 1, 1)
  66. GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", Total_Range_Speed), 1, 1, 1)
  67. else
  68. local Melee_Crit = GetCritChance("player")
  69. local Melee_Armor_Pen = GetArmorPenetration();
  70. local Total_Melee_Haste = GetMeleeHaste("player")
  71. local mainSpeed = UnitAttackSpeed("player");
  72. local MH = mainSpeed
  73.  
  74. GameTooltip:AddLine(STAT_CATEGORY_MELEE)
  75. GameTooltip:AddDoubleLine("Armor Penetration", format("%.2f%%", Melee_Armor_Pen), 1, 1, 1)
  76. GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Melee_Crit), 1, 1, 1)
  77. GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Melee_Haste), 1, 1, 1)
  78. GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", MH), 1, 1, 1)
  79. end
  80. end
  81. GameTooltip:AddLine' '
  82. GameTooltip:AddLine(STAT_CATEGORY_GENERAL)
  83. local masteryspell
  84. local Multi_Strike = GetMultistrike();
  85. local Life_Steal = GetLifesteal();
  86. --local Versatility = GetVersatility();
  87. local Versatility_Damage_Bonus = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_DONE) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_DONE);
  88. local Avoidance = GetAvoidance();
  89. local bonusArmor, isNegatedForSpec = UnitBonusArmor("player");
  90.  
  91. GameTooltip:AddDoubleLine(STAT_BONUS_ARMOR, format("%s", bonusArmor), 1, 1, 1)
  92. GameTooltip:AddDoubleLine(STAT_MULTISTRIKE, format("%.2f%%", Multi_Strike), 1, 1, 1)
  93. GameTooltip:AddDoubleLine(STAT_LIFESTEAL, format("%.2f%%", Life_Steal), 1, 1, 1)
  94. GameTooltip:AddDoubleLine(STAT_VERSATILITY, format("%.2f%%", Versatility_Damage_Bonus), 1, 1, 1)
  95. --GameTooltip:AddDoubleLine(STAT_VERSATILITY, format("%d", Versatility), 1, 1, 1)
  96. GameTooltip:AddDoubleLine(STAT_AVOIDANCE, format("%.2f%%", Avoidance), 1, 1, 1)
  97. if GetCombatRating(CR_MASTERY) ~= 0 and GetSpecialization() then
  98. if englishClass == "DRUID" then
  99. if playerRole == "Melee" then
  100. masteryspell = select(2, GetSpecializationMasterySpells(GetSpecialization()))
  101. elseif playerRole == "Tank" then
  102. masteryspell = select(1, GetSpecializationMasterySpells(GetSpecialization()))
  103. else
  104. masteryspell = GetSpecializationMasterySpells(GetSpecialization())
  105. end
  106. else
  107. masteryspell = GetSpecializationMasterySpells(GetSpecialization())
  108. end
  109.  
  110.  
  111. local Mastery = GetMasteryEffect("player")
  112. local masteryName, _, _, _, _, _, _, _, _ = GetSpellInfo(masteryspell)
  113. if masteryName then
  114. GameTooltip:AddDoubleLine(masteryName, format("%.2f%%", Mastery), 1, 1, 1)
  115. end
  116. end
  117. else
  118. GameTooltip:AddLine("No Stats Available unit Level 10")
  119. end
  120.  
  121. GameTooltip:Show()
  122. end
  123.  
  124. local function UpdateTank(self)
  125. local armorString = hexa..ARMOR..hexb..": "
  126. local displayNumberString = string.join("", "%s", "%d|r");
  127. local base, effectiveArmor, armor, posBuff, negBuff = UnitArmor("player");
  128. local Melee_Reduction = effectiveArmor
  129.  
  130. Text:SetFormattedText(displayNumberString, armorString, effectiveArmor)
  131. --Setup Tooltip
  132. self:SetAllPoints(Text)
  133. end
  134.  
  135. local function UpdateCaster(self)
  136. local spellpwr = GetSpellBonusDamage("2");
  137. local displayNumberString = string.join("", "%s", "%d|r");
  138.  
  139. Text:SetFormattedText(displayNumberString, hexa.."SP: "..hexb, spellpwr)
  140. --Setup Tooltip
  141. self:SetAllPoints(Text)
  142. end
  143.  
  144. local function UpdateMelee(self)
  145. local displayNumberString = string.join("", "%s", "%d|r");
  146.  
  147. if englishClass == "HUNTER" then
  148. local base, posBuff, negBuff = UnitRangedAttackPower("player")
  149. local Range_AP = base + posBuff + negBuff
  150. pwr = Range_AP
  151. else
  152. local base, posBuff, negBuff = UnitAttackPower("player")
  153. local Melee_AP = base + posBuff + negBuff
  154. pwr = Melee_AP
  155. end
  156.  
  157. Text:SetFormattedText(displayNumberString, hexa.."AP: "..hexb, pwr)
  158. --Setup Tooltip
  159. self:SetAllPoints(Text)
  160. end
  161.  
  162. -- initial delay for update (let the ui load)
  163. local int = 5
  164. local function Update(self, t)
  165. int = int - t
  166. if int > 0 then return end
  167. if UnitLevel("player") >= 10 then
  168. if playerRole == "Tank" then
  169. UpdateTank(self)
  170. elseif playerRole == "Caster" then
  171. UpdateCaster(self)
  172. elseif playerRole == "Melee" then
  173. UpdateMelee(self)
  174. end
  175. else
  176. Text:SetText(hexa.."No Stats"..hexb)
  177. end
  178. int = 2
  179. end
  180.  
  181. plugin:SetScript("OnEnter", function() ShowTooltip(plugin) end)
  182. plugin:SetScript("OnLeave", function() GameTooltip:Hide() end)
  183. plugin:SetScript("OnUpdate", Update)
  184. Update(plugin, 10)
  185.  
  186. return plugin -- important!
  187. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement