diff MyLilPony.lua @ 1:7dfbf42c2d60

Initial commit of MyLilPony
author syzler
date Mon, 04 Apr 2011 04:43:05 +0000
parents
children 9052b32b69c3
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MyLilPony.lua	Mon Apr 04 04:43:05 2011 +0000
@@ -0,0 +1,173 @@
+-- MyLilPony
+-- Copyright (c) 2011 Syzler
+--
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+function MyLilPony.OnLoad()
+    SlashCmdList["MyLilPony"] = MyLilPony.SlashHandler;
+    SLASH_MyLilPony1 = "/pony";
+    SLASH_MyLilPony2 = "/mlp";
+    SLASH_MyLilPony3 = "/mylilpony";
+    
+    MyLilPony.Log(format("Version %s loaded", MYLILPONY_VERSION));
+    MyLilPony.LoadDefaults();
+end
+
+function MyLilPony.LoadDefaults()
+    if MyLilPony.AutoDismount == nil then MyLilPony.AutoDismount = true end
+end
+
+function MyLilPony.AutoMount()
+    if UnitIsDead("player") or UnitIsGhost("player") then
+        MyLilPony.Log("You are dead");
+        return;
+    end
+    
+    if InCombatLockdown() then
+        MyLilPony.Log("You are in combat");
+        return;
+    end
+    
+    if IsMounted() and not MyLilPony.AutoDismount then
+        MyLilPony.Log("You are already mounted");
+        return;
+    end
+    
+    if IsMounted() and IsFlying() then
+        MyLilPony.Log("You are already flying");
+        return;
+    end
+    
+    local zone = GetRealZoneText();
+    
+    -- player is in Temple of Ahn'Qiraj (AQ40)
+    if zone == "Ahn'Qiraj" then
+        if not IsModifierKeyDown() and MyLilPony.CallMountByRegex("Qiraji Battle Tank") then
+            return
+        end
+    end
+    
+    -- player is in Wintergrasp
+    if zone == "Wintergrasp" then
+        -- always call ground mount if Wintergrasp is in progress
+        local _, _, wintergraspInProgress, _, _, _ = GetWorldPVPAreaInfo(1);
+        if wintergraspInProgress and MyLilPony.CallGroundMount() then
+            return;
+        end
+    end
+    
+    -- player is swimming in Vash'jir
+    if IsSwimming() and (zone == "Shimmering Expanse" or zone == "Kelp'thar Forest" or zone == "Abyssal Depths") then
+        -- normal behaviour in Vash'jir is to call the Abyssal Seahorse
+        -- modified behaviour is to attempt flight (i.e. you're at the surface)
+        if not IsModifierKeyDown() and MyLilPony.CallMountByName("Abyssal Seahorse") then
+            return;
+        elseif MyLilPony.CanFlyHere() and MyLilPony.CallFlyingMount() then
+            return;
+        elseif MyLilPony.CallAquaticMount() then
+            return;
+        end
+    end
+    
+    -- player is in flyable area and knows how to fly here too
+    if MyLilPony.CanFlyHere() and not IsModifierKeyDown() then
+        -- normal behaviour in flyable area is to call flying mount
+        if MyLilPony.CallFlyingMount() then
+            return;
+        end
+    end
+    
+    -- player is swimming
+    if IsSwimming() and not IsModifierKeyDown() then
+        -- normal behaviour while swimming is to call aquatic mount
+        if MyLilPony.CallAquaticMount() then
+            return;
+        end
+    end
+    
+    MyLilPony.CallGroundMount();
+end
+
+function MyLilPony.SlashHandler(arg)
+    if MyLilPony.StringMatchIgnoreCase(arg, "^auto$") then
+        MyLilPony.AutoMount();
+    elseif MyLilPony.StringMatchIgnoreCase(arg, "^random$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^rand$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^rng$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^r$") then
+        MyLilPony.CallMount();
+    elseif MyLilPony.StringMatchIgnoreCase(arg, "^ground$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^g$") then
+        MyLilPony.CallGroundMount();
+    elseif MyLilPony.StringMatchIgnoreCase(arg, "^flying$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^fly$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^air$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^a$") then
+        MyLilPony.CallFlyingMount();
+    elseif MyLilPony.StringMatchIgnoreCase(arg, "^aquatic$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^aqua$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^swim$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^s$") then
+        MyLilPony.CallAquaticMount();
+    elseif MyLilPony.StringMatchIgnoreCase(arg, "^target$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^tgt$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^t$") then
+        local result = MyLilPony.CallMountByMatch("target");
+        if not result then
+            MyLilPony.Log("No matching mounts were found");
+        end
+    elseif MyLilPony.StringMatchIgnoreCase(arg, "^exact .+$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^x .+$") then
+        local param = MyLilPony.StringMatchIgnoreCase(arg, "^.+ (.+)$");
+        local result = MyLilPony.CallMountByName(param);
+        if not result then
+            MyLilPony.Log(format("No matching mounts were found with NAME='%s'", param));
+        end
+    elseif MyLilPony.StringMatchIgnoreCase(arg, "^list .+$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^find .+$")
+        or MyLilPony.StringMatchIgnoreCase(arg, "^l .+$") then
+        local param = MyLilPony.StringMatchIgnoreCase(arg, "^.+ (.+)$");
+        local result = MyLilPony.ListMountsByPattern(param);
+        if not result then
+            MyLilPony.Log(format("No matching mounts were found with NAME like '%s'", param));
+        else
+            for _, name in pairs(result) do
+                MyLilPony.Print(name);
+            end
+        end
+    elseif MyLilPony.StringMatchIgnoreCase(arg, "^%d+$") then
+        local result = MyLilPony.CallMountById(tonumber(arg));
+        if not result then
+            MyLilPony.Log(format("No matching mounts were found with ID=%s", arg));
+        end
+    elseif MyLilPony.StringMatchIgnoreCase(arg, "^.+$") then
+        local result = MyLilPony.CallMountByPattern(arg);
+        if not result then
+            MyLilPony.Log(format("No matching mounts were found with NAME like '%s'", arg));
+        end
+    else
+        MyLilPony.Print(format("MyLilPony %s", MYLILPONY_VERSION));
+        MyLilPony.Print("Slash Command: /mylilpony (/pony, /mlp)");
+        MyLilPony.Print("  /mylilpony auto - Summons a \"suitable\" mount");
+        MyLilPony.Print("  /mylilpony random - Summons random mount");
+        MyLilPony.Print("  /mylilpony ground - Summons random ground mount");
+        MyLilPony.Print("  /mylilpony flying - Summons random flying mount");
+        MyLilPony.Print("  /mylilpony aquatic - Summons random aquatic mount");
+        MyLilPony.Print("  /mylilpony target - Summons same mount as targeted unit");
+        MyLilPony.Print("  /mylilpony list <NAME> - Lists mounts matching name");
+        MyLilPony.Print("  /mylilpony exact <NAME> - Summons mount by exact name");
+        MyLilPony.Print("  /mylilpony <ID> - Summons mount by spell or creature ID");
+        MyLilPony.Print("  /mylilpony <NAME> - Summons random mount matching name");
+    end
+end