-----------------
-- Stats
-----------------
if db.stats then
local statsPlugin = CreateFrame('Frame', nil, Datapanel)
statsPlugin:RegisterEvent("PLAYER_ENTERING_WORLD")
statsPlugin:SetFrameStrata("BACKGROUND")
statsPlugin:SetFrameLevel(3)
statsPlugin:EnableMouse(true)
local Text = statsPlugin:CreateFontString(nil, "OVERLAY")
Text:SetFont(db.font, db.fontSize,'THINOUTLINE')
PlacePlugin(db.stats, Text)
local function ShowTooltip(self)
local playerRole, specIndex, ClassByID
local anchor, panel, xoff, yoff = DataTextTooltipAnchor(Text)
GameTooltip:SetOwner(panel, anchor, xoff, yoff)
GameTooltip:ClearLines()
GameTooltip:AddLine(hexa..PLAYER_NAME.."'s"..hexb.." Statistics")
GameTooltip:AddLine' '
if playerStat == 1 then
local Total_Dodge = GetDodgeChance()
local Total_Parry = GetParryChance()
local Total_Block = GetBlockChance()
GameTooltip:AddLine(STAT_CATEGORY_DEFENSE)
GameTooltip:AddDoubleLine(DODGE_CHANCE, format("%.2f%%", Total_Dodge),1,1,1)
GameTooltip:AddDoubleLine(PARRY_CHANCE, format("%.2f%%", Total_Parry),1,1,1)
GameTooltip:AddDoubleLine(BLOCK_CHANCE, format("%.2f%%", Total_Block),1,1,1)
elseif playerStat == 4 then
local SC = GetSpellCritChance("2")
local Total_Spell_Haste = UnitSpellHaste("player")
local base, casting = GetManaRegen()
local manaRegenString = "%d / %d"
GameTooltip:AddLine(STAT_CATEGORY_SPELL)
GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", SC), 1, 1, 1)
GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Spell_Haste), 1, 1, 1)
GameTooltip:AddDoubleLine(MANA_REGEN, format(manaRegenString, base * 5, casting * 5), 1, 1, 1)
elseif playerStat == 2 then
if playerClass == 253 then
local Total_Range_Haste = GetRangedHaste("player")
local Range_Crit = GetRangedCritChance("25")
local speed = UnitRangedDamage("player")
local Total_Range_Speed = speed
local Melee_Crit = GetCritChance("player")
local Total_Melee_Haste = GetMeleeHaste("player")
local mainSpeed = UnitAttackSpeed("player");
local MH = mainSpeed
GameTooltip:AddLine(STAT_CATEGORY_MELEE)
GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Melee_Crit), 1, 1, 1)
GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Melee_Haste), 1, 1, 1)
GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", MH), 1, 1, 1)
GameTooltip:AddLine' '
GameTooltip:AddLine(STAT_CATEGORY_RANGED)
GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Range_Crit), 1, 1, 1)
GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Range_Haste), 1, 1, 1)
GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", Total_Range_Speed), 1, 1, 1)
else
local Melee_Crit = GetCritChance("player")
local Total_Melee_Haste = GetMeleeHaste("player")
local mainSpeed = UnitAttackSpeed("player");
local MH = mainSpeed
GameTooltip:AddLine(STAT_CATEGORY_MELEE)
GameTooltip:AddDoubleLine(STAT_CRITICAL_STRIKE, format("%.2f%%", Melee_Crit), 1, 1, 1)
GameTooltip:AddDoubleLine(STAT_HASTE, format("%.2f%%", Total_Melee_Haste), 1, 1, 1)
GameTooltip:AddDoubleLine(STAT_ATTACK_SPEED, format("%.2f".." (sec)", MH), 1, 1, 1)
end
end
--GameTooltip:AddLine' '
--GameTooltip:AddLine(STAT_CATEGORY_GENERAL)
GameTooltip:AddLine' '
GameTooltip:AddLine("|cffeda55fClick|r to Open Charater Frame")
GameTooltip:Show()
end
local function UpdateTank(self)
local armorString = hexa..ARMOR..hexb..": "
local displayNumberString = string.join("", "%s", "%d|r");
local base, effectiveArmor, armor, posBuff, negBuff = UnitArmor("player");
local Melee_Reduction = effectiveArmor
Text:SetFormattedText(displayNumberString, armorString, effectiveArmor)
--Setup Tooltip
self:SetAllPoints(Text)
end
local function UpdateCaster(self)
local spellpwr = GetSpellBonusDamage("2");
local displayNumberString = string.join("", "%s", "%d|r");
Text:SetFormattedText(displayNumberString, hexa.."SP: "..hexb, spellpwr)
--Setup Tooltip
self:SetAllPoints(Text)
end
local function UpdateDamager(self)
local displayNumberString = string.join("", "%s", "%d|r");
if playerClass == 253 then
local base, posBuff, negBuff = UnitRangedAttackPower("player")
local Range_AP = base + posBuff + negBuff
pwr = Range_AP
else
local base, posBuff, negBuff = UnitAttackPower("player")
local Melee_AP = base + posBuff + negBuff
pwr = Melee_AP
end
Text:SetFormattedText(displayNumberString, hexa.."AP: "..hexb, pwr)
--Setup Tooltip
self:SetAllPoints(Text)
end
local int = 5
local function Update(self, t)
int = int - t
if int > 0 then return end
if playerRole == nil then
Text:SetText(hexa.."No Stats"..hexb)
else
if playerRole == "TANK" then
UpdateTank(self)
elseif playerRole == "HEALER" then
UpdateCaster(self)
elseif playerRole == "DAMAGER" then
UpdateDamager(self)
end
end
int = 2
end
local function OnEvent(self, event, ...)
if event == 'PLAYER_ENTERING_WORLD' then
self:UnregisterEvent('PLAYER_ENTERING_WORLD')
end
if not playerRole then
specIndex = GetSpecialization()
playerRole = select(6, GetSpecializationInfo(specIndex))
playerStat = select(7, GetSpecializationInfo(specIndex))
playerClass = select(1, GetSpecializationInfo(specIndex))
--print("playerRole", playerRole, specIndex) -- What did we get?
--print("playerStat", playerStat, specIndex) -- What did we get?
print("playerClass", playerClass, specIndex) -- What did we get?
end
-- update datatext
if event ~= 'PLAYER_ENTERING_WORLD' then
self:SetScript('OnUpdate', Update)
end
end
statsPlugin:SetScript("OnEnter", function() ShowTooltip(statsPlugin) end)
statsPlugin:SetScript("OnLeave", function() GameTooltip:Hide() end)
statsPlugin:SetScript('OnEvent', OnEvent)
statsPlugin:SetScript("OnUpdate", Update)
statsPlugin:SetScript("OnMouseDown", function() ToggleCharacter("PaperDollFrame") end)
--Update(statsPlugin, 10)
end