Mercurial > wow > mylilpony
comparison libMyLilPony/libMyLilPony_mountFunctions.lua @ 1:7dfbf42c2d60
Initial commit of MyLilPony
author | syzler |
---|---|
date | Mon, 04 Apr 2011 04:43:05 +0000 |
parents | |
children | a4711e3c1eef |
comparison
equal
deleted
inserted
replaced
0:f6a1d182682e | 1:7dfbf42c2d60 |
---|---|
1 -- libMyLilPony | |
2 -- Copyright (c) 2011 Syzler | |
3 -- | |
4 -- This program is free software: you can redistribute it and/or modify | |
5 -- it under the terms of the GNU General Public License as published by | |
6 -- the Free Software Foundation, either version 3 of the License, or | |
7 -- (at your option) any later version. | |
8 -- | |
9 -- This program is distributed in the hope that it will be useful, | |
10 -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 -- GNU General Public License for more details. | |
13 -- | |
14 -- You should have received a copy of the GNU General Public License | |
15 -- along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | |
17 -- API functions for calling mounts | |
18 | |
19 function MyLilPony.CallMount() | |
20 local countMounts = GetNumCompanions("MOUNT"); | |
21 if countMounts > 0 then | |
22 local i = random(1, countMounts); | |
23 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", i); | |
24 MyLilPony.CallCompanion("MOUNT", i, not summoned); | |
25 return true; | |
26 end | |
27 return false; | |
28 end | |
29 | |
30 function MyLilPony.CallFlyingMount() | |
31 local filter = function (i) | |
32 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); | |
33 return not summoned and MyLilPony.IsFlyingMount(id); | |
34 end | |
35 return MyLilPony.CallMountByFilter(filter); | |
36 end | |
37 | |
38 function MyLilPony.CallGroundMount() | |
39 local filter = function (i) | |
40 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); | |
41 return not summoned and MyLilPony.IsGroundMount(id); | |
42 end | |
43 return MyLilPony.CallMountByFilter(filter); | |
44 end | |
45 | |
46 function MyLilPony.CallAquaticMount() | |
47 local filter = function (i) | |
48 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); | |
49 return not summoned and MyLilPony.IsAquaticMount(id); | |
50 end | |
51 return MyLilPony.CallMountByFilter(filter); | |
52 end | |
53 | |
54 function MyLilPony.CallMountBySlot(slotNumber) | |
55 local countMounts = GetNumCompanions("MOUNT"); | |
56 if slotNumber > 0 and slotNumber < countMounts+1 then | |
57 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", slotNumber); | |
58 MyLilPony.CallCompanion("MOUNT", slotNumber, not summoned); | |
59 return true; | |
60 end | |
61 return false; | |
62 end | |
63 | |
64 function MyLilPony.CallMountByName(mountName) | |
65 local result = false; | |
66 local countMounts = GetNumCompanions("MOUNT"); | |
67 for i = 1, countMounts do | |
68 local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i); | |
69 if name == mountName then | |
70 MyLilPony.CallCompanion("MOUNT", i, not summoned); | |
71 result = true; | |
72 do break end | |
73 end | |
74 end | |
75 return result; | |
76 end | |
77 | |
78 function MyLilPony.CallMountByPattern(mountNamePattern) | |
79 local filter = function (i) | |
80 local _, name, _, _, summoned = GetCompanionInfo("MOUNT", i); | |
81 return not summoned and MyLilPony.StringMatchIgnoreCase(name, mountNamePattern); | |
82 end | |
83 return MyLilPony.CallMountByFilter(filter); | |
84 end | |
85 | |
86 function MyLilPony.CallMountById(id) | |
87 local result = false; | |
88 local countMounts = GetNumCompanions("MOUNT"); | |
89 for i = 1, countMounts do | |
90 local creatureId, _, spellId, _, summoned = GetCompanionInfo("MOUNT", i); | |
91 if id == creatureId or id == spellId then | |
92 MyLilPony.CallCompanion("MOUNT", i, not summoned); | |
93 result = true; | |
94 do break end | |
95 end | |
96 end | |
97 return result; | |
98 end | |
99 | |
100 function MyLilPony.CallMountBySpell(spellId) | |
101 local result = false; | |
102 local countMounts = GetNumCompanions("MOUNT"); | |
103 for i = 1, countMounts do | |
104 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); | |
105 if id == spellId then | |
106 MyLilPony.CallCompanion("MOUNT", i, not summoned); | |
107 result = true; | |
108 do break end | |
109 end | |
110 end | |
111 return result; | |
112 end | |
113 | |
114 function MyLilPony.CallMountByCreature(creatureId) | |
115 local result = false; | |
116 local countMounts = GetNumCompanions("MOUNT"); | |
117 for i = 1, countMounts do | |
118 local id, _, _, _, summoned = GetCompanionInfo("MOUNT", i); | |
119 if id == creatureId then | |
120 MyLilPony.CallCompanion("MOUNT", i, not summoned); | |
121 result = true; | |
122 do break end | |
123 end | |
124 end | |
125 return result; | |
126 end | |
127 | |
128 function MyLilPony.CallMountByMatch(unit) | |
129 local result = false; | |
130 local unitBuffs = MyLilPony.GetUnitBuffs(unit); | |
131 local countMounts = GetNumCompanions("MOUNT"); | |
132 for i = 1, countMounts do | |
133 local _, _, id, _, summoned = GetCompanionInfo("MOUNT", i); | |
134 if unitBuffs[id] ~= nil then | |
135 MyLilPony.CallCompanion("MOUNT", i, not summoned); | |
136 result = true; | |
137 do break end | |
138 end | |
139 end | |
140 return result; | |
141 end | |
142 | |
143 function MyLilPony.CallMountByFilter(filter) | |
144 local countMounts = GetNumCompanions("MOUNT"); | |
145 if countMounts > 0 then | |
146 local results = {}; | |
147 local countResults = 0; | |
148 | |
149 for i = 1, countMounts do | |
150 if filter(i) then | |
151 countResults = countResults + 1; | |
152 results[countResults] = i; | |
153 end | |
154 end | |
155 | |
156 if countResults > 0 then | |
157 local i = random(1, countResults); | |
158 local _, _, _, _, summoned = GetCompanionInfo("MOUNT", results[i]); | |
159 MyLilPony.CallCompanion("MOUNT", results[i], not summoned); | |
160 return true; | |
161 end | |
162 end | |
163 return false; | |
164 end | |
165 | |
166 function MyLilPony.ListMounts() | |
167 local results = {}; | |
168 local countMounts = GetNumCompanions("MOUNT"); | |
169 for i = 1, countMounts do | |
170 local _, name, _, _, _ = GetCompanionInfo("MOUNT", i); | |
171 results[i] = name; | |
172 end | |
173 return results; | |
174 end | |
175 | |
176 function MyLilPony.ListGroundMounts() | |
177 local results = {}; | |
178 local countMounts = GetNumCompanions("MOUNT"); | |
179 local x = 1; | |
180 for i = 1, countMounts do | |
181 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i); | |
182 if MyLilPony.IsGroundMount(id) then | |
183 results[x] = name; | |
184 x = x + 1; | |
185 end | |
186 end | |
187 return results; | |
188 end | |
189 | |
190 function MyLilPony.ListFlyingMounts() | |
191 local results = {}; | |
192 local countMounts = GetNumCompanions("MOUNT"); | |
193 local x = 1; | |
194 for i = 1, countMounts do | |
195 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i); | |
196 if MyLilPony.IsFlyingMount(id) then | |
197 results[x] = name; | |
198 x = x + 1; | |
199 end | |
200 end | |
201 return results; | |
202 end | |
203 | |
204 function MyLilPony.ListAquaticMounts() | |
205 local results = {}; | |
206 local countMounts = GetNumCompanions("MOUNT"); | |
207 local x = 1; | |
208 for i = 1, countMounts do | |
209 local _, _, id, _, _ = GetCompanionInfo("MOUNT", i); | |
210 if MyLilPony.IsAquaticMount(id) then | |
211 results[x] = name; | |
212 x = x + 1; | |
213 end | |
214 end | |
215 return results; | |
216 end | |
217 | |
218 function MyLilPony.ListMountsByPattern(mountNamePattern) | |
219 local results = {}; | |
220 local countMounts = GetNumCompanions("MOUNT"); | |
221 local x = 1; | |
222 for i = 1, countMounts do | |
223 local _, name, _, _, _ = GetCompanionInfo("MOUNT", i); | |
224 if MyLilPony.StringMatchIgnoreCase(name, mountNamePattern) then | |
225 results[x] = name; | |
226 x = x + 1; | |
227 end | |
228 end | |
229 return results; | |
230 end | |
231 |