comparison libMyLilPony/libMyLilPony_mountFunctions.lua @ 60:81145a681a59

Fixed for legion xpack (patch 7.0) API changes
author syzler
date Sat, 13 Aug 2016 15:29:39 -0400
parents d3d070ea6341
children
comparison
equal deleted inserted replaced
59:12b9c632919d 60:81145a681a59
40 --- Summons a random mount. 40 --- Summons a random mount.
41 -- Does nothing if the only available mount is already summoned. 41 -- Does nothing if the only available mount is already summoned.
42 -- @return A Boolean value indicating whether or not a mount was successfully summoned. 42 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
43 function MyLilPony.CallMount() 43 function MyLilPony.CallMount()
44 local filter = function (i) 44 local filter = function (i)
45 local _, _, _, summoned, usable = C_MountJournal.GetMountInfo(i); 45 local _, _, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
46 return not summoned and usable; 46 return not summoned and usable;
47 end 47 end
48 return MyLilPony.CallMountByFilter(filter); 48 return MyLilPony.CallMountByFilter(filter);
49 end 49 end
50 50
51 --- Summons a random flying mount. 51 --- Summons a random flying mount.
52 -- Does nothing if the only available mount is already summoned. 52 -- Does nothing if the only available mount is already summoned.
53 -- @return A Boolean value indicating whether or not a mount was successfully summoned. 53 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
54 function MyLilPony.CallFlyingMount() 54 function MyLilPony.CallFlyingMount()
55 local filter = function (i) 55 local filter = function (i)
56 local _, id, _, summoned, usable = C_MountJournal.GetMountInfo(i); 56 local _, id, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
57 return not summoned and usable and MyLilPony.IsFlyingMountSlot(i); 57 return not summoned and usable and MyLilPony.IsFlyingMountSlot(i);
58 end 58 end
59 return MyLilPony.CallMountByFilter(filter); 59 return MyLilPony.CallMountByFilter(filter);
60 end 60 end
61 61
62 --- Summons a random ground mount. 62 --- Summons a random ground mount.
63 -- Does nothing if the only available mount is already summoned. 63 -- Does nothing if the only available mount is already summoned.
64 -- @return A Boolean value indicating whether or not a mount was successfully summoned. 64 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
65 function MyLilPony.CallGroundMount() 65 function MyLilPony.CallGroundMount()
66 local filter = function (i) 66 local filter = function (i)
67 local _, id, _, summoned, usable = C_MountJournal.GetMountInfo(i); 67 local _, id, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
68 return not summoned and usable and MyLilPony.IsGroundMountSlot(i); 68 return not summoned and usable and MyLilPony.IsGroundMountSlot(i);
69 end 69 end
70 return MyLilPony.CallMountByFilter(filter); 70 return MyLilPony.CallMountByFilter(filter);
71 end 71 end
72 72
73 --- Summons a random aquatic mount. 73 --- Summons a random aquatic mount.
74 -- Does nothing if the only available mount is already summoned. 74 -- Does nothing if the only available mount is already summoned.
75 -- @return A Boolean value indicating whether or not a mount was successfully summoned. 75 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
76 function MyLilPony.CallAquaticMount() 76 function MyLilPony.CallAquaticMount()
77 local filter = function (i) 77 local filter = function (i)
78 local _, id, _, summoned, usable = C_MountJournal.GetMountInfo(i); 78 local _, id, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
79 return not summoned and usable and MyLilPony.IsAquaticMountSlot(i); 79 return not summoned and usable and MyLilPony.IsAquaticMountSlot(i);
80 end 80 end
81 return MyLilPony.CallMountByFilter(filter); 81 return MyLilPony.CallMountByFilter(filter);
82 end 82 end
83 83
86 -- @param slotNumber The slot number of the desired mount in the mount spellbook. 86 -- @param slotNumber The slot number of the desired mount in the mount spellbook.
87 -- @return A Boolean value indicating whether or not a mount was successfully summoned. 87 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
88 function MyLilPony.CallMountBySlot(slotNumber) 88 function MyLilPony.CallMountBySlot(slotNumber)
89 local countMounts = C_MountJournal.GetNumMounts(); 89 local countMounts = C_MountJournal.GetNumMounts();
90 if slotNumber > 0 and slotNumber < countMounts+1 then 90 if slotNumber > 0 and slotNumber < countMounts+1 then
91 local _, _, _, summoned, usable = C_MountJournal.GetMountInfo(i); 91 local _, _, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
92 MyLilPony.CallMount(slotNumber, not summoned and usable); 92 MyLilPony.CallMount(slotNumber, not summoned and usable);
93 return true; 93 return true;
94 end 94 end
95 return false; 95 return false;
96 end 96 end
100 -- @param mountName The exact name (including correct upper/lower case) of the desired mount. 100 -- @param mountName The exact name (including correct upper/lower case) of the desired mount.
101 -- @return A Boolean value indicating whether or not a mount was successfully summoned. 101 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
102 function MyLilPony.CallMountByName(mountName) 102 function MyLilPony.CallMountByName(mountName)
103 local result = false; 103 local result = false;
104 for i in MyLilPony.EnumerateKnownMountSlotIDs() do 104 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
105 local name, _, _, summoned, usable = C_MountJournal.GetMountInfo(i); 105 local name, _, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
106 if name == mountName then 106 if name == mountName then
107 MyLilPony.CallMount(i, not summoned and usable); 107 MyLilPony.CallMount(i, not summoned and usable);
108 result = true; 108 result = true;
109 do break end 109 do break end
110 end 110 end
117 -- Does nothing if the specified mount is already summoned. 117 -- Does nothing if the specified mount is already summoned.
118 -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case). 118 -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case).
119 -- @return A Boolean value indicating whether or not a mount was successfully summoned. 119 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
120 function MyLilPony.CallMountByPattern(mountNamePattern) 120 function MyLilPony.CallMountByPattern(mountNamePattern)
121 local filter = function (i) 121 local filter = function (i)
122 local name, _, _, summoned, usable = C_MountJournal.GetMountInfo(i); 122 local name, _, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
123 return not summoned and usable and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern); 123 return not summoned and usable and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern);
124 end 124 end
125 return MyLilPony.CallMountByFilter(filter); 125 return MyLilPony.CallMountByFilter(filter);
126 end 126 end
127 127
130 -- @param id The creature or spell ID of the desired mount. 130 -- @param id The creature or spell ID of the desired mount.
131 -- @return A Boolean value indicating whether or not a mount was successfully summoned. 131 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
132 function MyLilPony.CallMountById(id) 132 function MyLilPony.CallMountById(id)
133 local result = false; 133 local result = false;
134 for i in MyLilPony.EnumerateKnownMountSlotIDs() do 134 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
135 local _, spellId, _, summoned, usable = C_MountJournal.GetMountInfo(i); 135 local _, spellId, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
136 local creatureId = C_MountJournal.GetMountInfoExtra(i); 136 local creatureId = C_MountJournal.GetMountInfoExtraByID(i);
137 if id == creatureId or id == spellId then 137 if id == creatureId or id == spellId then
138 MyLilPony.CallMount(i, not summoned and usable); 138 MyLilPony.CallMount(i, not summoned and usable);
139 result = true; 139 result = true;
140 do break end 140 do break end
141 end 141 end
148 -- @param spellId The spell ID of the desired mount. 148 -- @param spellId The spell ID of the desired mount.
149 -- @return A Boolean value indicating whether or not a mount was successfully summoned. 149 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
150 function MyLilPony.CallMountBySpell(spellId) 150 function MyLilPony.CallMountBySpell(spellId)
151 local result = false; 151 local result = false;
152 for i in MyLilPony.EnumerateKnownMountSlotIDs() do 152 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
153 local _, id, _, summoned, usable = C_MountJournal.GetMountInfo(i); 153 local _, id, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
154 if id == spellId then 154 if id == spellId then
155 MyLilPony.CallMount(i, not summoned and usable); 155 MyLilPony.CallMount(i, not summoned and usable);
156 result = true; 156 result = true;
157 do break end 157 do break end
158 end 158 end
165 -- @param creatureId The creature ID of the desired mount. 165 -- @param creatureId The creature ID of the desired mount.
166 -- @return A Boolean value indicating whether or not a mount was successfully summoned. 166 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
167 function MyLilPony.CallMountByCreature(creatureId) 167 function MyLilPony.CallMountByCreature(creatureId)
168 local result = false; 168 local result = false;
169 for i in MyLilPony.EnumerateKnownMountSlotIDs() do 169 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
170 local _, _, _, summoned, usable = C_MountJournal.GetMountInfo(i); 170 local _, _, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
171 local id = C_MountJournal.GetMountInfoExtra(i); 171 local id = C_MountJournal.GetMountInfoExtraByID(i);
172 if id == creatureId then 172 if id == creatureId then
173 MyLilPony.CallMount(i, not summoned and usable); 173 MyLilPony.CallMount(i, not summoned and usable);
174 result = true; 174 result = true;
175 do break end 175 do break end
176 end 176 end
187 -- @usage MyLilPony.CallMountByMatch("target"); 187 -- @usage MyLilPony.CallMountByMatch("target");
188 function MyLilPony.CallMountByMatch(unit) 188 function MyLilPony.CallMountByMatch(unit)
189 local result = false; 189 local result = false;
190 local unitBuffs = MyLilPony.GetUnitBuffs(unit); 190 local unitBuffs = MyLilPony.GetUnitBuffs(unit);
191 for i in MyLilPony.EnumerateKnownMountSlotIDs() do 191 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
192 local _, id, _, summoned, usable = C_MountJournal.GetMountInfo(i); 192 local _, id, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
193 if unitBuffs[id] ~= nil then 193 if unitBuffs[id] ~= nil then
194 MyLilPony.CallMount(i, not summoned and usable); 194 MyLilPony.CallMount(i, not summoned and usable);
195 result = true; 195 result = true;
196 do break end 196 do break end
197 end 197 end
202 --- Summons a random mount after filtering the mount spellbook. 202 --- Summons a random mount after filtering the mount spellbook.
203 -- Does nothing if the specified mount is already summoned. 203 -- Does nothing if the specified mount is already summoned.
204 -- @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. 204 -- @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.
205 -- @return A Boolean value indicating whether or not a mount was successfully summoned. 205 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
206 -- @usage local filter = function (i) 206 -- @usage local filter = function (i)
207 -- local name = C_MountJournal.GetMountInfo(i); 207 -- local name = C_MountJournal.GetMountInfoByID(i);
208 -- return string.match(name, pattern); 208 -- return string.match(name, pattern);
209 -- end 209 -- end
210 -- MyLilPony.CallMountByFilter(filter); 210 -- MyLilPony.CallMountByFilter(filter);
211 function MyLilPony.CallMountByFilter(filter) 211 function MyLilPony.CallMountByFilter(filter)
212 local mounts = {}; 212 local mounts = {};
218 end 218 end
219 end 219 end
220 220
221 if x > 0 then 221 if x > 0 then
222 local i = mounts[random(1, x)]; 222 local i = mounts[random(1, x)];
223 local _, _, _, summoned, usable = C_MountJournal.GetMountInfo(i); 223 local _, _, _, summoned, usable = C_MountJournal.GetMountInfoByID(i);
224 MyLilPony.CallMount(i, not summoned and usable); 224 MyLilPony.CallMount(i, not summoned and usable);
225 return true; 225 return true;
226 end 226 end
227 return false; 227 return false;
228 end 228 end
231 -- @return A list of mount names. 231 -- @return A list of mount names.
232 function MyLilPony.ListMounts() 232 function MyLilPony.ListMounts()
233 local results = {}; 233 local results = {};
234 local x = 1; 234 local x = 1;
235 for i in MyLilPony.EnumerateKnownMountSlotIDs() do 235 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
236 local name = C_MountJournal.GetMountInfo(i); 236 local name = C_MountJournal.GetMountInfoByID(i);
237 results[i] = name; 237 results[i] = name;
238 x = x + 1; 238 x = x + 1;
239 end 239 end
240 return results; 240 return results;
241 end 241 end
244 -- @return A list of ground mount names. 244 -- @return A list of ground mount names.
245 function MyLilPony.ListGroundMounts() 245 function MyLilPony.ListGroundMounts()
246 local results = {}; 246 local results = {};
247 local x = 1; 247 local x = 1;
248 for i in MyLilPony.EnumerateKnownMountSlotIDs() do 248 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
249 local name, id = C_MountJournal.GetMountInfo(i); 249 local name, id = C_MountJournal.GetMountInfoByID(i);
250 if MyLilPony.IsGroundMount(id) then 250 if MyLilPony.IsGroundMount(id) then
251 results[x] = name; 251 results[x] = name;
252 x = x + 1; 252 x = x + 1;
253 end 253 end
254 end 254 end
259 -- @return A list of flying mount names. 259 -- @return A list of flying mount names.
260 function MyLilPony.ListFlyingMounts() 260 function MyLilPony.ListFlyingMounts()
261 local results = {}; 261 local results = {};
262 local x = 1; 262 local x = 1;
263 for i in MyLilPony.EnumerateKnownMountSlotIDs() do 263 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
264 local name, id = C_MountJournal.GetMountInfo(i); 264 local name, id = C_MountJournal.GetMountInfoByID(i);
265 if MyLilPony.IsFlyingMount(id) then 265 if MyLilPony.IsFlyingMount(id) then
266 results[x] = name; 266 results[x] = name;
267 x = x + 1; 267 x = x + 1;
268 end 268 end
269 end 269 end
274 -- @return A list of aquatic mount names. 274 -- @return A list of aquatic mount names.
275 function MyLilPony.ListAquaticMounts() 275 function MyLilPony.ListAquaticMounts()
276 local results = {}; 276 local results = {};
277 local x = 1; 277 local x = 1;
278 for i in MyLilPony.EnumerateKnownMountSlotIDs() do 278 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
279 local name, id = C_MountJournal.GetMountInfo(i); 279 local name, id = C_MountJournal.GetMountInfoByID(i);
280 if MyLilPony.IsAquaticMount(id) then 280 if MyLilPony.IsAquaticMount(id) then
281 results[x] = name; 281 results[x] = name;
282 x = x + 1; 282 x = x + 1;
283 end 283 end
284 end 284 end
290 -- @return A list of matching mount names. 290 -- @return A list of matching mount names.
291 function MyLilPony.ListMountsByPattern(mountNamePattern) 291 function MyLilPony.ListMountsByPattern(mountNamePattern)
292 local results = {}; 292 local results = {};
293 local x = 1; 293 local x = 1;
294 for i in MyLilPony.EnumerateKnownMountSlotIDs() do 294 for i in MyLilPony.EnumerateKnownMountSlotIDs() do
295 local name = C_MountJournal.GetMountInfo(i); 295 local name = C_MountJournal.GetMountInfoByID(i);
296 if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then 296 if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then
297 results[x] = name; 297 results[x] = name;
298 x = x + 1; 298 x = x + 1;
299 end 299 end
300 end 300 end