comparison libMyLilPony/libMyLilPony_mountFunctions.lua @ 58:d3d070ea6341 1.2.1

Fixed CallMountXYZ functions to always exclude unusable mounts (e.g. faction and profession specific mounts).
author syzler
date Wed, 24 Jun 2015 21:00:10 -0400
parents 64e8f8e5fa41
children 81145a681a59
comparison
equal deleted inserted replaced
57:01083a070f3b 58:d3d070ea6341
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 = C_MountJournal.GetMountInfo(i); 45 local _, _, _, summoned, usable = C_MountJournal.GetMountInfo(i);
46 return not summoned; 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 = C_MountJournal.GetMountInfo(i); 56 local _, id, _, summoned, usable = C_MountJournal.GetMountInfo(i);
57 return not summoned 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 = C_MountJournal.GetMountInfo(i); 67 local _, id, _, summoned, usable = C_MountJournal.GetMountInfo(i);
68 return not summoned 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 = C_MountJournal.GetMountInfo(i); 78 local _, id, _, summoned, usable = C_MountJournal.GetMountInfo(i);
79 return not summoned 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
84 --- Summons a mount by slot number in mount spellbook. 84 --- Summons a mount by slot number in mount spellbook.
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 = C_MountJournal.GetMountInfo(i); 91 local _, _, _, summoned, usable = C_MountJournal.GetMountInfo(i);
92 MyLilPony.CallMount(slotNumber, not summoned); 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
97 97
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 = C_MountJournal.GetMountInfo(i); 105 local name, _, _, summoned, usable = C_MountJournal.GetMountInfo(i);
106 if name == mountName then 106 if name == mountName then
107 MyLilPony.CallMount(i, not summoned); 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
111 end 111 end
112 return result; 112 return result;
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 = C_MountJournal.GetMountInfo(i); 122 local name, _, _, summoned, usable = C_MountJournal.GetMountInfo(i);
123 return not summoned 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
128 --- Summons a mount by creature or spell ID. 128 --- Summons a mount by creature or spell ID.
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 = C_MountJournal.GetMountInfo(i); 135 local _, spellId, _, summoned, usable = C_MountJournal.GetMountInfo(i);
136 local creatureId = C_MountJournal.GetMountInfoExtra(i); 136 local creatureId = C_MountJournal.GetMountInfoExtra(i);
137 if id == creatureId or id == spellId then 137 if id == creatureId or id == spellId then
138 MyLilPony.CallMount(i, not summoned); 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
142 end 142 end
143 return result; 143 return result;
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 = C_MountJournal.GetMountInfo(i); 153 local _, id, _, summoned, usable = C_MountJournal.GetMountInfo(i);
154 if id == spellId then 154 if id == spellId then
155 MyLilPony.CallMount(i, not summoned); 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
159 end 159 end
160 return result; 160 return result;
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 = C_MountJournal.GetMountInfo(i); 170 local _, _, _, summoned, usable = C_MountJournal.GetMountInfo(i);
171 local id = C_MountJournal.GetMountInfoExtra(i); 171 local id = C_MountJournal.GetMountInfoExtra(i);
172 if id == creatureId then 172 if id == creatureId then
173 MyLilPony.CallMount(i, not summoned); 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
177 end 177 end
178 return result; 178 return result;
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 = C_MountJournal.GetMountInfo(i); 192 local _, id, _, summoned, usable = C_MountJournal.GetMountInfo(i);
193 if unitBuffs[id] ~= nil then 193 if unitBuffs[id] ~= nil then
194 MyLilPony.CallMount(i, not summoned); 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
198 end 198 end
199 return result; 199 return result;
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 = C_MountJournal.GetMountInfo(i); 223 local _, _, _, summoned, usable = C_MountJournal.GetMountInfo(i);
224 MyLilPony.CallMount(i, not summoned); 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
229 229