view MyLilPony.lua @ 14:b1e344c17ab5

Changing to BSD license for more flexibility in licensing for derived addons and using as a library.
author syzler
date Sun, 10 Apr 2011 07:12:30 +0000
parents cca898af07b4
children 21764271e02f
line wrap: on
line source
-- MyLilPony
-- Copyright (c) 2011, Syzler
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions
-- are met:
--
--  * Redistributions of source code must retain the above copyright
--    notice, this list of conditions and the following disclaimer.
--  * Redistributions in binary form must reproduce the above copyright
--    notice, this list of conditions and the following disclaimer in
--    the documentation and/or other materials provided with the
--    distribution.
--  * Neither the name of the MyLilPony Project nor the names of its
--    contributors may be used to endorse or promote products derived
--    from this software without specific prior written permission.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-- COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-- POSSIBILITY OF SUCH DAMAGE.

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() then
        -- normal behaviour in flyable area is to call flying mount
        if not IsModifierKeyDown() and MyLilPony.CallFlyingMount() then
            return;
        elseif IsSwimming() and MyLilPony.CallAquaticMount() then
            return;
        end
    end
    
    -- player is swimming
    if IsSwimming() then
        -- normal behaviour while swimming is to call aquatic mount
        if not IsModifierKeyDown() and MyLilPony.CallAquaticMount() then
            return;
        end
    end
    
    MyLilPony.CallGroundMount();
end

function MyLilPony.SlashHandler(args)
    local arg = SecureCmdOptionParse(args);
    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