diff 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
line wrap: on
line diff
--- a/libMyLilPony/libMyLilPony_mountFunctions.lua	Fri Sep 21 01:50:56 2012 -0400
+++ b/libMyLilPony/libMyLilPony_mountFunctions.lua	Sat Mar 07 02:52:57 2015 -0500
@@ -42,7 +42,7 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMount()
     local filter = function (i)
-        local _, _, _, _, summoned = GetCompanionInfo("MOUNT", i);
+        local _, _, _, summoned = C_MountJournal.GetMountInfo(i);
         return not summoned;
     end
     return MyLilPony.CallMountByFilter(filter);
@@ -53,7 +53,7 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallFlyingMount()
     local filter = function (i)
-        local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
+        local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
         return not summoned and MyLilPony.IsFlyingMount(id);
     end
     return MyLilPony.CallMountByFilter(filter);
@@ -64,7 +64,7 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallGroundMount()
     local filter = function (i)
-        local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
+        local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
         return not summoned and MyLilPony.IsGroundMount(id);
     end
     return MyLilPony.CallMountByFilter(filter);
@@ -75,7 +75,7 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallAquaticMount()
     local filter = function (i)
-        local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
+        local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
         return not summoned and MyLilPony.IsAquaticMount(id);
     end
     return MyLilPony.CallMountByFilter(filter);
@@ -86,9 +86,9 @@
 -- @param slotNumber The slot number of the desired mount in the mount spellbook.
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountBySlot(slotNumber)
-    local countMounts = GetNumCompanions("MOUNT");
+    local countMounts = C_MountJournal.GetNumMounts();
     if slotNumber > 0 and slotNumber < countMounts+1 then
-        local _, _, _, _, summoned = GetCompanionInfo("MOUNT", slotNumber);
+        local _, _, _, summoned = C_MountJournal.GetMountInfo(i);
         MyLilPony.CallCompanion("MOUNT", slotNumber, not summoned);
         return true;
     end
@@ -101,9 +101,8 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountByName(mountName)
     local result = false;
-    local countMounts = GetNumCompanions("MOUNT");
-    for i = 1, countMounts do
-        local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name, _, _, summoned = C_MountJournal.GetMountInfo(i);
         if name == mountName then
             MyLilPony.CallCompanion("MOUNT", i, not summoned);
             result = true;
@@ -120,7 +119,7 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountByPattern(mountNamePattern)
     local filter = function (i)
-        local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
+        local name, _, _, summoned = C_MountJournal.GetMountInfo(i);
         return not summoned and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern);
     end
     return MyLilPony.CallMountByFilter(filter);
@@ -132,9 +131,9 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountById(id)
     local result = false;
-    local countMounts = GetNumCompanions("MOUNT");
-    for i = 1, countMounts do
-        local creatureId, _, spellId, _, summoned = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local _, spellId, _, summoned = C_MountJournal.GetMountInfo(i);
+        local creatureId = C_MountJournal.GetMountInfoExtra(i);
         if id == creatureId or id == spellId then
             MyLilPony.CallCompanion("MOUNT", i, not summoned);
             result = true;
@@ -150,9 +149,8 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountBySpell(spellId)
     local result = false;
-    local countMounts = GetNumCompanions("MOUNT");
-    for i = 1, countMounts do
-        local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
         if id == spellId then
             MyLilPony.CallCompanion("MOUNT", i, not summoned);
             result = true;
@@ -168,9 +166,9 @@
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 function MyLilPony.CallMountByCreature(creatureId)
     local result = false;
-    local countMounts = GetNumCompanions("MOUNT");
-    for i = 1, countMounts do
-        local id, _, _, _, summoned = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local _, _, _, summoned = C_MountJournal.GetMountInfo(i);
+        local id = C_MountJournal.GetMountInfoExtra(i);
         if id == creatureId then
             MyLilPony.CallCompanion("MOUNT", i, not summoned);
             result = true;
@@ -190,9 +188,8 @@
 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);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local _, id, _, summoned = C_MountJournal.GetMountInfo(i);
         if unitBuffs[id] ~= nil then
             MyLilPony.CallCompanion("MOUNT", i, not summoned);
             result = true;
@@ -207,41 +204,38 @@
 -- @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.
 -- @return A Boolean value indicating whether or not a mount was successfully summoned.
 -- @usage local filter = function (i)
---     local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i);
---     return not summoned and string.match(name, pattern);
+--     local name = C_MountJournal.GetMountInfo(i);
+--     return string.match(name, pattern);
 -- end
 -- MyLilPony.CallMountByFilter(filter);
 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
+    local mounts = {};
+    local x = 0;
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        if filter(i) then
+            x = x + 1;
+            mounts[x] = 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
+    if x > 0 then
+        local i = mounts[random(1, x)];
+        local _, _, _, summoned =  C_MountJournal.GetMountInfo(i);
+        MyLilPony.CallCompanion("MOUNT", i, not summoned);
+        return true;
     end
     return false;
 end
 
 --- Lists available mounts by name.
--- @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.
+-- @return A list of mount names.
 function MyLilPony.ListMounts()
     local results = {};
-    local countMounts = GetNumCompanions("MOUNT");
-    for i = 1, countMounts do
-        local _, name, _, _, _ = GetCompanionInfo("MOUNT", i);
+    local x = 1;
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name = C_MountJournal.GetMountInfo(i);
         results[i] = name;
+        x = x + 1;
     end
     return results;
 end
@@ -250,10 +244,9 @@
 -- @return A list of ground mount names.
 function MyLilPony.ListGroundMounts()
     local results = {};
-    local countMounts = GetNumCompanions("MOUNT");
     local x = 1;
-    for i = 1, countMounts do
-        local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name, id = C_MountJournal.GetMountInfo(i);
         if MyLilPony.IsGroundMount(id) then
             results[x] = name;
             x = x + 1;
@@ -266,10 +259,9 @@
 -- @return A list of flying mount names.
 function MyLilPony.ListFlyingMounts()
     local results = {};
-    local countMounts = GetNumCompanions("MOUNT");
     local x = 1;
-    for i = 1, countMounts do
-        local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name, id = C_MountJournal.GetMountInfo(i);
         if MyLilPony.IsFlyingMount(id) then
             results[x] = name;
             x = x + 1;
@@ -282,10 +274,9 @@
 -- @return A list of aquatic mount names.
 function MyLilPony.ListAquaticMounts()
     local results = {};
-    local countMounts = GetNumCompanions("MOUNT");
     local x = 1;
-    for i = 1, countMounts do
-        local _, _, id, _, _ = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name, id = C_MountJournal.GetMountInfo(i);
         if MyLilPony.IsAquaticMount(id) then
             results[x] = name;
             x = x + 1;
@@ -299,10 +290,9 @@
 -- @return A list of matching mount names.
 function MyLilPony.ListMountsByPattern(mountNamePattern)
     local results = {};
-    local countMounts = GetNumCompanions("MOUNT");
     local x = 1;
-    for i = 1, countMounts do
-        local _, name, _, _, _ = GetCompanionInfo("MOUNT", i);
+    for i in MyLilPony.EnumerateKnownMountSlotIDs() do
+        local name = C_MountJournal.GetMountInfo(i);
         if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then
             results[x] = name;
             x = x + 1;
@@ -310,4 +300,3 @@
     end
     return results;
 end
-