vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 CTA_MESSAGE = "M";
2 CTA_GENERAL = "I";
3 CTA_GROUP_UPDATE = "G";
4 CTA_BLOCK = "X";
5 CTA_SEARCH = "S";
6  
7 CTA_MESSAGE_COLOURS = {
8 M = { r = 1, b = 1, g = 0.5 },
9 I = { r = 1, b = 0.5, g = 1 },
10 G = { r = 0.5, b = 0.5, g = 1 },
11 X = { r = 1, b = 0.5, g = 0.5 },
12 S = { r = 0.5, b = 1, g = 0.5 }
13 };
14  
15 CTA_Classes = {
16 init = function()
17 if( UnitFactionGroup(CTA_PLAYER) == CTA_ALLIANCE ) then
18 CTA_Classes[8] = "PALADIN";
19 else
20 CTA_Classes[8] = "SHAMAN";
21 end
22 end
23 };
24  
25 CTA_Classes[1] = "PRIEST";
26 CTA_Classes[2] = "MAGE";
27 CTA_Classes[3] = "WARLOCK";
28 CTA_Classes[4] = "DRUID";
29 CTA_Classes[5] = "HUNTER";
30 CTA_Classes[6] = "ROGUE";
31 CTA_Classes[7] = "WARRIOR";
32 CTA_Classes[8] = "PALADIN";
33  
34 CTA_Classes[CTA_PRIEST] = { id=1, txMin=0.50, txMax=0.75, tyMin=0.25, tyMax=0.50 };
35 CTA_Classes[CTA_MAGE] = { id=2, txMin=0.25, txMax=0.50, tyMin=0.00, tyMax=0.25 };
36 CTA_Classes[CTA_WARLOCK] = { id=3, txMin=0.75, txMax=1.00, tyMin=0.25, tyMax=0.50 };
37 CTA_Classes[CTA_DRUID] = { id=4, txMin=0.75, txMax=1.00, tyMin=0.00, tyMax=0.25 };
38 CTA_Classes[CTA_HUNTER] = { id=5, txMin=0.00, txMax=0.25, tyMin=0.25, tyMax=0.50 };
39 CTA_Classes[CTA_ROGUE] = { id=6, txMin=0.50, txMax=0.75, tyMin=0.00, tyMax=0.25 };
40 CTA_Classes[CTA_WARRIOR] = { id=7, txMin=0.00, txMax=0.25, tyMin=0.00, tyMax=0.25 };
41 CTA_Classes[CTA_PALADIN] = { id=8, txMin=0.00, txMax=0.25, tyMin=0.50, tyMax=0.75 };
42 CTA_Classes[CTA_SHAMAN] = { id=8, txMin=0.25, txMax=0.50, tyMin=0.25, tyMax=0.50 };
43  
44 CTA_Classes["PRIEST"] = { localName=CTA_PRIEST, id=1, txMin=0.50, txMax=0.75, tyMin=0.25, tyMax=0.50 };
45 CTA_Classes["MAGE"] = { localName=CTA_MAGE, id=2, txMin=0.25, txMax=0.50, tyMin=0.00, tyMax=0.25 };
46 CTA_Classes["WARLOCK"] = { localName=CTA_WARLOCK, id=3, txMin=0.75, txMax=1.00, tyMin=0.25, tyMax=0.50 };
47 CTA_Classes["DRUID"] = { localName=CTA_DRUID, id=4, txMin=0.75, txMax=1.00, tyMin=0.00, tyMax=0.25 };
48 CTA_Classes["HUNTER"] = { localName=CTA_HUNTER, id=5, txMin=0.00, txMax=0.25, tyMin=0.25, tyMax=0.50 };
49 CTA_Classes["ROGUE"] = { localName=CTA_ROGUE, id=6, txMin=0.50, txMax=0.75, tyMin=0.00, tyMax=0.25 };
50 CTA_Classes["WARRIOR"] = { localName=CTA_WARRIOR, id=7, txMin=0.00, txMax=0.25, tyMin=0.00, tyMax=0.25 };
51 CTA_Classes["PALADIN"] = { localName=CTA_PALADIN, id=8, txMin=0.00, txMax=0.25, tyMin=0.50, tyMax=0.75 };
52 CTA_Classes["SHAMAN"] = { localName=CTA_SHAMAN, id=8, txMin=0.25, txMax=0.50, tyMin=0.25, tyMax=0.50 };
53  
54  
55 local trim;
56 local getOps;
57 local recursiveSearch;
58 local cloneTable;
59  
60 trim = function( s )
61 if( not s ) then return nil; end
62 return( string.gsub(s, "^%s*(.-)%s*$", "%1") or s );
63 end
64  
65 getOps = function( source )
66 local operatorFound = nil;
67 local bracketCount = 0;
68 local inQuote = 0;
69 local pos = 0;
70  
71 local currentChar;
72 local prevChar = "x";
73 while( pos < string.len( source ) ) do
74 currentChar = string.sub( source, pos, pos );
75 if( ( currentChar == "+" or currentChar == "/" ) and bracketCount == 0 and inQuote == 0 ) then
76 operatorFound = 1;
77 break;
78 elseif( currentChar == "(" ) then
79 bracketCount = bracketCount + 1;
80 elseif( currentChar == ")" ) then
81 bracketCount = bracketCount - 1;
82 elseif( currentChar == "\"" ) then
83 inQuote = 1 - inQuote;
84 else
85 if( prevChar == " " and bracketCount == 0 and inQuote == 0 ) then
86 operatorFound = 2;
87 pos = pos - 1;
88 break;
89 end
90 end
91 prevChar = currentChar;
92 pos = pos + 1;
93 end
94 if( operatorFound == 2 ) then
95 return "/", string.sub( source, 1, pos - 1 ), string.sub( source, pos + 1 );
96 end
97 if( operatorFound ) then
98 return currentChar, string.sub( source, 1, pos - 1 ), string.sub( source, pos + 1 );
99 end
100 end
101  
102 recursiveSearch = function( source, search )
103 if( not ( source and search ) ) then
104 return nil;
105 end
106 local s = trim( search );
107 local operator, op1, op2 = getOps( s );
108  
109 if( operator ) then
110 local op1Res = recursiveSearch( source, op1 );
111 if( not op1Res ) then
112 return 0;
113 elseif( op1Res > 0 and operator == "/" ) then
114 return 1;
115 elseif( op1Res == 0 and operator == "+" ) then
116 return 0;
117 end
118  
119 local op2Res = recursiveSearch( source, op2, verbose );
120 if( not op2Res ) then
121 return 0;
122 elseif( op2Res > 0 and ( op1Res > 0 or operator == "/" ) ) then
123 return 1;
124 end
125 return 0;
126 else
127 local literal;
128 if( string.sub( s, 1, 1 ) == "-" ) then
129 return( 1 - recursiveSearch( source, trim( string.sub( s, 2 ) ) ) );
130 elseif( string.sub( s, 1, 1 ) == "(" and string.sub( s, string.len( s ) ) == ")" ) then
131 return recursiveSearch( source, trim( string.sub( s, 2, string.len( s ) - 1 ) ) );
132 elseif( string.sub( s, 1, 1 ) == "\"" and string.sub( s, string.len( s ) ) == "\"" ) then
133 s = trim( string.sub( s, 2, string.len( s ) - 1 ) );
134 literal = 1;
135 end
136 if( literal ) then
137 if( string.find( source, s ) ) then
138 return 1;
139 else
140 return 0;
141 end
142 else
143 if( string.find( source, s ) ) then
144 return 1;
145 else
146 for word in string.gfind( s, "%w+" ) do
147 if( string.find( source, "%s+"..word.."%s+" ) ) then
148 return 1;
149 elseif( string.find( source, "^"..word.."%s+" ) ) then
150 return 1;
151 elseif( string.find( source, "%s+"..word.."$" ) ) then
152 return 1;
153 end
154 end
155 return 0;
156 end
157 end
158 end
159 end
160  
161 cloneTable = function( t )
162 local new = {};
163 local i, v;
164 for i, v in t do
165 if ( type(v)=="table" ) then
166 new[i] = cloneTable(v);
167 else
168 new[i] = v;
169 end
170 end
171 return new;
172 end
173  
174  
175  
176 --[[
177 The CTA_Util table holds several utility functions.
178 ========================================================================================================================
179 --]]
180  
181 CTA_Util = {};
182  
183 --[[
184 ------------------------------------------------------------------------------------------------------------------------
185 Time
186 ------------------------------------------------------------------------------------------------------------------------
187 --]]
188  
189 CTA_Util.getTime = function()
190 local hour, minute = GetGameTime();
191 if( hour < 10 ) then hour = "0"..hour; end
192 if( minute < 10 ) then minute = "0"..minute; end
193 return hour..":"..minute;
194 end
195  
196 --[[
197 ------------------------------------------------------------------------------------------------------------------------
198 Searching
199 ------------------------------------------------------------------------------------------------------------------------
200 --]]
201  
202 CTA_Util.search = function ( s, q )
203 local source = string.lower( string.gsub( s, "|c(%w+)|H(%w+):(.+)|h(.+)|h|r", "%4" ) );
204 return recursiveSearch( source, string.lower( q ) ), source;
205 end
206  
207 --[[
208 ------------------------------------------------------------------------------------------------------------------------
209 Showing and filtering lists
210 ------------------------------------------------------------------------------------------------------------------------
211 --]]
212  
213 CTA_Util.updateList = function ( list, first, UIListName, maxResults, offset, showResultItem, size )
214  
215 while( size <= offset ) do
216 offset = offset - maxResults;
217 end
218 if( offset < 0 ) then offset = 0; end
219  
220 local pos = 0;
221 local current = first;
222 while( current ~= 0 and pos < offset ) do
223 pos = pos + 1;
224 current = list[current].next;
225 end
226 pos = 0;
227 while( current ~= 0 and pos < maxResults ) do
228 pos = pos + 1;
229 showResultItem( getglobal( UIListName..pos ), current );
230 current = list[current].next;
231 end
232 while( pos < maxResults ) do
233 pos = pos + 1;
234 getglobal( UIListName..pos ):Hide();
235 end
236 end
237  
238 CTA_Util.filterList = function ( list, satisfiesFilter )
239 local size = 0;
240 local first = 0;
241 local prev = 0;
242 for key, data in list do
243 if( not satisfiesFilter or satisfiesFilter( key ) ) then
244 size = size + 1;
245 if( first ~= 0 ) then
246 list[prev].next = key;
247 else
248 first = key;
249 end
250 prev = key;
251 end
252 data.next = 0;
253 end
254 return first, size;
255 end
256  
257 --[[
258 ------------------------------------------------------------------------------------------------------------------------
259 Output to chat, log and minimap
260 ------------------------------------------------------------------------------------------------------------------------
261 --]]
262  
263 CTA_Util.errorPrintln = function ( s )
264 UIErrorsFrame:AddMessage(s, 0.75, 0.75, 1.0, 1.0, UIERRORS_HOLD_TIME);
265 end
266  
267 CTA_Util.chatPrintln = function ( s )
268 DEFAULT_CHAT_FRAME:AddMessage( "CTA: "..( s or "nil" ), 1, 0.75, 0.0);
269 end
270  
271 CTA_Util.iconPrintln = function ( s, t )
272 if( not t ) then
273 CTA_MinimapMessageFrame:AddMessage( ( s or "nil" ), 1.0, 1.0, 0.5, 1.0, UIERRORS_HOLD_TIME);
274 else
275 local r = CTA_MESSAGE_COLOURS[t].r;
276 local g = CTA_MESSAGE_COLOURS[t].g;
277 local b = CTA_MESSAGE_COLOURS[t].b;
278 CTA_MinimapMessageFrame:AddMessage( ( s or "nil" ), r, g, b, 1.0, UIERRORS_HOLD_TIME);
279 end
280 end
281  
282 CTA_Util.logPrintln = function ( s, t )
283 local m = s;
284 if( not m ) then
285 m = "nil";
286 end
287 m = "["..CTA_Util.getTime().."] "..( m or "nil" );
288  
289 if( not t ) then
290 CTA_Log:AddMessage( m, 1.0, 1.0, 0.5 );
291 else
292 local r = CTA_MESSAGE_COLOURS[t].r;
293 local g = CTA_MESSAGE_COLOURS[t].g;
294 local b = CTA_MESSAGE_COLOURS[t].b;
295 CTA_Log:AddMessage( m, r, g, b );
296 end
297 end
298  
299 --[[
300 ------------------------------------------------------------------------------------------------------------------------
301 Communication
302 ------------------------------------------------------------------------------------------------------------------------
303 --]]
304  
305 CTA_Util.joinChannel = function( channel )
306 JoinChannelByName( channel );
307 RemoveChatWindowChannel( DEFAULT_CHAT_FRAME:GetID(), channel );
308 CTA_Util.logPrintln( CTA_CALL_TO_ARMS_LOADED );
309 CTA_Util.logPrintln( "Joined "..channel );
310 return 1;
311 end
312  
313 CTA_Util.sendChatMessage = function( message, messageType, channel, hidden )
314 local language = CTA_COMMON;
315 if( UnitFactionGroup(CTA_PLAYER) ~= CTA_ALLIANCE ) then
316 language = CTA_ORCISH;
317 end
318 if( not hidden ) then
319 SendChatMessage( string.gsub( message, "|c(%w+)|H(%w+):(.+)|h(.+)|h|r", "%4" ), messageType, language, channel );
320 elseif( hidden == 1 ) then
321 SendChatMessage( "[CTA] "..string.gsub( message, "|c(%w+)|H(%w+):(.+)|h(.+)|h|r", "%4" ), messageType, language, channel );
322 else
323 SendChatMessage( "<CTA> "..string.gsub( message, "|c(%w+)|H(%w+):(.+)|h(.+)|h|r", "%4" ), messageType, language, channel );
324 end
325 end
326  
327 --[[
328 ------------------------------------------------------------------------------------------------------------------------
329 Group
330 ------------------------------------------------------------------------------------------------------------------------
331 --]]
332  
333 CTA_Util.getGroupMemberInfo = function( index )
334 local name, rank, subgroup, level, class, fileName, zone, online, isDead;
335 if ( IsRaidLeader() and GetNumRaidMembers() > 0 ) then
336 name, rank, subgroup, level, class, fileName, zone, online, isDead = GetRaidRosterInfo(index);
337 elseif ( IsPartyLeader() and GetNumPartyMembers() > 0 ) then
338 local target = CTA_PLAYER;
339 if( index > 1 and index < 6 ) then
340 target = "PARTY"..(index-1);
341 end
342 name = UnitName(target);
343 level = UnitLevel(target);
344 class = UnitClass(target);
345 elseif( GetNumRaidMembers() == 0 and GetNumPartyMembers() == 0 and index == 1 ) then
346 local target = CTA_PLAYER;
347 name = UnitName(target);
348 level = UnitLevel(target);
349 class = UnitClass(target);
350 end
351 return name, level, class;
352 end
353  
354 CTA_Util.getNumGroupMembers = function()
355 if( GetNumRaidMembers() > 0 ) then
356 return GetNumRaidMembers();
357 elseif( GetNumPartyMembers() > 0 ) then
358 return GetNumPartyMembers() + 1;
359 else
360 return 1;
361 end
362 end
363  
364 --[[
365 ------------------------------------------------------------------------------------------------------------------------
366 Table functions
367 ------------------------------------------------------------------------------------------------------------------------
368 --]]
369  
370 CTA_Util.getn = function( list )
371 local c = 0;
372 for i, j in list do
373 c = c + 1;
374 end
375 return c;
376 end
377  
378 CTA_Util.cloneTable = function( t )
379 return cloneTable( t );
380 end
381  
382 --[[
383 ------------------------------------------------------------------------------------------------------------------------
384 Class codec functions
385 ------------------------------------------------------------------------------------------------------------------------
386 --]]
387  
388 CTA_Util.getClassCode = function( className )
389 return CTA_Classes[className].id;
390 end
391  
392 CTA_Util.getClassString = function( classSet )
393 local b = "";
394 local c = classSet;
395  
396 while( c > 0 ) do
397 local d = mod(c, 2);
398 b = d..b;
399 c = floor(c/2);
400 end
401 while(string.len(b) < 8 ) do
402 b = "0"..b;
403 end
404  
405 local pos = 8;
406 local t = "";
407 while( pos > 0 ) do
408 if( string.sub(b, pos, pos) == "1" ) then
409 t = t..CTA_Classes[ CTA_Classes[9-pos] ].localName.." ";
410 end
411 pos = pos - 1;
412 end
413 return t;
414 end
415  
416 --[[
417 ------------------------------------------------------------------------------------------------------------------------
418 Player information retrieval
419 ------------------------------------------------------------------------------------------------------------------------
420 --]]
421  
422 CTA_Util.getWhoInfo = function( playerName )
423 local numWhos, totalCount = GetNumWhoResults();
424 local name, guild, level, race, class, zone, group;
425 for i=1, totalCount do
426 name, guild, level, race, class, zone, group = GetWhoInfo(i);
427 if( name == playerName ) then
428 return name, guild, level, race, class, zone, group;
429 end
430 end
431 end