Mercurial > wow > mylilpony
diff libMyLilPony/libMyLilPony_mountFunctions.lua @ 1:7dfbf42c2d60
Initial commit of MyLilPony
author | syzler |
---|---|
date | Mon, 04 Apr 2011 04:43:05 +0000 |
parents | |
children | a4711e3c1eef |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libMyLilPony/libMyLilPony_mountFunctions.lua Mon Apr 04 04:43:05 2011 +0000 @@ -0,0 +1,231 @@ +-- libMyLilPony +-- Copyright (c) 2011 Syzler +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. + +-- API functions for calling mounts + +function MyLilPony.CallMount() + local countMounts = GetNumCompanions("MOUNT"); + if countMounts > 0 then + local i = random(1, countMounts); + local _, _, _, _, summoned = GetCompanionInfo("MOUNT", i); + MyLilPony.CallCompanion("MOUNT", i, not summoned); + return true; + end + return false; +end + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 + +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 +