Quantcast

Moar decimals

Darthpred [08-05-16 - 13:59]
Moar decimals
Filename
ElvUI_SLE/modules/Armory/CharacterArmory/Stats.lua
diff --git a/ElvUI_SLE/modules/Armory/CharacterArmory/Stats.lua b/ElvUI_SLE/modules/Armory/CharacterArmory/Stats.lua
index 87f7dc6..505b63a 100644
--- a/ElvUI_SLE/modules/Armory/CharacterArmory/Stats.lua
+++ b/ElvUI_SLE/modules/Armory/CharacterArmory/Stats.lua
@@ -2,15 +2,27 @@ local SLE, T, E, L, V, P, G = unpack(select(2, ...))
 if SLE._Compatibility["DejaCharacterStats"] then return end
 --Credits: Dejablue

---GLOBALS: PAPERDOLL_STATCATEGORIES, PAPERDOLL_STATINFO, PaperDollFrame_SetAttackSpeed, PaperDollFrame_SetMovementSpeed
+--GLOBALS: PAPERDOLL_STATCATEGORIES, PAPERDOLL_STATINFO, PaperDollFrame_SetAttackSpeed, PaperDollFrame_SetMovementSpeed, PaperDollFrame_SetLifesteal
+--GLOBALS: PaperDollFrame_SetVersatility, PaperDollFrame_SetMastery, PaperDollFrame_SetAvoidance, PaperDollFrame_SetDodge, PaperDollFrame_SetParry
+--GLOBALS: PaperDollFrame_SetBlock, PaperDollFrame_SetCritChance, PaperDollFrame_SetHaste
 local _G = _G
 local math_min, math_max= math.min, math.max

+local GetCombatRating, GetCombatRatingBonus = GetCombatRating, GetCombatRatingBonus
 local GetMeleeHaste, UnitAttackSpeed = GetMeleeHaste, UnitAttackSpeed
+local GetVersatilityBonus = GetVersatilityBonus
+local GetMasteryEffect, Mastery_OnEnter = GetMasteryEffect, Mastery_OnEnter
+local GetLifesteal = GetLifesteal
+local GetAvoidance = GetAvoidance
+local GetDodgeChance, GetParryChance, GetBlockChance, GetShieldBlock = GetDodgeChance, GetParryChance, GetBlockChance, GetShieldBlock
+local GetSpellCritChance, GetRangedCritChance, GetCritChance, GetCritChanceProvidesParryEffect = GetSpellCritChance, GetRangedCritChance, GetCritChance, GetCritChanceProvidesParryEffect
+local GetCritChanceProvidesParryEffect = GetCritChanceProvidesParryEffect
+local GetCombatRatingBonusForCombatRatingValue = GetCombatRatingBonusForCombatRatingValue
+local GetHaste = GetHaste
 local BreakUpLargeNumbers = BreakUpLargeNumbers
 local PaperDollFrame_SetLabelAndText = PaperDollFrame_SetLabelAndText
 local UnitSex = UnitSex
--- local PaperDollFrame_UpdateStats = PaperDollFrame_UpdateStats
+local PaperDollFrame_UpdateStats = PaperDollFrame_UpdateStats
 local PaperDollFrame_SetItemLevel = PaperDollFrame_SetItemLevel
 local GetItemLevelColor = GetItemLevelColor
 local MovementSpeed_OnEnter, MovementSpeed_OnUpdate = MovementSpeed_OnEnter, MovementSpeed_OnUpdate
@@ -21,11 +33,24 @@ local FONT_COLOR_CODE_CLOSE, HIGHLIGHT_FONT_COLOR_CODE = FONT_COLOR_CODE_CLOSE,
 local ATTACK_SPEED = ATTACK_SPEED
 local PAPERDOLLFRAME_TOOLTIP_FORMAT = PAPERDOLLFRAME_TOOLTIP_FORMAT
 local WEAPON_SPEED = WEAPON_SPEED
+local STAT_LIFESTEAL, CR_LIFESTEAL_TOOLTIP, CR_LIFESTEAL = STAT_LIFESTEAL, CR_LIFESTEAL_TOOLTIP, CR_LIFESTEAL
+local STAT_CRITICAL_STRIKE, CR_CRIT_SPELL, CR_CRIT_RANGED, CR_CRIT_MELEE, CR_CRIT_TOOLTIP = STAT_CRITICAL_STRIKE, CR_CRIT_SPELL, CR_CRIT_RANGED, CR_CRIT_MELEE, CR_CRIT_TOOLTIP
+local CR_CRIT_PARRY_RATING_TOOLTIP, CR_PARRY = CR_CRIT_PARRY_RATING_TOOLTIP, CR_PARRY
+local CR_HASTE_MELEE, STAT_HASTE, STAT_HASTE_TOOLTIP, STAT_HASTE_BASE_TOOLTIP = CR_HASTE_MELEE, STAT_HASTE, STAT_HASTE_TOOLTIP, STAT_HASTE_BASE_TOOLTIP
+local STAT_BLOCK, BLOCK_CHANCE, CR_BLOCK_TOOLTIP = STAT_BLOCK, BLOCK_CHANCE, CR_BLOCK_TOOLTIP
+local STAT_PARRY, PARRY_CHANCE, CR_PARRY_TOOLTIP = STAT_PARRY, PARRY_CHANCE, CR_PARRY_TOOLTIP
+local STAT_DODGE, DODGE_CHANCE, CR_DODGE_TOOLTIP, CR_DODGE = STAT_DODGE, DODGE_CHANCE, CR_DODGE_TOOLTIP, CR_DODGE
+local STAT_AVOIDANCE, CR_AVOIDANCE_TOOLTIP, CR_AVOIDANCE = STAT_AVOIDANCE, CR_AVOIDANCE_TOOLTIP, CR_AVOIDANCE
+local CR_VERSATILITY_DAMAGE_DONE, CR_VERSATILITY_DAMAGE_TAKEN, STAT_VERSATILITY, VERSATILITY_TOOLTIP_FORMAT, CR_VERSATILITY_TOOLTIP = CR_VERSATILITY_DAMAGE_DONE, CR_VERSATILITY_DAMAGE_TAKEN, STAT_VERSATILITY, VERSATILITY_TOOLTIP_FORMAT, CR_VERSATILITY_TOOLTIP
+local SHOW_MASTERY_LEVEL, STAT_MASTERY = SHOW_MASTERY_LEVEL, STAT_MASTERY
+local MAX_SPELL_SCHOOLS = MAX_SPELL_SCHOOLS
+local RED_FONT_COLOR_CODE = RED_FONT_COLOR_CODE

 local CA = CharacterArmory
 local totalShown = 0

---Replacing broken Blizz function
+--Replacing broken Blizz function and adding some decimals
+--Atteack speed
 function PaperDollFrame_SetAttackSpeed(statFrame, unit)
 	local meleeHaste = GetMeleeHaste();
 	local speed, offhandSpeed = UnitAttackSpeed(unit);
@@ -48,6 +73,7 @@ function PaperDollFrame_SetAttackSpeed(statFrame, unit)
 	statFrame:Show();
 end

+--Moving speed
 function PaperDollFrame_SetMovementSpeed(statFrame, unit)
 	statFrame.wasSwimming = nil;
 	statFrame.unit = unit;
@@ -60,6 +86,202 @@ function PaperDollFrame_SetMovementSpeed(statFrame, unit)
 	statFrame:Show();
 end

+-- Versatility
+function PaperDollFrame_SetVersatility(statFrame, unit)
+	if ( unit ~= "player" ) then
+		statFrame:Hide();
+		return;
+	end
+
+	local versatility = GetCombatRating(CR_VERSATILITY_DAMAGE_DONE);
+	local versatilityDamageBonus = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_DONE) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_DONE);
+	local versatilityDamageTakenReduction = GetCombatRatingBonus(CR_VERSATILITY_DAMAGE_TAKEN) + GetVersatilityBonus(CR_VERSATILITY_DAMAGE_TAKEN);
+-- PaperDollFrame_SetLabelAndText Format Change
+	PaperDollFrame_SetLabelAndText(statFrame, STAT_VERSATILITY, T.format("%.2f%%", versatilityDamageBonus) .. " / " .. T.format("%.2f%%", versatilityDamageTakenReduction), false, versatilityDamageBonus);
+
+	statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE .. T.format(VERSATILITY_TOOLTIP_FORMAT, STAT_VERSATILITY, versatilityDamageBonus, versatilityDamageTakenReduction) .. FONT_COLOR_CODE_CLOSE;
+	statFrame.tooltip2 = T.format(CR_VERSATILITY_TOOLTIP, versatilityDamageBonus, versatilityDamageTakenReduction, BreakUpLargeNumbers(versatility), versatilityDamageBonus, versatilityDamageTakenReduction);
+
+	statFrame:Show();
+end
+
+-- Mastery
+function PaperDollFrame_SetMastery(statFrame, unit)
+	if ( unit ~= "player" ) then
+		statFrame:Hide();
+		return;
+	end
+	if (T.UnitLevel("player") < SHOW_MASTERY_LEVEL) then
+		statFrame:Hide();
+		return;
+	end
+
+	local mastery = GetMasteryEffect();
+-- PaperDollFrame_SetLabelAndText Format Change
+	PaperDollFrame_SetLabelAndText(statFrame, STAT_MASTERY, T.format("%.2f%%", mastery), false, mastery);
+	statFrame.onEnterFunc = Mastery_OnEnter;
+	statFrame:Show();
+end
+
+-- Leech (Lifesteal)
+function PaperDollFrame_SetLifesteal(statFrame, unit)
+	if ( unit ~= "player" ) then
+		statFrame:Hide();
+		return;
+	end
+
+	local lifesteal = GetLifesteal();
+-- PaperDollFrame_SetLabelAndText Format Change
+	PaperDollFrame_SetLabelAndText(statFrame, STAT_LIFESTEAL, T.format("%.2f%%", lifesteal), false, lifesteal);
+	statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE .. T.format(PAPERDOLLFRAME_TOOLTIP_FORMAT, STAT_LIFESTEAL) .. " " .. T.format("%.2f%%", lifesteal) .. FONT_COLOR_CODE_CLOSE;
+
+	statFrame.tooltip2 = T.format(CR_LIFESTEAL_TOOLTIP, BreakUpLargeNumbers(GetCombatRating(CR_LIFESTEAL)), GetCombatRatingBonus(CR_LIFESTEAL));
+
+	statFrame:Show();
+end
+
+-- Avoidance
+function PaperDollFrame_SetAvoidance(statFrame, unit)
+	if ( unit ~= "player" ) then
+		statFrame:Hide();
+		return;
+	end
+
+	local avoidance = GetAvoidance();
+-- PaperDollFrame_SetLabelAndText Format Change
+	PaperDollFrame_SetLabelAndText(statFrame, STAT_AVOIDANCE, T.format("%.2f%%", avoidance), false, avoidance);
+	statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE .. T.format(PAPERDOLLFRAME_TOOLTIP_FORMAT, STAT_AVOIDANCE) .. " " .. T.format("%.2f%%", avoidance) .. FONT_COLOR_CODE_CLOSE;
+
+	statFrame.tooltip2 = T.format(CR_AVOIDANCE_TOOLTIP, BreakUpLargeNumbers(GetCombatRating(CR_AVOIDANCE)), GetCombatRatingBonus(CR_AVOIDANCE));
+
+	statFrame:Show();
+end
+
+-- Dodge Chance
+function PaperDollFrame_SetDodge(statFrame, unit)
+	if (unit ~= "player") then
+		statFrame:Hide();
+		return;
+	end
+
+	local chance = GetDodgeChance();
+-- PaperDollFrame_SetLabelAndText Format Change
+	PaperDollFrame_SetLabelAndText(statFrame, STAT_DODGE, T.format("%.2f%%", chance), false, chance);
+	statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..T.format(PAPERDOLLFRAME_TOOLTIP_FORMAT, DODGE_CHANCE).." "..T.format("%.2f", chance).."%"..FONT_COLOR_CODE_CLOSE;
+	statFrame.tooltip2 = T.format(CR_DODGE_TOOLTIP, GetCombatRating(CR_DODGE), GetCombatRatingBonus(CR_DODGE));
+	statFrame:Show();
+end
+
+-- Parry Chance
+function PaperDollFrame_SetParry(statFrame, unit)
+	if (unit ~= "player") then
+		statFrame:Hide();
+		return;
+	end
+
+	local chance = GetParryChance();
+-- PaperDollFrame_SetLabelAndText Format Change
+	PaperDollFrame_SetLabelAndText(statFrame, STAT_PARRY, T.format("%.2f%%", chance), false, chance);
+	statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..T.format(PAPERDOLLFRAME_TOOLTIP_FORMAT, PARRY_CHANCE).." "..T.format("%.2f", chance).."%"..FONT_COLOR_CODE_CLOSE;
+	statFrame.tooltip2 = T.format(CR_PARRY_TOOLTIP, GetCombatRating(CR_PARRY), GetCombatRatingBonus(CR_PARRY));
+	statFrame:Show();
+end
+
+-- Block Chance
+function PaperDollFrame_SetBlock(statFrame, unit)
+	if (unit ~= "player") then
+		statFrame:Hide();
+		return;
+	end
+
+	local chance = GetBlockChance();
+-- PaperDollFrame_SetLabelAndText Format Change
+	PaperDollFrame_SetLabelAndText(statFrame, STAT_BLOCK, T.format("%.2f%%", chance), false, chance);
+	statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..T.format(PAPERDOLLFRAME_TOOLTIP_FORMAT, BLOCK_CHANCE).." "..T.format("%.2f", chance).."%"..FONT_COLOR_CODE_CLOSE;
+	statFrame.tooltip2 = T.format(CR_BLOCK_TOOLTIP, GetShieldBlock());
+	statFrame:Show();
+end
+
+-- Crit Chance
+function PaperDollFrame_SetCritChance(statFrame, unit)
+	if ( unit ~= "player" ) then
+		statFrame:Hide();
+		return;
+	end
+
+	local rating;
+	local spellCrit, rangedCrit, meleeCrit;
+	local critChance;
+
+	-- Start at 2 to skip physical damage
+	local holySchool = 2;
+	local minCrit = GetSpellCritChance(holySchool);
+	statFrame.spellCrit = {};
+	statFrame.spellCrit[holySchool] = minCrit;
+	local spellCrit;
+	for i=(holySchool+1), MAX_SPELL_SCHOOLS do
+		spellCrit = GetSpellCritChance(i);
+		minCrit = math_min(minCrit, spellCrit);
+		statFrame.spellCrit[i] = spellCrit;
+	end
+	spellCrit = minCrit
+	rangedCrit = GetRangedCritChance();
+	meleeCrit = GetCritChance();
+
+	if (spellCrit >= rangedCrit and spellCrit >= meleeCrit) then
+		critChance = spellCrit;
+		rating = CR_CRIT_SPELL;
+	elseif (rangedCrit >= meleeCrit) then
+		critChance = rangedCrit;
+		rating = CR_CRIT_RANGED;
+	else
+		critChance = meleeCrit;
+		rating = CR_CRIT_MELEE;
+	end
+-- PaperDollFrame_SetLabelAndText Format Change
+	PaperDollFrame_SetLabelAndText(statFrame, STAT_CRITICAL_STRIKE, T.format("%.2f%%", critChance), false, critChance);
+
+	statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..T.format(PAPERDOLLFRAME_TOOLTIP_FORMAT, STAT_CRITICAL_STRIKE).." "..T.format("%.2f%%", critChance)..FONT_COLOR_CODE_CLOSE;
+	local extraCritChance = GetCombatRatingBonus(rating);
+	local extraCritRating = GetCombatRating(rating);
+	if (GetCritChanceProvidesParryEffect()) then
+		statFrame.tooltip2 = T.format(CR_CRIT_PARRY_RATING_TOOLTIP, BreakUpLargeNumbers(extraCritRating), extraCritChance, GetCombatRatingBonusForCombatRatingValue(CR_PARRY, extraCritRating));
+	else
+		statFrame.tooltip2 = T.format(CR_CRIT_TOOLTIP, BreakUpLargeNumbers(extraCritRating), extraCritChance);
+	end
+	statFrame:Show();
+end
+
+-- Haste
+function PaperDollFrame_SetHaste(statFrame, unit)
+	if ( unit ~= "player" ) then
+		statFrame:Hide();
+		return;
+	end
+
+	local haste = GetHaste();
+	local rating = CR_HASTE_MELEE;
+
+	local hasteFormatString;
+	if (haste < 0) then
+		hasteFormatString = RED_FONT_COLOR_CODE.."%s"..FONT_COLOR_CODE_CLOSE;
+	else
+		hasteFormatString = "%s";
+	end
+-- PaperDollFrame_SetLabelAndText Format Change
+	PaperDollFrame_SetLabelAndText(statFrame, STAT_HASTE, T.format(hasteFormatString, T.format("%.2f%%", haste)), false, haste);
+	statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE .. T.format(PAPERDOLLFRAME_TOOLTIP_FORMAT, STAT_HASTE) .. " " .. T.format(hasteFormatString, T.format("%.2f%%", haste)) .. FONT_COLOR_CODE_CLOSE;
+
+	local _, class = T.UnitClass(unit);
+	statFrame.tooltip2 = _G["STAT_HASTE_"..class.."_TOOLTIP"];
+	if (not statFrame.tooltip2) then
+		statFrame.tooltip2 = STAT_HASTE_TOOLTIP;
+	end
+	statFrame.tooltip2 = statFrame.tooltip2 .. T.format(STAT_HASTE_BASE_TOOLTIP, BreakUpLargeNumbers(GetCombatRating(rating)), GetCombatRatingBonus(rating));
+
+	statFrame:Show();
+end
+
 local PAPERDOLL_AttributesIndexDefaultStats ={
 	[1] = "HEALTH",
 	[2] = "POWER",