Advertisement
Guest User

Updated AutoConfirmRoll

a guest
Sep 9th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.99 KB | None | 0 0
  1. -------------------------------------------
  2. --- Author: Ketho (EU-Boulderfist)      ---
  3. --- License: Public Domain              ---
  4. --- Created: 2011.11.21                 ---
  5. --- Version: 0.7 [2012.08.28]           ---
  6. -------------------------------------------
  7. --- Curse           http://www.curse.com/addons/wow/autoconfirmroll
  8. --- WoWInterface    http://www.wowinterface.com/downloads/info20516-AutoConfirmRoll.html
  9.  
  10. local NAME = ...
  11. local VERSION = 0.7
  12. local BUILD = "Release"
  13.  
  14. AutoConfirmRoll = LibStub("AceAddon-3.0"):NewAddon(NAME, "AceEvent-3.0", "AceConsole-3.0")
  15. local ACR = AutoConfirmRoll
  16.  
  17. local ACR2 = LibStub("AceConfigRegistry-3.0")
  18. local ACD = LibStub("AceConfigDialog-3.0")
  19.  
  20. local profile
  21.  
  22.     ---------------
  23.     --- Options ---
  24.     ---------------
  25.  
  26. local rollTypes = {} -- cache
  27.  
  28. local remap = {
  29.     Need = 1,
  30.     Greed = 2,
  31.     Disenchant = 3,
  32. }
  33.  
  34. local ITEM_QUALITY = {}
  35.  
  36. for i = 2, 4 do
  37.     ITEM_QUALITY[i] = format("%s%s|r", ITEM_QUALITY_COLORS[i].hex, _G["ITEM_QUALITY"..i.."_DESC"])
  38. end
  39.  
  40. local defaults = {
  41.     profile = {
  42.         Need = true,
  43.         Greed = true,
  44.         Disenchant = true,
  45.         Loot = true,
  46.         Threshold = 4,
  47.         Party = true,
  48.         Raid = true,
  49.     },
  50. }
  51.  
  52. local options = {
  53.     type = "group",
  54.     name = format("%s |cffADFF2Fv%s|r", NAME, VERSION),
  55.     handler = ACR,
  56.     args = {
  57.         inline1 = {
  58.             type = "group", order = 1,
  59.             name = " ",
  60.             inline = true,
  61.             get = "GetValue", set = "SetValueRoll",
  62.             args = {
  63.                 Need = {
  64.                     type = "toggle", order = 1,
  65.                     width = "full", descStyle = "",
  66.                     name = "|TInterface\\Buttons\\UI-GroupLoot-Dice-Up:16:16|t "..NEED,
  67.                 },
  68.                 Greed = {
  69.                     type = "toggle", order = 2,
  70.                     width = "full", descStyle = "",
  71.                     name = "|TInterface\\Buttons\\UI-GroupLoot-Coin-Up:16:16|t "..GREED,
  72.                 },
  73.                 Disenchant = {
  74.                     type = "toggle", order = 3,
  75.                     width = "full", descStyle = "",
  76.                     name = "|TInterface\\Buttons\\UI-GroupLoot-DE-Up:16:16|t "..ROLL_DISENCHANT,
  77.                 },
  78.                 Loot = {
  79.                     type = "toggle", order = 4,
  80.                     width = "full", desc = "|cff71D5FFAutoConfirmLoot|r\n"..LOOT_NO_DROP,
  81.                     name = "|TInterface\\Cursor\\Pickup:16:16:1|t "..LOOT,
  82.                     set = "SetValue"
  83.                 },
  84.             },
  85.         },
  86.         spacing = {type = "description", order = 2, name = ""},
  87.         inline2 = {
  88.             type = "group", order = 3,
  89.             name = FILTERS,
  90.             inline = true,
  91.             get = "GetValue", set = "SetValue",
  92.             args = {
  93.                 Threshold = {
  94.                     type = "select", order = 1,
  95.                     descStyle = "",
  96.                     name = " "..LOOT_THRESHOLD,
  97.                     values = ITEM_QUALITY,
  98.                 },
  99.                 spacing = {type = "description", order = 2, name = " "},
  100.                 Party = {
  101.                     type = "toggle", order = 3,
  102.                     width = "full", descStyle = "",
  103.                     name = " |cffA8A8FF"..PARTY.."|r",
  104.                 },
  105.                 Raid = {
  106.                     type = "toggle", order = 4,
  107.                     width = "full", descStyle = "",
  108.                     name = " |cffFF7F00"..RAID.."|r",
  109.                 },
  110.             },
  111.         },
  112.     },
  113. }
  114.  
  115. function ACR:GetValue(i)
  116.     return profile[i[#i]]
  117. end
  118.  
  119. function ACR:SetValue(i, v)
  120.     profile[i[#i]] = v
  121. end
  122.  
  123. function ACR:SetValueRoll(i, v)
  124.     profile[i[#i]] = v
  125.     rollTypes[remap[i[#i]]] = v
  126. end
  127.  
  128.     ---------------------------
  129.     --- Ace3 Initialization ---
  130.     ---------------------------
  131.  
  132. local slashCmds = {"acr", "autoconfirm", "autoconfirmroll"}
  133.  
  134. function ACR:OnInitialize()
  135.     self.db = LibStub("AceDB-3.0"):New("AutoConfirmRollDB", defaults, true)
  136.    
  137.     self.db.RegisterCallback(self, "OnProfileChanged", "RefreshDB")
  138.     self.db.RegisterCallback(self, "OnProfileCopied", "RefreshDB")
  139.     self.db.RegisterCallback(self, "OnProfileReset", "RefreshDB")
  140.     self:RefreshDB()
  141.    
  142.     self.db.global.version = VERSION
  143.     self.db.global.build = BUILD
  144.    
  145.     ACR2:RegisterOptionsTable("AutoConfirmRoll_Main", options)
  146.    
  147.     local profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
  148.     ACR2:RegisterOptionsTable("AutoConfirmRoll_Profiles", profiles)
  149.    
  150.     ACD:AddToBlizOptions("AutoConfirmRoll_Main", NAME)
  151.     ACD:AddToBlizOptions("AutoConfirmRoll_Profiles", profiles.name, NAME)
  152.    
  153.     ACD:SetDefaultSize("AutoConfirmRoll_Main", 280, 385)
  154.    
  155.     for _, v in ipairs(slashCmds) do
  156.         self:RegisterChatCommand(v, "SlashCommand")
  157.     end
  158. end
  159.  
  160. function ACR:OnEnable()
  161.     self:RegisterEvent("CONFIRM_LOOT_ROLL", "CONFIRM_ROLL")
  162.     self:RegisterEvent("CONFIRM_DISENCHANT_ROLL", "CONFIRM_ROLL")
  163.     self:RegisterEvent("LOOT_BIND_CONFIRM")
  164. end
  165.  
  166. function ACR:RefreshDB()
  167.     profile = self.db.profile
  168.  
  169.     rollTypes = {
  170.         profile.Need,
  171.         profile.Greed,
  172.         profile.Disenchant,
  173.     }
  174. end
  175.  
  176. local enable = {
  177.     ["1"] = true,
  178.     on = true,
  179.     enable = true,
  180.     load = true,
  181. }
  182.  
  183. local disable = {
  184.     ["0"] = true,
  185.     off = true,
  186.     disable = true,
  187.     unload = true,
  188. }
  189.  
  190. function ACR:SlashCommand(input)
  191.     if strtrim(input) == "" then
  192.         ACD:Open("AutoConfirmRoll_Main")
  193.     elseif enable[input] then
  194.         self:Enable()
  195.         self:Print("|cffADFF2F"..VIDEO_OPTIONS_ENABLED.."|r")
  196.     elseif disable[input] then
  197.         self:Disable()
  198.         self:Print("|cffFF2424"..VIDEO_OPTIONS_DISABLED.."|r")
  199.     end
  200. end
  201.  
  202.     --------------
  203.     --- Events ---
  204.     --------------
  205.  
  206. local function IsGroup()
  207.     local numParty = GetNumSubgroupMembers()
  208.     local numRaid = GetNumGroupMembers()
  209.     local isParty = profile.Party and (numRaid == 0 and numParty > 0)
  210.     local isRaid = profile.Raid and numRaid > 0
  211.     return isRaid or isParty
  212. end
  213.  
  214. function ACR:CONFIRM_ROLL(event, id, lootType)
  215.     print ("CONFIRM_ROLL event handed to ACR")
  216.     local qualityThreshold = select(4, GetLootRollItemInfo(id)) <= profile.Threshold
  217.     if rollTypes[lootType] and qualityThreshold and IsGroup() then
  218.         ConfirmLootRoll(id, lootType)
  219.         --Manually hiding StaticPopup for compatibility with ElvUI
  220.         StaticPopup_Hide("CONFIRM_LOOT_ROLL")
  221.     end
  222. end
  223.  
  224. local f = CreateFrame("Frame")
  225.  
  226. function ACR:LOOT_BIND_CONFIRM(event, slot)
  227.     local qualityThreshold = select(4, GetLootSlotInfo(slot)) <= profile.Threshold
  228.     if profile.Loot and qualityThreshold then
  229.         -- delay by a single OnUpdate iteration
  230.         f:SetScript("OnUpdate", function(self, elapsed)
  231.             ConfirmLootSlot(slot)
  232.             self:SetScript("OnUpdate", nil)
  233.         end)
  234.         -- in contrary to ConfirmLootRoll, ConfirmLootSlot doesn't include hiding the StaticPopup
  235.         StaticPopup_Hide("LOOT_BIND")
  236.     end
  237. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement