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