Advertisement
CelestialFury

RaidDefenseStats.lua

Feb 23rd, 2012
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.36 KB | None | 0 0
  1. local name, rds = ...
  2. RDS = rds
  3.  
  4. local Frame1, Frame2
  5. local StrengthAdjust, ParryAdjust, DodgeAdjust, MasteryAdjust = 0, 0, 0, 0
  6. local BuffStrengthAdjust, BuffParryAdjust, BuffDodgeAdjust, BuffMasteryAdjust, BuffMultiplierAdjust = 0, 0, 0, 0, 1
  7.  
  8. local function InjectRaidDefStats()
  9.     local defenseCategory = PAPERDOLL_STATCATEGORIES["DEFENSE"]
  10.     tinsert(defenseCategory.stats, "MASTERY")
  11.     tinsert(defenseCategory.stats, "TOTALAVOIDANCE")
  12.     tinsert(defenseCategory.stats, "COMBATTABLE")
  13.     local MY_RACES = {
  14.         NightElf = 194,
  15.         BloodElf = 195,
  16.         Goblin = 196,
  17.         Orc = 192,
  18.         Tauren = 194,
  19.         Troll = 190,
  20.         Undead = 197,
  21.         Draenei = 190,
  22.         Dwarf = 194,
  23.         Gnome = 193,
  24.         Human = 189,
  25.         Worgen = 192,
  26.         }
  27.     local race = MY_RACES[select(2, UnitRace("player"))]
  28.    
  29.  
  30.    
  31.      PAPERDOLL_STATINFO["TOTALAVOIDANCE"] = {
  32.         updateFunc = function(statFrame, unit)
  33.             Frame1 = statFrame
  34.             if (unit ~= "player") then
  35.                 statFrame:Hide();
  36.                 return;
  37.             end
  38.     local dodge = GetDodgeChance()
  39.     local DodgeAdjustChance = ( DodgeAdjust + BuffDodgeAdjust ) / 176.7189
  40.     local dodgeBeforeDR = 0.956 * ( 1 / (( 1 / ( dodge - 5 )) - 0.0152366 ))
  41.     local dodgeAdjusted = dodgeBeforeDR + DodgeAdjustChance
  42.     local dodgeAdjustedDR = ( 1 / ((  0.0152366 + ( 0.956 / dodgeAdjusted )))) + 5 -- total dodge % after DR
  43.     local strength = select(1, UnitStat("player", 1))    
  44.     local raceStrength = strength - race
  45.     local parryFromStrength = (floor((ceil(( raceStrength + StrengthAdjust + BuffStrengthAdjust ) * BuffMultiplierAdjust ) - raceStrength ) * 0.27 )) /  176.7189   -- Parry % from Strength adjustments(Including Kings/MOTW and BS/HoW )
  46.     local parryFromAdjust = ( ParryAdjust + BuffParryAdjust ) / 176.7189 --parry% from Parry Adjustments
  47.     local parryBeforeDR = 0.956 * ( 1 / (( 1 / ( GetParryChance() - 5 )) - 0.0152366 ))
  48.     local parryAdjusted = parryFromStrength + parryFromAdjust + parryBeforeDR -- total parry % Buffed before DR
  49.     local parryAdjustedDR = ( 1 / ((  0.0152366 + ( 0.956 / parryAdjusted)))) + 5   --total parry % (Buffed)after DR
  50.     -- mastery with food
  51.     local masteryRating = ( GetMastery() * 179.28004 ) + MasteryAdjust + BuffMasteryAdjust
  52.     if select(2, UnitClass("player")) == "PALADIN" then
  53.         BPM = 2.25 else
  54.         BPM = 1.5
  55.     end
  56.     if select(2, UnitClass("player")) == "PALADIN" then
  57.     blockAdjusted = (( masteryRating / 179.28004 )* BPM ) + 5 else
  58.     blockAdjusted = (( masteryRating / 179.28004 )* BPM ) + 20
  59.     end
  60.     local missChance = 5
  61.     if select(2, UnitRace("player")) == "NightElf" then
  62.         missChance = 7
  63.     end
  64.     local totalChance = dodgeAdjustedDR + parryAdjustedDR + blockAdjusted + missChance
  65.     local chance = dodgeAdjustedDR + parryAdjustedDR
  66.     local ratio = parryAdjustedDR/dodgeAdjustedDR
  67.     PaperDollFrame_SetLabelAndText(statFrame, "Total Avoidance", chance, 1);
  68.     statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, "Avoidance").." "..string.format("%.02f", chance).."%"..FONT_COLOR_CODE_CLOSE;
  69.     statFrame:Show();
  70.         end
  71.     }
  72.     PAPERDOLL_STATINFO["COMBATTABLE"] = {
  73.     updateFunc = function(statFrame, unit)
  74.     Frame2 = statFrame
  75.     if (unit ~= "player") then
  76.         statFrame:Hide();
  77.         return;
  78.     end
  79.     local dodge = GetDodgeChance()
  80.     local DodgeAdjustChance = ( DodgeAdjust + BuffDodgeAdjust ) / 176.7189
  81.     local dodgeBeforeDR = 0.956 * ( 1 / (( 1 / ( dodge - 5 )) - 0.0152366 ))
  82.     local dodgeAdjusted = dodgeBeforeDR + DodgeAdjustChance
  83.     local dodgeAdjustedDR = ( 1 / ((  0.0152366 + ( 0.956 / dodgeAdjusted )))) + 5 -- total dodge % after DR
  84.     local strength = select(1, UnitStat("player", 1))    
  85.     local raceStrength = strength - race
  86.     local parryFromStrength = (floor((ceil(( raceStrength + StrengthAdjust + BuffStrengthAdjust ) * BuffMultiplierAdjust ) - raceStrength ) * 0.27 )) /  176.7189   -- Parry % from Strength adjustments(Including Kings/MOTW and BS/HoW )
  87.     local parryFromAdjust = ( ParryAdjust + BuffParryAdjust ) / 176.7189 --parry% from Parry Adjustments
  88.     local parryBeforeDR = 0.956 * ( 1 / (( 1 / ( GetParryChance() - 5 )) - 0.0152366 ))
  89.     local parryAdjusted = parryFromStrength + parryFromAdjust + parryBeforeDR -- total parry % Buffed before DR
  90.     local parryAdjustedDR = ( 1 / ((  0.0152366 + ( 0.956 / parryAdjusted)))) + 5   --total parry % (Buffed)after DR
  91.     -- mastery with food
  92.     local masteryRating = ( GetMastery() * 179.28004 ) + MasteryAdjust + BuffMasteryAdjust
  93.     if select(2, UnitClass("player")) == "PALADIN" then
  94.         BPM = 2.25 else
  95.         BPM = 1.5
  96.     end
  97.     if select(2, UnitClass("player")) == "PALADIN" then
  98.     blockAdjusted = (( masteryRating / 179.28 )* BPM ) + 5 else
  99.     blockAdjusted = (( masteryRating / 179.28 )* BPM ) + 20
  100.     end
  101.     local missChance = 5
  102.     if select(2, UnitRace("player")) == "NightElf" then
  103.         missChance = 7
  104.     end
  105.     local totalChance = dodgeAdjustedDR + parryAdjustedDR + blockAdjusted + missChance
  106.     local ratio = parryAdjustedDR/dodgeAdjustedDR
  107.     PaperDollFrame_SetLabelAndText(statFrame, "C T Coverage", totalChance, 1, true)
  108.     statFrame.tooltip = HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, "Combat Table Coverage\n")..FONT_COLOR_CODE_CLOSE.."Automatically updates\nwhen you select buffs\nor input Stat change values\n\n\n".."Dodge:    "..HIGHLIGHT_FONT_COLOR_CODE..string.format("%.02f", dodgeAdjustedDR).."% \n"..FONT_COLOR_CODE_CLOSE.."Parry:      "..HIGHLIGHT_FONT_COLOR_CODE..string.format("%.02f", parryAdjustedDR).."% \n"..FONT_COLOR_CODE_CLOSE.."Block:     "..HIGHLIGHT_FONT_COLOR_CODE..string.format("%.02f", blockAdjusted).."% \n\n"..FONT_COLOR_CODE_CLOSE.."TOTAL:   "..HIGHLIGHT_FONT_COLOR_CODE..string.format("%.02f", totalChance).."% \n\n"..FONT_COLOR_CODE_CLOSE..string.format("Dodge: Parry Ratio:     1:%.02f",ratio);
  109.     statFrame:Show();
  110.         end
  111.     }
  112.     local class = select(2, UnitClass("player"))
  113.     if class ~= "WARRIOR" and class ~= "PALADIN" then
  114.         PAPERDOLL_STATINFO["BLOCK"] = nil
  115.     end
  116. end
  117.  
  118. local function onEvent(this, event, arg1)
  119.  
  120.     if event == "ADDON_LOADED" or event == "PLAYER_ALIVE" then
  121.         rds.Opts.Load()
  122.         InjectRaidDefStats()
  123.         rds.frame:SetScript("OnEvent", nil)
  124.     end
  125.     end
  126.  
  127.  
  128.  
  129. rds.Opts = CreateFrame("Frame", "R_D_S_Options", CharacterStatsPane, "BasicFrameTemplate") --Create the options Frame
  130.  
  131. local NewEditbox = function(name)
  132.     local parent = rds.Opts
  133.        
  134.     if _G[parent:GetName() .. name .. 'Editbox'] then
  135.         return _G[parent:GetName() .. name .. 'Editbox']
  136.     end
  137.    
  138.     local editBox = CreateFrame('EditBox', parent:GetName() .. name .. 'Editbox', parent, 'InputBoxTemplate')
  139.     editBox:SetText(0)
  140.  
  141.    
  142.     editBox:SetNumeric(true) --Makes the editbox only accept numbers.
  143.     editBox:SetSize(45, 20)
  144.     editBox:SetAutoFocus(false)
  145.     editBox:SetScript('OnEscapePressed', function(self) self:ClearFocus() end)
  146.     editBox.mod = 1
  147.     editBox:SetScript('OnTextChanged', function(self)
  148.         if editBox.AcquireText then
  149.             editBox.AcquireText(self:GetNumber() * editBox.mod)
  150.         end
  151.     end)
  152.  
  153.     editBox:SetScript('OnEditFocusLost', function(self)
  154.         if self:GetNumber() == 0 then
  155.             self:SetText(0)
  156.         end
  157.     end)
  158.  
  159.     editBox:SetScript('OnEnterPressed', function(self)
  160.         self:ClearFocus()
  161.     end)
  162.  
  163.     editBox.title = editBox:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  164.     editBox.title:SetText(name)
  165.     editBox.PosNeg = CreateFrame("Button", editBox:GetName().."PosNeg", editBox, "UIMenuButtonStretchTemplate")
  166.     editBox.PosNeg:SetSize(30, 20)
  167.     editBox.PosNeg:SetPoint("Right", editBox, "Left", -2, -0)
  168.     editBox.PosNeg:SetText("+")
  169.     editBox.PosNeg:SetNormalFontObject("GameFontNormalLarge")
  170.     editBox.PosNeg.tooltipText = "Click to set positive or negative."
  171.    
  172.     editBox.PosNeg:SetScript("OnClick", function(self)
  173.         if editBox.mod > 0 then
  174.             editBox.mod = -1
  175.             self:SetText("-")
  176.         else
  177.             editBox.mod = 1
  178.             self:SetText("+")
  179.         end
  180.         editBox.AcquireText(editBox:GetNumber() * editBox.mod)
  181.     end)
  182.    
  183.    
  184.     local prev = parent.prevEditBox
  185.     if prev then
  186.         editBox:SetPoint("Top", prev,"Bottom", 0, -10)
  187.         editBox.title:SetPoint("TopLeft", prev.title, "TopLeft", 0, -30)
  188.     else
  189.         editBox:SetPoint("TopLeft", 102, -53)
  190.         editBox.title:SetPoint("TopLeft", parent, 20, -56)
  191.     end
  192.    
  193.     editBox.title:SetJustifyH("LEFT")
  194.     editBox.title:SetJustifyV("LEFT")
  195.  
  196.     parent.prevEditBox = editBox
  197.     return editBox
  198. end
  199. local prevDrop
  200. local NewDropDownMenu = function(name, parent, title, items)
  201.     if _G[name] then
  202.         return _G[name]
  203.     end
  204.  
  205.     local drop = CreateFrame("Button", name, rds.Opts, "UIDropDownMenuTemplate")
  206.     drop:ClearAllPoints()
  207.     drop:Show()
  208.     drop.text = rds.Opts:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  209.     drop.text:SetPoint("BottomLeft", drop,"TopLeft",0, 0)
  210.     drop.text:SetText(title)
  211.    
  212.     local function OnClick(self)
  213.         UIDropDownMenu_SetSelectedID(drop, self:GetID())
  214.         drop.OnClick(self.value)
  215.     end
  216.  
  217.     local function initialize(self, level)
  218.         local info = UIDropDownMenu_CreateInfo()
  219.         for k,v in pairs(items) do
  220.             info = UIDropDownMenu_CreateInfo()
  221.             info.text = v
  222.             info.value = v
  223.             info.func = OnClick
  224.             UIDropDownMenu_AddButton(info, level)
  225.         end
  226.     end
  227.  
  228.     UIDropDownMenu_Initialize(drop, initialize)
  229.     UIDropDownMenu_SetWidth(drop, 160);
  230.     UIDropDownMenu_SetButtonWidth(drop, 160)
  231.     UIDropDownMenu_SetSelectedID(drop, 1)
  232.     UIDropDownMenu_JustifyText(drop, "LEFT")
  233.    
  234.     local prev = prevDrop
  235.    
  236.     if prev then
  237.         drop:SetPoint("Top", prev,"Bottom", 0 ,-17)
  238.     else
  239.         drop:SetPoint("TopLeft", rds.Opts,"TopLeft", 155, -47)
  240.     end
  241.     prevDrop = drop
  242.    
  243.    
  244.     drop.StrengthValue = 0
  245.     drop.ParryValue = 0
  246.     drop.DodgeValue = 0
  247.     drop.MasteryValue = 0
  248.     drop.BuffValue = 1
  249.    
  250.     return drop
  251. end
  252.  
  253. function rds.Opts.Load()
  254.     rds.Opts:Hide()
  255.     rds.Opts:SetPoint("TopRight", CharacterFrame, 380,-10)
  256.     rds.Opts:SetSize(370, 260)
  257.     rds.Opts.title = rds.Opts:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
  258.     rds.Opts.title:SetPoint("TopLeft", 110 ,-2)
  259.     rds.Opts.title:SetText(HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, "Raid Defense Stats")..FONT_COLOR_CODE_CLOSE)
  260.    
  261.  
  262.    
  263.     local f = CreateFrame("Button", rds.Opts:GetName().."Mini", CharacterStatsPane,"UIPanelButtonTemplate")
  264.     f:SetSize(32, 32)
  265.     f:SetPoint("TopRight", CharacterFrame, -150, -29)
  266.     f:SetScript("OnEnter", function() f:ShowButtonTooltip() end)
  267.     f:SetScript("OnLeave", function() f:HideButtonTooltip() end)
  268.     f:SetScript("OnClick", function(self)
  269.         PlaySound("igCharacterInfoTab")
  270.         ToggleFrame(rds.Opts)
  271.     end)
  272.    
  273.     function f:ShowButtonTooltip()
  274.         GameTooltip:SetOwner(f, "ANCHOR_TOPRIGHT", 152,2 )
  275.         GameTooltip:AddLine(HIGHLIGHT_FONT_COLOR_CODE..format(PAPERDOLLFRAME_TOOLTIP_FORMAT, "Raid Defense Stats")..FONT_COLOR_CODE_CLOSE)
  276.         GameTooltip:Show()
  277.     end
  278.     function f:HideButtonTooltip()
  279.         GameTooltip:Hide()
  280.         end
  281.     SLASH_RDS1 = "/rds";
  282.     SlashCmdList["RDS"] = function(msg)
  283.         rds_SlashCommandHandler(msg);
  284.     end
  285.     function rds_SlashCommandHandler(msg)
  286.     PlaySound("igCharacterInfoTab")
  287.     ToggleFrame(rds.Opts)
  288.    
  289.     end
  290.  
  291.    
  292.    
  293.     f:SetNormalTexture("Interface\\Icons\\INV_Shield_06")
  294.     f:SetPushedTexture("Interface\\Icons\\INV_Shield_06")
  295.     f:SetHighlightTexture("Interface\\Icons\\INV_Shield_06")
  296.  
  297.     f:GetNormalTexture():SetTexCoord(0, 1, 0, 1)
  298.     f:GetPushedTexture():SetTexCoord(0, 1, 0, 1)
  299.     f:GetHighlightTexture():SetTexCoord(0, 1, 0, 1)
  300.  
  301.     f:GetNormalTexture():SetBlendMode("DISABLE")
  302.     f:GetPushedTexture():SetBlendMode("DISABLE")
  303.     f:GetHighlightTexture():SetBlendMode("DISABLE")
  304.  
  305.     rds.Opts:UnregisterEvent("PLAYER_ENTERING_WORLD")
  306.    
  307.     NewEditbox("Strength").AcquireText = function(number)
  308.         StrengthAdjust = number --These numbers are updated as you type.
  309.         PAPERDOLL_STATINFO["TOTALAVOIDANCE"].updateFunc(Frame1, "player")
  310.         PAPERDOLL_STATINFO["COMBATTABLE"].updateFunc(Frame2, "player")
  311.     end
  312.  
  313.     NewEditbox("Dodge").AcquireText = function(number)
  314.         DodgeAdjust = number
  315.         PAPERDOLL_STATINFO["TOTALAVOIDANCE"].updateFunc(Frame1, "player")
  316.         PAPERDOLL_STATINFO["COMBATTABLE"].updateFunc(Frame2, "player")
  317.     end
  318.  
  319.     NewEditbox("Parry").AcquireText = function(number)
  320.         ParryAdjust = number
  321.        
  322.         PAPERDOLL_STATINFO["TOTALAVOIDANCE"].updateFunc(Frame1, "player")
  323.         PAPERDOLL_STATINFO["COMBATTABLE"].updateFunc(Frame2, "player")
  324.     end
  325.  
  326.     NewEditbox("Mastery").AcquireText = function(number)
  327.         MasteryAdjust = number
  328.         PAPERDOLL_STATINFO["TOTALAVOIDANCE"].updateFunc(Frame1, "player")
  329.         PAPERDOLL_STATINFO["COMBATTABLE"].updateFunc(Frame2, "player")
  330.     end
  331.    
  332.     rds.Opts.text = rds.Opts:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  333.     rds.Opts.text:SetPoint("BottomLeft", 20 ,10)
  334.     rds.Opts.text:SetText("The values are updated as you type or select a Buff.\nPlease ensure you have none of these Buffs present\nwhen using this:\nHorn of Winter/Battle Shout\nKings/GOTW\nWell Fed.")
  335.  
  336.     local food, strength, stat
  337.  
  338.     local function UpdateBuffStats()
  339.         BuffStrengthAdjust = strength.StrengthValue + food.StrengthValue
  340.         BuffParryAdjust =  food.ParryValue
  341.         BuffDodgeAdjust =  food.DodgeValue
  342.         BuffMasteryAdjust = food.MasteryValue
  343.         BuffMultiplierAdjust = stat.BuffValue
  344.  
  345.    
  346.         PAPERDOLL_STATINFO["TOTALAVOIDANCE"].updateFunc(Frame1, "player")
  347.         PAPERDOLL_STATINFO["COMBATTABLE"].updateFunc(Frame2, "player")
  348.     end
  349.  
  350. --Start of foodbuffs dropdown
  351.    
  352.     food = NewDropDownMenu("FoodBuffs", rds.Opts, " Select the Food you use in a Raid.", {
  353.     "None",
  354.     "Beer-Basted Crocolisk",
  355.     "Mushroom Sauce Mudfish",
  356.     "Fortune Cookie",
  357.     "Seafood Magnifique Feast",
  358.     "Blackbelly Sushi",
  359.     "Lavascale Minestrone",
  360.     })
  361.     food.OnClick = function(buff)
  362.         if buff == "None" then
  363.             food.StrengthValue = 0
  364.             food.ParryValue = 0
  365.             food.DodgeValue = 0
  366.             food.MasteryValue = 0
  367.             food.BuffValue = 0
  368.         elseif buff == "Beer-Basted Crocolisk" then
  369.             food.StrengthValue = 90
  370.             food.ParryValue = 0
  371.             food.DodgeValue = 0
  372.             food.MasteryValue = 0
  373.             food.BuffValue = 0
  374.         elseif buff == "Mushroom Sauce Mudfish" then
  375.             food.StrengthValue = 0
  376.             food.ParryValue = 0
  377.             food.DodgeValue = 90
  378.             food.MasteryValue = 0
  379.             food.BuffValue = 0
  380.         elseif buff == "Fortune Cookie" then
  381.             food.StrengthValue = 0
  382.             food.ParryValue = 0
  383.             food.DodgeValue = 90
  384.             food.MasteryValue = 0
  385.             food.BuffValue = 0
  386.         elseif buff == "Seafood Magnifique Feast" then
  387.             food.StrengthValue = 0
  388.             food.ParryValue = 0
  389.             food.DodgeValue = 90
  390.             food.MasteryValue = 0
  391.             food.BuffValue = 0
  392.         elseif buff == "Blackbelly Sushi" then
  393.             food.StrengthValue = 0
  394.             food.ParryValue = 90
  395.             food.DodgeValue = 0
  396.             food.MasteryValue = 0
  397.             food.BuffValue = 0
  398.         elseif buff == "Lavascale Minestrone" then
  399.             food.StrengthValue = 0
  400.             food.ParryValue = 0
  401.             food.DodgeValue = 0
  402.             food.MasteryValue = 90
  403.             food.BuffValue = 0
  404.         end
  405.         UpdateBuffStats()
  406.     end
  407. --End of FoodBuffs dropdown
  408.  
  409. --Start of StrengthBuffs dropdown
  410.     strength = NewDropDownMenu("StrengthBuffs", rds.Opts, "  Select Strength Buffs you receive.", {
  411.     "None",
  412.     "Battle Shout",
  413.     "Horn of Winter",
  414.     })
  415.     strength.OnClick = function(buff)
  416.         if buff == "None" then
  417.             strength.StrengthValue = 0
  418.             strength.BuffValue = 0
  419.         else
  420.             strength.StrengthValue = 549
  421.             strength.BuffValue = 0
  422.         end
  423.         UpdateBuffStats()
  424.     end
  425. --End of StrengthBuffs dropdown
  426.  
  427. -- --Start of StatBuffs dropdown
  428.     stat = NewDropDownMenu("StatBuffs", rds.Opts, "      Select Stat Buffs you receive.", {
  429.     "None",
  430.     "Kings",
  431.     "Gift of the Wild",
  432.     })
  433.     stat.OnClick = function(buff)
  434.         if buff == "None" then
  435.         stat.BuffValue = 1
  436.         else stat.BuffValue = 1.05
  437.         end
  438.         UpdateBuffStats()
  439.     end
  440. -- --End of StatBuffs dropdown
  441. end
  442.  
  443. rds.frame = CreateFrame("Frame")
  444. rds.frame:RegisterEvent("ADDON_LOADED")
  445. rds.frame:SetScript("OnEvent", onEvent)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement