Advertisement
Guest User

Untitled

a guest
Dec 29th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 24.77 KB | None | 0 0
  1. MountManager = LibStub("AceAddon-3.0"):NewAddon("MountManager", "AceConsole-3.0", "AceEvent-3.0")
  2. local L = LibStub("AceLocale-3.0"):GetLocale("MountManager")
  3.  
  4. ------------------------------------------------------------------
  5. -- Local Settings
  6. ------------------------------------------------------------------
  7. local state = {}
  8. local options = {
  9.     name = "MountManager",
  10.     handler = MountManager,
  11.     type = "group",
  12.     args = {
  13.         desc = {
  14.             type = "description",
  15.             name = L["Description"],
  16.             order = 0,
  17.         },
  18.         showInChat = {
  19.             type = "toggle",
  20.             name = L["Show in Chat"],
  21.             desc = L["Toggles the display of the mount name in the chat window."],
  22.             get = "GetShowInChat",
  23.             set = "SetShowInChat",
  24.             width = "full",
  25.         },
  26.         alwaysDifferent = {
  27.             type = "toggle",
  28.             name = L["Always Different"],
  29.             desc = L["Always select a different mount than the previous one."],
  30.             get = "GetAlwaysDifferent",
  31.             set = "SetAlwaysDifferent",
  32.             width = "full",
  33.         },
  34.         safeFlying = {
  35.             type = "toggle",
  36.             name = L["Safe Flying"],
  37.             desc = L["Toggles the ability to dismount when flying"],
  38.             get = "GetSafeFlying",
  39.             set = "SetSafeFlying",
  40.             width = "full",
  41.         },
  42.         oneClick = {
  43.             type = "toggle",
  44.             name = L["One Click"],
  45.             desc = L["One click will dismount you and summon the next available mount."],
  46.             get = "GetOneClick",
  47.             set = "SetOneClick",
  48.             width = "full",
  49.         },
  50.         autoNextMount = {
  51.             type = "toggle",
  52.             name = L["Automatic Next Mount"],
  53.             desc = L["Automatically determine the next available random mount after summoning the currently selected one."],
  54.             get = "GetAutoNextMount",
  55.             set = "SetAutoNextMount",
  56.             width = "full",
  57.         },
  58.     },
  59. }
  60. local defaults = {
  61.     char = {
  62.         level = level,
  63.         race = race,
  64.         class = class,
  65.         faction = faction,
  66.         prof = {},
  67.         mount_skill = 0,
  68.         serpent = false,
  69.         classmounts = true,
  70.         mounts = {
  71.             skill = {},
  72.             ground = {},
  73.             flying = {},
  74.             water = {},
  75.             aq = {},
  76.             vashj = {},
  77.         }
  78.     },
  79.     profile = {
  80.         showInChat = false,
  81.         alwaysDifferent = true,
  82.         safeFlying = true,
  83.         oneClick = true,
  84.         autoNextMount = true
  85.     },
  86. }
  87.  
  88. -- This variable is used for determining the ability to fly in the old world
  89. local flightTest = 60025
  90. -- Worgen racial
  91. local worgenRacial = 87840
  92. -- Druid travel forms
  93. local druidForms = {
  94.     travel = 783,
  95.     aquatic = 1066,
  96.     flight = 33943,
  97.     swiftflight = 40120
  98. }
  99. -- Shaman ghost wolf form
  100. local ghostWolf = 2645
  101. -- Monk zen flight
  102. local zenFlight = 125883
  103.  
  104. -- A list of all the Vashj'ir zones for reference
  105. local vashj = {
  106.     [613] = true, -- Vashj'ir
  107.     [610] = true, -- Kelp'thar Forest
  108.     [615] = true, -- Shimmering Expanse
  109.     [614] = true  -- Abyssal Depths
  110. }
  111. -- Chauffeured
  112. local chauffeured = {
  113.     [678] = 179244, -- Chauffeured Mechano-Hog
  114.     [679] = 179245, -- Chauffeured Mekgineer's Chopper
  115. }
  116. local SetMapToCurrentZone = SetMapToCurrentZone;
  117.  
  118. ------------------------------------------------------------------
  119. -- Property Accessors
  120. ------------------------------------------------------------------
  121. function MountManager:GetShowInChat(info)
  122.     return self.db.profile.showInChat
  123. end
  124. function MountManager:SetShowInChat(info, value)
  125.     self.db.profile.showInChat = value
  126. end
  127.  
  128. function MountManager:GetAlwaysDifferent(info)
  129.     return self.db.profile.alwaysDifferent
  130. end
  131. function MountManager:SetAlwaysDifferent(info, value)
  132.     self.db.profile.alwaysDifferent = value
  133. end
  134.  
  135. function MountManager:GetSafeFlying(info)
  136.     return self.db.profile.safeFlying
  137. end
  138. function MountManager:SetSafeFlying(info, value)
  139.     self.db.profile.safeFlying = value
  140. end
  141.  
  142. function MountManager:GetOneClick(info)
  143.     return self.db.profile.oneClick
  144. end
  145. function MountManager:SetOneClick(info, value)
  146.     self.db.profile.oneClick = value
  147. end
  148.  
  149. function MountManager:GetAutoNextMount(info)
  150.     return self.db.profile.autoNextMount
  151. end
  152. function MountManager:SetAutoNextMount(info, value)
  153.     self.db.profile.autoNextMount = value
  154. end
  155.  
  156. ------------------------------------------------------------------
  157. -- Initialization
  158. ------------------------------------------------------------------
  159. function MountManager:OnInitialize()
  160.     -- Called when the addon is loaded
  161.     self.db = LibStub("AceDB-3.0"):New("MountManagerDB", defaults, "Default")
  162.  
  163.     LibStub("AceConfig-3.0"):RegisterOptionsTable("MountManager", options)
  164.     self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MountManager", "MountManager")
  165.     self:RegisterChatCommand("mountmanager", "ChatCommand")
  166.     self:RegisterChatCommand("mm", "ChatCommand")
  167. end
  168.  
  169. function MountManager:OnEnable()
  170.     -- Setup current character values
  171.     self.db.char.level = UnitLevel("player")
  172.     self.db.char.race = select(2, UnitRace("player"))
  173.     self.db.char.class = UnitClass("player")
  174.     self.db.char.class2 = select(2, UnitClass("player"))
  175.     self.db.char.faction = UnitFactionGroup("player")
  176.     local prof1, prof2 = GetProfessions()
  177.     if prof1 ~= nil then
  178.         local name1, _, rank1 = GetProfessionInfo(prof1)
  179.         local name2, _, rank2 = GetProfessionInfo(prof2)
  180.         self.db.char.prof = {
  181.             [name1] = rank1,
  182.             [name2] = rank2
  183.         }
  184.     end
  185.     self:LEARNED_SPELL_IN_TAB()
  186.    
  187.     -- Track the current combat state for summoning
  188.     self:RegisterEvent("PLAYER_REGEN_DISABLED", "UpdateCombatState")
  189.     self:RegisterEvent("PLAYER_REGEN_ENABLED", "UpdateCombatState")
  190.     self:RegisterEvent("PET_BATTLE_OPENING_START", "UpdatePetBattleState")
  191.     self:RegisterEvent("PET_BATTLE_OPENING_DONE", "UpdatePetBattleState")
  192.     self:RegisterEvent("PET_BATTLE_CLOSE", "UpdatePetBattleState")
  193.    
  194.     -- Track the current zone and player state for summoning restrictions
  195.     self:RegisterEvent("ZONE_CHANGED_NEW_AREA")                     -- new world zone
  196.     self:RegisterEvent("ZONE_CHANGED", "UpdateZoneStatus")          -- new sub-zone
  197.     self:RegisterEvent("ZONE_CHANGED_INDOORS", "UpdateZoneStatus")  -- new city sub-zone
  198.     -- self:RegisterEvent("UPDATE_WORLD_STATES", "UpdateZoneStatus")    -- world pvp objectives updated
  199.     self:RegisterEvent("SPELL_UPDATE_USABLE", "UpdateZoneStatus")   -- self-explanatory
  200.    
  201.     --[[-- Handle entering and exiting water
  202.     local f = CreateFrame("Frame", "MyStateWatcher", UIParent, "SecureHandlerStateTemplate")
  203.     f:SetScript("OnShow", function() self:UpdateZoneStatus() end)
  204.     f:SetScript("OnHide", function() self:UpdateZoneStatus() end)
  205.     RegisterStateDriver(f, "visibility", "[swimming] show; hide")]]
  206.    
  207.     -- Track riding skill to determine what mounts can be used
  208.     if self.db.char.mount_skill ~= 5 or not self.db.char.serpent then
  209.         self:RegisterEvent("LEARNED_SPELL_IN_TAB")
  210.     end
  211.    
  212.     -- Learned a new mount
  213.     self:RegisterEvent("COMPANION_LEARNED")
  214.    
  215.     -- Perform an initial scan
  216.     self:ScanForNewMounts()
  217.     self:ScanForRaceClass()
  218.     self:ZONE_CHANGED_NEW_AREA()
  219.    
  220.     -- Track spell cast, to generate a new mount after the current has been cast
  221.     self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
  222.    
  223.     self:RegisterEvent("ADDON_LOADED")
  224. end
  225.  
  226. ------------------------------------------------------------------
  227. -- Event Handling
  228. ------------------------------------------------------------------
  229. function MountManager:ChatCommand(input)
  230.     if input == "rescan" then
  231.         self:Print(L["Beginning rescan..."])
  232.  
  233.         self.db.char.mounts = {
  234.             skill = {},
  235.             ground = {},
  236.             flying = {},
  237.             water = {},
  238.             aq = {},
  239.             vashj = {},
  240.         }
  241.        
  242.         self:ScanForNewMounts()
  243.         self:ScanForRaceClass()
  244.  
  245.         self:Print(L["Rescan complete"])
  246.     else
  247.         InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
  248.     end
  249. end
  250.  
  251. function MountManager:UpdateCombatState()
  252.     state.inCombat = UnitAffectingCombat("player") == 1
  253. end
  254. function MountManager:UpdatePetBattleState(event)
  255.     state.inPetBattle = C_PetBattles.IsInBattle() == true
  256. end
  257.  
  258. function MountManager:ZONE_CHANGED_NEW_AREA()
  259.     if not InCombatLockdown() then
  260.         C_Map.GetBestMapForUnit("player");
  261.         state.zone = C_Map.GetBestMapForUnit("player")
  262.     end
  263.    
  264.     self:UpdateZoneStatus()
  265. end
  266. function MountManager:UpdateZoneStatus(event)
  267.     if InCombatLockdown() or state.inCombat or state.inPetBattle then return end
  268.    
  269.     local prevSwimming = state.isSwimming
  270.     local prevFlyable = state.isFlyable
  271.    
  272.     state.isSwimming = IsSwimming() or IsSubmerged()
  273.    
  274.     local usable, _ = IsUsableSpell(flightTest)
  275.     if IsFlyableArea() and self.db.char.mount_skill > 2 and usable == true then
  276.         state.isFlyable = true
  277.     else
  278.         state.isFlyable = false
  279.     end
  280.    
  281.     if (prevSwimming ~= state.isSwimming) or (prevFlyable ~= state.isFlyable) then
  282.         self:GenerateMacro()
  283.     end
  284. end
  285.  
  286. function MountManager:LEARNED_SPELL_IN_TAB()
  287.     if IsSpellKnown(90265) then -- Master (310 flight)
  288.         self.db.char.mount_skill = 5
  289.     elseif IsSpellKnown(34091) then -- Artisan (280 flight)
  290.         self.db.char.mount_skill = 4
  291.     elseif IsSpellKnown(34090) then -- Expert (150 flight)
  292.         self.db.char.mount_skill = 3
  293.     elseif IsSpellKnown(33391) then -- Journeyman (100 ground)
  294.         self.db.char.mount_skill = 2
  295.     elseif IsSpellKnown(33388) then -- Apprentice (60 ground)
  296.         self.db.char.mount_skill = 1
  297.     end
  298.    
  299.     --if IsSpellKnown(130487) then -- Cloud Serpent Riding
  300.         self.db.char.serpent = true
  301.     --end
  302.    
  303.     --[[if self.db.char.class == "Monk" then
  304.         self.db.char.mounts["flying"][zenFlight] = IsSpellKnown(zenFlight);
  305.     end]]
  306. end
  307.  
  308. function MountManager:COMPANION_LEARNED()
  309.     self:ScanForNewMounts()
  310. end
  311.  
  312. function MountManager:UNIT_SPELLCAST_SUCCEEDED(event, unitTarget, castGUID, spellId)
  313.     if self.db.profile.autoNextMount and unit == "player" and spellId == select(7, GetSpellInfo(state.mount)) then
  314.         self:GenerateMacro()
  315.     end
  316. end
  317.  
  318. function MountManager:UPDATE_SHAPESHIFT_FORMS()
  319.     if IsSpellKnown(druidForms.travel) then
  320.         self.db.char.mounts["skill"][druidForms.travel] = true
  321.     end
  322.     if IsSpellKnown(druidForms.aquatic) then
  323.         self.db.char.mounts["water"][druidForms.aquatic] = true
  324.     end
  325.     if IsSpellKnown(druidForms.flight) then
  326.         self.db.char.mounts["flying"][druidForms.flight] = true
  327.     end
  328.     if IsSpellKnown(druidForms.swiftflight) then
  329.         self.db.char.mounts["flying"][druidForms.swiftflight] = true
  330.     end
  331. end
  332.  
  333. function MountManager:ADDON_LOADED(event, addon)
  334.     if (addon == "Blizzard_PetJournal") then
  335.         self:HijackMountFrame()
  336.     end
  337. end
  338.  
  339. ------------------------------------------------------------------
  340. -- Mount Methods
  341. ------------------------------------------------------------------
  342. function MountManager:ScanForNewMounts()
  343.     local newMounts = 0
  344.     for _, id in pairs(C_MountJournal.GetMountIDs()) do
  345.         local name, spellID, _, _, _, _, _, isFactionSpecific, faction, _, isCollected = C_MountJournal.GetMountInfoByID(id)
  346.         --make sure its valid and not already found
  347.         local correctFaction = not isFactionSpecific or (self.db.char.faction == "Horde" and faction == 0) or (self.db.char.faction == "Alliance" and faction == 1)
  348.         if correctFaction == true and isCollected == true and not self:MountExists(spellID) then
  349.             newMounts = newMounts + 1
  350.            
  351.             local _, _, _, _, mountType = C_MountJournal.GetMountInfoExtraByID(id)
  352.            
  353.             -- 284 for 2 Chopper / Mechano-Hog
  354.             -- 269 for 2 Water Striders (Azure and Crimson)
  355.             -- 254 for 1 Subdued Seahorse (Vashj'ir and water)
  356.             -- 248 for 163 "typical" flying mounts, including those that change based on level
  357.             -- 247 for 1 Red Flying Cloud (flying mount)
  358.             -- 242 for 1 Swift Spectral Gryphon (the one we fly while dead)
  359.             -- 241 for 4 Qiraji Battle Tanks (AQ only)
  360.             -- 232 for 1 Abyssal Seahorse (Vashj'ir only)
  361.             -- 231 for 2 Turtles (Riding and Sea)
  362.             -- 230 for 298 land mounts
  363.             if mountType == 241 then
  364.                 self.db.char.mounts["aq"] = self.db.char.mounts["aq"] or {}
  365.                 self.db.char.mounts["aq"][spellID] = true
  366.             end
  367.             if mountType == 232 or mountType == 254 then
  368.                 self.db.char.mounts["vashj"] = self.db.char.mounts["vashj"] or {}
  369.                 self.db.char.mounts["vashj"][spellID] = true
  370.             end
  371.             if mountType == 247 or mountType == 248 then
  372.                 self.db.char.mounts["flying"] = self.db.char.mounts["flying"] or {}
  373.                 self.db.char.mounts["flying"][spellID] = true
  374.             end
  375.             if mountType == 231 or mountType == 254 or mountType == 269 then
  376.                 self.db.char.mounts["water"] = self.db.char.mounts["water"] or {}
  377.                 self.db.char.mounts["water"][spellID] = true
  378.             end
  379.             if mountType == 230 or mountType == 231 or mountType == 269 or mountType == 284 then
  380.                 self.db.char.mounts["ground"] = self.db.char.mounts["ground"] or {}
  381.                 self.db.char.mounts["ground"][spellID] = true
  382.             end
  383.         end
  384.     end
  385.    
  386.     if newMounts > 0 then
  387.         self:Print(string.format("|cff20ff20%s|r %s", newMounts, L["new mount(s) found!"]))
  388.         self:UpdateMountChecks()
  389.     end
  390. end
  391. function MountManager:ScanForRaceClass()
  392.     if self.db.char.race == "Worgen" and self.db.char.mount_skill > 0 then
  393.         self.db.char.mounts["ground"][worgenRacial] = true;
  394.     end
  395.     if self.db.char.class == "Druid" then
  396.         self:UPDATE_SHAPESHIFT_FORMS()
  397.     end
  398.     if self.db.char.class == "Monk" then
  399.         self.db.char.mounts["flying"][zenFlight] = IsSpellKnown(zenFlight);
  400.     end
  401.     if self.db.char.class == "Shaman" and self.db.char.level > 14 then
  402.         self.db.char.mounts["skill"][ghostWolf] = true;
  403.     end
  404. end
  405. function MountManager:MountExists(spellID)
  406.     for mountType, typeTable in pairs(self.db.char.mounts) do
  407.         if typeTable[spellID] ~= nil then
  408.             return true
  409.         end
  410.     end
  411.     return false
  412. end
  413. function MountManager:SummonMount(mount)
  414.     for _, id in pairs(C_MountJournal.GetMountIDs()) do
  415.         local _, spellID = C_MountJournal.GetMountInfoByID(id)
  416.         if spellID == mount then
  417.             C_MountJournal.SummonByID(id)
  418.             return
  419.         end
  420.     end
  421. end
  422.  
  423. ------------------------------------------------------------------
  424. -- Mount Configuration
  425. ------------------------------------------------------------------
  426. function MountManager:HijackMountFrame()
  427.     self.companionButtons = {}
  428.  
  429.     local numMounts = (C_MountJournal.GetMountIDs())
  430.     local scrollFrame = MountJournal.ListScrollFrame
  431.     local buttons = scrollFrame.buttons
  432.  
  433.     -- build out check buttons
  434.     for idx = 1, #buttons do
  435.         local parent = buttons[idx];
  436.         if idx <= numMounts then
  437.             local button = CreateFrame("CheckButton", "MountCheckButton" .. idx, parent, "UICheckButtonTemplate")
  438.             button:SetEnabled(false)
  439.             button:SetPoint("TOPRIGHT", 0, 0)
  440.             button:HookScript("OnClick", function(self)
  441.                 MountManager:MountCheckButton_OnClick(self)
  442.             end)
  443.  
  444.             self.companionButtons[idx] = button
  445.         end
  446.     end
  447.  
  448.     -- hook up events to update check state on scrolling
  449.     scrollFrame:HookScript("OnMouseWheel", function(self)
  450.         MountManager:UpdateMountChecks()
  451.     end)
  452.     scrollFrame:HookScript("OnVerticalScroll", function(self)
  453.         MountManager:UpdateMountChecks()
  454.     end)
  455.    
  456.     ---- hook up events to update check state on search or filter change
  457.     hooksecurefunc("MountJournal_UpdateMountList", function(self)
  458.         MountManager:UpdateMountChecks()
  459.     end);
  460.  
  461.     -- force an initial update on the journal, as it's coded to only do it upon scroll or selection
  462.     MountJournal_UpdateMountList()
  463. end
  464.  
  465. function MountManager:UpdateMountChecks()
  466.     if self.companionButtons then
  467.         local offset = HybridScrollFrame_GetOffset(MountJournal.ListScrollFrame);
  468.    
  469.         for idx, button in ipairs(self.companionButtons) do
  470.             local parent = button:GetParent()
  471.            
  472.             -- Get information about the currently selected mount
  473.             local spellID = parent.spellID
  474.             local id = self:FindSelectedID(spellID)
  475.             local _, _, _, _, _, _, _, isFactionSpecific, faction, _, isCollected = C_MountJournal.GetMountInfoByID(id)
  476.             local correctFaction = (not isFactionSpecific or (self.db.char.faction == "Horde" and faction == 0) or (self.db.char.faction == "Alliance" and faction == 1))
  477.            
  478.             if correctFaction == true and isCollected == true and parent:IsEnabled() == true then
  479.                    
  480.                 -- Set the checked state based on the currently saved value
  481.                 local checked = false;
  482.                 for mountType, typeTable in pairs(self.db.char.mounts) do
  483.                     if typeTable[spellID] ~= nil then
  484.                         checked = typeTable[spellID]
  485.                     end
  486.                 end
  487.  
  488.                 button:SetEnabled(true)
  489.                 button:SetChecked(checked)
  490.                 button:SetAlpha(1.0);
  491.             else
  492.                 button:SetEnabled(false)
  493.                 button:SetChecked(false)
  494.                 button:SetAlpha(0.25);
  495.             end
  496.         end
  497.     end
  498. end
  499.  
  500. function MountManager:MountCheckButton_OnClick(button)
  501.     local spellID = button:GetParent().spellID
  502.    
  503.     -- Toggle the saved value for the selected mount
  504.     for mountType, typeTable in pairs(self.db.char.mounts) do
  505.         if typeTable[spellID] ~= nil then
  506.             if typeTable[spellID] == true then
  507.                 typeTable[spellID] = false
  508.             else
  509.                 typeTable[spellID] = true
  510.             end
  511.         end
  512.     end
  513. end
  514. function MountManager:FindSelectedID(selectedSpellID)
  515.     for _, id in pairs(C_MountJournal.GetMountIDs()) do
  516.         local _, spellID = MountJournal_GetMountInfoByID(id);
  517.         if spellID == selectedSpellID then
  518.             return id;
  519.         end
  520.     end
  521.  
  522.     return nil;
  523. end
  524.  
  525. function MountManager:MountManagerButton_OnClick(button)
  526.     if button == "LeftButton" then
  527.         if IsIndoors() then return end
  528.        
  529.         if IsFlying() then
  530.             if self.db.profile.safeFlying == false then
  531.                 Dismount()
  532.             end
  533.         else
  534.             local speed = GetUnitSpeed("player")
  535.            
  536.             if IsMounted() then
  537.                 Dismount()
  538.                 if speed == 0 and self.db.profile.oneClick then
  539.                     self:SummonMount(state.mount)
  540.                 end
  541.             else
  542.                 if speed == 0 then
  543.                     self:SummonMount(state.mount)
  544.                 end    
  545.             end
  546.         end
  547.     else
  548.         self:GenerateMacro()
  549.     end
  550. end
  551.  
  552. ------------------------------------------------------------------
  553. -- Macro Setup
  554. ------------------------------------------------------------------
  555. function MountManager:GenerateMacro()
  556.     if InCombatLockdown() or state.inCombat or state.inPetBattle then return end
  557.    
  558.     -- Create base macro for mount selection
  559.     local index = GetMacroIndexByName("MountManager")
  560.     if index == 0 then
  561.         index = CreateMacro("MountManager", 1, "", 1, nil)
  562.     end
  563.    
  564.     if self.db.char.level < 20 then
  565.         local id = (UnitFactionGroup("player") == "Horde") and 678 or 679
  566.         state.mount = select(5, C_MountJournal.GetMountInfoByID(id)) and chauffeured[id]
  567.     else
  568.         state.mount = self:GetRandomMount()
  569.     end
  570.    
  571.     if state.mount then
  572.         local name, rank, icon = GetSpellInfo(state.mount)
  573.         --icon = string.sub(icon, 17)
  574.        
  575.         if self.db.profile.showInChat then
  576.             self:Print(string.format("%s |cff20ff20%s|r", L["The next selected mount is"], name))
  577.         end
  578.        
  579.         EditMacro(index, "MountManager", icon, string.format("/script MountManagerButton:Click(GetMouseButtonClicked());\n#showtooltip %s", name))
  580.     else
  581.         self:Print(L["There is no mount available for the current character."])
  582.     end
  583. end
  584.  
  585. function MountManager:GetRandomMount()
  586.     if self.db.char.mount_skill == 0 then
  587.         return nil
  588.     end
  589.    
  590.     -- Determine state order for looking for a mount
  591.     local typeList = {}
  592.     local keyDown = IsModifierKeyDown()
  593.     if vashj[state.zone] then -- in Vashj'ir
  594.         if state.isSwimming == true and not keyDown then
  595.             typeList = { "vashj", "water", "ground" }
  596.         elseif state.isFlyable == true then
  597.             typeList = { "flying", "vashj", "water", "ground" }
  598.         else
  599.             typeList = { "ground" }
  600.         end
  601.     elseif state.zone == 766 then -- in AQ
  602.         if keyDown then
  603.             typeList = { "ground" }
  604.         elseif state.isSwimming == true then
  605.             typeList = { "water", "aq", "ground" }
  606.         else
  607.             typeList = { "aq", "ground" }
  608.         end
  609.     elseif state.isSwimming == true then
  610.         if state.isFlyable == true and not keyDown then
  611.             typeList = { "flying", "water", "ground" }
  612.         else
  613.             typeList = { "water", "ground" }
  614.         end
  615.     elseif state.isFlyable == true and not keyDown then
  616.         typeList = { "flying", "ground" }
  617.     else
  618.         typeList = { "ground" }
  619.     end
  620.    
  621.     -- Cycle through the type list
  622.     for i, type in pairs(typeList) do
  623.         -- Make a sublist of any valid mounts of the selected type
  624.         local mounts = {}
  625.         for mount, active in pairs(self.db.char.mounts[type]) do
  626.             if self.db.char.mounts[type][mount] == true and self:CheckProfession(mount) and self:CheckSerpent(mount) and self:CheckClass(mount) then
  627.                 mounts[#mounts + 1] = mount
  628.             end
  629.         end
  630.        
  631.         -- If there were any matching mounts of the current type, then proceed, otherwise move to the next type
  632.         if #mounts > 0 then
  633.             -- Grab a random mount from the narrowed list
  634.             local rand = random(1, #mounts)
  635.             local mount = mounts[rand]
  636.             if state.mount == mount and self.db.profile.alwaysDifferent and #mounts > 1 then
  637.                 while state.mount == mount do
  638.                     rand = random(1, #mounts)
  639.                     mount = mounts[rand]
  640.                 end
  641.             end
  642.             return mount
  643.         end
  644.     end
  645.    
  646.     -- If this point has been reached, then no matching mount was found
  647.     return nil
  648. end
  649.  
  650. -- Profession restricted mounts
  651. local TAILORING_ID = 110426
  652. local ENGINEERING_ID = 110403
  653. local profMounts =  {
  654.     [61451] = { TAILORING_ID, 300 }, --Flying Carpet
  655.     [61309] = { TAILORING_ID, 300 }, --Magnificent Flying Carpet
  656.     [75596] = { TAILORING_ID, 300 }, --Frosty Flying Carpet
  657.     [169952] = { TAILORING_ID, 300 }, --Creeping Carpet
  658.    
  659.     [44153] = { ENGINEERING_ID, 300 }, --Flying Machine
  660.     [44151] = { ENGINEERING_ID, 300 }, --Turbo-Charged Flying Machine
  661. }
  662. function MountManager:CheckProfession(spell)
  663.     if profMounts[spell] then
  664.         local skill = GetSpellInfo(profMounts[spell][1])
  665.         local req = profMounts[spell][2]
  666.         if self.db.char.prof[skill] then
  667.             return self.db.char.prof[skill] >= req
  668.         else
  669.             return false
  670.         end
  671.     end
  672.     return true
  673. end
  674.  
  675. -- Cloud Serpents
  676. local serpents = {
  677.     [113199] = true, --Jade Cloud Serpent
  678.     [123992] = true, --Azure Cloud Serpent
  679.     [123993] = true, --Golden Cloud Serpent
  680.     [127154] = true, --Onyx Cloud Serpent
  681.     [127156] = true, --Crimson Cloud Serpent
  682.     [127170] = true, --Astral Cloud Serpent
  683.    
  684.     [127158] = true, --Heavenly Onyx Cloud Serpent
  685.     [127161] = true, --Heavenly Crimson Cloud Serpent
  686.     [127164] = true, --Heavenly Golden Cloud Serpent
  687.     [127165] = true, --Heavenly Jade Cloud Serpent
  688.     [127169] = true, --Heavenly Azure Cloud Serpent
  689.    
  690.     [124408] = true, --Thundering Jade Cloud Serpent
  691.     [129918] = true, --Thundering August Cloud Serpent
  692.     [132036] = true, --Thundering Ruby Cloud Serpent
  693. }
  694. function MountManager:CheckSerpent(spell)
  695.     if serpents[spell] then
  696.         return self.db.char.serpent
  697.     end
  698.     return true
  699. end
  700.  
  701. -- Class Mounts
  702. local classmounts =  { 
  703.     [229387] = "DEATHKNIGHT", --Deathlord's Vilebrood Vanquisher
  704.     [48778] = "DEATHKNIGHT", --Acherus Deathcharger
  705.     [54729] = "DEATHKNIGHT", --Winged Steed of the Ebon Blade
  706.     [200175] = "DEMONHUNTER", --Felsaber
  707.     [229417] = "DEMONHUNTER", --Slayer's Felbroken Shrieker
  708.     [229386] = "HUNTER", --Huntmaster's Loyal Wolfhawk
  709.     [229438] = "HUNTER", --Huntmaster's Fierce Wolfhawk
  710.     [229439] = "HUNTER", --Huntmaster's Dire Wolfhawk
  711.     [229376] = "MAGE", --Archmage's Prismatic Disc
  712.     [229385] = "MONK", --Ban-Lu, Grandmaster's Companion
  713.     [23214] = "PALADIN", --Charger
  714.     [34767] = "PALADIN", --Thalassian Charger
  715.     [73630] = "PALADIN", --HGreat Exarch's Elekk
  716.     [69826] = "PALADIN", --Great Sunwalker Kodo
  717.     [66906] = "PALADIN", --Argent Charger
  718.     [231435] = "PALADIN", --Highlord's Golden Charger
  719.     [231589] = "PALADIN", --Highlord's Valorous Charge
  720.     [231588] = "PALADIN", --Highlord's Vigilant Charger
  721.     [231587] = "PALADIN", --Highlord's Vengeful Charger
  722.     [229377] = "PRIEST", --High Priest's Lightsworn Seeker
  723.     [231434] = "ROGUE", --Shadowblade's Murderous Omen
  724.     [231523] = "ROGUE", --Shadowblade's Lethal Omen
  725.     [231524] = "ROGUE", --Shadowblade's Baneful Omen
  726.     [231525] = "ROGUE", --Shadowblade's Crimson Omen
  727.     [231442] = "SHAMAN", --Farseer's Raging Tempest
  728.     [5784] = "WARLOCK", --Felsteed
  729.     [23161] = "WARLOCK", --Dreadsteed
  730.     [238452] = "WARLOCK", --Netherlord's Brimstone Wrathsteed
  731.     [238454] = "WARLOCK", --Netherlord's Accursed Wrathsteed
  732.     [232412] = "WARLOCK", --Netherlord's Chaotic Wrathsteed
  733.     [229388] = "WARRIOR", --Battlelord's Bloodthirsty War Wyrm
  734. }
  735.  
  736. function MountManager:CheckClass(spell)
  737.     if classmounts[spell] then
  738.         if classmounts[spell] == self.db.char.class2 then
  739.             return self.db.char.classmounts
  740.         else
  741.             return false
  742.         end
  743.     end
  744.     return true
  745. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement