plumwd

RandomMount.lua

Sep 2nd, 2015
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.90 KB | None | 0 0
  1. local CollectMe = LibStub("AceAddon-3.0"):GetAddon("CollectMe")
  2. local RandomMount = CollectMe:NewModule("RandomMount")
  3. local MountDB = CollectMe:GetModule("MountDB")
  4.  
  5. function RandomMount:Summon(type)
  6.     local db = CollectMe.db.profile
  7.    
  8.     if not IsMounted() then
  9.         local zone_mounts, type_mounts, fallback_mounts = {}, {}, {}
  10.         local zone_id, is_swimming, is_flyable_area = CollectMe.ZoneDB:Current(), IsSwimming(), IsFlyableArea()
  11.         local collected, _, infos = MountDB:Get()
  12.  
  13.         --IsFlyableArea() falsely returns true for Dreanor
  14.         --if(GetCurrentMapContinent() == 7) then
  15.         --    is_flyable_area = false
  16.        --end
  17.  
  18.         for _,id in pairs(collected) do
  19.             -- check if current mount is in priority pool and if it is usable here
  20.             if db.random.mounts[id] ~= nil and db.random.mounts[id] ~= false and IsUsableSpell(id) ~= nil and infos[id].summonable then
  21.                 -- setting up zone table (aquatic handled by that too currently)
  22.                 if infos[id].zones ~= nil and infos[id].zones[zone_id] ~= nil then
  23.                     table.insert(zone_mounts, infos[id].index)
  24.                 end
  25.  
  26.                 if #zone_mounts == 0 then
  27.                     -- swimming mounts
  28.                     if is_swimming == true then
  29.                         if infos[id].type == MountDB.SWIM or (db.summon.mounts.flying_in_water == true and infos[id].type == MountDB.FLY and is_flyable_area == true) then
  30.                             table.insert(type_mounts, infos[id].index)
  31.                         end
  32.                         -- flying mounts
  33.                     elseif is_flyable_area == true then
  34.                         if infos[id].type == MountDB.FLY then
  35.                             table.insert(type_mounts, infos[id].index)
  36.                         end
  37.                     end
  38.                 end
  39.                 if infos[id].type == MountDB.GROUND or (db.summon.mounts.flying_on_ground  == true and infos[id].type == MountDB.FLY) then
  40.                     table.insert(fallback_mounts, infos[id].index)
  41.                 end
  42.             end
  43.         end
  44.  
  45.         if type == MountDB.GROUND and #fallback_mounts > 0 then
  46.             self:Mount(fallback_mounts)
  47.         elseif #zone_mounts > 0 then
  48.             self:Mount(zone_mounts)
  49.         elseif #type_mounts > 0 then
  50.             self:Mount(type_mounts)
  51.         elseif #fallback_mounts > 0 then
  52.             self:Mount(fallback_mounts)
  53.         else
  54.             if IsIndoors() == nil and UnitAffectingCombat("player") == nil then
  55.                 CollectMe:Print(CollectMe.L["You haven't configured your mount priorities yet. Please open the random mount tab"])
  56.             end
  57.         end
  58.  
  59.     elseif db.summon.mounts.no_dismount == false then
  60.         Dismount()
  61.     end
  62. end
  63.  
  64. function RandomMount:Mount(t)
  65.     local call = math.random(1, #t);
  66.     C_MountJournal.Summon(t[call]);
  67. end
Advertisement
Add Comment
Please, Sign In to add comment