annotate libMyLilPony/libMyLilPony_mountFunctions.lua @ 50:22011265a16f 1.2.0-b1

Updated and fixed for draenor xpack (patch 6.0) API changes
author syzler
date Sat, 07 Mar 2015 02:52:57 -0500
parents 2ae5f67e313a
children 64e8f8e5fa41
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@50 45 local _, _, _, summoned = C_MountJournal.GetMountInfo(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@50 56 local _, id, _, summoned = C_MountJournal.GetMountInfo(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@50 67 local _, id, _, summoned = C_MountJournal.GetMountInfo(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@50 78 local _, id, _, summoned = C_MountJournal.GetMountInfo(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@50 89 local countMounts = C_MountJournal.GetNumMounts();
syzler@1 90 if slotNumber > 0 and slotNumber < countMounts+1 then
syzler@50 91 local _, _, _, summoned = C_MountJournal.GetMountInfo(i);
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@50 104 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
syzler@50 105 local name, _, _, summoned = C_MountJournal.GetMountInfo(i);
syzler@6 106 if name == mountName then
syzler@1 107 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 108 result = true;
syzler@1 109 do break end
syzler@6 110 end
syzler@6 111 end
syzler@1 112 return result;
syzler@1 113 end
syzler@1 114
syzler@6 115 --- Summons a mount by name pattern match.
syzler@6 116 -- If the pattern matches multiple mounts, a random one is chosen.
syzler@6 117 -- Does nothing if the specified mount is already summoned.
syzler@6 118 -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case).
syzler@6 119 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 120 function MyLilPony.CallMountByPattern(mountNamePattern)
syzler@1 121 local filter = function (i)
syzler@50 122 local name, _, _, summoned = C_MountJournal.GetMountInfo(i);
syzler@1 123 return not summoned and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern);
syzler@1 124 end
syzler@1 125 return MyLilPony.CallMountByFilter(filter);
syzler@1 126 end
syzler@1 127
syzler@6 128 --- Summons a mount by creature or spell ID.
syzler@6 129 -- Does nothing if the specified mount is already summoned.
syzler@6 130 -- @param id The creature or spell ID of the desired mount.
syzler@6 131 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 132 function MyLilPony.CallMountById(id)
syzler@1 133 local result = false;
syzler@50 134 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
syzler@50 135 local _, spellId, _, summoned = C_MountJournal.GetMountInfo(i);
syzler@50 136 local creatureId = C_MountJournal.GetMountInfoExtra(i);
syzler@6 137 if id == creatureId or id == spellId then
syzler@1 138 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 139 result = true;
syzler@1 140 do break end
syzler@6 141 end
syzler@6 142 end
syzler@1 143 return result;
syzler@1 144 end
syzler@1 145
syzler@6 146 --- Summons a mount by spell ID.
syzler@6 147 -- Does nothing if the specified mount is already summoned.
syzler@6 148 -- @param spellId The spell ID of the desired mount.
syzler@6 149 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 150 function MyLilPony.CallMountBySpell(spellId)
syzler@1 151 local result = false;
syzler@50 152 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
syzler@50 153 local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
syzler@6 154 if id == spellId then
syzler@1 155 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 156 result = true;
syzler@1 157 do break end
syzler@6 158 end
syzler@6 159 end
syzler@1 160 return result;
syzler@1 161 end
syzler@1 162
syzler@6 163 --- Summons a mount by creature ID.
syzler@6 164 -- Does nothing if the specified mount is already summoned.
syzler@6 165 -- @param creatureId The creature ID of the desired mount.
syzler@6 166 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@1 167 function MyLilPony.CallMountByCreature(creatureId)
syzler@1 168 local result = false;
syzler@50 169 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
syzler@50 170 local _, _, _, summoned = C_MountJournal.GetMountInfo(i);
syzler@50 171 local id = C_MountJournal.GetMountInfoExtra(i);
syzler@6 172 if id == creatureId then
syzler@1 173 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 174 result = true;
syzler@1 175 do break end
syzler@6 176 end
syzler@6 177 end
syzler@1 178 return result;
syzler@1 179 end
syzler@1 180
syzler@6 181 --- Summons a mount by attempting to match the mount of the specified unit.
syzler@6 182 -- The function checks the buffs of the specified unit against the mount spellbook for matches.
syzler@6 183 -- As a result, the function will only likely work against player characters.
syzler@6 184 -- Does nothing if the specified unit's mount is already summoned.
syzler@19 185 -- @param unit The UnitId (e.g. "target", "player", "focus", "party1", etc.) of the unit whose mount is desired.
syzler@6 186 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@7 187 -- @usage MyLilPony.CallMountByMatch("target");
syzler@1 188 function MyLilPony.CallMountByMatch(unit)
syzler@1 189 local result = false;
syzler@1 190 local unitBuffs = MyLilPony.GetUnitBuffs(unit);
syzler@50 191 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
syzler@50 192 local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
syzler@6 193 if unitBuffs[id] ~= nil then
syzler@1 194 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 195 result = true;
syzler@1 196 do break end
syzler@6 197 end
syzler@6 198 end
syzler@1 199 return result;
syzler@1 200 end
syzler@1 201
syzler@6 202 --- Summons a random mount after filtering the mount spellbook.
syzler@6 203 -- Does nothing if the specified mount is already summoned.
syzler@6 204 -- @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 205 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
syzler@6 206 -- @usage local filter = function (i)
syzler@50 207 -- local name = C_MountJournal.GetMountInfo(i);
syzler@50 208 -- return string.match(name, pattern);
syzler@6 209 -- end
syzler@7 210 -- MyLilPony.CallMountByFilter(filter);
syzler@1 211 function MyLilPony.CallMountByFilter(filter)
syzler@50 212 local mounts = {};
syzler@50 213 local x = 0;
syzler@50 214 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
syzler@50 215 if filter(i) then
syzler@50 216 x = x + 1;
syzler@50 217 mounts[x] = i;
syzler@1 218 end
syzler@50 219 end
syzler@1 220
syzler@50 221 if x > 0 then
syzler@50 222 local i = mounts[random(1, x)];
syzler@50 223 local _, _, _, summoned = C_MountJournal.GetMountInfo(i);
syzler@50 224 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@50 225 return true;
syzler@1 226 end
syzler@1 227 return false;
syzler@1 228 end
syzler@1 229
syzler@6 230 --- Lists available mounts by name.
syzler@50 231 -- @return A list of mount names.
syzler@1 232 function MyLilPony.ListMounts()
syzler@1 233 local results = {};
syzler@50 234 local x = 1;
syzler@50 235 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
syzler@50 236 local name = C_MountJournal.GetMountInfo(i);
syzler@1 237 results[i] = name;
syzler@50 238 x = x + 1;
syzler@1 239 end
syzler@1 240 return results;
syzler@1 241 end
syzler@1 242
syzler@6 243 --- Lists available ground mounts by name.
syzler@6 244 -- @return A list of ground mount names.
syzler@1 245 function MyLilPony.ListGroundMounts()
syzler@1 246 local results = {};
syzler@1 247 local x = 1;
syzler@50 248 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
syzler@50 249 local name, id = C_MountJournal.GetMountInfo(i);
syzler@1 250 if MyLilPony.IsGroundMount(id) then
syzler@1 251 results[x] = name;
syzler@1 252 x = x + 1;
syzler@1 253 end
syzler@1 254 end
syzler@1 255 return results;
syzler@1 256 end
syzler@1 257
syzler@6 258 --- Lists available flying mounts by name.
syzler@6 259 -- @return A list of flying mount names.
syzler@1 260 function MyLilPony.ListFlyingMounts()
syzler@1 261 local results = {};
syzler@1 262 local x = 1;
syzler@50 263 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
syzler@50 264 local name, id = C_MountJournal.GetMountInfo(i);
syzler@1 265 if MyLilPony.IsFlyingMount(id) then
syzler@1 266 results[x] = name;
syzler@1 267 x = x + 1;
syzler@1 268 end
syzler@1 269 end
syzler@1 270 return results;
syzler@1 271 end
syzler@1 272
syzler@6 273 --- Lists available aquatic mounts by name.
syzler@6 274 -- @return A list of aquatic mount names.
syzler@1 275 function MyLilPony.ListAquaticMounts()
syzler@1 276 local results = {};
syzler@1 277 local x = 1;
syzler@50 278 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
syzler@50 279 local name, id = C_MountJournal.GetMountInfo(i);
syzler@1 280 if MyLilPony.IsAquaticMount(id) then
syzler@1 281 results[x] = name;
syzler@1 282 x = x + 1;
syzler@1 283 end
syzler@1 284 end
syzler@1 285 return results;
syzler@1 286 end
syzler@1 287
syzler@6 288 --- Lists available mounts names whose name matches a given pattern.
syzler@6 289 -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case).
syzler@6 290 -- @return A list of matching mount names.
syzler@1 291 function MyLilPony.ListMountsByPattern(mountNamePattern)
syzler@1 292 local results = {};
syzler@1 293 local x = 1;
syzler@50 294 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
syzler@50 295 local name = C_MountJournal.GetMountInfo(i);
syzler@1 296 if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then
syzler@1 297 results[x] = name;
syzler@1 298 x = x + 1;
syzler@1 299 end
syzler@1 300 end
syzler@1 301 return results;
syzler@1 302 end