syzler@14: -- Copyright (c) 2011, Syzler syzler@14: -- All rights reserved. syzler@1: -- syzler@14: -- Redistribution and use in source and binary forms, with or without syzler@14: -- modification, are permitted provided that the following conditions syzler@14: -- are met: syzler@1: -- syzler@14: -- * Redistributions of source code must retain the above copyright syzler@14: -- notice, this list of conditions and the following disclaimer. syzler@14: -- * Redistributions in binary form must reproduce the above copyright syzler@14: -- notice, this list of conditions and the following disclaimer in syzler@14: -- the documentation and/or other materials provided with the syzler@14: -- distribution. syzler@14: -- * Neither the name of the MyLilPony Project nor the names of its syzler@14: -- contributors may be used to endorse or promote products derived syzler@14: -- from this software without specific prior written permission. syzler@1: -- syzler@14: -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS syzler@14: -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT syzler@14: -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS syzler@14: -- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE syzler@14: -- COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, syzler@14: -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, syzler@14: -- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; syzler@14: -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER syzler@14: -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT syzler@14: -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN syzler@14: -- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE syzler@14: -- POSSIBILITY OF SUCH DAMAGE. syzler@1: syzler@15: ------------------------------------------------------------------------ syzler@15: -- Project: MyLilPony syzler@15: -- Project Version: @project-version@ syzler@15: -- Last Author: @file-author@ syzler@15: -- Last Updated: @file-date-iso@ syzler@15: -- syzler@15: -- Main addon code syzler@15: ------------------------------------------------------------------------ syzler@15: syzler@1: function MyLilPony.OnLoad() syzler@1: SlashCmdList["MyLilPony"] = MyLilPony.SlashHandler; syzler@1: SLASH_MyLilPony1 = "/pony"; syzler@1: SLASH_MyLilPony2 = "/mlp"; syzler@1: SLASH_MyLilPony3 = "/mylilpony"; syzler@1: syzler@25: MyLilPony.Log(format(L["msgVersionLoaded"], MYLILPONY_VERSION)); syzler@1: MyLilPony.LoadDefaults(); syzler@1: end syzler@1: syzler@1: function MyLilPony.LoadDefaults() syzler@1: if MyLilPony.AutoDismount == nil then MyLilPony.AutoDismount = true end syzler@1: end syzler@1: syzler@1: function MyLilPony.AutoMount() syzler@1: if UnitIsDead("player") or UnitIsGhost("player") then syzler@25: MyLilPony.Log(L["msgYouAreDead"]); syzler@1: return; syzler@1: end syzler@1: syzler@1: if InCombatLockdown() then syzler@25: MyLilPony.Log(L["msgYouAreInCombat"]); syzler@1: return; syzler@1: end syzler@1: syzler@1: if IsMounted() and not MyLilPony.AutoDismount then syzler@25: MyLilPony.Log(L["msgYouAreMounted"]); syzler@1: return; syzler@1: end syzler@1: syzler@1: if IsMounted() and IsFlying() then syzler@25: MyLilPony.Log(L["msgYouAreFlying"]); syzler@1: return; syzler@1: end syzler@1: syzler@1: local zone = GetRealZoneText(); syzler@1: syzler@1: -- player is in Temple of Ahn'Qiraj (AQ40) syzler@1: if zone == "Ahn'Qiraj" then syzler@18: if not IsModifierKeyDown() and MyLilPony.CallMountByPattern("Qiraji Battle Tank") then syzler@18: return; syzler@1: end syzler@1: end syzler@1: syzler@1: -- player is in Wintergrasp syzler@1: if zone == "Wintergrasp" then syzler@1: -- always call ground mount if Wintergrasp is in progress syzler@1: local _, _, wintergraspInProgress, _, _, _ = GetWorldPVPAreaInfo(1); syzler@1: if wintergraspInProgress and MyLilPony.CallGroundMount() then syzler@1: return; syzler@1: end syzler@1: end syzler@1: syzler@1: -- player is swimming in Vash'jir syzler@1: if IsSwimming() and (zone == "Shimmering Expanse" or zone == "Kelp'thar Forest" or zone == "Abyssal Depths") then syzler@1: -- normal behaviour in Vash'jir is to call the Abyssal Seahorse syzler@1: -- modified behaviour is to attempt flight (i.e. you're at the surface) syzler@1: if not IsModifierKeyDown() and MyLilPony.CallMountByName("Abyssal Seahorse") then syzler@1: return; syzler@1: elseif MyLilPony.CanFlyHere() and MyLilPony.CallFlyingMount() then syzler@1: return; syzler@1: elseif MyLilPony.CallAquaticMount() then syzler@1: return; syzler@1: end syzler@1: end syzler@1: syzler@1: -- player is in flyable area and knows how to fly here too syzler@13: if MyLilPony.CanFlyHere() then syzler@1: -- normal behaviour in flyable area is to call flying mount syzler@13: if not IsModifierKeyDown() and MyLilPony.CallFlyingMount() then syzler@13: return; syzler@13: elseif IsSwimming() and MyLilPony.CallAquaticMount() then syzler@1: return; syzler@1: end syzler@1: end syzler@1: syzler@1: -- player is swimming syzler@13: if IsSwimming() then syzler@1: -- normal behaviour while swimming is to call aquatic mount syzler@13: if not IsModifierKeyDown() and MyLilPony.CallAquaticMount() then syzler@1: return; syzler@1: end syzler@1: end syzler@1: syzler@1: MyLilPony.CallGroundMount(); syzler@1: end syzler@1: syzler@11: function MyLilPony.SlashHandler(args) syzler@19: local arg, unit = SecureCmdOptionParse(args); syzler@1: if MyLilPony.StringMatchIgnoreCase(arg, "^auto$") then syzler@1: MyLilPony.AutoMount(); syzler@1: elseif MyLilPony.StringMatchIgnoreCase(arg, "^random$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^rand$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^rng$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^r$") then syzler@1: MyLilPony.CallMount(); syzler@1: elseif MyLilPony.StringMatchIgnoreCase(arg, "^ground$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^g$") then syzler@1: MyLilPony.CallGroundMount(); syzler@1: elseif MyLilPony.StringMatchIgnoreCase(arg, "^flying$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^fly$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^air$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^a$") then syzler@1: MyLilPony.CallFlyingMount(); syzler@1: elseif MyLilPony.StringMatchIgnoreCase(arg, "^aquatic$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^aqua$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^swim$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^s$") then syzler@1: MyLilPony.CallAquaticMount(); syzler@19: elseif MyLilPony.StringMatchIgnoreCase(arg, "^match$") syzler@19: or MyLilPony.StringMatchIgnoreCase(arg, "^m$") syzler@19: or MyLilPony.StringMatchIgnoreCase(arg, "^target$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^tgt$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^t$") then syzler@19: if unit == "" or unit == nil then unit = "target" end syzler@19: local result = MyLilPony.CallMountByMatch(unit); syzler@1: if not result then syzler@25: MyLilPony.Log(L["msgNoMatchingMountsFound"]); syzler@1: end syzler@1: elseif MyLilPony.StringMatchIgnoreCase(arg, "^exact .+$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^x .+$") then syzler@1: local param = MyLilPony.StringMatchIgnoreCase(arg, "^.+ (.+)$"); syzler@1: local result = MyLilPony.CallMountByName(param); syzler@1: if not result then syzler@25: MyLilPony.Log(format(L["msgNoMatchingMountsForName"], param)); syzler@1: end syzler@1: elseif MyLilPony.StringMatchIgnoreCase(arg, "^list .+$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^find .+$") syzler@1: or MyLilPony.StringMatchIgnoreCase(arg, "^l .+$") then syzler@1: local param = MyLilPony.StringMatchIgnoreCase(arg, "^.+ (.+)$"); syzler@1: local result = MyLilPony.ListMountsByPattern(param); syzler@1: if not result then syzler@25: MyLilPony.Log(format(L["msgNoMatchingMountsForPattern"], param)); syzler@1: else syzler@1: for _, name in pairs(result) do syzler@1: MyLilPony.Print(name); syzler@1: end syzler@30: MyLilPony.Print(format(L["msgCountMatchingMountsForPattern"], #result)); syzler@1: end syzler@1: elseif MyLilPony.StringMatchIgnoreCase(arg, "^%d+$") then syzler@1: local result = MyLilPony.CallMountById(tonumber(arg)); syzler@1: if not result then syzler@25: MyLilPony.Log(format(L["msgNoMatchingMountsForId"], arg)); syzler@1: end syzler@1: elseif MyLilPony.StringMatchIgnoreCase(arg, "^.+$") then syzler@1: local result = MyLilPony.CallMountByPattern(arg); syzler@1: if not result then syzler@25: MyLilPony.Log(format(L["msgNoMatchingMountsForPattern"], arg)); syzler@1: end syzler@1: else syzler@1: MyLilPony.Print(format("MyLilPony %s", MYLILPONY_VERSION)); syzler@25: MyLilPony.Print(L["szCommandHelp"].." (/mylilpony, /pony, /mlp)"); syzler@22: MyLilPony.Print(" /mylilpony auto - "..L["msgHelpCommandAuto"]); syzler@22: MyLilPony.Print(" /mylilpony random - "..L["msgHelpCommandRandom"]); syzler@22: MyLilPony.Print(" /mylilpony ground - "..L["msgHelpCommandGround"]); syzler@22: MyLilPony.Print(" /mylilpony flying - "..L["msgHelpCommandFlying"]); syzler@22: MyLilPony.Print(" /mylilpony aquatic - "..L["msgHelpCommandAquatic"]); syzler@22: MyLilPony.Print(" /mylilpony match - "..L["msgHelpCommandTarget"]); syzler@22: MyLilPony.Print(" /mylilpony [@] match - "..L["msgHelpCommandMatch"]); syzler@22: MyLilPony.Print(" /mylilpony list - "..L["msgHelpCommandList"]); syzler@22: MyLilPony.Print(" /mylilpony exact - "..L["msgHelpCommandExact"]); syzler@22: MyLilPony.Print(" /mylilpony - "..L["msgHelpCommandId"]); syzler@22: MyLilPony.Print(" /mylilpony - "..L["msgHelpCommandName"]); syzler@1: end syzler@1: end syzler@17: syzler@17: MyLilPony.OnLoad();