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