annotate 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
rev   line source
syzler@1 1 -- MyLilPony
syzler@14 2 -- Copyright (c) 2011, Syzler
syzler@14 3 -- All rights reserved.
syzler@1 4 --
syzler@14 5 -- Redistribution and use in source and binary forms, with or without
syzler@14 6 -- modification, are permitted provided that the following conditions
syzler@14 7 -- are met:
syzler@1 8 --
syzler@14 9 -- * Redistributions of source code must retain the above copyright
syzler@14 10 -- notice, this list of conditions and the following disclaimer.
syzler@14 11 -- * Redistributions in binary form must reproduce the above copyright
syzler@14 12 -- notice, this list of conditions and the following disclaimer in
syzler@14 13 -- the documentation and/or other materials provided with the
syzler@14 14 -- distribution.
syzler@14 15 -- * Neither the name of the MyLilPony Project nor the names of its
syzler@14 16 -- contributors may be used to endorse or promote products derived
syzler@14 17 -- from this software without specific prior written permission.
syzler@1 18 --
syzler@14 19 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
syzler@14 20 -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
syzler@14 21 -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
syzler@14 22 -- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
syzler@14 23 -- COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
syzler@14 24 -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
syzler@14 25 -- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
syzler@14 26 -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
syzler@14 27 -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
syzler@14 28 -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
syzler@14 29 -- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
syzler@14 30 -- POSSIBILITY OF SUCH DAMAGE.
syzler@1 31
syzler@1 32 function MyLilPony.OnLoad()
syzler@1 33 SlashCmdList["MyLilPony"] = MyLilPony.SlashHandler;
syzler@1 34 SLASH_MyLilPony1 = "/pony";
syzler@1 35 SLASH_MyLilPony2 = "/mlp";
syzler@1 36 SLASH_MyLilPony3 = "/mylilpony";
syzler@1 37
syzler@1 38 MyLilPony.Log(format("Version %s loaded", MYLILPONY_VERSION));
syzler@1 39 MyLilPony.LoadDefaults();
syzler@1 40 end
syzler@1 41
syzler@1 42 function MyLilPony.LoadDefaults()
syzler@1 43 if MyLilPony.AutoDismount == nil then MyLilPony.AutoDismount = true end
syzler@1 44 end
syzler@1 45
syzler@1 46 function MyLilPony.AutoMount()
syzler@1 47 if UnitIsDead("player") or UnitIsGhost("player") then
syzler@1 48 MyLilPony.Log("You are dead");
syzler@1 49 return;
syzler@1 50 end
syzler@1 51
syzler@1 52 if InCombatLockdown() then
syzler@1 53 MyLilPony.Log("You are in combat");
syzler@1 54 return;
syzler@1 55 end
syzler@1 56
syzler@1 57 if IsMounted() and not MyLilPony.AutoDismount then
syzler@1 58 MyLilPony.Log("You are already mounted");
syzler@1 59 return;
syzler@1 60 end
syzler@1 61
syzler@1 62 if IsMounted() and IsFlying() then
syzler@1 63 MyLilPony.Log("You are already flying");
syzler@1 64 return;
syzler@1 65 end
syzler@1 66
syzler@1 67 local zone = GetRealZoneText();
syzler@1 68
syzler@1 69 -- player is in Temple of Ahn'Qiraj (AQ40)
syzler@1 70 if zone == "Ahn'Qiraj" then
syzler@1 71 if not IsModifierKeyDown() and MyLilPony.CallMountByRegex("Qiraji Battle Tank") then
syzler@1 72 return
syzler@1 73 end
syzler@1 74 end
syzler@1 75
syzler@1 76 -- player is in Wintergrasp
syzler@1 77 if zone == "Wintergrasp" then
syzler@1 78 -- always call ground mount if Wintergrasp is in progress
syzler@1 79 local _, _, wintergraspInProgress, _, _, _ = GetWorldPVPAreaInfo(1);
syzler@1 80 if wintergraspInProgress and MyLilPony.CallGroundMount() then
syzler@1 81 return;
syzler@1 82 end
syzler@1 83 end
syzler@1 84
syzler@1 85 -- player is swimming in Vash'jir
syzler@1 86 if IsSwimming() and (zone == "Shimmering Expanse" or zone == "Kelp'thar Forest" or zone == "Abyssal Depths") then
syzler@1 87 -- normal behaviour in Vash'jir is to call the Abyssal Seahorse
syzler@1 88 -- modified behaviour is to attempt flight (i.e. you're at the surface)
syzler@1 89 if not IsModifierKeyDown() and MyLilPony.CallMountByName("Abyssal Seahorse") then
syzler@1 90 return;
syzler@1 91 elseif MyLilPony.CanFlyHere() and MyLilPony.CallFlyingMount() then
syzler@1 92 return;
syzler@1 93 elseif MyLilPony.CallAquaticMount() then
syzler@1 94 return;
syzler@1 95 end
syzler@1 96 end
syzler@1 97
syzler@1 98 -- player is in flyable area and knows how to fly here too
syzler@13 99 if MyLilPony.CanFlyHere() then
syzler@1 100 -- normal behaviour in flyable area is to call flying mount
syzler@13 101 if not IsModifierKeyDown() and MyLilPony.CallFlyingMount() then
syzler@13 102 return;
syzler@13 103 elseif IsSwimming() and MyLilPony.CallAquaticMount() then
syzler@1 104 return;
syzler@1 105 end
syzler@1 106 end
syzler@1 107
syzler@1 108 -- player is swimming
syzler@13 109 if IsSwimming() then
syzler@1 110 -- normal behaviour while swimming is to call aquatic mount
syzler@13 111 if not IsModifierKeyDown() and MyLilPony.CallAquaticMount() then
syzler@1 112 return;
syzler@1 113 end
syzler@1 114 end
syzler@1 115
syzler@1 116 MyLilPony.CallGroundMount();
syzler@1 117 end
syzler@1 118
syzler@11 119 function MyLilPony.SlashHandler(args)
syzler@11 120 local arg = SecureCmdOptionParse(args);
syzler@1 121 if MyLilPony.StringMatchIgnoreCase(arg, "^auto$") then
syzler@1 122 MyLilPony.AutoMount();
syzler@1 123 elseif MyLilPony.StringMatchIgnoreCase(arg, "^random$")
syzler@1 124 or MyLilPony.StringMatchIgnoreCase(arg, "^rand$")
syzler@1 125 or MyLilPony.StringMatchIgnoreCase(arg, "^rng$")
syzler@1 126 or MyLilPony.StringMatchIgnoreCase(arg, "^r$") then
syzler@1 127 MyLilPony.CallMount();
syzler@1 128 elseif MyLilPony.StringMatchIgnoreCase(arg, "^ground$")
syzler@1 129 or MyLilPony.StringMatchIgnoreCase(arg, "^g$") then
syzler@1 130 MyLilPony.CallGroundMount();
syzler@1 131 elseif MyLilPony.StringMatchIgnoreCase(arg, "^flying$")
syzler@1 132 or MyLilPony.StringMatchIgnoreCase(arg, "^fly$")
syzler@1 133 or MyLilPony.StringMatchIgnoreCase(arg, "^air$")
syzler@1 134 or MyLilPony.StringMatchIgnoreCase(arg, "^a$") then
syzler@1 135 MyLilPony.CallFlyingMount();
syzler@1 136 elseif MyLilPony.StringMatchIgnoreCase(arg, "^aquatic$")
syzler@1 137 or MyLilPony.StringMatchIgnoreCase(arg, "^aqua$")
syzler@1 138 or MyLilPony.StringMatchIgnoreCase(arg, "^swim$")
syzler@1 139 or MyLilPony.StringMatchIgnoreCase(arg, "^s$") then
syzler@1 140 MyLilPony.CallAquaticMount();
syzler@1 141 elseif MyLilPony.StringMatchIgnoreCase(arg, "^target$")
syzler@1 142 or MyLilPony.StringMatchIgnoreCase(arg, "^tgt$")
syzler@1 143 or MyLilPony.StringMatchIgnoreCase(arg, "^t$") then
syzler@1 144 local result = MyLilPony.CallMountByMatch("target");
syzler@1 145 if not result then
syzler@1 146 MyLilPony.Log("No matching mounts were found");
syzler@1 147 end
syzler@1 148 elseif MyLilPony.StringMatchIgnoreCase(arg, "^exact .+$")
syzler@1 149 or MyLilPony.StringMatchIgnoreCase(arg, "^x .+$") then
syzler@1 150 local param = MyLilPony.StringMatchIgnoreCase(arg, "^.+ (.+)$");
syzler@1 151 local result = MyLilPony.CallMountByName(param);
syzler@1 152 if not result then
syzler@1 153 MyLilPony.Log(format("No matching mounts were found with NAME='%s'", param));
syzler@1 154 end
syzler@1 155 elseif MyLilPony.StringMatchIgnoreCase(arg, "^list .+$")
syzler@1 156 or MyLilPony.StringMatchIgnoreCase(arg, "^find .+$")
syzler@1 157 or MyLilPony.StringMatchIgnoreCase(arg, "^l .+$") then
syzler@1 158 local param = MyLilPony.StringMatchIgnoreCase(arg, "^.+ (.+)$");
syzler@1 159 local result = MyLilPony.ListMountsByPattern(param);
syzler@1 160 if not result then
syzler@1 161 MyLilPony.Log(format("No matching mounts were found with NAME like '%s'", param));
syzler@1 162 else
syzler@1 163 for _, name in pairs(result) do
syzler@1 164 MyLilPony.Print(name);
syzler@1 165 end
syzler@1 166 end
syzler@1 167 elseif MyLilPony.StringMatchIgnoreCase(arg, "^%d+$") then
syzler@1 168 local result = MyLilPony.CallMountById(tonumber(arg));
syzler@1 169 if not result then
syzler@1 170 MyLilPony.Log(format("No matching mounts were found with ID=%s", arg));
syzler@1 171 end
syzler@1 172 elseif MyLilPony.StringMatchIgnoreCase(arg, "^.+$") then
syzler@1 173 local result = MyLilPony.CallMountByPattern(arg);
syzler@1 174 if not result then
syzler@1 175 MyLilPony.Log(format("No matching mounts were found with NAME like '%s'", arg));
syzler@1 176 end
syzler@1 177 else
syzler@1 178 MyLilPony.Print(format("MyLilPony %s", MYLILPONY_VERSION));
syzler@1 179 MyLilPony.Print("Slash Command: /mylilpony (/pony, /mlp)");
syzler@1 180 MyLilPony.Print(" /mylilpony auto - Summons a \"suitable\" mount");
syzler@1 181 MyLilPony.Print(" /mylilpony random - Summons random mount");
syzler@1 182 MyLilPony.Print(" /mylilpony ground - Summons random ground mount");
syzler@1 183 MyLilPony.Print(" /mylilpony flying - Summons random flying mount");
syzler@1 184 MyLilPony.Print(" /mylilpony aquatic - Summons random aquatic mount");
syzler@1 185 MyLilPony.Print(" /mylilpony target - Summons same mount as targeted unit");
syzler@1 186 MyLilPony.Print(" /mylilpony list <NAME> - Lists mounts matching name");
syzler@1 187 MyLilPony.Print(" /mylilpony exact <NAME> - Summons mount by exact name");
syzler@1 188 MyLilPony.Print(" /mylilpony <ID> - Summons mount by spell or creature ID");
syzler@1 189 MyLilPony.Print(" /mylilpony <NAME> - Summons random mount matching name");
syzler@1 190 end
syzler@1 191 end