Advertisement
Guest User

DamagePerPowerCalc

a guest
Aug 30th, 2019
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. local _, core = ...; -- Namespace
  2.  
  3. --------------------------------------
  4. -- Custom Slash Command
  5. --------------------------------------
  6. core.commands = {
  7.     ["config"] = core.Config.Toggle, -- this is a function (no knowledge of Config object)
  8.    
  9.     ["help"] = function()
  10.         print(" ");
  11.         core:Print("List of slash commands:")
  12.         core:Print("|cff00cc66/at config|r - shows config menu");
  13.         core:Print("|cff00cc66/at help|r - shows help info");
  14.         print(" ");
  15.     end,
  16.    
  17.     ["example"] = {
  18.         ["test"] = function(...)
  19.             core:Print("My Value:", tostringall(...));
  20.         end
  21.     }
  22. };
  23.  
  24. local function HandleSlashCommands(str)
  25.     if (#str == 0) then
  26.         -- User just entered "/at" with no additional args.
  27.         core.commands.help();
  28.         return;    
  29.     end
  30.    
  31.     local args = {};
  32.     for _, arg in ipairs({ string.split(' ', str) }) do
  33.         if (#arg > 0) then
  34.             table.insert(args, arg);
  35.         end
  36.     end
  37.    
  38.     local path = core.commands; -- required for updating found table.
  39.    
  40.     for id, arg in ipairs(args) do
  41.         if (#arg > 0) then -- if string length is greater than 0.
  42.             arg = arg:lower();         
  43.             if (path[arg]) then
  44.                 if (type(path[arg]) == "function") then            
  45.                     -- all remaining args passed to our function!
  46.                     path[arg](select(id + 1, unpack(args)));
  47.                     return;                
  48.                 elseif (type(path[arg]) == "table") then               
  49.                     path = path[arg]; -- another sub-table found!
  50.                 end
  51.             else
  52.                 -- does not exist!
  53.                 core.commands.help();
  54.                 return;
  55.             end
  56.         end
  57.     end
  58. end
  59.  
  60. function core:Print(...)
  61.     local hex = select(4, self.Config:GetThemeColor());
  62.     local prefix = string.format("|cff%s%s|r", hex:upper(), "Damage Per Power Calc:"); 
  63.     DEFAULT_CHAT_FRAME:AddMessage(string.join(" ", prefix, ...));
  64. end
  65.  
  66. -- WARNING: self automatically becomes events frame!
  67. function core:init(event, name)
  68.     if (name ~= "DamageManaEfficiencyCalculator") then return end
  69.  
  70.     -- allows using left and right buttons to move through chat 'edit' box
  71.     for i = 1, NUM_CHAT_WINDOWS do
  72.         _G["ChatFrame"..i.."EditBox"]:SetAltArrowKeyMode(false);
  73.     end
  74.    
  75.     ----------------------------------
  76.     -- Register Slash Commands!
  77.     ----------------------------------
  78.     SLASH_RELOADUI1 = "/rl"; -- new slash command for reloading UI
  79.     SlashCmdList.RELOADUI = ReloadUI;
  80.  
  81.     SLASH_FRAMESTK1 = "/fs"; -- new slash command for showing framestack tool
  82.     SlashCmdList.FRAMESTK = function()
  83.         LoadAddOn("Blizzard_DebugTools");
  84.         FrameStackTooltip_Toggle();
  85.     end
  86.  
  87.     SLASH_AuraTracker1 = "/at";
  88.     SlashCmdList.AuraTracker = HandleSlashCommands;
  89.    
  90.     core:Print("Welcome back", UnitName("player").."!");
  91. end
  92.  
  93.  
  94.  
  95. print("Create Local Variables")
  96.  
  97. local SpellDescription
  98. local DamageLow
  99. local DamageHigh
  100. local PowerCost
  101. local DamagePerPowerCost
  102. local InSpellID
  103. local ResultString
  104.  
  105. print("Create function core:mainDamagePerPowerCalc()")
  106.  
  107. function core:myFunction(InSpellID)
  108. --Do Damage Per Power Stuff
  109.     local PowerCostTable = GetSpellPowerCost(InSpellID);
  110.     local cleanPowerCostTable = PowerCostTable[1];
  111.  
  112.     local SpellName, rank, icon, castTime, minRange, maxRange = GetSpellInfo(InSpellID)
  113.  
  114.     SpellDescription = GetSpellDescription(InSpellID)
  115.     DamageLow = SpellDescription:match("(%d+)");
  116.     DamageHigh = SpellDescription:match(".-%d+.-([%d%.%,]+)");
  117.     PowerCost = cleanPowerCostTable["cost"];
  118.     DamagePerPowerCost = (DamageLow + DamageHigh) / (2 * PowerCost);
  119.  
  120.     ResultString = (SpellName .. ": " .. DamagePerPowerCost .. " Dmg/Power");
  121.     return true;
  122. end
  123.  
  124. --https://www.wowinterface.com/forums/showthread.php?t=57396
  125. print("Running script from wowinterface.com")
  126.  
  127. GameTooltip:HookScript("OnTooltipSetSpell", function(self)
  128.     local name, NewSpellID = self:GetSpell()
  129.     if NewSpellID then
  130.         -- Work with the spell ID you now have access to
  131.         core.myFunction(NewSpellID)
  132.         print (ResultString)
  133.     end
  134. end)
  135.  
  136. print("")
  137.  
  138.  
  139. local events = CreateFrame("Frame");
  140. events:RegisterEvent("ADDON_LOADED");
  141. events:SetScript("OnEvent", core.init);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement