syzler@14: -- Copyright (c) 2011, Syzler syzler@14: -- All rights reserved. syzler@1: -- syzler@14: -- Redistribution and use in source and binary forms, with or without syzler@14: -- modification, are permitted provided that the following conditions syzler@14: -- are met: syzler@1: -- syzler@14: -- * Redistributions of source code must retain the above copyright syzler@14: -- notice, this list of conditions and the following disclaimer. syzler@14: -- * Redistributions in binary form must reproduce the above copyright syzler@14: -- notice, this list of conditions and the following disclaimer in syzler@14: -- the documentation and/or other materials provided with the syzler@14: -- distribution. syzler@14: -- * Neither the name of the MyLilPony Project nor the names of its syzler@14: -- contributors may be used to endorse or promote products derived syzler@14: -- from this software without specific prior written permission. syzler@1: -- syzler@14: -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS syzler@14: -- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT syzler@14: -- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS syzler@14: -- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE syzler@14: -- COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, syzler@14: -- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, syzler@14: -- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; syzler@14: -- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER syzler@14: -- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT syzler@14: -- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN syzler@14: -- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE syzler@14: -- POSSIBILITY OF SUCH DAMAGE. syzler@1: syzler@15: ------------------------------------------------------------------------ syzler@15: -- Project: libMyLilPony syzler@15: -- Project Version: @project-version@ syzler@15: -- Last Author: @file-author@ syzler@15: -- Last Updated: @file-date-iso@ syzler@15: -- syzler@1: -- API functions for calling mounts syzler@15: ------------------------------------------------------------------------ syzler@1: syzler@5: --- Summons a random mount. syzler@5: -- Does nothing if the only available mount is already summoned. syzler@6: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@1: function MyLilPony.CallMount() syzler@5: local filter = function (i) syzler@1: local _, _, _, _, summoned = GetCompanionInfo("MOUNT", i); syzler@5: return not summoned; syzler@1: end syzler@5: return MyLilPony.CallMountByFilter(filter); syzler@1: end syzler@1: syzler@6: --- Summons a random flying mount. syzler@6: -- Does nothing if the only available mount is already summoned. syzler@6: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@1: function MyLilPony.CallFlyingMount() syzler@1: local filter = function (i) syzler@1: local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); syzler@1: return not summoned and MyLilPony.IsFlyingMount(id); syzler@1: end syzler@1: return MyLilPony.CallMountByFilter(filter); syzler@1: end syzler@1: syzler@6: --- Summons a random ground mount. syzler@6: -- Does nothing if the only available mount is already summoned. syzler@6: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@1: function MyLilPony.CallGroundMount() syzler@1: local filter = function (i) syzler@1: local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); syzler@1: return not summoned and MyLilPony.IsGroundMount(id); syzler@1: end syzler@1: return MyLilPony.CallMountByFilter(filter); syzler@1: end syzler@1: syzler@6: --- Summons a random aquatic mount. syzler@6: -- Does nothing if the only available mount is already summoned. syzler@6: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@1: function MyLilPony.CallAquaticMount() syzler@1: local filter = function (i) syzler@1: local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); syzler@1: return not summoned and MyLilPony.IsAquaticMount(id); syzler@1: end syzler@1: return MyLilPony.CallMountByFilter(filter); syzler@1: end syzler@1: syzler@6: --- Summons a mount by slot number in mount spellbook. syzler@6: -- Does nothing if the specified mount is already summoned. syzler@6: -- @param slotNumber The slot number of the desired mount in the mount spellbook. syzler@6: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@1: function MyLilPony.CallMountBySlot(slotNumber) syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: if slotNumber > 0 and slotNumber < countMounts+1 then syzler@1: local _, _, _, _, summoned = GetCompanionInfo("MOUNT", slotNumber); syzler@1: MyLilPony.CallCompanion("MOUNT", slotNumber, not summoned); syzler@1: return true; syzler@1: end syzler@1: return false; syzler@1: end syzler@1: syzler@6: --- Summons a mount by exact name match. syzler@6: -- Does nothing if the specified mount is already summoned. syzler@6: -- @param mountName The exact name (including correct upper/lower case) of the desired mount. syzler@6: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@1: function MyLilPony.CallMountByName(mountName) syzler@1: local result = false; syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: for i = 1, countMounts do syzler@6: local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i); syzler@6: if name == mountName then syzler@1: MyLilPony.CallCompanion("MOUNT", i, not summoned); syzler@1: result = true; syzler@1: do break end syzler@6: end syzler@6: end syzler@1: return result; syzler@1: end syzler@1: syzler@6: --- Summons a mount by name pattern match. syzler@6: -- If the pattern matches multiple mounts, a random one is chosen. syzler@6: -- Does nothing if the specified mount is already summoned. syzler@6: -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case). syzler@6: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@1: function MyLilPony.CallMountByPattern(mountNamePattern) syzler@1: local filter = function (i) syzler@1: local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i); syzler@1: return not summoned and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern); syzler@1: end syzler@1: return MyLilPony.CallMountByFilter(filter); syzler@1: end syzler@1: syzler@6: --- Summons a mount by creature or spell ID. syzler@6: -- Does nothing if the specified mount is already summoned. syzler@6: -- @param id The creature or spell ID of the desired mount. syzler@6: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@1: function MyLilPony.CallMountById(id) syzler@1: local result = false; syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: for i = 1, countMounts do syzler@6: local creatureId, _, spellId, _, summoned = GetCompanionInfo("MOUNT", i); syzler@6: if id == creatureId or id == spellId then syzler@1: MyLilPony.CallCompanion("MOUNT", i, not summoned); syzler@1: result = true; syzler@1: do break end syzler@6: end syzler@6: end syzler@1: return result; syzler@1: end syzler@1: syzler@6: --- Summons a mount by spell ID. syzler@6: -- Does nothing if the specified mount is already summoned. syzler@6: -- @param spellId The spell ID of the desired mount. syzler@6: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@1: function MyLilPony.CallMountBySpell(spellId) syzler@1: local result = false; syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: for i = 1, countMounts do syzler@6: local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); syzler@6: if id == spellId then syzler@1: MyLilPony.CallCompanion("MOUNT", i, not summoned); syzler@1: result = true; syzler@1: do break end syzler@6: end syzler@6: end syzler@1: return result; syzler@1: end syzler@1: syzler@6: --- Summons a mount by creature ID. syzler@6: -- Does nothing if the specified mount is already summoned. syzler@6: -- @param creatureId The creature ID of the desired mount. syzler@6: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@1: function MyLilPony.CallMountByCreature(creatureId) syzler@1: local result = false; syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: for i = 1, countMounts do syzler@6: local id, _, _, _, summoned = GetCompanionInfo("MOUNT", i); syzler@6: if id == creatureId then syzler@1: MyLilPony.CallCompanion("MOUNT", i, not summoned); syzler@1: result = true; syzler@1: do break end syzler@6: end syzler@6: end syzler@1: return result; syzler@1: end syzler@1: syzler@6: --- Summons a mount by attempting to match the mount of the specified unit. syzler@6: -- The function checks the buffs of the specified unit against the mount spellbook for matches. syzler@6: -- As a result, the function will only likely work against player characters. syzler@6: -- Does nothing if the specified unit's mount is already summoned. syzler@19: -- @param unit The UnitId (e.g. "target", "player", "focus", "party1", etc.) of the unit whose mount is desired. syzler@6: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@7: -- @usage MyLilPony.CallMountByMatch("target"); syzler@1: function MyLilPony.CallMountByMatch(unit) syzler@1: local result = false; syzler@1: local unitBuffs = MyLilPony.GetUnitBuffs(unit); syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: for i = 1, countMounts do syzler@6: local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); syzler@6: if unitBuffs[id] ~= nil then syzler@1: MyLilPony.CallCompanion("MOUNT", i, not summoned); syzler@1: result = true; syzler@1: do break end syzler@6: end syzler@6: end syzler@1: return result; syzler@1: end syzler@1: syzler@6: --- Summons a random mount after filtering the mount spellbook. syzler@6: -- Does nothing if the specified mount is already summoned. syzler@6: -- @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: -- @return A Boolean value indicating whether or not a mount was successfully summoned. syzler@6: -- @usage local filter = function (i) syzler@6: -- local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i); syzler@6: -- return not summoned and string.match(name, pattern); syzler@6: -- end syzler@7: -- MyLilPony.CallMountByFilter(filter); syzler@1: function MyLilPony.CallMountByFilter(filter) syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: if countMounts > 0 then syzler@1: local results = {}; syzler@1: local countResults = 0; syzler@1: syzler@1: for i = 1, countMounts do syzler@1: if filter(i) then syzler@1: countResults = countResults + 1; syzler@1: results[countResults] = i; syzler@1: end syzler@1: end syzler@1: syzler@1: if countResults > 0 then syzler@1: local i = random(1, countResults); syzler@1: local _, _, _, _, summoned = GetCompanionInfo("MOUNT", results[i]); syzler@1: MyLilPony.CallCompanion("MOUNT", results[i], not summoned); syzler@1: return true; syzler@1: end syzler@1: end syzler@1: return false; syzler@1: end syzler@1: syzler@6: --- Lists available mounts by name. syzler@6: -- @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: function MyLilPony.ListMounts() syzler@1: local results = {}; syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: for i = 1, countMounts do syzler@1: local _, name, _, _, _ = GetCompanionInfo("MOUNT", i); syzler@1: results[i] = name; syzler@1: end syzler@1: return results; syzler@1: end syzler@1: syzler@6: --- Lists available ground mounts by name. syzler@6: -- @return A list of ground mount names. syzler@1: function MyLilPony.ListGroundMounts() syzler@1: local results = {}; syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: local x = 1; syzler@1: for i = 1, countMounts do syzler@1: local _, _, id, _, _ = GetCompanionInfo("MOUNT", i); syzler@1: if MyLilPony.IsGroundMount(id) then syzler@1: results[x] = name; syzler@1: x = x + 1; syzler@1: end syzler@1: end syzler@1: return results; syzler@1: end syzler@1: syzler@6: --- Lists available flying mounts by name. syzler@6: -- @return A list of flying mount names. syzler@1: function MyLilPony.ListFlyingMounts() syzler@1: local results = {}; syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: local x = 1; syzler@1: for i = 1, countMounts do syzler@1: local _, _, id, _, _ = GetCompanionInfo("MOUNT", i); syzler@1: if MyLilPony.IsFlyingMount(id) then syzler@1: results[x] = name; syzler@1: x = x + 1; syzler@1: end syzler@1: end syzler@1: return results; syzler@1: end syzler@1: syzler@6: --- Lists available aquatic mounts by name. syzler@6: -- @return A list of aquatic mount names. syzler@1: function MyLilPony.ListAquaticMounts() syzler@1: local results = {}; syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: local x = 1; syzler@1: for i = 1, countMounts do syzler@1: local _, _, id, _, _ = GetCompanionInfo("MOUNT", i); syzler@1: if MyLilPony.IsAquaticMount(id) then syzler@1: results[x] = name; syzler@1: x = x + 1; syzler@1: end syzler@1: end syzler@1: return results; syzler@1: end syzler@1: syzler@6: --- Lists available mounts names whose name matches a given pattern. syzler@6: -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case). syzler@6: -- @return A list of matching mount names. syzler@1: function MyLilPony.ListMountsByPattern(mountNamePattern) syzler@1: local results = {}; syzler@1: local countMounts = GetNumCompanions("MOUNT"); syzler@1: local x = 1; syzler@1: for i = 1, countMounts do syzler@1: local _, name, _, _, _ = GetCompanionInfo("MOUNT", i); syzler@1: if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then syzler@1: results[x] = name; syzler@1: x = x + 1; syzler@1: end syzler@1: end syzler@1: return results; syzler@1: end syzler@1: