View Single Post
07-25-13, 06:07 PM   #23
Niketa
A Wyrmkin Dreamwalker
 
Niketa's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2013
Posts: 54
Ok as far as functionality I think I'm done... I just need to test to make sure it works on all the stored bosses (which I run most of the raids this weekend, a couple I will have to check aside from my raids).

Is there anything that I've done that I should have done differently?

Lua Code:
  1. local bossNPCID = {
  2.     [55294] = true, -- Ultraxion
  3.    
  4.     -- Madness of Deathwing... check combat log next time to see if there's any NPC that shows up regardless of what platform we start at.--
  5.     [56846] = true, -- Madness of Deathwing: Arm Tentacle
  6.     [56167] = true, -- Madness of Deathwing: Arm Tentacle
  7.     [56168] = true, -- Madness of Deathwing: Wing Tentacle (Need to check if there's a second NPCID during raid, only one listed on WoWhead.)
  8.     [56173] = true, -- Madness of Deathwing: Deathwing
  9.     ----------------------------------------------------------------------------------------------------------------------------------------
  10.    
  11.     [52530] = true, -- Alysrazor
  12.     [52409] = true, -- Ragnaros
  13.     [46753] = true, -- Al'akir
  14.     [33136] = true, -- Yogg-Saron: Guardian of Yogg-Saron
  15.     [60410] = true, -- Elegon
  16.     [36597] = true, -- The Lich King
  17.     [10184] = true, -- Onyxia
  18.     [16152] = true, -- Attumen the Huntsman
  19.     [19622] = true, -- Kael'thas Sunstrider
  20.     [28859] = true, -- Malygos
  21.     [28860] = true, -- Sartharion
  22.     [69712] = true -- Ji-Kun
  23. }
  24.  
  25. local mobIDfromGUID = setmetatable ({}, { __index = function(t, guid)
  26.     local mobID = tonumber(strsub(guid, 6, 10), 16)
  27.     t[guid] = mobID
  28.     return mobID
  29. end })
  30.  
  31. local events = CreateFrame("Frame")
  32. local method, threshold, thresholdtrigger, revertthreshold, mobName, nokill, loottrigger = nil
  33.  
  34. events:RegisterEvent("PLAYER_ENTERING_WORLD")
  35. events:RegisterEvent("PARTY_LEADER_CHANGED")
  36.  
  37. events:SetScript("OnEvent", function(self, event, ...)
  38.     return self[event] and self[event](self, event, ...)
  39. end)
  40.  
  41. function events:PLAYER_ENTERING_WORLD(event)
  42.     local ininstance, instancetype = IsInInstance("player")
  43.     local isgroupleader = UnitIsGroupLeader("player")
  44.    
  45.     if ininstance == 1 and instancetype == "raid" then -- check if player is in a raid instance
  46.         if isgroupleader then -- enable functionality if player is raid leader
  47.             print("|cff00ff00Niketa's Mount Looter enabled!")
  48.             self:RegisterEvent("PLAYER_REGEN_DISABLED")
  49.             self:RegisterEvent("PLAYER_REGEN_ENABLED")
  50.         else -- print error message if player is not raid leader and disable functionality
  51.             print("|cff00ff00Niketa's Mount Looter disabled: You need to be raid leader to use this addon.")
  52.             self:UnregisterEvent("PLAYER_REGEN_DISABLED")
  53.             self:RegisterEvent("PLAYER_REGEN_ENABLED")
  54.         end
  55.     end
  56. end
  57.  
  58. events.PARTY_LEADER_CHANGED = events.PLAYER_ENTERING_WORLD -- creates alias of PEW function for PLC
  59.  
  60. function events:PLAYER_REGEN_DISABLED(event)
  61.     self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  62. end
  63.  
  64. function events:PLAYER_REGEN_ENABLED(event)
  65.     self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  66. end
  67.  
  68. function events:COMBAT_LOG_EVENT_UNFILTERED(event, ...)
  69.     local _, eventType, _, sourceGUID, sourceName, _, _, destGUID, destName, _, _ = ...
  70.     local mobIDa, mobIDb = mobIDfromGUID[sourceGUID], mobIDfromGUID[destGUID]
  71.    
  72.     -- get mobName from either sourceName or destName
  73.     if bossNPCID[mobIDa] then
  74.         mobName = sourceName
  75.     elseif bossNPCID[mobIDb] then
  76.         mobName = destName
  77.     end
  78.     ---------------------------------------------------
  79.    
  80.     if not bossNPCID[mobIDa] and not bossNPCID[mobIDb] then -- if not in table quit
  81.         return
  82.     elseif eventType == "UNIT_DIED" and bossNPCID[mobIDb] then -- only register if boss is dest and dead
  83.         nokill, mobName = nil
  84.         loottrigger = true
  85.         self:RegisterEvent("LOOT_OPENED")
  86.         return
  87.     elseif nokill then
  88.         return
  89.     end
  90.    
  91.     -- if boss matches and it's the first pull change loot ------------------------
  92.    
  93.     self:RegisterEvent("PARTY_LOOT_METHOD_CHANGED")
  94.    
  95.     nokill = true -- flag as pulled but not killed
  96.    
  97.     if not method and not threshold then
  98.     method, threshold = GetLootMethod(), GetLootThreshold()
  99.     else
  100.         return
  101.     end
  102.  
  103.     if method ~= "master" then
  104.         if threshold ~= 4 then -- set both
  105.             SetLootMethod("master", UnitName("player"))
  106.             thresholdtrigger = true -- set variable to trigger setlootthreshold
  107.         else -- not master, but already epic; set master
  108.             SetLootMethod("master", UnitName("player"))
  109.         end
  110.     elseif threshold ~= 4 then -- if master and not epic, set epic
  111.             SetLootThreshold(4)
  112.     end
  113. end
  114.  
  115. function events:PARTY_LOOT_METHOD_CHANGED(event, ...)
  116.     if thresholdtrigger then
  117.         thresholdtrigger = nil
  118.         SetLootThreshold(4)
  119.     elseif revertthreshold then
  120.         revertthreshold = nil
  121.         SetLootThreshold(threshold)
  122.         threshold = nil
  123.         self:UnregisterEvent(self)
  124.     else -- loot method changed manually before kill
  125.         local newmethod, newthreshold = GetLootMethod(), GetLootThreshold()
  126.        
  127.         if newmethod ~= "master" then -- changed method
  128.             if newmethod ~= method then -- if new method is not stored method, restore threshold and reset
  129.                 SetLootThreshold(threshold)
  130.                 print("|cff00ff00Niketa's Mount Looter: You've changed your loot method before killing "..mobName..". Your previous loot threshold has been restored and your new settings will be saved next time you engage "..mobName..".")
  131.                 method, threshold, mobName, nokill = nil
  132.                 self:UnregisterEvent(self)
  133.             else -- restore threshold, no reset
  134.                 SetLootThreshold(threshold)
  135.                 method, threshold = nil
  136.             end
  137.         elseif newthreshold ~= 4 then -- changed threshold
  138.             if newthreshold ~= threshold then -- if new threshold is not stored threshold, restore method and reset
  139.                 if method ~= "master" then
  140.                 SetLootMethod(method)
  141.                 end
  142.            
  143.                 print("|cff00ff00Niketa's Mount Looter: You've changed your loot threshold before killing "..mobName..". Your previous loot method has been restored and your new settings will be saved next time you engage "..mobName..".")
  144.                 method, threshold, mobName, nokill = nil
  145.                 self:UnregisterEvent(self)
  146.             else -- restore method, no reset
  147.                 if method ~= "master" then
  148.                 SetLootMethod(method)
  149.                 method, threshold = nil
  150.                 end
  151.             end
  152.         end
  153.     end
  154. end
  155.  
  156. function events:LOOT_OPENED(event, ...)
  157.     if not method or not threshold then
  158.         loottrigger = nil
  159.         self:UnregisterEvent(self)
  160.         self:UnregisterEvent("PARTY_LOOT_METHOD_CHANGED")
  161.     elseif loottrigger then
  162.         loottrigger = nil
  163.         SetLootMethod(method)
  164.         method = nil
  165.         revertthreshold = true
  166.         self:UnregisterEvent(self)
  167.     end
  168. end

Last edited by Niketa : 07-25-13 at 06:14 PM.
  Reply With Quote