annotate libMyLilPony/libMyLilPony_mountFunctions.lua @ 5:a4711e3c1eef

Fixed the basic CallMount function to ignore already summoned mounts.
author syzler
date Tue, 05 Apr 2011 00:49:50 +0000
parents 7dfbf42c2d60
children 21d6611a1307
rev   line source
syzler@1 1 -- libMyLilPony
syzler@1 2 -- Copyright (c) 2011 Syzler
syzler@1 3 --
syzler@1 4 -- This program is free software: you can redistribute it and/or modify
syzler@1 5 -- it under the terms of the GNU General Public License as published by
syzler@1 6 -- the Free Software Foundation, either version 3 of the License, or
syzler@1 7 -- (at your option) any later version.
syzler@1 8 --
syzler@1 9 -- This program is distributed in the hope that it will be useful,
syzler@1 10 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
syzler@1 11 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
syzler@1 12 -- GNU General Public License for more details.
syzler@1 13 --
syzler@1 14 -- You should have received a copy of the GNU General Public License
syzler@1 15 -- along with this program. If not, see <http://www.gnu.org/licenses/>.
syzler@1 16
syzler@1 17 -- API functions for calling mounts
syzler@1 18
syzler@5 19 --- Summons a random mount.
syzler@5 20 -- Does nothing if the only available mount is already summoned.
syzler@5 21 -- @return A Boolean value indicating whether or not a new mount was summoned.
syzler@1 22 function MyLilPony.CallMount()
syzler@5 23 local filter = function (i)
syzler@1 24 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@5 25 return not summoned;
syzler@1 26 end
syzler@5 27 return MyLilPony.CallMountByFilter(filter);
syzler@1 28 end
syzler@1 29
syzler@1 30 function MyLilPony.CallFlyingMount()
syzler@1 31 local filter = function (i)
syzler@1 32 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 33 return not summoned and MyLilPony.IsFlyingMount(id);
syzler@1 34 end
syzler@1 35 return MyLilPony.CallMountByFilter(filter);
syzler@1 36 end
syzler@1 37
syzler@1 38 function MyLilPony.CallGroundMount()
syzler@1 39 local filter = function (i)
syzler@1 40 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 41 return not summoned and MyLilPony.IsGroundMount(id);
syzler@1 42 end
syzler@1 43 return MyLilPony.CallMountByFilter(filter);
syzler@1 44 end
syzler@1 45
syzler@1 46 function MyLilPony.CallAquaticMount()
syzler@1 47 local filter = function (i)
syzler@1 48 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 49 return not summoned and MyLilPony.IsAquaticMount(id);
syzler@1 50 end
syzler@1 51 return MyLilPony.CallMountByFilter(filter);
syzler@1 52 end
syzler@1 53
syzler@1 54 function MyLilPony.CallMountBySlot(slotNumber)
syzler@1 55 local countMounts = GetNumCompanions("MOUNT");
syzler@1 56 if slotNumber > 0 and slotNumber < countMounts+1 then
syzler@1 57 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", slotNumber);
syzler@1 58 MyLilPony.CallCompanion("MOUNT", slotNumber, not summoned);
syzler@1 59 return true;
syzler@1 60 end
syzler@1 61 return false;
syzler@1 62 end
syzler@1 63
syzler@1 64 function MyLilPony.CallMountByName(mountName)
syzler@1 65 local result = false;
syzler@1 66 local countMounts = GetNumCompanions("MOUNT");
syzler@1 67 for i = 1, countMounts do
syzler@1 68 local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 69 if name == mountName then
syzler@1 70 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 71 result = true;
syzler@1 72 do break end
syzler@1 73 end
syzler@1 74 end
syzler@1 75 return result;
syzler@1 76 end
syzler@1 77
syzler@1 78 function MyLilPony.CallMountByPattern(mountNamePattern)
syzler@1 79 local filter = function (i)
syzler@1 80 local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 81 return not summoned and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern);
syzler@1 82 end
syzler@1 83 return MyLilPony.CallMountByFilter(filter);
syzler@1 84 end
syzler@1 85
syzler@1 86 function MyLilPony.CallMountById(id)
syzler@1 87 local result = false;
syzler@1 88 local countMounts = GetNumCompanions("MOUNT");
syzler@1 89 for i = 1, countMounts do
syzler@1 90 local creatureId, _, spellId, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 91 if id == creatureId or id == spellId then
syzler@1 92 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 93 result = true;
syzler@1 94 do break end
syzler@1 95 end
syzler@1 96 end
syzler@1 97 return result;
syzler@1 98 end
syzler@1 99
syzler@1 100 function MyLilPony.CallMountBySpell(spellId)
syzler@1 101 local result = false;
syzler@1 102 local countMounts = GetNumCompanions("MOUNT");
syzler@1 103 for i = 1, countMounts do
syzler@1 104 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 105 if id == spellId then
syzler@1 106 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 107 result = true;
syzler@1 108 do break end
syzler@1 109 end
syzler@1 110 end
syzler@1 111 return result;
syzler@1 112 end
syzler@1 113
syzler@1 114 function MyLilPony.CallMountByCreature(creatureId)
syzler@1 115 local result = false;
syzler@1 116 local countMounts = GetNumCompanions("MOUNT");
syzler@1 117 for i = 1, countMounts do
syzler@1 118 local id, _, _, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 119 if id == creatureId then
syzler@1 120 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 121 result = true;
syzler@1 122 do break end
syzler@1 123 end
syzler@1 124 end
syzler@1 125 return result;
syzler@1 126 end
syzler@1 127
syzler@1 128 function MyLilPony.CallMountByMatch(unit)
syzler@1 129 local result = false;
syzler@1 130 local unitBuffs = MyLilPony.GetUnitBuffs(unit);
syzler@1 131 local countMounts = GetNumCompanions("MOUNT");
syzler@1 132 for i = 1, countMounts do
syzler@1 133 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
syzler@1 134 if unitBuffs[id] ~= nil then
syzler@1 135 MyLilPony.CallCompanion("MOUNT", i, not summoned);
syzler@1 136 result = true;
syzler@1 137 do break end
syzler@1 138 end
syzler@1 139 end
syzler@1 140 return result;
syzler@1 141 end
syzler@1 142
syzler@1 143 function MyLilPony.CallMountByFilter(filter)
syzler@1 144 local countMounts = GetNumCompanions("MOUNT");
syzler@1 145 if countMounts > 0 then
syzler@1 146 local results = {};
syzler@1 147 local countResults = 0;
syzler@1 148
syzler@1 149 for i = 1, countMounts do
syzler@1 150 if filter(i) then
syzler@1 151 countResults = countResults + 1;
syzler@1 152 results[countResults] = i;
syzler@1 153 end
syzler@1 154 end
syzler@1 155
syzler@1 156 if countResults > 0 then
syzler@1 157 local i = random(1, countResults);
syzler@1 158 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", results[i]);
syzler@1 159 MyLilPony.CallCompanion("MOUNT", results[i], not summoned);
syzler@1 160 return true;
syzler@1 161 end
syzler@1 162 end
syzler@1 163 return false;
syzler@1 164 end
syzler@1 165
syzler@1 166 function MyLilPony.ListMounts()
syzler@1 167 local results = {};
syzler@1 168 local countMounts = GetNumCompanions("MOUNT");
syzler@1 169 for i = 1, countMounts do
syzler@1 170 local _, name, _, _, _ = GetCompanionInfo("MOUNT", i);
syzler@1 171 results[i] = name;
syzler@1 172 end
syzler@1 173 return results;
syzler@1 174 end
syzler@1 175
syzler@1 176 function MyLilPony.ListGroundMounts()
syzler@1 177 local results = {};
syzler@1 178 local countMounts = GetNumCompanions("MOUNT");
syzler@1 179 local x = 1;
syzler@1 180 for i = 1, countMounts do
syzler@1 181 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
syzler@1 182 if MyLilPony.IsGroundMount(id) then
syzler@1 183 results[x] = name;
syzler@1 184 x = x + 1;
syzler@1 185 end
syzler@1 186 end
syzler@1 187 return results;
syzler@1 188 end
syzler@1 189
syzler@1 190 function MyLilPony.ListFlyingMounts()
syzler@1 191 local results = {};
syzler@1 192 local countMounts = GetNumCompanions("MOUNT");
syzler@1 193 local x = 1;
syzler@1 194 for i = 1, countMounts do
syzler@1 195 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
syzler@1 196 if MyLilPony.IsFlyingMount(id) then
syzler@1 197 results[x] = name;
syzler@1 198 x = x + 1;
syzler@1 199 end
syzler@1 200 end
syzler@1 201 return results;
syzler@1 202 end
syzler@1 203
syzler@1 204 function MyLilPony.ListAquaticMounts()
syzler@1 205 local results = {};
syzler@1 206 local countMounts = GetNumCompanions("MOUNT");
syzler@1 207 local x = 1;
syzler@1 208 for i = 1, countMounts do
syzler@1 209 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
syzler@1 210 if MyLilPony.IsAquaticMount(id) then
syzler@1 211 results[x] = name;
syzler@1 212 x = x + 1;
syzler@1 213 end
syzler@1 214 end
syzler@1 215 return results;
syzler@1 216 end
syzler@1 217
syzler@1 218 function MyLilPony.ListMountsByPattern(mountNamePattern)
syzler@1 219 local results = {};
syzler@1 220 local countMounts = GetNumCompanions("MOUNT");
syzler@1 221 local x = 1;
syzler@1 222 for i = 1, countMounts do
syzler@1 223 local _, name, _, _, _ = GetCompanionInfo("MOUNT", i);
syzler@1 224 if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then
syzler@1 225 results[x] = name;
syzler@1 226 x = x + 1;
syzler@1 227 end
syzler@1 228 end
syzler@1 229 return results;
syzler@1 230 end
syzler@1 231