Mercurial > wow > mylilpony
comparison libMyLilPony/libMyLilPony_mountFunctions.lua @ 50:22011265a16f 1.2.0-b1
Updated and fixed for draenor xpack (patch 6.0) API changes
| author | syzler |
|---|---|
| date | Sat, 07 Mar 2015 02:52:57 -0500 |
| parents | 2ae5f67e313a |
| children | 64e8f8e5fa41 |
comparison
equal
deleted
inserted
replaced
| 49:d29ceeeab123 | 50:22011265a16f |
|---|---|
| 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 = GetCompanionInfo("MOUNT", i); | 45 local _, _, _, summoned = C_MountJournal.GetMountInfo(i); |
| 46 return not summoned; | 46 return not summoned; |
| 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 = GetCompanionInfo("MOUNT", i); | 56 local _, id, _, summoned = C_MountJournal.GetMountInfo(i); |
| 57 return not summoned and MyLilPony.IsFlyingMount(id); | 57 return not summoned and MyLilPony.IsFlyingMount(id); |
| 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 = GetCompanionInfo("MOUNT", i); | 67 local _, id, _, summoned = C_MountJournal.GetMountInfo(i); |
| 68 return not summoned and MyLilPony.IsGroundMount(id); | 68 return not summoned and MyLilPony.IsGroundMount(id); |
| 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 = GetCompanionInfo("MOUNT", i); | 78 local _, id, _, summoned = C_MountJournal.GetMountInfo(i); |
| 79 return not summoned and MyLilPony.IsAquaticMount(id); | 79 return not summoned and MyLilPony.IsAquaticMount(id); |
| 80 end | 80 end |
| 81 return MyLilPony.CallMountByFilter(filter); | 81 return MyLilPony.CallMountByFilter(filter); |
| 82 end | 82 end |
| 83 | 83 |
| 84 --- Summons a mount by slot number in mount spellbook. | 84 --- Summons a mount by slot number in mount spellbook. |
| 85 -- Does nothing if the specified mount is already summoned. | 85 -- Does nothing if the specified mount is already summoned. |
| 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 = GetNumCompanions("MOUNT"); | 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 = GetCompanionInfo("MOUNT", slotNumber); | 91 local _, _, _, summoned = C_MountJournal.GetMountInfo(i); |
| 92 MyLilPony.CallCompanion("MOUNT", slotNumber, not summoned); | 92 MyLilPony.CallCompanion("MOUNT", slotNumber, not summoned); |
| 93 return true; | 93 return true; |
| 94 end | 94 end |
| 95 return false; | 95 return false; |
| 96 end | 96 end |
| 99 -- Does nothing if the specified mount is already summoned. | 99 -- Does nothing if the specified mount is already summoned. |
| 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 local countMounts = GetNumCompanions("MOUNT"); | 104 for i in MyLilPony.EnumerateKnownMountSlotIDs() do |
| 105 for i = 1, countMounts do | 105 local name, _, _, summoned = C_MountJournal.GetMountInfo(i); |
| 106 local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i); | |
| 107 if name == mountName then | 106 if name == mountName then |
| 108 MyLilPony.CallCompanion("MOUNT", i, not summoned); | 107 MyLilPony.CallCompanion("MOUNT", i, not summoned); |
| 109 result = true; | 108 result = true; |
| 110 do break end | 109 do break end |
| 111 end | 110 end |
| 118 -- Does nothing if the specified mount is already summoned. | 117 -- Does nothing if the specified mount is already summoned. |
| 119 -- @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). |
| 120 -- @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. |
| 121 function MyLilPony.CallMountByPattern(mountNamePattern) | 120 function MyLilPony.CallMountByPattern(mountNamePattern) |
| 122 local filter = function (i) | 121 local filter = function (i) |
| 123 local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i); | 122 local name, _, _, summoned = C_MountJournal.GetMountInfo(i); |
| 124 return not summoned and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern); | 123 return not summoned and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern); |
| 125 end | 124 end |
| 126 return MyLilPony.CallMountByFilter(filter); | 125 return MyLilPony.CallMountByFilter(filter); |
| 127 end | 126 end |
| 128 | 127 |
| 130 -- Does nothing if the specified mount is already summoned. | 129 -- Does nothing if the specified mount is already summoned. |
| 131 -- @param id The creature or spell ID of the desired mount. | 130 -- @param id The creature or spell ID of the desired mount. |
| 132 -- @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. |
| 133 function MyLilPony.CallMountById(id) | 132 function MyLilPony.CallMountById(id) |
| 134 local result = false; | 133 local result = false; |
| 135 local countMounts = GetNumCompanions("MOUNT"); | 134 for i in MyLilPony.EnumerateKnownMountSlotIDs() do |
| 136 for i = 1, countMounts do | 135 local _, spellId, _, summoned = C_MountJournal.GetMountInfo(i); |
| 137 local creatureId, _, spellId, _, summoned = GetCompanionInfo("MOUNT", i); | 136 local creatureId = C_MountJournal.GetMountInfoExtra(i); |
| 138 if id == creatureId or id == spellId then | 137 if id == creatureId or id == spellId then |
| 139 MyLilPony.CallCompanion("MOUNT", i, not summoned); | 138 MyLilPony.CallCompanion("MOUNT", i, not summoned); |
| 140 result = true; | 139 result = true; |
| 141 do break end | 140 do break end |
| 142 end | 141 end |
| 148 -- Does nothing if the specified mount is already summoned. | 147 -- Does nothing if the specified mount is already summoned. |
| 149 -- @param spellId The spell ID of the desired mount. | 148 -- @param spellId The spell ID of the desired mount. |
| 150 -- @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. |
| 151 function MyLilPony.CallMountBySpell(spellId) | 150 function MyLilPony.CallMountBySpell(spellId) |
| 152 local result = false; | 151 local result = false; |
| 153 local countMounts = GetNumCompanions("MOUNT"); | 152 for i in MyLilPony.EnumerateKnownMountSlotIDs() do |
| 154 for i = 1, countMounts do | 153 local _, id, _, summoned = C_MountJournal.GetMountInfo(i); |
| 155 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); | |
| 156 if id == spellId then | 154 if id == spellId then |
| 157 MyLilPony.CallCompanion("MOUNT", i, not summoned); | 155 MyLilPony.CallCompanion("MOUNT", i, not summoned); |
| 158 result = true; | 156 result = true; |
| 159 do break end | 157 do break end |
| 160 end | 158 end |
| 166 -- Does nothing if the specified mount is already summoned. | 164 -- Does nothing if the specified mount is already summoned. |
| 167 -- @param creatureId The creature ID of the desired mount. | 165 -- @param creatureId The creature ID of the desired mount. |
| 168 -- @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. |
| 169 function MyLilPony.CallMountByCreature(creatureId) | 167 function MyLilPony.CallMountByCreature(creatureId) |
| 170 local result = false; | 168 local result = false; |
| 171 local countMounts = GetNumCompanions("MOUNT"); | 169 for i in MyLilPony.EnumerateKnownMountSlotIDs() do |
| 172 for i = 1, countMounts do | 170 local _, _, _, summoned = C_MountJournal.GetMountInfo(i); |
| 173 local id, _, _, _, summoned = GetCompanionInfo("MOUNT", i); | 171 local id = C_MountJournal.GetMountInfoExtra(i); |
| 174 if id == creatureId then | 172 if id == creatureId then |
| 175 MyLilPony.CallCompanion("MOUNT", i, not summoned); | 173 MyLilPony.CallCompanion("MOUNT", i, not summoned); |
| 176 result = true; | 174 result = true; |
| 177 do break end | 175 do break end |
| 178 end | 176 end |
| 188 -- @return A Boolean value indicating whether or not a mount was successfully summoned. | 186 -- @return A Boolean value indicating whether or not a mount was successfully summoned. |
| 189 -- @usage MyLilPony.CallMountByMatch("target"); | 187 -- @usage MyLilPony.CallMountByMatch("target"); |
| 190 function MyLilPony.CallMountByMatch(unit) | 188 function MyLilPony.CallMountByMatch(unit) |
| 191 local result = false; | 189 local result = false; |
| 192 local unitBuffs = MyLilPony.GetUnitBuffs(unit); | 190 local unitBuffs = MyLilPony.GetUnitBuffs(unit); |
| 193 local countMounts = GetNumCompanions("MOUNT"); | 191 for i in MyLilPony.EnumerateKnownMountSlotIDs() do |
| 194 for i = 1, countMounts do | 192 local _, id, _, summoned = C_MountJournal.GetMountInfo(i); |
| 195 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); | |
| 196 if unitBuffs[id] ~= nil then | 193 if unitBuffs[id] ~= nil then |
| 197 MyLilPony.CallCompanion("MOUNT", i, not summoned); | 194 MyLilPony.CallCompanion("MOUNT", i, not summoned); |
| 198 result = true; | 195 result = true; |
| 199 do break end | 196 do break end |
| 200 end | 197 end |
| 205 --- Summons a random mount after filtering the mount spellbook. | 202 --- Summons a random mount after filtering the mount spellbook. |
| 206 -- Does nothing if the specified mount is already summoned. | 203 -- Does nothing if the specified mount is already summoned. |
| 207 -- @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. |
| 208 -- @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. |
| 209 -- @usage local filter = function (i) | 206 -- @usage local filter = function (i) |
| 210 -- local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i); | 207 -- local name = C_MountJournal.GetMountInfo(i); |
| 211 -- return not summoned and string.match(name, pattern); | 208 -- return string.match(name, pattern); |
| 212 -- end | 209 -- end |
| 213 -- MyLilPony.CallMountByFilter(filter); | 210 -- MyLilPony.CallMountByFilter(filter); |
| 214 function MyLilPony.CallMountByFilter(filter) | 211 function MyLilPony.CallMountByFilter(filter) |
| 215 local countMounts = GetNumCompanions("MOUNT"); | 212 local mounts = {}; |
| 216 if countMounts > 0 then | 213 local x = 0; |
| 217 local results = {}; | 214 for i in MyLilPony.EnumerateKnownMountSlotIDs() do |
| 218 local countResults = 0; | 215 if filter(i) then |
| 219 | 216 x = x + 1; |
| 220 for i = 1, countMounts do | 217 mounts[x] = i; |
| 221 if filter(i) then | 218 end |
| 222 countResults = countResults + 1; | 219 end |
| 223 results[countResults] = i; | |
| 224 end | |
| 225 end | |
| 226 | 220 |
| 227 if countResults > 0 then | 221 if x > 0 then |
| 228 local i = random(1, countResults); | 222 local i = mounts[random(1, x)]; |
| 229 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", results[i]); | 223 local _, _, _, summoned = C_MountJournal.GetMountInfo(i); |
| 230 MyLilPony.CallCompanion("MOUNT", results[i], not summoned); | 224 MyLilPony.CallCompanion("MOUNT", i, not summoned); |
| 231 return true; | 225 return true; |
| 232 end | |
| 233 end | 226 end |
| 234 return false; | 227 return false; |
| 235 end | 228 end |
| 236 | 229 |
| 237 --- Lists available mounts by name. | 230 --- Lists available mounts by name. |
| 238 -- @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. | 231 -- @return A list of mount names. |
| 239 function MyLilPony.ListMounts() | 232 function MyLilPony.ListMounts() |
| 240 local results = {}; | 233 local results = {}; |
| 241 local countMounts = GetNumCompanions("MOUNT"); | 234 local x = 1; |
| 242 for i = 1, countMounts do | 235 for i in MyLilPony.EnumerateKnownMountSlotIDs() do |
| 243 local _, name, _, _, _ = GetCompanionInfo("MOUNT", i); | 236 local name = C_MountJournal.GetMountInfo(i); |
| 244 results[i] = name; | 237 results[i] = name; |
| 238 x = x + 1; | |
| 245 end | 239 end |
| 246 return results; | 240 return results; |
| 247 end | 241 end |
| 248 | 242 |
| 249 --- Lists available ground mounts by name. | 243 --- Lists available ground mounts by name. |
| 250 -- @return A list of ground mount names. | 244 -- @return A list of ground mount names. |
| 251 function MyLilPony.ListGroundMounts() | 245 function MyLilPony.ListGroundMounts() |
| 252 local results = {}; | 246 local results = {}; |
| 253 local countMounts = GetNumCompanions("MOUNT"); | 247 local x = 1; |
| 254 local x = 1; | 248 for i in MyLilPony.EnumerateKnownMountSlotIDs() do |
| 255 for i = 1, countMounts do | 249 local name, id = C_MountJournal.GetMountInfo(i); |
| 256 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i); | |
| 257 if MyLilPony.IsGroundMount(id) then | 250 if MyLilPony.IsGroundMount(id) then |
| 258 results[x] = name; | 251 results[x] = name; |
| 259 x = x + 1; | 252 x = x + 1; |
| 260 end | 253 end |
| 261 end | 254 end |
| 264 | 257 |
| 265 --- Lists available flying mounts by name. | 258 --- Lists available flying mounts by name. |
| 266 -- @return A list of flying mount names. | 259 -- @return A list of flying mount names. |
| 267 function MyLilPony.ListFlyingMounts() | 260 function MyLilPony.ListFlyingMounts() |
| 268 local results = {}; | 261 local results = {}; |
| 269 local countMounts = GetNumCompanions("MOUNT"); | 262 local x = 1; |
| 270 local x = 1; | 263 for i in MyLilPony.EnumerateKnownMountSlotIDs() do |
| 271 for i = 1, countMounts do | 264 local name, id = C_MountJournal.GetMountInfo(i); |
| 272 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i); | |
| 273 if MyLilPony.IsFlyingMount(id) then | 265 if MyLilPony.IsFlyingMount(id) then |
| 274 results[x] = name; | 266 results[x] = name; |
| 275 x = x + 1; | 267 x = x + 1; |
| 276 end | 268 end |
| 277 end | 269 end |
| 280 | 272 |
| 281 --- Lists available aquatic mounts by name. | 273 --- Lists available aquatic mounts by name. |
| 282 -- @return A list of aquatic mount names. | 274 -- @return A list of aquatic mount names. |
| 283 function MyLilPony.ListAquaticMounts() | 275 function MyLilPony.ListAquaticMounts() |
| 284 local results = {}; | 276 local results = {}; |
| 285 local countMounts = GetNumCompanions("MOUNT"); | 277 local x = 1; |
| 286 local x = 1; | 278 for i in MyLilPony.EnumerateKnownMountSlotIDs() do |
| 287 for i = 1, countMounts do | 279 local name, id = C_MountJournal.GetMountInfo(i); |
| 288 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i); | |
| 289 if MyLilPony.IsAquaticMount(id) then | 280 if MyLilPony.IsAquaticMount(id) then |
| 290 results[x] = name; | 281 results[x] = name; |
| 291 x = x + 1; | 282 x = x + 1; |
| 292 end | 283 end |
| 293 end | 284 end |
| 297 --- Lists available mounts names whose name matches a given pattern. | 288 --- Lists available mounts names whose name matches a given pattern. |
| 298 -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case). | 289 -- @param mountNamePattern A string pattern against which mount names are matched (does not require correct upper/lower case). |
| 299 -- @return A list of matching mount names. | 290 -- @return A list of matching mount names. |
| 300 function MyLilPony.ListMountsByPattern(mountNamePattern) | 291 function MyLilPony.ListMountsByPattern(mountNamePattern) |
| 301 local results = {}; | 292 local results = {}; |
| 302 local countMounts = GetNumCompanions("MOUNT"); | 293 local x = 1; |
| 303 local x = 1; | 294 for i in MyLilPony.EnumerateKnownMountSlotIDs() do |
| 304 for i = 1, countMounts do | 295 local name = C_MountJournal.GetMountInfo(i); |
| 305 local _, name, _, _, _ = GetCompanionInfo("MOUNT", i); | |
| 306 if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then | 296 if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then |
| 307 results[x] = name; | 297 results[x] = name; |
| 308 x = x + 1; | 298 x = x + 1; |
| 309 end | 299 end |
| 310 end | 300 end |
| 311 return results; | 301 return results; |
| 312 end | 302 end |
| 313 |
