annotate MyLilPony.lua @ 30:af32bee5a3d1 i18n

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