annotate libMyLilPony/libMyLilPony_mountFunctions.lua @ 48:83e9649a6606 1.1.7

Fixed Abyssal Seahorse mounting in certain subzones of Vashj'ir
author syzler
date Thu, 20 Sep 2012 01:28:44 -0400
parents 2ae5f67e313a
children 22011265a16f
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: libMyLilPony
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@1 37 -- API functions for calling mounts
syzler@15 38 ------------------------------------------------------------------------
syzler@1 39
syzler@5 40 --- Summons a random mount.
syzler@5 41 -- Does nothing if the only available mount is already summoned.
syzler@6 42 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 43 function MyLilPony.CallMount()
syzler@5 44 local filter = function (i)
syzler@1 45 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@5 46 return not summoned;
syzler@1 47 end
syzler@5 48 return MyLilPony.CallMountByFilter(filter);
syzler@1 49 end
syzler@1 50
syzler@6 51 --- Summons a random flying mount.
syzler@6 52 -- Does nothing if the only available mount is already summoned.
syzler@6 53 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 54 function MyLilPony.CallFlyingMount()
syzler@1 55 local filter = function (i)
syzler@1 56 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 57 return not summoned and MyLilPony.IsFlyingMount(id);
syzler@1 58 end
syzler@1 59 return MyLilPony.CallMountByFilter(filter);
syzler@1 60 end
syzler@1 61
syzler@6 62 --- Summons a random ground mount.
syzler@6 63 -- Does nothing if the only available mount is already summoned.
syzler@6 64 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 65 function MyLilPony.CallGroundMount()
syzler@1 66 local filter = function (i)
syzler@1 67 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 68 return not summoned and MyLilPony.IsGroundMount(id);
syzler@1 69 end
syzler@1 70 return MyLilPony.CallMountByFilter(filter);
syzler@1 71 end
syzler@1 72
syzler@6 73 --- Summons a random aquatic mount.
syzler@6 74 -- Does nothing if the only available mount is already summoned.
syzler@6 75 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 76 function MyLilPony.CallAquaticMount()
syzler@1 77 local filter = function (i)
syzler@1 78 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 79 return not summoned and MyLilPony.IsAquaticMount(id);
syzler@1 80 end
syzler@1 81 return MyLilPony.CallMountByFilter(filter);
syzler@1 82 end
syzler@1 83
syzler@6 84 --- Summons a mount by slot number in mount spellbook.
syzler@6 85 -- Does nothing if the specified mount is already summoned.
syzler@6 86 -- @param slotNumber The slot number of the desired mount in the mount spellbook.
syzler@6 87 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 88 function MyLilPony.CallMountBySlot(slotNumber)
syzler@1 89 local countMounts = GetNumCompanions("MOUNT");
syzler@1 90 if slotNumber > 0 and slotNumber < countMounts+1 then
syzler@1 91 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", slotNumber);
syzler@1 92 MyLilPony.CallCompanion("MOUNT", slotNumber, not summoned);
syzler@1 93 return true;
syzler@1 94 end
syzler@1 95 return false;
syzler@1 96 end
syzler@1 97
syzler@6 98 --- Summons a mount by exact name match.
syzler@6 99 -- Does nothing if the specified mount is already summoned.
syzler@6 100 -- @param mountName The exact name (including correct upper/lower case) of the desired mount.
syzler@6 101 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 102 function MyLilPony.CallMountByName(mountName)
syzler@1 103 local result = false;
syzler@1 104 local countMounts = GetNumCompanions("MOUNT");
syzler@1 105 for i = 1, countMounts do
syzler@6 106 local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@6 107 if name == mountName then
syzler@1 108 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 109 result = true;
syzler@1 110 do break end
syzler@6 111 end
syzler@6 112 end
syzler@1 113 return result;
syzler@1 114 end
syzler@1 115
syzler@6 116 --- Summons a mount by name pattern match.
syzler@6 117 -- If the pattern matches multiple mounts, a random one is chosen.
syzler@6 118 -- Does nothing if the specified mount is already summoned.
syzler@6 119 -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case).
syzler@6 120 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 121 function MyLilPony.CallMountByPattern(mountNamePattern)
syzler@1 122 local filter = function (i)
syzler@1 123 local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 124 return not summoned and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern);
syzler@1 125 end
syzler@1 126 return MyLilPony.CallMountByFilter(filter);
syzler@1 127 end
syzler@1 128
syzler@6 129 --- Summons a mount by creature or spell ID.
syzler@6 130 -- Does nothing if the specified mount is already summoned.
syzler@6 131 -- @param id The creature or spell ID of the desired mount.
syzler@6 132 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 133 function MyLilPony.CallMountById(id)
syzler@1 134 local result = false;
syzler@1 135 local countMounts = GetNumCompanions("MOUNT");
syzler@1 136 for i = 1, countMounts do
syzler@6 137 local creatureId, _, spellId, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@6 138 if id == creatureId or id == spellId then
syzler@1 139 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 140 result = true;
syzler@1 141 do break end
syzler@6 142 end
syzler@6 143 end
syzler@1 144 return result;
syzler@1 145 end
syzler@1 146
syzler@6 147 --- Summons a mount by spell ID.
syzler@6 148 -- Does nothing if the specified mount is already summoned.
syzler@6 149 -- @param spellId The spell ID of the desired mount.
syzler@6 150 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 151 function MyLilPony.CallMountBySpell(spellId)
syzler@1 152 local result = false;
syzler@1 153 local countMounts = GetNumCompanions("MOUNT");
syzler@1 154 for i = 1, countMounts do
syzler@6 155 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@6 156 if id == spellId then
syzler@1 157 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 158 result = true;
syzler@1 159 do break end
syzler@6 160 end
syzler@6 161 end
syzler@1 162 return result;
syzler@1 163 end
syzler@1 164
syzler@6 165 --- Summons a mount by creature ID.
syzler@6 166 -- Does nothing if the specified mount is already summoned.
syzler@6 167 -- @param creatureId The creature ID of the desired mount.
syzler@6 168 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 169 function MyLilPony.CallMountByCreature(creatureId)
syzler@1 170 local result = false;
syzler@1 171 local countMounts = GetNumCompanions("MOUNT");
syzler@1 172 for i = 1, countMounts do
syzler@6 173 local id, _, _, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@6 174 if id == creatureId then
syzler@1 175 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 176 result = true;
syzler@1 177 do break end
syzler@6 178 end
syzler@6 179 end
syzler@1 180 return result;
syzler@1 181 end
syzler@1 182
syzler@6 183 --- Summons a mount by attempting to match the mount of the specified unit.
syzler@6 184 -- The function checks the buffs of the specified unit against the mount spellbook for matches.
syzler@6 185 -- As a result, the function will only likely work against player characters.
syzler@6 186 -- Does nothing if the specified unit's mount is already summoned.
syzler@19 187 -- @param unit The UnitId (e.g. "target", "player", "focus", "party1", etc.) of the unit whose mount is desired.
syzler@6 188 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@7 189 -- @usage MyLilPony.CallMountByMatch("target");
syzler@1 190 function MyLilPony.CallMountByMatch(unit)
syzler@1 191 local result = false;
syzler@1 192 local unitBuffs = MyLilPony.GetUnitBuffs(unit);
syzler@1 193 local countMounts = GetNumCompanions("MOUNT");
syzler@1 194 for i = 1, countMounts do
syzler@6 195 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@6 196 if unitBuffs[id] ~= nil then
syzler@1 197 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 198 result = true;
syzler@1 199 do break end
syzler@6 200 end
syzler@6 201 end
syzler@1 202 return result;
syzler@1 203 end
syzler@1 204
syzler@6 205 --- Summons a random mount after filtering the mount spellbook.
syzler@6 206 -- Does nothing if the specified mount is already summoned.
syzler@6 207 -- @param filter A filter callback function which takes a single mount slot number and returns a Boolean value indicating whether or not the the indicated mount should be included.
syzler@6 208 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@6 209 -- @usage local filter = function (i)
syzler@6 210 -- local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@6 211 -- return not summoned and string.match(name, pattern);
syzler@6 212 -- end
syzler@7 213 -- MyLilPony.CallMountByFilter(filter);
syzler@1 214 function MyLilPony.CallMountByFilter(filter)
syzler@1 215 local countMounts = GetNumCompanions("MOUNT");
syzler@1 216 if countMounts > 0 then
syzler@1 217 local results = {};
syzler@1 218 local countResults = 0;
syzler@1 219
syzler@1 220 for i = 1, countMounts do
syzler@1 221 if filter(i) then
syzler@1 222 countResults = countResults + 1;
syzler@1 223 results[countResults] = i;
syzler@1 224 end
syzler@1 225 end
syzler@1 226
syzler@1 227 if countResults > 0 then
syzler@1 228 local i = random(1, countResults);
syzler@1 229 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", results[i]);
syzler@1 230 MyLilPony.CallCompanion("MOUNT", results[i], not summoned);
syzler@1 231 return true;
syzler@1 232 end
syzler@1 233 end
syzler@1 234 return false;
syzler@1 235 end
syzler@1 236
syzler@6 237 --- Lists available mounts by name.
syzler@6 238 -- @return A list of mount names. Since this function returns all known mounts, the index of each entry in the list is also the mount's slot number.
syzler@1 239 function MyLilPony.ListMounts()
syzler@1 240 local results = {};
syzler@1 241 local countMounts = GetNumCompanions("MOUNT");
syzler@1 242 for i = 1, countMounts do
syzler@1 243 local _, name, _, _, _ = GetCompanionInfo("MOUNT", i);
syzler@1 244 results[i] = name;
syzler@1 245 end
syzler@1 246 return results;
syzler@1 247 end
syzler@1 248
syzler@6 249 --- Lists available ground mounts by name.
syzler@6 250 -- @return A list of ground mount names.
syzler@1 251 function MyLilPony.ListGroundMounts()
syzler@1 252 local results = {};
syzler@1 253 local countMounts = GetNumCompanions("MOUNT");
syzler@1 254 local x = 1;
syzler@1 255 for i = 1, countMounts do
syzler@1 256 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
syzler@1 257 if MyLilPony.IsGroundMount(id) then
syzler@1 258 results[x] = name;
syzler@1 259 x = x + 1;
syzler@1 260 end
syzler@1 261 end
syzler@1 262 return results;
syzler@1 263 end
syzler@1 264
syzler@6 265 --- Lists available flying mounts by name.
syzler@6 266 -- @return A list of flying mount names.
syzler@1 267 function MyLilPony.ListFlyingMounts()
syzler@1 268 local results = {};
syzler@1 269 local countMounts = GetNumCompanions("MOUNT");
syzler@1 270 local x = 1;
syzler@1 271 for i = 1, countMounts do
syzler@1 272 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
syzler@1 273 if MyLilPony.IsFlyingMount(id) then
syzler@1 274 results[x] = name;
syzler@1 275 x = x + 1;
syzler@1 276 end
syzler@1 277 end
syzler@1 278 return results;
syzler@1 279 end
syzler@1 280
syzler@6 281 --- Lists available aquatic mounts by name.
syzler@6 282 -- @return A list of aquatic mount names.
syzler@1 283 function MyLilPony.ListAquaticMounts()
syzler@1 284 local results = {};
syzler@1 285 local countMounts = GetNumCompanions("MOUNT");
syzler@1 286 local x = 1;
syzler@1 287 for i = 1, countMounts do
syzler@1 288 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
syzler@1 289 if MyLilPony.IsAquaticMount(id) then
syzler@1 290 results[x] = name;
syzler@1 291 x = x + 1;
syzler@1 292 end
syzler@1 293 end
syzler@1 294 return results;
syzler@1 295 end
syzler@1 296
syzler@6 297 --- Lists available mounts names whose name matches a given pattern.
syzler@6 298 -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case).
syzler@6 299 -- @return A list of matching mount names.
syzler@1 300 function MyLilPony.ListMountsByPattern(mountNamePattern)
syzler@1 301 local results = {};
syzler@1 302 local countMounts = GetNumCompanions("MOUNT");
syzler@1 303 local x = 1;
syzler@1 304 for i = 1, countMounts do
syzler@1 305 local _, name, _, _, _ = GetCompanionInfo("MOUNT", i);
syzler@1 306 if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then
syzler@1 307 results[x] = name;
syzler@1 308 x = x + 1;
syzler@1 309 end
syzler@1 310 end
syzler@1 311 return results;
syzler@1 312 end
syzler@1 313