syzler@1: -- libMyLilPony syzler@1: -- Copyright (c) 2011 Syzler syzler@1: -- syzler@1: -- This program is free software: you can redistribute it and/or modify syzler@1: -- it under the terms of the GNU General Public License as published by syzler@1: -- the Free Software Foundation, either version 3 of the License, or syzler@1: -- (at your option) any later version. syzler@1: -- syzler@1: -- This program is distributed in the hope that it will be useful, syzler@1: -- but WITHOUT ANY WARRANTY; without even the implied warranty of syzler@1: -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the syzler@1: -- GNU General Public License for more details. syzler@1: -- syzler@1: -- You should have received a copy of the GNU General Public License syzler@1: -- along with this program. If not, see . syzler@1: syzler@1: -- API functions for calling mounts 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@6: -- @param unit The unit frame name (e.g. "target", "player", "focus") 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: