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@6
|
21 -- @return A Boolean value indicating whether or not a mount was successfully 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@6
|
30 --- Summons a random flying mount.
|
syzler@6
|
31 -- Does nothing if the only available mount is already summoned.
|
syzler@6
|
32 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
|
syzler@1
|
33 function MyLilPony.CallFlyingMount()
|
syzler@1
|
34 local filter = function (i)
|
syzler@1
|
35 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
|
syzler@1
|
36 return not summoned and MyLilPony.IsFlyingMount(id);
|
syzler@1
|
37 end
|
syzler@1
|
38 return MyLilPony.CallMountByFilter(filter);
|
syzler@1
|
39 end
|
syzler@1
|
40
|
syzler@6
|
41 --- Summons a random ground mount.
|
syzler@6
|
42 -- Does nothing if the only available mount is already summoned.
|
syzler@6
|
43 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
|
syzler@1
|
44 function MyLilPony.CallGroundMount()
|
syzler@1
|
45 local filter = function (i)
|
syzler@1
|
46 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
|
syzler@1
|
47 return not summoned and MyLilPony.IsGroundMount(id);
|
syzler@1
|
48 end
|
syzler@1
|
49 return MyLilPony.CallMountByFilter(filter);
|
syzler@1
|
50 end
|
syzler@1
|
51
|
syzler@6
|
52 --- Summons a random aquatic mount.
|
syzler@6
|
53 -- Does nothing if the only available mount is already summoned.
|
syzler@6
|
54 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
|
syzler@1
|
55 function MyLilPony.CallAquaticMount()
|
syzler@1
|
56 local filter = function (i)
|
syzler@1
|
57 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
|
syzler@1
|
58 return not summoned and MyLilPony.IsAquaticMount(id);
|
syzler@1
|
59 end
|
syzler@1
|
60 return MyLilPony.CallMountByFilter(filter);
|
syzler@1
|
61 end
|
syzler@1
|
62
|
syzler@6
|
63 --- Summons a mount by slot number in mount spellbook.
|
syzler@6
|
64 -- Does nothing if the specified mount is already summoned.
|
syzler@6
|
65 -- @param slotNumber The slot number of the desired mount in the mount spellbook.
|
syzler@6
|
66 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
|
syzler@1
|
67 function MyLilPony.CallMountBySlot(slotNumber)
|
syzler@1
|
68 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
69 if slotNumber > 0 and slotNumber < countMounts+1 then
|
syzler@1
|
70 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", slotNumber);
|
syzler@1
|
71 MyLilPony.CallCompanion("MOUNT", slotNumber, not summoned);
|
syzler@1
|
72 return true;
|
syzler@1
|
73 end
|
syzler@1
|
74 return false;
|
syzler@1
|
75 end
|
syzler@1
|
76
|
syzler@6
|
77 --- Summons a mount by exact name match.
|
syzler@6
|
78 -- Does nothing if the specified mount is already summoned.
|
syzler@6
|
79 -- @param mountName The exact name (including correct upper/lower case) of the desired mount.
|
syzler@6
|
80 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
|
syzler@1
|
81 function MyLilPony.CallMountByName(mountName)
|
syzler@1
|
82 local result = false;
|
syzler@1
|
83 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
84 for i = 1, countMounts do
|
syzler@6
|
85 local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
|
syzler@6
|
86 if name == mountName then
|
syzler@1
|
87 MyLilPony.CallCompanion("MOUNT", i, not summoned);
|
syzler@1
|
88 result = true;
|
syzler@1
|
89 do break end
|
syzler@6
|
90 end
|
syzler@6
|
91 end
|
syzler@1
|
92 return result;
|
syzler@1
|
93 end
|
syzler@1
|
94
|
syzler@6
|
95 --- Summons a mount by name pattern match.
|
syzler@6
|
96 -- If the pattern matches multiple mounts, a random one is chosen.
|
syzler@6
|
97 -- Does nothing if the specified mount is already summoned.
|
syzler@6
|
98 -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case).
|
syzler@6
|
99 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
|
syzler@1
|
100 function MyLilPony.CallMountByPattern(mountNamePattern)
|
syzler@1
|
101 local filter = function (i)
|
syzler@1
|
102 local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
|
syzler@1
|
103 return not summoned and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern);
|
syzler@1
|
104 end
|
syzler@1
|
105 return MyLilPony.CallMountByFilter(filter);
|
syzler@1
|
106 end
|
syzler@1
|
107
|
syzler@6
|
108 --- Summons a mount by creature or spell ID.
|
syzler@6
|
109 -- Does nothing if the specified mount is already summoned.
|
syzler@6
|
110 -- @param id The creature or spell ID of the desired mount.
|
syzler@6
|
111 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
|
syzler@1
|
112 function MyLilPony.CallMountById(id)
|
syzler@1
|
113 local result = false;
|
syzler@1
|
114 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
115 for i = 1, countMounts do
|
syzler@6
|
116 local creatureId, _, spellId, _, summoned = GetCompanionInfo("MOUNT", i);
|
syzler@6
|
117 if id == creatureId or id == spellId then
|
syzler@1
|
118 MyLilPony.CallCompanion("MOUNT", i, not summoned);
|
syzler@1
|
119 result = true;
|
syzler@1
|
120 do break end
|
syzler@6
|
121 end
|
syzler@6
|
122 end
|
syzler@1
|
123 return result;
|
syzler@1
|
124 end
|
syzler@1
|
125
|
syzler@6
|
126 --- Summons a mount by spell ID.
|
syzler@6
|
127 -- Does nothing if the specified mount is already summoned.
|
syzler@6
|
128 -- @param spellId The spell ID of the desired mount.
|
syzler@6
|
129 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
|
syzler@1
|
130 function MyLilPony.CallMountBySpell(spellId)
|
syzler@1
|
131 local result = false;
|
syzler@1
|
132 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
133 for i = 1, countMounts do
|
syzler@6
|
134 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
|
syzler@6
|
135 if id == spellId then
|
syzler@1
|
136 MyLilPony.CallCompanion("MOUNT", i, not summoned);
|
syzler@1
|
137 result = true;
|
syzler@1
|
138 do break end
|
syzler@6
|
139 end
|
syzler@6
|
140 end
|
syzler@1
|
141 return result;
|
syzler@1
|
142 end
|
syzler@1
|
143
|
syzler@6
|
144 --- Summons a mount by creature ID.
|
syzler@6
|
145 -- Does nothing if the specified mount is already summoned.
|
syzler@6
|
146 -- @param creatureId The creature ID of the desired mount.
|
syzler@6
|
147 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
|
syzler@1
|
148 function MyLilPony.CallMountByCreature(creatureId)
|
syzler@1
|
149 local result = false;
|
syzler@1
|
150 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
151 for i = 1, countMounts do
|
syzler@6
|
152 local id, _, _, _, summoned = GetCompanionInfo("MOUNT", i);
|
syzler@6
|
153 if id == creatureId then
|
syzler@1
|
154 MyLilPony.CallCompanion("MOUNT", i, not summoned);
|
syzler@1
|
155 result = true;
|
syzler@1
|
156 do break end
|
syzler@6
|
157 end
|
syzler@6
|
158 end
|
syzler@1
|
159 return result;
|
syzler@1
|
160 end
|
syzler@1
|
161
|
syzler@6
|
162 --- Summons a mount by attempting to match the mount of the specified unit.
|
syzler@6
|
163 -- The function checks the buffs of the specified unit against the mount spellbook for matches.
|
syzler@6
|
164 -- As a result, the function will only likely work against player characters.
|
syzler@6
|
165 -- Does nothing if the specified unit's mount is already summoned.
|
syzler@6
|
166 -- @param unit The unit frame name (e.g. "target", "player", "focus") of the unit whose mount is desired.
|
syzler@6
|
167 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
|
syzler@7
|
168 -- @usage MyLilPony.CallMountByMatch("target");
|
syzler@1
|
169 function MyLilPony.CallMountByMatch(unit)
|
syzler@1
|
170 local result = false;
|
syzler@1
|
171 local unitBuffs = MyLilPony.GetUnitBuffs(unit);
|
syzler@1
|
172 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
173 for i = 1, countMounts do
|
syzler@6
|
174 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
|
syzler@6
|
175 if unitBuffs[id] ~= nil then
|
syzler@1
|
176 MyLilPony.CallCompanion("MOUNT", i, not summoned);
|
syzler@1
|
177 result = true;
|
syzler@1
|
178 do break end
|
syzler@6
|
179 end
|
syzler@6
|
180 end
|
syzler@1
|
181 return result;
|
syzler@1
|
182 end
|
syzler@1
|
183
|
syzler@6
|
184 --- Summons a random mount after filtering the mount spellbook.
|
syzler@6
|
185 -- Does nothing if the specified mount is already summoned.
|
syzler@6
|
186 -- @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
|
187 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
|
syzler@6
|
188 -- @usage local filter = function (i)
|
syzler@6
|
189 -- local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
|
syzler@6
|
190 -- return not summoned and string.match(name, pattern);
|
syzler@6
|
191 -- end
|
syzler@7
|
192 -- MyLilPony.CallMountByFilter(filter);
|
syzler@1
|
193 function MyLilPony.CallMountByFilter(filter)
|
syzler@1
|
194 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
195 if countMounts > 0 then
|
syzler@1
|
196 local results = {};
|
syzler@1
|
197 local countResults = 0;
|
syzler@1
|
198
|
syzler@1
|
199 for i = 1, countMounts do
|
syzler@1
|
200 if filter(i) then
|
syzler@1
|
201 countResults = countResults + 1;
|
syzler@1
|
202 results[countResults] = i;
|
syzler@1
|
203 end
|
syzler@1
|
204 end
|
syzler@1
|
205
|
syzler@1
|
206 if countResults > 0 then
|
syzler@1
|
207 local i = random(1, countResults);
|
syzler@1
|
208 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", results[i]);
|
syzler@1
|
209 MyLilPony.CallCompanion("MOUNT", results[i], not summoned);
|
syzler@1
|
210 return true;
|
syzler@1
|
211 end
|
syzler@1
|
212 end
|
syzler@1
|
213 return false;
|
syzler@1
|
214 end
|
syzler@1
|
215
|
syzler@6
|
216 --- Lists available mounts by name.
|
syzler@6
|
217 -- @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
|
218 function MyLilPony.ListMounts()
|
syzler@1
|
219 local results = {};
|
syzler@1
|
220 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
221 for i = 1, countMounts do
|
syzler@1
|
222 local _, name, _, _, _ = GetCompanionInfo("MOUNT", i);
|
syzler@1
|
223 results[i] = name;
|
syzler@1
|
224 end
|
syzler@1
|
225 return results;
|
syzler@1
|
226 end
|
syzler@1
|
227
|
syzler@6
|
228 --- Lists available ground mounts by name.
|
syzler@6
|
229 -- @return A list of ground mount names.
|
syzler@1
|
230 function MyLilPony.ListGroundMounts()
|
syzler@1
|
231 local results = {};
|
syzler@1
|
232 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
233 local x = 1;
|
syzler@1
|
234 for i = 1, countMounts do
|
syzler@1
|
235 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
|
syzler@1
|
236 if MyLilPony.IsGroundMount(id) then
|
syzler@1
|
237 results[x] = name;
|
syzler@1
|
238 x = x + 1;
|
syzler@1
|
239 end
|
syzler@1
|
240 end
|
syzler@1
|
241 return results;
|
syzler@1
|
242 end
|
syzler@1
|
243
|
syzler@6
|
244 --- Lists available flying mounts by name.
|
syzler@6
|
245 -- @return A list of flying mount names.
|
syzler@1
|
246 function MyLilPony.ListFlyingMounts()
|
syzler@1
|
247 local results = {};
|
syzler@1
|
248 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
249 local x = 1;
|
syzler@1
|
250 for i = 1, countMounts do
|
syzler@1
|
251 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
|
syzler@1
|
252 if MyLilPony.IsFlyingMount(id) then
|
syzler@1
|
253 results[x] = name;
|
syzler@1
|
254 x = x + 1;
|
syzler@1
|
255 end
|
syzler@1
|
256 end
|
syzler@1
|
257 return results;
|
syzler@1
|
258 end
|
syzler@1
|
259
|
syzler@6
|
260 --- Lists available aquatic mounts by name.
|
syzler@6
|
261 -- @return A list of aquatic mount names.
|
syzler@1
|
262 function MyLilPony.ListAquaticMounts()
|
syzler@1
|
263 local results = {};
|
syzler@1
|
264 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
265 local x = 1;
|
syzler@1
|
266 for i = 1, countMounts do
|
syzler@1
|
267 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
|
syzler@1
|
268 if MyLilPony.IsAquaticMount(id) then
|
syzler@1
|
269 results[x] = name;
|
syzler@1
|
270 x = x + 1;
|
syzler@1
|
271 end
|
syzler@1
|
272 end
|
syzler@1
|
273 return results;
|
syzler@1
|
274 end
|
syzler@1
|
275
|
syzler@6
|
276 --- Lists available mounts names whose name matches a given pattern.
|
syzler@6
|
277 -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case).
|
syzler@6
|
278 -- @return A list of matching mount names.
|
syzler@1
|
279 function MyLilPony.ListMountsByPattern(mountNamePattern)
|
syzler@1
|
280 local results = {};
|
syzler@1
|
281 local countMounts = GetNumCompanions("MOUNT");
|
syzler@1
|
282 local x = 1;
|
syzler@1
|
283 for i = 1, countMounts do
|
syzler@1
|
284 local _, name, _, _, _ = GetCompanionInfo("MOUNT", i);
|
syzler@1
|
285 if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then
|
syzler@1
|
286 results[x] = name;
|
syzler@1
|
287 x = x + 1;
|
syzler@1
|
288 end
|
syzler@1
|
289 end
|
syzler@1
|
290 return results;
|
syzler@1
|
291 end
|
syzler@1
|
292
|