Want more features on Pastebin? Sign Up, it's FREE!
Guest

Battle pet update

By: a guest on Dec 29th, 2012  |  syntax: Lua  |  size: 15.05 KB  |  views: 51  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. --[[
  2. Battle Pet Daily Tamer
  3.  
  4. 12/22/2012 1.0.5 added toggle window onto worldmap for turning paws on/off, removed panel option
  5. 12/21/2012 1.0.4 code cleanup
  6. 12/20/2012 1.0.3 overhauled pre-req system to work with both factions
  7. 12/18/2012 1.0.2 added non-satchel dailies (default off), fix for tooltip on full-screen map, temporary option to ignore pre-req dailies until horde dailies confirmed, right-clicking paw will zoom map out
  8. 12/16/2012 1.0.1 temporary fix for alliance/horde pre-req wierdness for taming EK/kalimdor, pet type icons on tamer tooltips
  9. 12/15/2012 1.0.0 initial release
  10.  
  11. todo:
  12. - fix deepholm icon placement
  13. - add darkmoon daily
  14. - resource pool for paws?
  15. - replace astrolabe with static data
  16.  
  17. ]]
  18.  
  19. BattlePetDailyTamerSettings = {} -- savedvariable
  20.  
  21. local dailytamer = CreateFrame("Frame","BattlePetDailyTamer")
  22. local astrolabe = DongleStub("Astrolabe-1.0")
  23.  
  24. --[[    DailyInfo is indexed by the questID of each tamer's daily quest
  25.  
  26.         [questID] = {
  27.                 [1] = prereq group,                     -- group daily belongs to (ie "EK" "KL" "OL" etc)
  28.                 [2] = "Npc Name",       -- name of the tamer
  29.                 [3] = mapID,                                            -- mapID (for astrolabe)
  30.                 [4] = zone,                                                     -- zone (for astrolabe)
  31.                 [5] = xpos,                                                     -- xpos (for astrolabe)
  32.                 [6] = ypos,                                                     -- ypos (for astrolabe)
  33.                 [7] = hasSatchel,                               -- whether this tamer rewards a satchel
  34.                 [8] = petlevel,                                 -- level of pets for this tamer
  35.                 [9] = pettype1,                                 -- pet type of tamer's first pet (1-10)
  36.          [10] = pettype2,                                       -- pet type of tamer's second pet (1-10)
  37.          [11] = pettype3                                        -- pet type of tamer's third pet (1-10)
  38.          1 = Hum
  39.          2 = Dra
  40.          3 = Fly
  41.          4 = Und
  42.          5 = Cri
  43.          6 = Mag
  44.          7 = Ele
  45.          8 = Bea
  46.          9 = Aqa
  47.          10 = Mech
  48.         }
  49. ]]
  50. dailytamer.DailyInfo = {
  51.  
  52.         -- pre-MoP satchel dailies
  53.         [31916]={"EK","Lydia Accoste",32,0,0.401,0.765,true,19,4,7,4},
  54.         [31909]={"KL","Stone Cold Trixxy",281,0,0.656,0.645,true,19,3,8,2},
  55.         [31926]={"OL","Bloodknight Antari",473,0,0.305,0.418,true,24,6,7,2},
  56.         [31935]={"NR","Major Payne",492,0,0.774,0.196,true,25,8,10,7},
  57.         [31971]={"CA","Obalis",720,0,0.566,0.420,true,25,5,3,8},
  58.         -- pandaren satchel dailies
  59.         [31955]={"MP","Farmer Nishi",807,0,0.461,0.437,true,25,8,7,7},
  60.         [31991]={"MP","Seeker Zusshi",810,0,0.363,0.522,true,25,7,5,9},
  61.         [31957]={"MP","Wastewalker Shu",858,0,0.551,0.376,true,25,9,8,7},
  62.         [31953]={"MP","Hyuna of the Shrines",806,0,0.480,0.541,true,25,9,8,3},
  63.         [31954]={"MP","Mo'ruk",857,0,0.622,0.459,true,25,3,9,8},
  64.         [31958]={"MP","Aki the Chosen",811,0,0.675,0.406,true,25,5,2,9},
  65.         [31956]={"MP","Courageous Yon",809,0,0.358,0.732,true,25,8,5,3},
  66.         -- spirit satchel dailies
  67.         [32434]={"PS","Burning Pandaren Spirit",810,0,0.571,0.421,true,25,7,2,3},
  68.         [32441]={"PS","Thundering Pandaren Spirit",811,0,0.673,0.144,true,25,7,5,8},
  69.         [32439]={"PS","Flowing Pandaren Spirit",858,0,0.611,0.875,true,25,7,9,5},
  70.         [32440]={"PS","Whispering Pandaren Spirit",806,0,0.289,0.360,true,25,7,2,5},
  71.  
  72.         -- eastern kingdom non-satchel dailies
  73.         [31693]={"EK","Julia Stevens",30,0,0.417,0.837,false,2,8,8,nil},
  74.         [31780]={"EK","Old MacDonald",39,0,0.609,0.185,false,3,3,10,5},
  75.         [31781]={"EK","Lindsay",36,0,0.333,0.526,false,5,5,5,5},
  76.         [31850]={"EK","Eric Davidson",34,0,0.199,0.446,false,7,8,8,8},
  77.         [31852]={"EK","Steven Lisbane",37,0,0.460,0.404,false,9,8,8,6},
  78.         [31851]={"EK","Bill Buckler",673,0,0.515,0.734,false,11,1,3,3},
  79.         [31910]={"EK","David Kosse",26,0,0.630,0.546,false,13,8,5,6},
  80.         [31911]={"EK","Deiza Plaguehorn",23,0,0.670,0.524,false,14,8,8,4},
  81.         [31912]={"EK","Kortas Darkhammer",28,0,0.353,0.277,false,15,2,2,2},
  82.         [31913]={"EK","Everessa",38,0,0.768,0.415,false,16,9,3,8},
  83.         [31914]={"EK","Durin Darkhammer",29,0,0.255,0.475,false,17,3,5,7},
  84.  
  85.         -- kalimdor non-stachel dailies
  86.         [31818]={"KL","Zunta",4,0,0.439,0.289,false,2,5,8,nil},
  87.         [31854]={"KL","Analynn",43,0,0.202,0.295,false,5,3,9,5},
  88.         [31817]={"KL","Merda Stronghoof",101,0,0.571,0.457,false,9,7,9,5},
  89.         [31862]={"KL","Zonya the Sadist",81,0,0.597,0.716,false,7,8,8,5},
  90.         [31819]={"KL","Dagra the Fierce",11,0,0.586,0.531,false,3,8,8,5},
  91.         [31871]={"KL","Traitor Gluk",121,0,0.597,0.496,false,13,2,5,8},
  92.         [31904]={"KL","Cassandra Kaboom",607,0,0.396,0.791,false,11,10,10,10},
  93.         [31908]={"KL","Elena Flutterfly",241,0,0.461,0.603,false,17,6,3,2},
  94.         [31906]={"KL","Kela Grimtotem",61,0,0.319,0.329,false,15,8,5,5},
  95.         [31907]={"KL","Zoltan",182,0,0.400,0.566,false,16,6,10,6},
  96.         [31905]={"KL","Grazzle the Great",141,0,0.539,0.749,false,14,2,2,2},
  97.  
  98.         -- outland non-satchel dailies
  99.         [31922]={"OL","Nicki Tinytech",465,0,0.643,0.493,false,20,10,10,10},
  100.         [31923]={"OL","Ras'an",467,0,0.172,0.505,false,21,3,6,1},
  101.         [31924]={"OL","Narrok",477,0,0.610,0.494,false,22,5,9,8},
  102.         [31925]={"OL","Morulu The Elder",481,0,0.588,0.701,false,23,9,9,9},
  103.  
  104.         -- northrend non-satchel dailies
  105.         [31934]={"NR","Gutretch",496,0,0.132,0.668,false,25,8,8,5},
  106.         [31931]={"NR","Beegle Blastfuse",491,0,0.286,0.339,false,25,3,3,9},
  107.         [31932]={"NR","Nearly Headless Jacob",510,0,0.501,0.590,false,25,4,4,4},
  108.         [31933]={"NR","Okrut Dragonwaste",488,0,0.590,0.771,false,25,2,4,4},
  109.  
  110.         -- cataclysm non-satchel dailies
  111.         [31972]={"CA","Brok",606,0,0.614,0.327,false,25,8,6,5},
  112.         [31974]={"CA","Goz Banefury",700,0,0.566,0.568,false,25,7,6,8},
  113.         [31973]={"CA","Bordin Steadyfist",640,0,0.499,0.570,false,25,7,5,7},
  114.  
  115. }
  116.  
  117. -- taming a continent is sometimes a faction-specific quest
  118. -- when a continent is known to be cleared, completed=1 added to its table
  119. dailytamer.DailyPreReqs = {
  120.         ["EK"] = {questIDs={31902,31903}}, -- Eastern Kingdom (both sides)
  121.         ["KL"] = {questIDs={31889,31891}}, -- Kalimdor (both sides)
  122.         ["OL"] = {questIDs={31919,31921}}, -- Outland
  123.         ["NR"] = {questIDs={31927,31929}}, -- Northrend
  124.         ["CA"] = {questIDs={31966,31967}}, -- Cataclysm
  125.         ["MP"] = {questIDs={31951}},                     -- Pandaria
  126.         ["PS"] = {questIDs={32428}},                     -- Pandaria Spirits
  127. }
  128.  
  129. -- these are quest IDs to faction-specific dailies. in init we remove the opposing faction tamers.
  130. -- if an alliance tames kalimdor it grants horde only access to kalimdor dailies
  131. -- if a horde tames EK it grants alliance only access to EK dailies
  132. -- lydia accoste and stone cold trixxy are available to both factions
  133. dailytamer.FactionSpecificDailies = {
  134.         ["Alliance"] = {31693,31780,31781,31850,31852,31851,31910,31911,31912,31913,31914},
  135.         ["Horde"] = {31818,31854,31817,31862,31819,31871,31904,31908,31906,31907,31905},
  136. }
  137.  
  138. -- overlay over WorldMapButton, to be the parent for our buttons
  139. dailytamer.WorldMapOverlay = CreateFrame("Frame","BattlePetDailyTamerWorldMapOverlay",WorldMapButton)
  140. dailytamer.WorldMapOverlay:SetAllPoints(true)
  141.  
  142. -- tooltip used on WorldMapOverlay
  143. dailytamer.WorldMapTooltip = CreateFrame("GameTooltip","BattlePetDailyTamerTooltip",nil,"GameTooltipTemplate")
  144.  
  145. dailytamer.Paws = {} -- table of buttons that we'll place on world map
  146. dailytamer:SetScript("OnEvent",function(self,event)
  147.         if event=="PLAYER_LOGIN" then
  148.                 self:Initialize()
  149.         elseif event=="WORLD_MAP_UPDATE" and WorldMapFrame:IsVisible() then
  150.                 self:Show()
  151.         end
  152. end)
  153. -- WORLD_MAP_UPDATE can fire up to a 100 times when crossing zone boundries.
  154. -- instead of reacting to every event, wait one frame after the events fire
  155. dailytamer:Hide()
  156. dailytamer:SetScript("OnUpdate",function(self,elasped)
  157.         self:Hide()
  158.         self:UpdatePaws()
  159. end)
  160. dailytamer:RegisterEvent("WORLD_MAP_UPDATE")
  161. dailytamer:RegisterEvent("PLAYER_LOGIN")
  162.  
  163. -- takes numbers 1-10 representing pet types and returns a string of pet icons (or '?' if unknown)
  164. function dailytamer:GetPetTypeIconsInText(...)
  165.         local txt=""
  166.         for i=1,select("#",...) do
  167.                 if select(i,...) then
  168.                         if PET_TYPE_SUFFIX[select(i,...)] then
  169.                                 txt=txt.."\124TInterface\\PetBattles\\PetIcon-"..PET_TYPE_SUFFIX[select(i,...)]..":20:20:0:0:128:256:102:63:129:168\124t"
  170.                         else
  171.                                 txt=txt.."\124TInterface\\Icons\\INV_Misc_QuestionMark:20\124t"
  172.                         end
  173.                 end
  174.         end
  175.         return txt
  176. end
  177.  
  178. --[[ added by neonic to calc at/def pets
  179.          1 = Hum
  180.          2 = Dra
  181.          3 = Fly
  182.          4 = Und
  183.          5 = Cri
  184.          6 = Mag
  185.          7 = Ele
  186.          8 = Bea
  187.          9 = Aqa
  188.          10 = Mech
  189. ]]
  190. function PetR(Pet,mode)
  191.         if Pet == 1 then
  192.         PetAt = 4
  193.         PetDef = 8
  194.         end
  195.         if Pet == 2 then
  196.         PetAt = 1
  197.         PetDef = 4
  198.         end
  199.         if Pet == 3 then
  200.         PetAt = 6
  201.         PetDef = 2
  202.         end
  203.         if Pet == 4 then
  204.         PetAt = 5
  205.         PetDef = 9
  206.         end
  207.         if Pet == 5 then
  208.         PetAt = 8
  209.         PetDef = 1
  210.         end
  211.         if Pet == 6 then
  212.         PetAt = 2
  213.         PetDef = 10
  214.         end
  215.         if Pet == 7 then
  216.         PetAt = 9
  217.         PetDef = 5
  218.         end
  219.         if Pet == 8 then
  220.         PetAt = 10
  221.         PetDef = 3
  222.         end
  223.         if Pet == 9 then
  224.         PetAt = 3
  225.         PetDef = 6
  226.         end
  227.         if Pet == 10 then
  228.         PetAt = 7
  229.         PetDef = 7
  230.         end
  231.        
  232.         if mode == 1 then
  233.         return PetAt
  234.         end
  235.         if mode == 2 then
  236.         return PetDef
  237.         end
  238. end    
  239.  
  240. -- stuff to do on login
  241. function dailytamer:Initialize()
  242.  
  243.         -- remove faction-specific dailies (EK before Lydia and Kalimdor before Trixxy)
  244.         local faction = UnitFactionGroup("player")
  245.         faction = faction=="Alliance" and "Horde" or faction=="Horde" and "Alliance" or "Neutral"
  246.         if self.FactionSpecificDailies[faction] then
  247.                 for i=1,#self.FactionSpecificDailies[faction] do
  248.                         self.DailyInfo[self.FactionSpecificDailies[faction][i]] = nil
  249.                 end
  250.         end
  251.  
  252.         -- create buttons for the paws we'll put on the map
  253.         for questID,tamer in pairs(self.DailyInfo) do
  254.                 self.Paws[questID] = CreateFrame("Button",nil,self.WorldMapOverlay)
  255.                 local button = self.Paws[questID]
  256.                 button:SetSize(20,20)
  257.                 button.texture = button:CreateTexture(nil,"ARTWORK")
  258.                 button.texture:SetAllPoints(true)
  259.                 button.texture:SetTexture("Interface\\AddOns\\Battle Pet Daily Tamer\\paw.tga")
  260.                 button:SetHighlightTexture("Interface\\AddOns\\Battle Pet Daily Tamer\\paw.tga")
  261.                 button.tamerName = tamer[2]
  262.                 button.mapID = tamer[3]
  263.                 button.tooltip = self.WorldMapTooltip
  264.                 if tamer[8]>0 then
  265.                         button.tamerPets = self:GetPetTypeIconsInText(tamer[9],tamer[10],tamer[11])
  266.                         button.tamerPetsAt = self:GetPetTypeIconsInText(PetR(tamer[9],1),PetR(tamer[10],1),PetR(tamer[11],1))
  267.                         button.tamerPetsDe = self:GetPetTypeIconsInText(PetR(tamer[9],2),PetR(tamer[10],2),PetR(tamer[11],2))
  268.                 end
  269.           button:SetScript("OnEnter",function(self)
  270.                         self.tooltip:SetScale(GameTooltip:GetEffectiveScale())
  271.             self.tooltip:SetOwner(self,"ANCHOR_LEFT")
  272.             self.tooltip:AddLine(self.tamerName .. "|cffbbbbbb (Lv"..tamer[8]..") ")
  273.                         if self.tamerPets then
  274.                                 self.tooltip:AddLine(self.tamerPets..": Enemy Pets")
  275.                                 self.tooltip:AddLine(self.tamerPetsAt..": +50% Attack")
  276.                                 self.tooltip:AddLine(self.tamerPetsDe..": +33% Defense:")
  277.                         end
  278.             self.tooltip:Show()
  279.           end)
  280.           button:SetScript("OnLeave",function(self) self.tooltip:Hide() end)
  281.                 button:SetScript("OnClick",function(self,button)
  282.                         if button=="RightButton" then
  283.                                 WorldMapZoomOutButton_OnClick() -- zoom out on paw right-click
  284.                         else
  285.                                 PlaySound("igMainMenuOptionCheckBoxOn")
  286.                                 SetMapByID(self.mapID) -- zoom in on paw left-click
  287.                         end
  288.                 end)
  289.                 button:RegisterForClicks("AnyUp")
  290.         end
  291.  
  292.         BattlePetDailyTamerToggle:UpdateToggleState()
  293. end
  294.  
  295. -- draw paws on map
  296. function dailytamer:UpdatePaws()
  297.  
  298.         -- remove all paws if we unchecked green paw in toggle frame
  299.         if BattlePetDailyTamerSettings.HideDailies then
  300.                 for _,button in pairs(self.Paws) do
  301.                         button:Hide()
  302.                 end
  303.                 return
  304.         end
  305.  
  306.         -- check for prerequisite quests being done for any not known to be complete
  307.         for k,v in pairs(self.DailyPreReqs) do
  308.                 if not v.completed then
  309. --                      for i=1,#v.questIDs do
  310. --                              if IsQuestFlaggedCompleted(v.questIDs[i]) then
  311. --                                      v.completed = 1
  312. --                                      break
  313. --                              end
  314. --                      end
  315.                 v.completed=1 --hacked by neonic as broken
  316.                 end
  317.         end
  318.         -- put the paws on the map
  319.         for questID,tamer in pairs(self.DailyInfo) do
  320.                 if not tamer[7] and not BattlePetDailyTamerSettings.TrackNonSatchels then
  321.                         self.Paws[questID]:Hide()
  322.                 elseif not IsQuestFlaggedCompleted(questID) and self.DailyPreReqs[tamer[1]].completed then
  323.                         -- if daily quest is not completed (and account has completed pre-req quest)
  324.                         astrolabe:PlaceIconOnWorldMap(self.WorldMapOverlay,self.Paws[questID],tamer[3],tamer[4],tamer[5],tamer[6])
  325.                         if tamer[7] then
  326.                                 self.Paws[questID].texture:SetVertexColor(.25,1,.25,1) -- satchel daily
  327.                         else
  328.                                 self.Paws[questID].texture:SetVertexColor(.5,.85,1,1) -- non-satchel daily
  329.                         end
  330.                 else
  331.                         self.Paws[questID]:Hide()
  332.                 end
  333.         end
  334. end
  335.  
  336. --[[ Toggle frame in lowerleft corner of WorldMapFrame for tuning paws on/off ]]--
  337.  
  338. local toggle=CreateFrame("Frame","BattlePetDailyTamerToggle",BattlePetDailyTamerWorldMapOverlay)
  339. toggle:SetSize(116,36)
  340. toggle:SetPoint("BOTTOMLEFT")
  341. toggle.back=toggle:CreateTexture(nil,"BACKGROUND")
  342. toggle.back:SetPoint("TOPLEFT",4,-4)
  343. toggle.back:SetPoint("BOTTOMRIGHT",-4,4)
  344. toggle.back:SetTexture("Interface\\WorldMap\\UI-WorldMap-Middle1")
  345. toggle:SetBackdrop( { insets={left=4,right=4,top=4,bottom=4}, edgeFile="Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 16 } )
  346. toggle:SetBackdropBorderColor(.82,.5,.1)
  347. toggle:SetFrameStrata("HIGH")
  348.  
  349. function toggle:UpdateToggleState()
  350.         local settings = BattlePetDailyTamerSettings
  351.         self.check1:SetChecked(not settings.HideDailies)
  352.         self.check2:SetChecked(settings.TrackNonSatchels)
  353.         if settings.HideDailies then
  354.                 self:SetWidth(64)
  355.                 self.back:SetTexCoord(0.05,0.25, 0.859375,1)
  356.                 self.paw2:Hide()
  357.                 self.check2:Hide()
  358.         else
  359.                 self:SetWidth(116)
  360.                 self.back:SetTexCoord(0.05,0.546875, 0.859375,1)
  361.                 self.paw2:Show()
  362.                 self.check2:Show()
  363.         end
  364. end
  365.  
  366. -- green paw (all dailies)
  367. toggle.paw1=toggle:CreateTexture(nil,"ARTWORK")
  368. toggle.paw1:SetSize(24,24)
  369. toggle.paw1:SetPoint("LEFT",toggle,"LEFT",6,0)
  370. toggle.paw1:SetTexture("Interface\\AddOns\\Battle Pet Daily Tamer\\paw.tga")
  371. toggle.paw1:SetVertexColor(.25,1,.25,1)
  372. toggle.check1=CreateFrame("CheckButton",nil,toggle,"UICheckButtonTemplate")
  373. toggle.check1:SetSize(32,32)
  374. toggle.check1:SetPoint("LEFT",toggle.paw1,"RIGHT",-2,-1)
  375. toggle.check1:SetScript("OnClick",function(self)
  376.         BattlePetDailyTamerSettings.HideDailies = not self:GetChecked()
  377.         self:GetParent():UpdateToggleState()
  378.         BattlePetDailyTamer:UpdatePaws()
  379. end)
  380. toggle.check1:SetScript("OnEnter",function(self)
  381.         local tooltip = BattlePetDailyTamer.WorldMapTooltip
  382.         tooltip:SetScale(GameTooltip:GetEffectiveScale()*.85)
  383.         tooltip:SetOwner(self,"ANCHOR_TOP")
  384.         tooltip:AddLine("Battle Pet Dailies")
  385.         tooltip:Show()
  386. end)
  387. toggle.check1:SetScript("OnLeave",function(self)
  388.         BattlePetDailyTamer.WorldMapTooltip:Hide()
  389. end)
  390.  
  391. -- blue paw (non-satchel dailies)
  392. toggle.paw2=toggle:CreateTexture(nil,"ARTWORK")
  393. toggle.paw2:SetSize(24,24)
  394. toggle.paw2:SetPoint("LEFT",toggle.check1,"RIGHT",-2,1)
  395. toggle.paw2:SetTexture("Interface\\AddOns\\Battle Pet Daily Tamer\\paw.tga")
  396. toggle.paw2:SetVertexColor(.5,.85,1,1)
  397. toggle.check2=CreateFrame("CheckButton",nil,toggle,"UICheckButtonTemplate")
  398. toggle.check2:SetSize(32,32)
  399. toggle.check2:SetPoint("LEFT",toggle.paw2,"RIGHT",-2,-1)
  400. toggle.check2:SetScript("OnClick",function(self)
  401.         BattlePetDailyTamerSettings.TrackNonSatchels = self:GetChecked()
  402.         BattlePetDailyTamer:UpdatePaws()
  403. end)
  404. toggle.check2:SetScript("OnEnter",function(self)
  405.         local tooltip = BattlePetDailyTamer.WorldMapTooltip
  406.         tooltip:SetScale(GameTooltip:GetEffectiveScale()*.85)
  407.         tooltip:SetOwner(self,"ANCHOR_TOP")
  408.         tooltip:AddLine("Non-Satchel Dailies")
  409.         tooltip:Show()
  410. end)
  411. toggle.check2:SetScript("OnLeave",function(self)
  412.         BattlePetDailyTamer.WorldMapTooltip:Hide()
  413. end)
clone this paste RAW Paste Data