vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 -- //////////////////////////////////////////////
3 -- Variables Init
4 -- //////////////////////////////////////////////
5 ]]
6 local rpgoCP_TITLE ="CharacterProfiler";
7 local rpgoCP_ABBR ="CP";
8 local rpgoCP_AUTHOR ="calvin";
9 local rpgoCP_EMAIL ="calvin@rpgoutfitter.com";
10 local rpgoCP_URL ="www.rpgoutfitter.com";
11 local rpgoCP_DATE ="June 20, 2006";
12 local rpgoCP_PROVIDER ="rpgo";
13 local rpgoCP_VERSION ="1.5.4a";
14 local rpgoCP_PROFILEDB ="1.5.4a";
15 local rpgoCP_TOOLTIP ="rpgoCPtooltip";
16 local rpgoCP_OPTION ="";
17 -- //////////////////////////////////////////////
18 if(not rpgoColorTitle) then rpgoColorTitle="909090"; end
19 if(not rpgoColorGreen) then rpgoColorGreen="00cc00"; end
20 if(not rpgoColorRed) then rpgoColorRed ="ff0000"; end
21 -- //////////////////////////////////////////////
22 local timeWait=3;
23 local timePlayed=-1;
24 local timeLevelPlayed=-1;
25 local TradeSkillCode={optimal=4,medium=3,easy=2,trivial=1,header=0};
26 local UnitPower={"Rage","Focus","Energy","Happiness"};UnitPower[0]="Mana";
27 local UnitSlots={"Head","Neck","Shoulder","Shirt","Chest","Waist","Legs","Feet","Wrist","Hands","Finger0","Finger1","Trinket0","Trinket1","Back","MainHand","SecondaryHand","Ranged","Tabard"};UnitSlots[0]="Ammo";
28 local UnitStatName={"Strength","Agility","Stamina","Intellect","Spirit"};
29 local UnitResistName={"Holy","Fire","Nature","Frost","Shadow","Arcane"};
30 local CPevents={"PLAYER_LOGIN","PLAYER_ENTERING_WORLD","PLAYER_LEVEL_UP","TIME_PLAYED_MSG",
31 "CRAFT_SHOW","CRAFT_CLOSE","CRAFT_UPDATE","SPELLS_CHANGED","TRADE_SKILL_SHOW","TRADE_SKILL_UPDATE","TRADE_SKILL_CLOSE",
32 "BANKFRAME_CLOSED","MAIL_SHOW","MAIL_INBOX_UPDATE","MAIL_CLOSED","MERCHANT_CLOSED","MINIMAP_ZONE_CHANGED","GOSSIP_SHOW","GOSSIP_CLOSED",
33 "PLAYER_CONTROL_LOST","PLAYER_CONTROL_GAINED","QUEST_FINISHED","PET_STABLE_CLOSED"};
34 local CPprefs={
35 enabled=true,tooltipshtml=true,reagenthtml=true,talentsfull=true,questsfull=false,lite=true,debug=false,honorold=true,ver=010500,
36 scan={inventory=true,talents=true,honor=true,reputation=true,spells=true,pet=true,equipment=true,mail=true,professions=true,skills=true,quests=true,bank=true}
37 };
38 local rpgoCP_Usage={
39 {"/cp","-- usage/help"},
40 {"/cp [on|off]","-- turns on|off"},
41 {"/cp export","-- force export"},
42 {"/cp show","-- show current session scan"},
43 {"/cp lite [on|off]","-- turns on|off lite scanning","this will disable scanning while in raid or instance"},
44 {"/cp purge [all|server|char]","-- purge info"}
45 };
46  
47 --[[//////////////////////////////////////////////
48 -- rpgoCP Core Functions
49 -- OnLoad,RegisterEvents,LoadVar,EventHandler,InitState,InitPrefs
50 -- ////////////////////////////////////////////]]
51  
52 --[[// OnLoad
53 -- ////////////////////////////////////////////]]
54 function rpgoCP_OnLoad()
55 this:RegisterEvent("ADDON_LOADED");
56 this:RegisterEvent("VARIABLES_LOADED");
57 SLASH_RPGOCP1="/cp";
58 SLASH_RPGOCP2="/rpgocp";
59 SLASH_RPGOCP3="/profiler";
60 SlashCmdList["RPGOCP"]=function(msg) rpgoCP_ChatCommand(msg); end
61 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_TITLE).." [v" .. rpgoCP_VERSION .. "] loaded.");
62 end
63  
64 --[[// RegisterEvents
65 -- ////////////////////////////////////////////]]
66 function rpgoCP_RegisterEvents()
67 rpgoCP_debug("CP: RegisterEvents");
68 if(rpgoCPpref and rpgoCPpref["enabled"]) then
69 rpgoCP_debug(" Events Registered");
70 for index,event in CPevents do
71 rpgoCPframe:RegisterEvent(event);
72 end
73 else
74 rpgoCP_debug(" Events Unregistered");
75 for index,event in CPevents do
76 rpgoCPframe:UnregisterEvent(event);
77 end
78 end
79 end
80  
81 --[[// EventHandler
82 -- ////////////////////////////////////////////]]
83 function rpgoCP_EventHandler(event,arg1,arg2)
84 --if(rpgoDebugArg and event) then rpgoDebugArg(rpgoCP_ABBR,event,arg1,arg2); end
85 if(event=="ADDON_LOADED" and arg1==rpgoCP_TITLE) then
86 rpgoCP_myAddons();
87 this:UnregisterEvent("ADDON_LOADED");
88 return;
89 elseif(event=="VARIABLES_LOADED") then
90 rpgoCP_InitState();
91 rpgoCP_InitPref();
92 rpgoCP_RegisterEvents();
93 rpgoCP_LoadVar();
94 this:UnregisterEvent("VARIABLES_LOADED");
95 return;
96 elseif(event=="PLAYER_LOGIN") then
97 return;
98 elseif(event=="PLAYER_ENTERING_WORLD") then
99 return;
100 elseif(event=="CRAFT_UPDATE") then
101 rpgoCP_TradeTimer(event,arg1)
102 return;
103 elseif(event=="TRADE_SKILL_UPDATE") then
104 rpgoCP_TradeTimer(event,arg1)
105 return;
106 elseif(not event) then
107 return;
108 end
109  
110 if(not rpgoCPpref or not rpgoCPpref["enabled"]) then return; end
111 if(event=="SPELLS_CHANGED" and not rpgoCPstate["_loaded"]) then
112 return;
113 elseif(event=="MINIMAP_ZONE_CHANGED" and not rpgoCPstate["_loaded"]) then
114 return;
115 elseif(event=="PLAYER_LEAVING_WORLD" and not rpgoCPstate["_loaded"]) then
116 return;
117 elseif(event=="BAG_UPDATE") then
118 rpgoCP_UpdateBagScan(arg1);
119 elseif(event=="MAIL_SHOW") then
120  
121 elseif(event=="TIME_PLAYED_MSG") then
122 rpgoCP_UpdatePlayed(arg1,arg2);
123 return;
124 elseif(event=="PLAYER_CONTROL_LOST") then
125 this:UnregisterEvent("MINIMAP_ZONE_CHANGED");
126 return;
127 elseif(event=="PLAYER_CONTROL_GAINED") then
128 this:RegisterEvent("MINIMAP_ZONE_CHANGED");
129 if(rpgoCPstate["_loaded"]) then rpgoCP_UpdateZone(); end
130 return;
131 end
132 if(rpgo_LiteScan(rpgoCPpref["lite"]) and event~="RPGOCP_EXPORT") then return; end
133 debugprofilestart();
134 if(not rpgoCPstate["_lock"] and rpgoCPplayer) then
135 rpgoCPstate["_lock"]=1;
136 if(not rpgoCPstate["_loaded"]) then
137 rpgoCP_InitProfile();
138 rpgoCP_LoadProfile();
139 end
140 if(event=="RPGOCP_SCAN") then
141 rpgoCP_UpdateProfile();
142 elseif(event=="PLAYER_LEAVING_WORLD") then
143 rpgoCP_UpdateProfile();
144 elseif(event=="RPGOCP_EXPORT") then
145 rpgoCP_ForceExport();
146 elseif(event=="MINIMAP_ZONE_CHANGED") then
147 rpgoCP_UpdateZone();
148 elseif(event=="SPELLS_CHANGED" and arg1=="LeftButton") then
149 rpgoCP_GetSpellBook();
150 rpgoCP_GetPetSpellBook();
151 elseif(event=="BANKFRAME_CLOSED") then
152 rpgoCP_GetBank();
153 rpgoCP_GetEquipment();
154 rpgoCP_GetInventory();
155 elseif(event=="MAIL_CLOSED") then
156 rpgoCP_GetMail();
157 rpgoCP_GetEquipment();
158 rpgoCP_GetInventory();
159 elseif(event=="MERCHANT_CLOSED") then
160 rpgoCP_GetEquipment();
161 rpgoCP_GetInventory();
162 elseif(event=="TRADE_SKILL_SHOW") then
163 rpgoCP_GetSkills();
164 rpgoCP_GetTradeSkill();
165 elseif(event=="CRAFT_SHOW") then
166 rpgoCP_GetSkills();
167 rpgoCP_GetCraft();
168 elseif(event=="PLAYER_LEVEL_UP") then
169 rpgoCP_LoadProfile();
170 elseif(event=="QUEST_FINISHED") then
171 rpgoCP_GetQuests(force);
172 elseif(event=="PET_STABLE_CLOSED") then
173 rpgoCP_ScanPetStable();
174 end
175 rpgoCPstate["_lock"]=nil;
176 end
177 --rpgoCP_debug("time: "..debugprofilestop().."ms");
178 end
179  
180 --[[// InitState
181 -- ////////////////////////////////////////////]]
182 function rpgoCP_InitState(arg)
183 local ttFrame=getglobal(rpgoCP_TOOLTIP);
184 ttFrame:SetOwner(UIParent,"ANCHOR_NONE");
185 rpgoCP_debug("CP: InitState");
186 local _,tmpClass=UnitClass("player");
187 rpgoCPstate={
188 _vars=nil,_loaded=nil,_lock=nil,_bagevent=nil,
189 _player=UnitName("player"),_server=GetRealmName(),_class=tmpClass,
190 _skills={},
191 Equipment=0, EquipmentKey=0,
192 Guild=nil, GuildNum=nil,
193 Inventory={},
194 Bag={},
195 Bank={}, BankTime=0,
196 Skills=0,
197 Talents=0,
198 SpellBook={},
199 Professions={},
200 Reputation=0,
201 Quests=0, QuestsLog=0,
202 Mail=nil, MailTime=0,
203 Honor=0,
204 Stable={},
205 Pets={}, PetSpell={},
206 };
207 end
208  
209 --[[// InitPrefs
210 -- ////////////////////////////////////////////]]
211 function rpgoCP_InitPref()
212 rpgoCP_debug("CP: InitPref");
213 if(not CPprefs) then return; end
214 if(not rpgoCPpref) then
215 rpgoCPpref={};
216 elseif(rpgoCPpref and (not rpgoCPpref["ver"] or rpgoCPpref["ver"] < 010500) ) then
217 rpgoCP_ConvertPref();
218 end
219 rpgo_TidyPref(rpgoCPpref,CPprefs);
220 rpgo_InitPref(rpgoCPpref,CPprefs);
221 end
222  
223 --[[// ConvertPrefs
224 -- ////////////////////////////////////////////]]
225 function rpgoCP_ConvertPref()
226 if(not rpgoCPprefNew) then
227 rpgoCPprefNew={};
228 end
229 if(rpgoCPpref and (not rpgoCPpref["ver"] or rpgoCPpref["ver"] < 010500) ) then
230 rpgoCP_ConvertPrefSub(rpgoCPpref,rpgoCPprefNew);
231 end
232 rpgoCPpref=rpgoCPprefNew;
233 rpgoCPpref["ver"]=010500;
234 end
235  
236 --[[// LoadVar
237 -- ////////////////////////////////////////////]]
238 function rpgoCP_LoadVar()
239 rpgoCP_debug("CP: LoadVar");
240 rpgoCPserver=GetRealmName();
241 rpgoCPplayer=UnitName("player");
242 _,rpgoCPclass=UnitClass("player");
243 rpgoCPstate["_vars"]=1;
244 end
245  
246 --[[// OverLoaded functions
247 -- PLAYER_QUITTING/PLAYER_LEAVING_WORLD
248 -- PetAbandon - to grab drop of pet
249 -- ////////////////////////////////////////////]]
250 rpgoOldQuit=Quit;
251 function Quit()
252 if(rpgoCPpref and rpgoCPpref["enabled"] and rpgoCPstate["_loaded"]) then
253 rpgoCP_EventHandler('RPGOCP_SCAN');
254 RequestTimePlayed();
255 end
256 return rpgoOldQuit();
257 end
258  
259 rpgoOldLogout=Logout;
260 function Logout()
261 if(rpgoCPpref and rpgoCPpref["enabled"] and rpgoCPstate["_loaded"]) then
262 rpgoCP_EventHandler('RPGOCP_SCAN');
263 RequestTimePlayed();
264 end
265 return rpgoOldLogout();
266 end
267  
268 rpgoOldPetAbandon=PetAbandon;
269 function PetAbandon()
270 if(rpgoCPpref and rpgoCPpref["enabled"]) then
271 petName=UnitName("pet");
272 if (rpgoCPstate["Stable"][petName]) then
273 rpgoCPstate["Stable"][petName]=nil; end
274 if (rpgoCPstate["Pets"][petName]) then
275 rpgoCPstate["Pets"][petName]=nil; end
276 if (rpgoCPstate["PetSpell"][petName]) then
277 rpgoCPstate["PetSpell"][petName]=nil; end
278 if (myProfile[rpgoCPserver][rpgoCPplayer]["Pets"] and myProfile[rpgoCPserver][rpgoCPplayer]["Pets"][petName]) then
279 myProfile[rpgoCPserver][rpgoCPplayer]["Pets"][petName]=nil; end
280 end
281 return rpgoOldPetAbandon();
282 end
283  
284 --[[// ChatCommand
285 -- ////////////////////////////////////////////]]
286 function rpgoCP_ChatCommand(argline)
287 arg=rpgo_Str2Ary(argline);
288 if(arg[2]) then
289 arg[2]=string.lower(arg[2]);
290 end
291 if(arg[1]) then
292 arg[1]=string.lower(arg[1]);
293 if(arg[1]=="off") then
294 rpgoCP_Toggle(false);
295 return;
296 elseif(arg[1]=="on") then
297 rpgoCP_Toggle(true);
298 return;
299 elseif(arg[1]=="show") then
300 rpgoCP_Show();
301 return;
302 elseif(arg[1]=="export") then
303 rpgoCP_EventHandler('RPGOCP_EXPORT');
304 return;
305 elseif(arg[1]=="debug") then
306 rpgoCP_TogglePref("Debug",arg[2]);
307 return;
308 elseif(arg[1]=="purge") then
309 rpgoCP_Purge(arg[2]);
310 return;
311 elseif(CPprefs[arg[1]]) then
312 rpgoCP_TogglePref(arg[1],arg[2]);
313 return;
314 end
315 end
316 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_TITLE).." Usage [v" .. rpgoCP_VERSION .. "]");
317 for index=1,table.getn(rpgoCP_Usage),1 do
318 rpgo_VerboseMsg(rpgo_AssempleHelp(rpgoCP_Usage[index]));
319 end
320 rpgoCP_TogglePref("enabled");
321 end
322  
323 --[[// Toggle
324 -- ////////////////////////////////////////////]]
325 function rpgoCP_Toggle(val)
326 --local valold=rpgoCPpref["enabled"];
327 if(rpgoCPpref["enabled"]~=val) then
328 rpgoCP_TogglePref("enabled",val);
329 rpgoCP_RegisterEvents();
330 if(val) then
331 rpgoCP_InitState(1);
332 rpgoCP_LoadVar();
333 if(not rpgoCPstate["_loaded"]) then
334 rpgoCP_InitProfile();
335 rpgoCP_LoadProfile();
336 end
337 else
338 rpgoCPstate=nil;
339 end
340 else
341 rpgoCP_TogglePref("enabled",val);
342 end
343 end
344  
345 function rpgoCP_TogglePref(pref,val)
346 local msg="["..pref.."]";
347 if(val=="on") then val=true;
348 elseif(val=="off") then val=false; end
349 if(type(val)=="boolean" and rpgoCPpref[pref]~=val) then
350 rpgoCPpref[pref]=val; msg=msg.." changed";
351 else msg=msg.." currently"; end
352 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": "..msg..": "..rpgo_ColorizePref(rpgoCPpref[pref]));
353 end
354  
355 --[[// Show
356 -- ////////////////////////////////////////////]]
357 function rpgoCP_Show()
358 if(rpgoCPpref["enabled"]) then
359 if(rpgoCPplayer and rpgoCPstate["_loaded"]) then
360 local msg="";
361 local item=nil;
362 local count=0;
363 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": character info scanned this session");
364  
365 msg="Profile for: " .. rpgoCPplayer .. "@" .. rpgoCPserver;
366 if(myProfile[rpgoCPserver][rpgoCPplayer]["Level"]) then
367 msg=msg.." (lvl "..myProfile[rpgoCPserver][rpgoCPplayer]["Level"]..")"
368 end
369 rpgo_VerboseMsg(" "..msg);
370 msg="Zone: ";
371 if(myProfile[rpgoCPserver][rpgoCPplayer]["Zone"]) then
372 msg=msg..myProfile[rpgoCPserver][rpgoCPplayer]["Zone"];
373 if(myProfile[rpgoCPserver][rpgoCPplayer]["SubZone"] and myProfile[rpgoCPserver][rpgoCPplayer]["SubZone"]~="") then
374 msg=msg.."/"..myProfile[rpgoCPserver][rpgoCPplayer]["SubZone"];
375 end
376 else
377 msg=msg..rpgo_ColorizeMsg(rpgoColorRed," not scanned");
378 end
379 rpgo_VerboseMsg(" "..msg);
380  
381 msg="Guild Info: ";
382 if(rpgoCPstate["Guild"]==0) then
383 msg=msg.."not in a guild";
384 elseif(rpgoCPstate["Guild"]) then
385 if(myProfile[rpgoCPserver][rpgoCPplayer]["Guild"]["GuildName"] and myProfile[rpgoCPserver][rpgoCPplayer]["Guild"]["Title"]) then
386 msg=msg.."Name:"..myProfile[rpgoCPserver][rpgoCPplayer]["Guild"]["Name"].." Title:"..myProfile[rpgoCPserver][rpgoCPplayer]["Guild"]["Title"];
387 else
388 msg=msg..rpgo_ColorizeMsg(rpgoColorRed," not scanned1");
389 end
390 else
391 msg=msg..rpgo_ColorizeMsg(rpgoColorRed," not scanned2");
392 end
393 rpgo_VerboseMsg(" " .. msg);
394  
395 msg="";
396 msg=msg .. "Equipment:"..rpgoCPstate["Equipment"].."/"..table.getn(UnitSlots);
397 msg=msg .. " Skills:" ..rpgoCPstate["Skills"];
398 msg=msg .. " Talents:" ..rpgoCPstate["Talents"];
399 if(rpgoCPstate["Mail"]) then
400 msg=msg .. " Mail:" ..rpgoCPstate["Mail"];
401 end
402 rpgo_VerboseMsg(" " .. msg);
403  
404 msg="";
405 msg=msg .. "Quests:" ..rpgoCPstate["Quests"];
406 msg=msg .. " Reputation: " ..rpgoCPstate["Reputation"];
407 if(rpgoCPstate["Honor"]~=0 and myProfile[rpgoCPserver][rpgoCPplayer]["Honor"]["RankName"]) then
408 msg=msg .. " Honor: " ..myProfile[rpgoCPserver][rpgoCPplayer]["Honor"]["RankName"];
409 else
410 msg=msg .. " Honor: "..NONE;
411 end
412 rpgo_VerboseMsg(" " .. msg);
413  
414 count=0;
415 msg="Professions:";
416 for item in rpgoCPstate["Professions"] do
417 msg=msg .. " " .. item..":"..rpgoCPstate["Professions"][item];
418 count=count+1;
419 end
420 if(count==0) then
421 msg=msg..rpgo_ColorizeMsg(rpgoColorRed," not scanned")..". to scan: open each profession";
422 end
423 rpgo_VerboseMsg(" " .. msg);
424  
425 count=0;
426 msg="SpellBook:";
427 for item in rpgoCPstate["SpellBook"] do
428 msg=msg .. " " .. item..":"..rpgoCPstate["SpellBook"][item];
429 count=count+1;
430 end
431 if(count==0) then
432 msg=msg..rpgo_ColorizeMsg(rpgoColorRed," not scanned")..". to scan: open your spellbook";
433 end
434 rpgo_VerboseMsg(" " .. msg);
435  
436 count=0;
437 msg="Inventory:";
438 for item in rpgoCPstate["Inventory"] do
439 msg=msg .. " Bag" .. item..":"..rpgoCPstate["Inventory"][item]["inv"].."/"..rpgoCPstate["Inventory"][item]["slot"];
440 count=count+1;
441 end
442 if(count==0) then
443 msg=msg..rpgo_ColorizeMsg(rpgoColorRed," not scanned")..". to scan: open your bank or 'character info'";
444 end
445 rpgo_VerboseMsg(" " .. msg);
446 count=0;
447 msg="Bank:";
448 for item in rpgoCPstate["Bank"] do
449 msg=msg .. " Bag" .. item .. ":".. rpgoCPstate["Bank"][item]["inv"].."/"..rpgoCPstate["Bank"][item]["slot"];
450 count=count+1;
451 end
452 if(count==0) then
453 msg=msg..rpgo_ColorizeMsg(rpgoColorRed," not scanned")..". to scan: open your bank";
454 end
455 rpgo_VerboseMsg(" " .. msg);
456 if((rpgoCPclass=="HUNTER" and UnitLevel("player")>9) or rpgoCPclass=="WARLOCK") then
457 count=0;
458 msg="Pets: ";
459 for item in rpgoCPstate["Pets"] do
460 msg=msg..item.." ";
461 if(rpgoCPstate["PetSpell"][item]) then
462 msg=msg.."(spells:"..rpgoCPstate["PetSpell"][item]..") ";
463 end
464 count=count+1;
465 end
466 if(count==0) then
467 msg=msg..rpgo_ColorizeMsg(rpgoColorRed," not scanned");
468 end
469 rpgo_VerboseMsg(" " .. msg);
470 end
471 if(rpgoCPclass=="HUNTER" and UnitLevel("player")>9) then
472 count=0;
473 msg="Stable: ";
474 for item in rpgoCPstate["Stable"] do
475 msg=msg..rpgoCPstate["Stable"][item].." ";
476 count=count+1;
477 end
478 if(count==0) then
479 msg=msg..rpgo_ColorizeMsg(rpgoColorRed," not scanned")..". to scan: open the stable";
480 end
481 rpgo_VerboseMsg(" " .. msg);
482 end
483 else
484 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": "..rpgo_ColorizeMsg(rpgoColorRed,"no character scanned"));
485 end
486 else
487 rpgoCP_TogglePref("enabled");
488 end
489 end
490  
491 --[[//////////////////////////////////////////////
492 -- InitProfile
493 -- ////////////////////////////////////////////]]
494 function rpgoCP_InitProfile()
495 if ( not myProfile ) then
496 myProfile={};
497 end
498 if ( not myProfile[rpgoCPserver] ) then
499 myProfile[rpgoCPserver]={};
500 end
501 if ( not myProfile[rpgoCPserver][rpgoCPplayer] ) then
502 myProfile[rpgoCPserver][rpgoCPplayer]={};
503 end
504 end
505  
506 --[[//////////////////////////////////////////////
507 -- UpdateProfile
508 -- ////////////////////////////////////////////]]
509 function rpgoCP_UpdateProfile()
510 rpgoCP_GetGuild(force);
511 rpgoCP_GetBuffs(myProfile[rpgoCPserver][rpgoCPplayer]);
512 rpgoCP_GetEquipment();
513 rpgoCP_GetInventory();
514 rpgoCP_GetTalents();
515 rpgoCP_GetSkills();
516 rpgoCP_GetReputation();
517 rpgoCP_GetQuests();
518 rpgoCP_GetHonor();
519 rpgoCP_UpdateZone();
520 rpgoCP_ScanPetInfo();
521 rpgoCP_UpdatePlayed();
522 rpgoCP_UpdateDate();
523 end
524  
525 --[[//////////////////////////////////////////////
526 -- ForceExport
527 -- ////////////////////////////////////////////]]
528 function rpgoCP_ForceExport()
529 local tmpState=rpgoCPstate;
530 rpgoCP_InitState(1);
531 rpgoCPstate["Bank"]=tmpState["Bank"];
532 rpgoCPstate["Professions"]=tmpState["Professions"];
533 rpgoCPstate["SpellBook"]=tmpState["SpellBook"];
534 rpgoCPstate["Stable"]=tmpState["Stable"];
535 rpgoCPstate["Pets"]=tmpState["Pets"];
536 rpgoCPstate["PetSpell"]=tmpState["PetSpell"];
537 rpgoCPstate["Mail"]=tmpState["Mail"];
538 rpgoCP_InitProfile();
539 rpgoCP_LoadProfile();
540 rpgoCP_UpdateProfile();
541 rpgoCP_ScanPetInfo();
542 rpgoCP_Show();
543 end
544  
545 --[[//////////////////////////////////////////////
546 -- Purge
547 -- ////////////////////////////////////////////]]
548 function rpgoCP_Purge(arg)
549 if(arg) then
550 if(arg=="char" and myProfile and myProfile[rpgoCPserver]) then
551 myProfile[rpgoCPserver][rpgoCPplayer]=nil;
552 elseif(arg=="server" and myProfile) then
553 myProfile[rpgoCPserver]=nil;
554 elseif(arg=="all") then
555 myProfile=nil;
556 end
557 rpgoCP_InitState(1);
558 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": "..arg.." info purged");
559 else
560 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": "..arg.." was not purged");
561 end
562  
563 end
564  
565 --[[//////////////////////////////////////////////
566 -- LoadProfile
567 -- ////////////////////////////////////////////]]
568 function rpgoCP_LoadProfile()
569 local structChar=myProfile[rpgoCPserver][rpgoCPplayer];
570 structChar["ProfilerVersion"]=rpgoCP_PROFILEDB;
571 structChar["CPversion"]=rpgoCP_VERSION;
572 structChar["CPprovider"]=rpgoCP_PROVIDER;
573 structChar["DBversion"]=rpgoCP_PROFILEDB;
574  
575 structChar["Name"]=rpgoCPplayer;
576 structChar["Server"]=rpgoCPserver;
577 structChar["Locale"]=GetLocale();
578 structChar["Race"]=UnitRace("player");
579 structChar["Class"]=UnitClass("player");
580 structChar["Sex"]=rpgo_UnitSexString("player");
581 _,structChar["Faction"]=UnitFactionGroup("player");
582 structChar["Hearth"]=GetBindLocation();
583 structChar["Zone"]=GetZoneText();
584 structChar["SubZone"]=GetSubZoneText();
585 structChar["TalentPoints"]=UnitCharacterPoints("player");
586 structChar["TimePlayed"]=timePlayed;
587 structChar["TimeLevelPlayed"]=timeLevelPlayed;
588 rpgoCP_GetGuild();
589 rpgoCP_GetEquipment();
590 rpgoCP_UpdateZone();
591 rpgoCP_UpdateDate();
592 rpgoCPstate["_loaded"]=1;
593 end
594  
595 --[[//////////////////////////////////////////////
596 -- rpgoCP Extract functions
597 -- ////////////////////////////////////////////]]
598 function rpgoCP_GetGuild(force)
599 local isGuildMember=IsInGuild();
600 if(not isGuildMember) then
601 rpgoCPstate["Guild"]=0;
602 myProfile[rpgoCPserver][rpgoCPplayer]["Guild"]=nil;
603 else
604 local numGuildMembers=GetNumGuildMembers();
605 if(force or not rpgoCPstate["Guild"] or rpgoCPstate["GuildNum"]~=numGuildMembers) then
606 myProfile[rpgoCPserver][rpgoCPplayer]["Guild"]={} ;
607 local structGuild=myProfile[rpgoCPserver][rpgoCPplayer]["Guild"];
608 local guildName,guildRankName,guildRankIndex=GetGuildInfo("player");
609 if(guildName) then
610 structGuild["Name"]=guildName;
611 structGuild["Title"]=guildRankName;
612 structGuild["Rank"]=guildRankIndex;
613 rpgoCPstate["Guild"]=1;
614 rpgoCPstate["GuildNum"]=numGuildMembers;
615 --toRemove
616 structGuild["GuildName"]=structGuild["Name"];
617 end
618 end
619 end
620 end
621  
622 function rpgoCP_GetSkills()
623 if(rpgoCPpref["scan"]["skills"]) then
624 local count=GetNumSkillLines();
625 if(rpgoCPstate["Skills"]~=count) then
626 myProfile[rpgoCPserver][rpgoCPplayer]["Skills"]={};
627 local structSkill=myProfile[rpgoCPserver][rpgoCPplayer]["Skills"];
628 local skillheader="";
629 local order=1;
630 rpgoCPstate["Skills"]=0;
631 for i=1,GetNumSkillLines(),1 do
632 local skillName,isHeader,isExpanded,skillRank,numTempPoints,skillModifier,skillMaxRank,isAbandonable,stepCost,rankCost,minLevel,skillCostType=GetSkillLineInfo(i);
633 if(isHeader==1) then
634 skillheader=skillName;
635 structSkill[skillheader]={};
636 structSkill[skillheader]["Order"]=order;
637 order=order+1;
638 else
639 structSkill[skillheader][skillName]=skillRank..":"..skillMaxRank;
640 if(skillMaxRank~=1) then
641 rpgoCPstate["_skills"][skillName]=skillRank;
642 end
643 end
644 rpgoCPstate["Skills"]=rpgoCPstate["Skills"]+1;
645 end
646 end
647 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
648 myProfile[rpgoCPserver][rpgoCPplayer]["Skills"]=nil;
649 end
650 end
651  
652 function rpgoCP_GetReputation()
653 if(rpgoCPpref["scan"]["reputation"]) then
654 local numFactions=GetNumFactions();
655 if(rpgoCPstate["Reputation"]~=numFactions) then
656 local thisHeader,name,description,standingID,barMin,barMax,barValue,atWar,canToggle,isHeader,isCollapsed;
657 rpgoCPstate["Reputation"]=0;
658 myProfile[rpgoCPserver][rpgoCPplayer]["Reputation"]={};
659 local structRep=myProfile[rpgoCPserver][rpgoCPplayer]["Reputation"];
660 structRep["Count"]=numFactions;
661 thisHeader=NONE;
662 for index=1,numFactions do
663 name,description,standingID,barMin,barMax,barValue,atWar,canToggle,isHeader,isCollapsed=GetFactionInfo(index);
664 if(not atWar) then atWar=0; end
665 if(isHeader) then
666 thisHeader=name;
667 structRep[thisHeader]={};
668 elseif(standingID) then
669 structRep[thisHeader][name]={};
670 structRep[thisHeader][name]["Standing"]=getglobal("FACTION_STANDING_LABEL"..standingID);
671 structRep[thisHeader][name]["AtWar"]=atWar;
672 structRep[thisHeader][name]["Value"]=barValue-barMin.."/"..barMax-barMin;
673 end
674 rpgoCPstate["Reputation"]=rpgoCPstate["Reputation"]+1;
675 end
676 end
677 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
678 myProfile[rpgoCPserver][rpgoCPplayer]["Reputation"]=nil;
679 end
680 end
681  
682 function rpgoCP_GetHonor()
683 if(rpgoCPpref["scan"]["honor"]) then
684 local lifetimeHK,lifetimeDK,lifetimeHighestRank=GetPVPLifetimeStats();
685 if(rpgoCPstate["Honor"]~=lifetimeHK) then
686 local hk,dk,contrib,rank;
687 local currRankName,currRankNumber,currRankDesc,currRankIcon,currRankProgress;
688 local lifetimeRankName,lifetimeRankNumber=GetPVPRankInfo(lifetimeHighestRank);
689 if ( not lifetimeRankName ) then
690 lifetimeRankName=NONE; end
691 local currRankName,currRankNumber=GetPVPRankInfo(UnitPVPRank("player"));
692 if ( not currRankName ) then
693 currRankName=NONE; end
694 currRankIcon="";
695 if ( currRankNumber > 0 ) then
696 currRankIcon=format("%s%02d","Interface\\PvPRankBadges\\PvPRank",currRankNumber);
697 end
698 currRankDesc="("..RANK.." "..currRankNumber..")";
699 currRankProgress=format("%02.02f",GetPVPRankProgress()*100);
700  
701 myProfile[rpgoCPserver][rpgoCPplayer]["Honor"]={};
702 local structHonor=myProfile[rpgoCPserver][rpgoCPplayer]["Honor"];
703 structHonor["Current"]=rpgo_Arg2Tab("Rank","Icon","Description","Progress",currRankName,currRankIcon,currRankDesc,currRankProgress);
704 structHonor["Lifetime"]=rpgo_Arg2Tab("Rank","Name","HK","DK",lifetimeHighestRank,lifetimeRankName,lifetimeHK,lifetimeDK);
705 structHonor["LastWeek"]=rpgo_Arg2Tab("HK","DK","Contribution","Rank",GetPVPLastWeekStats());
706 structHonor["ThisWeek"]=rpgo_Arg2Tab("HK","Contribution",GetPVPThisWeekStats());
707 structHonor["Yesterday"]=rpgo_Arg2Tab("HK","DK","Contribution",GetPVPYesterdayStats());
708 structHonor["Session"]=rpgo_Arg2Tab("HK","DK",GetPVPSessionStats());
709  
710 --toRemove
711 if(rpgoCPpref["honorold"]) then
712 structHonor["RankName"]=currRankName;
713 structHonor["RankInfo"]=currRankDesc;
714 structHonor["RankIcon"]=currRankIcon;
715  
716 structHonor["LifetimeHighestRank"]=lifetimeHighestRank;
717 structHonor["LifetimeRankName"]=lifetimeRankName;
718 structHonor["LifetimeHK"]=lifetimeHK;
719 structHonor["LifetimeDK"]=lifetimeDK;
720  
721 hk,dk,contrib,rank=GetPVPLastWeekStats();
722 structHonor["LastWeekHK"]=hk;
723 structHonor["LastWeekDK"]=dk;
724 structHonor["LastWeekContribution"]=contrib;
725 structHonor["LastWeekRank"]=rank;
726  
727 hk,contrib=GetPVPThisWeekStats();
728  
729 hk,dk,contrib=GetPVPYesterdayStats();
730 structHonor["YesterdayHK"]=hk;
731 structHonor["YesterdayDK"]=dk;
732 structHonor["YesterdayContribution"]=contrib;
733  
734 hk,dk=GetPVPSessionStats();
735 structHonor["SessionHK"]=hk;
736 structHonor["SessionDK"]=dk;
737 end
738 rpgoCPstate["Honor"]=lifetimeHK;
739 end
740 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
741 myProfile[rpgoCPserver][rpgoCPplayer]["Honor"]=nil;
742 end
743 end
744  
745 function rpgoCP_GetTalents()
746 if(rpgoCPpref["scan"]["talents"] and UnitLevel("player") > 9 ) then
747 local numTabs=GetNumTalentTabs();
748 if(rpgoCPstate["Talents"]~=numTabs) then
749 local numTalents,tabIndex,talentIndex
750 local tabName,texture,points,fileName;
751 local nameTalent,iconTexture,iconX,iconY,currentRank,maxRank;
752 myProfile[rpgoCPserver][rpgoCPplayer]["Talents"]={};
753 local structTalent=myProfile[rpgoCPserver][rpgoCPplayer]["Talents"];
754 rpgoCPstate["Talents"]=0;
755 for tabIndex=1,numTabs do
756 numTalents=GetNumTalents(tabIndex);
757 tabName,texture,points,fileName=GetTalentTabInfo(tabIndex);
758 structTalent[tabName]={};
759 structTalent[tabName]["PointsSpent"]=points;
760 structTalent[tabName]["Background"]="Interface\\TalentFrame\\" .. fileName;
761 structTalent[tabName]["Order"]=tabIndex;
762 for talentIndex=1,numTalents do
763 nameTalent,iconTexture,iconX,iconY,currentRank,maxRank=GetTalentInfo(tabIndex,talentIndex);
764 if(currentRank > 0 or rpgoCPpref["talentsfull"]) then
765 structTalent[tabName][nameTalent]={ };
766 structTalent[tabName][nameTalent]["Rank"]=currentRank..":"..maxRank;
767 structTalent[tabName][nameTalent]["Location"]=iconX..":"..iconY;
768 structTalent[tabName][nameTalent]["Texture"]=iconTexture;
769 end
770 if(rpgoCPpref["talentsfull"]) then
771 if(not structTalent[tabName][nameTalent]) then
772 structTalent[tabName][nameTalent]={};
773 end
774 rpgoCPtooltip:SetTalent(tabIndex,talentIndex)
775 structTalent[tabName][nameTalent]["Tooltip"]=rpgo_TooltipScan();
776 end
777 end
778 rpgoCPstate["Talents"]=rpgoCPstate["Talents"]+1;
779 end
780 end
781 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
782 myProfile[rpgoCPserver][rpgoCPplayer]["Talents"]=nil;
783 end
784 end
785  
786 function rpgoCP_GetQuests(force)
787 if(rpgoCPpref["scan"]["quests"]) then
788 local numEntries,numQuests=GetNumQuestLogEntries();
789 if(force or rpgoCPstate["QuestsLog"]~=numEntries) then
790 local header=UNKNOWN;
791 myProfile[rpgoCPserver][rpgoCPplayer]["Quests"]={};
792 local structQuest=myProfile[rpgoCPserver][rpgoCPplayer]["Quests"];
793 local slot,index,num,j; slot=1;
794 rpgoCPstate["Quests"]=0;
795 for index=1,numEntries,1 do
796 local questTitle,level,questTag,isHeader,isCollapsed,isComplete=GetQuestLogTitle(index);
797 if(isHeader) then
798 header=questTitle;
799 structQuest[header]={}
800 elseif(questTitle) then
801 structQuest[header][slot]={}
802 structQuest[header][slot]["Title"]=questTitle;
803 structQuest[header][slot]["Level"]=level;
804 structQuest[header][slot]["Complete"]=isComplete;
805 if(questTag) then
806 structQuest[header][slot]["Tag"]=questTag;
807 end
808 SelectQuestLogEntry(index);
809 if(rpgoCPpref["questsfull"]) then
810 structQuest[header][slot]["Description"],structQuest[header][slot]["Objective"]=GetQuestLogQuestText(index);
811 elseif(structQuest[header][slot]["Description"]) then
812 structQuest[header][slot]["Description"]=nil;
813 structQuest[header][slot]["Objective"]=nil;
814 end
815 num=GetNumQuestLeaderBoards(index);
816 if(num and num > 0) then
817 structQuest[header][slot]["Tasks"]={};
818 for j=1,num,1 do
819 structQuest[header][slot]["Tasks"][j]=rpgo_Arg2Tab("Note","Type","Done",GetQuestLogLeaderBoard(j,index));
820 end
821 end
822 num=GetQuestLogRewardMoney(index);
823 if(num and num~=0) then
824 structQuest[header][slot]["RewardMoney"]=num;
825 end
826 num=GetNumQuestLogRewards(index);
827 if(num and num > 0) then
828 structQuest[header][slot]["Rewards"]={};
829 for j=1,num,1 do
830 _,_,numItems,_,_=GetQuestLogRewardInfo(j);
831 table.insert(structQuest[header][slot]["Rewards"],rpgoCP_ScanItemInfo(GetQuestLogItemLink("reward",j),nil,numItems));
832 end
833 end
834 num=GetNumQuestLogChoices(index);
835 if(num and num > 0) then
836 structQuest[header][slot]["Choice"]={};
837 for j=1,num,1 do
838 _,_,numItems,_,_=GetQuestLogChoiceInfo(j);
839 table.insert(structQuest[header][slot]["Choice"],rpgoCP_ScanItemInfo(GetQuestLogItemLink("choice",j),nil,numItems));
840 end
841 end
842  
843  
844  
845 slot=slot+1;
846 rpgoCPstate["Quests"]=rpgoCPstate["Quests"]+1;
847 end
848 rpgoCPstate["QuestsLog"]=rpgoCPstate["QuestsLog"]+1;
849 end
850 end
851 elseif ( myProfile[rpgoCPserver][rpgoCPplayer] ) then
852 myProfile[rpgoCPserver][rpgoCPplayer]["Quests"]=nil;
853 end
854 end
855  
856 function rpgoCP_GetStats(structStats,unit)
857 if(not unit) then unit="player"; end
858 structStats["Level"]=UnitLevel(unit);
859 structStats["Health"]=UnitHealthMax(unit);
860 structStats["Mana"]=UnitManaMax(unit);
861 structStats["Power"]=UnitPower[UnitPowerType(unit)];
862 structStats["Stats"]={};
863 for i=1,table.getn(UnitStatName),1 do
864 local stat,effectiveStat,posBuff,negBuff=UnitStat(unit,i);
865 structStats["Stats"][UnitStatName[i]]=(stat - posBuff - negBuff)..":"..effectiveStat..":"..posBuff..":"..negBuff;
866 end
867 local baseArm,effectiveArmor,armor,positiveArm,negativeArm=UnitArmor(unit);
868 structStats["Armor"]=baseArm..":"..effectiveArmor..":"..positiveArm;
869 structStats["Stats"]["Armor"]=baseArm..":"..effectiveArmor..":"..positiveArm..":"..negativeArm;
870 local base,modifier = UnitDefense(unit);
871 structStats["Defense"]=base;
872 structStats["Stats"]["Defense"]=base..":"..base+modifier..":"..modifier..":0";
873 structStats["Resists"]={};
874 for i=1,table.getn(UnitResistName),1 do
875 local base,resistance,positive,negative=UnitResistance(unit,i);
876 structStats["Resists"][UnitResistName[i]]=base..":"..resistance..":"..positive..":"..negative;
877 end
878 if(unit=="player") then
879 structStats["Money"]=rpgo_Arg2Tab("Gold","Silver","Copper",rpgo_GetMoney());
880 structStats["TalentPoints"]=UnitCharacterPoints("player");
881 structStats["Experience"]=UnitXP("player")..":"..UnitXPMax("player");
882 local XPrest=GetXPExhaustion();
883 if(not XPrest) then XPrest=0; end
884 structStats["XP"]=structStats["Experience"]..":"..XPrest;
885 structStats["DodgePercent"]=format("%02.02f",GetDodgeChance());
886 structStats["BlockPercent"]=format("%02.02f",GetBlockChance());
887 if(not structStats["CritPercent"]) then
888 structStats["CritPercent"]="0";
889 end
890 if(not structStats["ParryPercent"]) then
891 structStats["ParryPercent"]="0";
892 end
893 local mitigation=(effectiveArmor)/((85 * structStats["Level"])+400);
894 mitigation=100*(mitigation/(mitigation+1));
895 structStats["MitigationPercent"]=format("%02.02f",mitigation);
896 local spellIndex=1;
897 local spellName,subSpellName=GetSpellName(spellIndex,BOOKTYPE_SPELL);
898 local tmpStr=nil;
899 local scanAttack=true;
900 local scanParry=true;
901 while spellName do
902 if(spellName==ATTACK) then
903 rpgoCPtooltip:SetSpell(spellIndex,BOOKTYPE_SPELL);
904 if(rpgoCPtooltipTextLeft2:GetText()) then
905 local ttText=rpgoCPtooltipTextLeft2:GetText();
906 local startString,endString=string.find(ttText,'(%d+\.%d+)%% ');
907 if(startString) then
908 tmpStr=string.sub(ttText,startString,endString-2);
909 structStats["CritPercent"]=tmpStr;
910 end
911 end
912 rpgoCPtooltip:ClearLines();
913 scanAttack=nil;
914 elseif(spellName==PARRY) then
915 structStats["ParryPercent"]=format("%02.02f",GetParryChance());
916 scanParry=nil;
917 end
918 if(not scanAttack and not scanParry) then break; end
919 spellIndex=spellIndex+1;
920 spellName,subSpellName=GetSpellName(spellIndex,BOOKTYPE_SPELL);
921 end
922 end
923 end
924  
925 function rpgoCP_CharacterDamageFrame(unit,prefix)
926 if(not unit) then unit="player"; end
927 if(not prefix) then prefix="Character"; end
928 local damageFrame = getglobal(prefix.."DamageFrame");
929 rpgoCPtooltip:ClearLines();
930 rpgoCPtooltip:SetText(INVTYPE_WEAPONMAINHAND);
931 rpgoCPtooltip:AddDoubleLine(ATTACK_SPEED_COLON, format("%.2f", damageFrame.attackSpeed));
932 rpgoCPtooltip:AddDoubleLine(DAMAGE_COLON, damageFrame.damage);
933 rpgoCPtooltip:AddDoubleLine(DAMAGE_PER_SECOND, format("%.1f", damageFrame.dps));
934 -- Check for offhand weapon
935 if ( damageFrame.offhandAttackSpeed ) then
936 rpgoCPtooltip:AddLine(" ");
937 rpgoCPtooltip:AddLine(INVTYPE_WEAPONOFFHAND);
938 rpgoCPtooltip:AddDoubleLine(ATTACK_SPEED_COLON, format("%.2f", damageFrame.offhandAttackSpeed));
939 rpgoCPtooltip:AddDoubleLine(DAMAGE_COLON, damageFrame.offhandDamage);
940 rpgoCPtooltip:AddDoubleLine(DAMAGE_PER_SECOND, format("%.1f", damageFrame.offhandDps));
941 end
942 end
943  
944 function rpgoCP_CharacterRangedDamageFrame(unit,prefix)
945 if(not unit) then unit="player"; end
946 if(not prefix) then prefix="Character"; end
947 local damageFrame = getglobal(prefix.."RangedDamageFrame");
948 if (not damageFrame.damage) then return; end
949 rpgoCPtooltip:ClearLines();
950 rpgoCPtooltip:SetText(INVTYPE_RANGED);
951 rpgoCPtooltip:AddDoubleLine(ATTACK_SPEED_COLON, format("%.2f", damageFrame.attackSpeed));
952 rpgoCPtooltip:AddDoubleLine(DAMAGE_COLON, damageFrame.damage);
953 rpgoCPtooltip:AddDoubleLine(DAMAGE_PER_SECOND, format("%.1f", damageFrame.dps));
954 end
955  
956 function rpgoCP_GetAttackRating(structAttack,unit,prefix)
957 if(not unit) then unit="player"; end
958 if(not prefix) then prefix="Character"; end
959 PaperDollFrame_SetDamage(unit,prefix);
960 PaperDollFrame_SetAttackPower(unit,prefix);
961 PaperDollFrame_SetAttackBothHands(unit,prefix);
962 local damageFrame = getglobal(prefix.."DamageFrame");
963 local damageText = getglobal(prefix.."DamageFrameStatText");
964 local mainHandAttackBase,mainHandAttackMod = UnitAttackBothHands(unit);
965  
966 structAttack["Melee Attack"]={};
967 structAttack["Melee Attack"]["AttackSpeed"]=format("%.2f", damageFrame.attackSpeed);
968 structAttack["Melee Attack"]["AttackDPS"]=format("%.1f", damageFrame.dps);
969 structAttack["Melee Attack"]["AttackRating"]=mainHandAttackBase+mainHandAttackMod;
970 local tt=damageText:GetText();
971  
972 if(string.find(tt,'|c%x%x%x%x%x%x%x%x')) then
973 structAttack["Melee Attack"]["DamageRange"]=string.gsub(tt,"^|c%x%x%x%x%x%x%x%x?(%d+)%s?-%s?(%d+)|r?$","%1:%2");
974 else
975 structAttack["Melee Attack"]["DamageRange"]=string.gsub(tt,"^(%d+)%s?-%s?(%d+)$","%1:%2");
976 end
977 tt=damageFrame.damage;
978 if(string.find(tt,'|c%x%x%x%x%x%x%x%x')) then
979 structAttack["Melee Attack"]["DamageRangeBase"]=string.gsub(tt,"^(%d+)%s?-%s?(%d+)|c%x%x%x%x%x%x%x%x x%d+%%|r?$","%1:%2");
980 else
981 structAttack["Melee Attack"]["DamageRangeBase"]=string.gsub(tt,"^(%d+)%s?-%s?(%d+)$","%1:%2");
982 end
983 rpgoCP_CharacterDamageFrame();
984 local tt=rpgo_TooltipScan();
985 if(rpgoCPpref.tooltipshtml) then
986 tt=string.gsub(tt,"|c%x%x%x%x%x%x%x%x(.+)|r","%1");
987 end
988 structAttack["Melee Attack"]["DamageRangeTooltip"]=tt;
989 if ( damageFrame.offhandAttackSpeed ) then
990 structAttack["Melee Attack"]["AttackSpeed2"]=format("%.2f", damageFrame.offhandAttackSpeed);
991 structAttack["Melee Attack"]["AttackDPS2"]=format("%.1f", damageFrame.offhandDps);
992 tt=damageFrame.offhandDamage;
993 if(string.find(tt,'|c%x%x%x%x%x%x%x%x')) then
994 structAttack["Melee Attack"]["DamageRange2"]=string.gsub(tt,"^(%d+)%s?-%s?(%d+)|c%x%x%x%x%x%x%x%x x%d+%%|r","%1:%2");
995 else
996 structAttack["Melee Attack"]["DamageRange2"]=string.gsub(tt,"^(%d+)%s?-%s?(%d+)","%1:%2");
997 end
998 end
999 local base,posBuff,negBuff = UnitAttackPower(unit);
1000 apDPS=max((base+posBuff+negBuff),0)/ATTACK_POWER_MAGIC_NUMBER;
1001 structAttack["Melee Attack"]["AttackPower"]=base+posBuff+negBuff;
1002 structAttack["Melee Attack"]["AttackPower2"]=base..":"..base+posBuff+negBuff..":"..posBuff..":"..negBuff;
1003 structAttack["Melee Attack"]["AttackPowerDPS"]=format("%.1f",apDPS);
1004 structAttack["Melee Attack"]["AttackPowerTooltip"]=format(MELEE_ATTACK_POWER_TOOLTIP,apDPS);
1005  
1006 if(unit=="player") then
1007 local rangedTexture = GetInventoryItemTexture("player",18);
1008 if ( not rangedTexture ) then
1009 structAttack["Ranged Attack"]=nil;
1010 else
1011 PaperDollFrame_SetRangedAttack(unit,prefix);
1012 PaperDollFrame_SetRangedDamage(unit,prefix);
1013 PaperDollFrame_SetRangedAttackPower(unit,prefix);
1014 local damageFrame = getglobal(prefix.."RangedDamageFrame");
1015 local damageText = getglobal(prefix.."RangedDamageFrameStatText");
1016 if(PaperDollFrame.noRanged) then
1017 structAttack["Ranged Attack"]=nil;
1018 else
1019 structAttack["Ranged Attack"]={};
1020 structAttack["Ranged Attack"]["AttackSpeed"]=format("%.2f", damageFrame.attackSpeed);
1021 structAttack["Ranged Attack"]["AttackDPS"]=format("%.1f", damageFrame.dps);
1022 structAttack["Ranged Attack"]["AttackRating"]=UnitRangedAttack(unit);
1023 tt=damageText:GetText();
1024 if(string.find(tt,'|c%x%x%x%x%x%x%x%x')) then
1025 structAttack["Ranged Attack"]["DamageRange"]=string.gsub(tt,"^(%d+)%s?-%s?(%d+)|c%x%x%x%x%x%x%x%x x%d+%%|r","%1:%2");
1026 else
1027 structAttack["Ranged Attack"]["DamageRange"]=string.gsub(tt,"^(%d+)%s?-%s?(%d+)","%1:%2");
1028 end
1029 tt=damageFrame.damage;
1030 if(string.find(tt,'|c%x%x%x%x%x%x%x%x')) then
1031 structAttack["Ranged Attack"]["DamageRangeBase"]=string.gsub(tt,"^(%d+)%s?-%s?(%d+)|c%x%x%x%x%x%x%x%x x%d+%%|r?$","%1:%2");
1032 else
1033 structAttack["Ranged Attack"]["DamageRangeBase"]=string.gsub(tt,"^(%d+)%s?-%s?(%d+)$","%1:%2");
1034 end
1035 rpgoCP_CharacterRangedDamageFrame();
1036 local tt=rpgo_TooltipScan();
1037 if(rpgoCPpref.tooltipshtml) then
1038 tt=string.gsub(tt,"|c%x%x%x%x%x%x%x%x(.+)|r","%1");
1039 end
1040 structAttack["Ranged Attack"]["DamageRangeTooltip"]=tt;
1041 if( HasWandEquipped() ) then
1042 structAttack["Ranged Attack"]["AttackPower"]=nil;
1043 structAttack["Ranged Attack"]["AttackPowerDPS"]=nil;
1044 structAttack["Ranged Attack"]["AttackPowerTooltip"]=nil;
1045 else
1046 local base,pos,neg=UnitRangedAttackPower(unit);
1047 apDPS=base/ATTACK_POWER_MAGIC_NUMBER;
1048 structAttack["Ranged Attack"]["AttackPower"]=base+pos+neg;
1049 structAttack["Ranged Attack"]["AttackPowerDPS"]=format("%.1f",apDPS);
1050 structAttack["Ranged Attack"]["AttackPowerTooltip"]=format(RANGED_ATTACK_POWER_TOOLTIP,apDPS);
1051 end
1052 end
1053 end
1054 end
1055 end
1056  
1057 function rpgoCP_GetBuffs(structBuffs,unit)
1058 if(not unit) then unit="player"; end
1059 local index=1;
1060 local buffTexture;
1061 if(UnitBuff(unit,index)) then
1062 structBuffs["Buffs"]={};
1063 while(UnitBuff(unit,index)) do
1064 buffTexture=UnitBuff(unit,index);
1065 rpgoCPtooltip:SetUnitBuff(unit,index);
1066 structBuffs["Buffs"][index]={};
1067 structBuffs["Buffs"][index]["Name"]=rpgo_GetItemInfoTT();
1068 structBuffs["Buffs"][index]["Tooltip"]=rpgo_TooltipScan();
1069 structBuffs["Buffs"][index]["Texture"]=buffTexture;
1070 index=index+1
1071 end
1072 else
1073 structBuffs["Buffs"]=nil;
1074 end
1075 index=1;
1076 if(UnitDebuff(unit,index)) then
1077 structBuffs["Debuffs"]={};
1078 while(UnitDebuff(unit,index)) do
1079 buffTexture=UnitDebuff(unit,index);
1080 rpgoCPtooltip:SetUnitDebuff(unit,index);
1081 structBuffs["Debuffs"][index]={};
1082 structBuffs["Debuffs"][index]["Name"]=rpgo_GetItemInfoTT();
1083 structBuffs["Debuffs"][index]["Tooltip"]=rpgo_TooltipScan();
1084 structBuffs["Debuffs"][index]["Texture"]=buffTexture;
1085 index=index + 1
1086 end
1087 else
1088 structBuffs["Debuffs"]=nil;
1089 end
1090 end
1091  
1092 function rpgoCP_GetEquipment(force)
1093 if(rpgoCPpref["scan"]["equipment"]) then
1094 if( force or rpgoCPstate["Equipment"]==0 or rpgoCPstate["EquipmentKey"]~=rpgoCP_GetEQKey() ) then
1095 local id,curItemLink,curItemTexture,curItemName,curItemColor,index,slot;
1096 rpgoCPstate["Equipment"]=0;
1097 rpgoCPstate["EquipmentKey"]=0;
1098 myProfile[rpgoCPserver][rpgoCPplayer]["Equipment"]={};
1099 local structEquip=myProfile[rpgoCPserver][rpgoCPplayer]["Equipment"];
1100 for index,slot in UnitSlots do
1101 curItemTexture=GetInventoryItemTexture("player",index);
1102 if(index==0) then
1103 --AmmoSlot magik
1104 if(curItemTexture) then
1105 rpgoCPtooltip:SetInventoryItem("player",index);
1106 curItemName,curItemColor=rpgo_GetItemInfoTT();
1107 if(curItemName) then
1108 curItemLink="|c"..curItemColor.."|Hitem:0:0:0:0|h["..curItemName.."]|h|r";
1109 id=1;
1110 end
1111 end
1112 else
1113 curItemLink=GetInventoryItemLink("player",index);
1114 _,id,_=rpgo_GetItemID(curItemLink);
1115 end
1116 if(curItemLink) then
1117 rpgoCPtooltip:SetInventoryItem("player",index);
1118 structEquip[slot]=rpgoCP_ScanItemInfo(curItemLink,curItemTexture,nil,rpgo_TooltipScan());
1119 rpgoCPstate["Equipment"]=rpgoCPstate["Equipment"]+1;
1120 rpgoCPstate["EquipmentKey"]=rpgoCPstate["EquipmentKey"]+id;
1121 curItemLink=nil;
1122 end
1123 end
1124 end
1125 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
1126 structEquip=nil;
1127 end
1128 rpgoCP_GetStats(myProfile[rpgoCPserver][rpgoCPplayer]);
1129 rpgoCP_GetAttackRating(myProfile[rpgoCPserver][rpgoCPplayer]);
1130 end
1131  
1132 function rpgoCP_GetMail()
1133 if(rpgoCPpref["scan"]["mail"]) then
1134 numMessages=GetInboxNumItems();
1135 if( (not rpgoCPstate["Mail"]) or (rpgoCPstate["Mail"]~=numMessages and numMessages~=0) ) then
1136 rpgoCPstate["Mail"]=0;
1137 myProfile[rpgoCPserver][rpgoCPplayer]["MailBox"]={};
1138 local structMail=myProfile[rpgoCPserver][rpgoCPplayer]["MailBox"];
1139 for index=1,numMessages do
1140 local _,_,mailSender,mailSubject,mailCoin,_,mailDays=GetInboxHeaderInfo(index);
1141 local itemName,itemIcon,itemQty,_,_=GetInboxItem(index);
1142 if(not mailSender) then mailSender=UNKNOWN; end
1143 structMail[index]={};
1144 structMail[index]["Sender"]=mailSender;
1145 structMail[index]["Subject"]=mailSubject;
1146 structMail[index]["Coin"]=mailCoin;
1147 structMail[index]["CoinIcon"]=GetCoinIcon(mailCoin);
1148 structMail[index]["Days"]=mailDays;
1149 structMail[index]["Item"]={};
1150 structMail[index]["Item"]["Name"]=itemName;
1151 structMail[index]["Item"]["Icon"]=itemIcon;
1152 structMail[index]["Item"]["Quantity"]=itemQty;
1153 rpgoCPtooltip:SetInboxItem(index);
1154 structMail[index]["Item"]["Tooltip"]=rpgo_TooltipScan();
1155 rpgoCPstate["Mail"]=rpgoCPstate["Mail"]+1;
1156 end
1157 myProfile[rpgoCPserver][rpgoCPplayer]["MailDateUTC"]=date("!%m/%d/%y %H:%M:%S");
1158 end
1159 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
1160 myProfile[rpgoCPserver][rpgoCPplayer]["MailBox"]=nil;
1161 myProfile[rpgoCPserver][rpgoCPplayer]["MailDateUTC"]=nil;
1162 end
1163 end
1164  
1165 function rpgoCP_GetInventory()
1166 local bagNum=0;
1167 if(rpgoCPpref["scan"]["inventory"]) then
1168 if(not bagContainerText) then bagContainerText=""; end
1169 if(not myProfile[rpgoCPserver][rpgoCPplayer]["Inventory"]) then
1170 myProfile[rpgoCPserver][rpgoCPplayer]["Inventory"]={};
1171 rpgoCPstate["Inventory"]={};
1172 end
1173 local structInventory=myProfile[rpgoCPserver][rpgoCPplayer]["Inventory"];
1174 for bag=0,4,1 do
1175 bagName="Bag" .. bag;
1176 local bagname,link,texture,color,item,itemname;
1177 if(bag==0) then
1178 bagname=GetBagName(bag);
1179 baglink="|cffffffff|Hitem:0:0:0:0|h["..bagname.."]|h|r";
1180 texture="Interface\\Buttons\\Button-Backpack-Up";
1181 rpgoCPtooltip:SetText(bagname);
1182 rpgoCPtooltip:AddLine(format(CONTAINER_SLOTS,rpgoCP_GetContainerNumSlots(bag),bagContainerText));
1183 else
1184 baglink=GetInventoryItemLink("player",(ContainerIDToInventoryID(bag)));
1185 texture=GetInventoryItemTexture("player",(ContainerIDToInventoryID(bag)));
1186 rpgoCPtooltip:SetInventoryItem("player",(ContainerIDToInventoryID(bag)))
1187 end
1188 if(baglink) then
1189 local bagContentsTemp=nil;
1190 if(structInventory[bagName] and structInventory[bagName]["Contents"]) then
1191 bagContentsTemp=structInventory[bagName]["Contents"];
1192 end
1193 structInventory[bagName]=rpgoCP_ScanBagInfo(bag,baglink,texture,rpgo_TooltipScan());
1194 if(not rpgoCPstate["Inventory"][bag] or not rpgoCPstate["Bag"][bag]) then
1195 structInventory[bagName]["Contents"]=rpgoCP_GetContainerItems("Inventory",bag,bag);
1196 rpgoCPstate["Bag"][bag]=1;
1197 else
1198 structInventory[bagName]["Contents"]=bagContentsTemp;
1199 bagContentsTemp=nil;
1200 end
1201 else
1202 structInventory[bagName]=nil;
1203 end
1204 bagNum=bag;
1205 end
1206 if(HasKey and HasKey()) then
1207 local bag,bagname,link,texture,color,item,itemname;
1208 bag=bagNum+1;
1209 bagName="Bag" .. bag;
1210 texture="Interface\\Buttons\\UI-Button-KeyRing";
1211 baglink="|cffffffff|Hitem:0:0:0:0|h["..KEYRING.."]|h|r";
1212 rpgoCPtooltip:SetText(KEYRING);
1213 rpgoCPtooltip:AddLine(format(CONTAINER_SLOTS,rpgoCP_GetContainerNumSlots(KEYRING_CONTAINER),bagContainerText));
1214 local bagContentsTemp=nil;
1215 if(structInventory[bagName] and structInventory[bagName]["Contents"]) then
1216 bagContentsTemp=structInventory[bagName]["Contents"];
1217 end
1218 structInventory[bagName]=rpgoCP_ScanBagInfo(KEYRING_CONTAINER,baglink,texture,rpgo_TooltipScan());
1219 structInventory[bagName]["Name"]=KEYRING;
1220 if(not rpgoCPstate["Inventory"][bag] or not rpgoCPstate["Bag"][bag]) then
1221 structInventory[bagName]["Contents"]=rpgoCP_GetContainerItems("Inventory",KEYRING_CONTAINER,bag);
1222 rpgoCPstate["Bag"][bag]=1;
1223 else
1224 structInventory[bagName]["Contents"]=bagContentsTemp;
1225 bagContentsTemp=nil;
1226 end
1227 rpgoCPstate["Bag"][bag]=1;
1228 end
1229 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
1230 myProfile[rpgoCPserver][rpgoCPplayer]["Inventory"]=nil;
1231 rpgoCPstate["Inventory"]={};
1232 end
1233 end
1234  
1235 function rpgoCP_GetBank()
1236 if(rpgoCPpref["scan"]["bank"]) then
1237 if(rpgoCPstate["BankTime"] < GetTime()-timeWait) then
1238 if(not myProfile[rpgoCPserver][rpgoCPplayer]["Bank"]) then
1239 myProfile[rpgoCPserver][rpgoCPplayer]["Bank"]={};
1240 rpgoCPstate["Bank"]={};
1241 end
1242 local structBank=myProfile[rpgoCPserver][rpgoCPplayer]["Bank"];
1243 local bag,bagnum;
1244 bag=BANK_CONTAINER;
1245 bagnum=0;
1246 local bagContentsTemp=nil;
1247 if(structBank["Contents"]) then
1248 bagContentsTemp=structBank["Contents"];
1249 end
1250 local bankKey=rpgoCP_GetBagKey(BANK_CONTAINER);
1251 if(not rpgoCPstate["Bank"][bagnum] or not rpgoCPstate["Bank"][bagnum]["key"] or rpgoCPstate["Bank"][bagnum]["key"]~=bankKey) then
1252 structBank["Contents"]=rpgoCP_GetContainerItems("Bank",BANK_CONTAINER,bagnum);
1253 rpgoCPstate["Bank"][bagnum]["key"]=bankKey;
1254 else
1255 structBank["Contents"]=bagContentsTemp;
1256 bagContentsTemp=nil;
1257 end
1258 local bag,size,slot,link;
1259 for bagnum=1,GetNumBankSlots() do
1260 bag=bagnum+4;
1261 bagName="Bag" .. bagnum;
1262 baglink=GetInventoryItemLink("player",(ContainerIDToInventoryID(bag)));
1263 texture=GetInventoryItemTexture("player",(ContainerIDToInventoryID(bag)));
1264 if(baglink) then
1265 bagContentsTemp=nil;
1266 if(structBank[bagName] and structBank[bagName]["Contents"]) then
1267 bagContentsTemp=structBank[bagName]["Contents"];
1268 end
1269 rpgoCPtooltip:SetInventoryItem("player",(ContainerIDToInventoryID(bag)))
1270 structBank[bagName]=rpgoCP_ScanBagInfo(bag,baglink,texture,rpgo_TooltipScan());
1271 if(not rpgoCPstate["Bank"][bagnum] or not rpgoCPstate["Bag"][bag]) then
1272 structBank[bagName]["Contents"]=rpgoCP_GetContainerItems("Bank",bag,bagnum);
1273 rpgoCPstate["Bag"][bag]=1;
1274 else
1275 structBank[bagName]["Contents"]=bagContentsTemp;
1276 bagContentsTemp=nil;
1277 end
1278 else
1279 rpgoCPstate["Bank"][bagnum]=nil;
1280 structBank[bagName]=nil;
1281 end
1282 end
1283 rpgoCPstate["BankTime"]=GetTime();
1284 end
1285 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
1286 myProfile[rpgoCPserver][rpgoCPplayer]["Bank"]=nil;
1287 rpgoCPstate["Bank"]={};
1288 end
1289 end
1290  
1291 function rpgoCP_GetContainerItems(container,bagID,bagnum)
1292 local bagContents={};
1293 local itemlink,texture;
1294 rpgoCPstate[container][bagnum]={};
1295 rpgoCPstate[container][bagnum]["slot"]=0;
1296 rpgoCPstate[container][bagnum]["inv"]=0;
1297 for slot=1,rpgoCP_GetContainerNumSlots(bagID) do
1298 itemlink=GetContainerItemLink(bagID,slot);
1299 texture,itemCount,locked,quality=GetContainerItemInfo(bagID,slot);
1300 if(itemlink) then
1301 if(bagID==BANK_CONTAINER) then
1302 rpgoCPtooltip:SetInventoryItem("player",BankButtonIDToInvSlotID(slot));
1303 else
1304 rpgoCPtooltip:SetBagItem(bagID,slot);
1305 end
1306 bagContents[slot]=rpgoCP_ScanItemInfo(itemlink,texture,itemCount,rpgo_TooltipScan());
1307 rpgoCPstate[container][bagnum]["inv"]=rpgoCPstate[container][bagnum]["inv"]+1;
1308 end
1309 rpgoCPstate[container][bagnum]["slot"]=rpgoCPstate[container][bagnum]["slot"]+1;
1310 end
1311 if(not rpgoCPstate["_bagevent"]) then
1312 this:RegisterEvent("BAG_UPDATE");
1313 rpgoCPstate["_bagevent"]=1;
1314 end
1315 --rpgoCP_debug("GetInventory: "..container.."|"..bagID.."|"..bagnum);
1316 return bagContents;
1317 end
1318  
1319 function rpgoCP_GetContainerNumSlots(bagID)
1320 if(bagID == KEYRING_CONTAINER) then
1321 return GetKeyRingSize();
1322 else
1323 return GetContainerNumSlots(bagID);
1324 end
1325 end
1326  
1327 function rpgoCP_GetTradeSkill()
1328 if(rpgoCPpref["scan"]["professions"]) then
1329 local reagentsUnknown=nil;
1330 local skillLineName,skillLineRank,skillLineMaxRank=GetTradeSkillLine();
1331 if(not skillLineName) then
1332 return;
1333 elseif ( (skillLineName=="") or (skillLineName==UNKNOWN) ) then
1334 return;
1335 end
1336 -- expand the tree so we can see all the recipes
1337 ExpandTradeSkillSubClass(0);
1338 if(not rpgoCPstate["Professions"][skillLineName]) then
1339 rpgoCPstate["Professions"][skillLineName]={};
1340 end
1341 if ( not myProfile[rpgoCPserver][rpgoCPplayer]["Professions"] ) then
1342 myProfile[rpgoCPserver][rpgoCPplayer]["Professions"]={};
1343 end
1344 local structProf=myProfile[rpgoCPserver][rpgoCPplayer]["Professions"];
1345  
1346 -- get the number of recipes and loop through each one
1347 local numTradeSkills=GetNumTradeSkills();
1348 local skillHeader=nil;
1349 if(numTradeSkills>0 and (not rpgoCPstate["Professions"][skillLineName] or numTradeSkills~=rpgoCPstate["Professions"][skillLineName]) ) then
1350 local TradeSkillTemp=nil;
1351 if(not structProf[skillLineName]) then
1352 structProf[skillLineName]={};
1353 elseif(structProf[skillLineName]) then
1354 TradeSkillTemp=structProf[skillLineName];
1355 structProf[skillLineName]={};
1356 end
1357 rpgoCPstate["Professions"][skillLineName]=0;
1358 for itemIndex=1,numTradeSkills,1 do
1359 local skillName,skillDifficulty,numAvailable,isExpanded=GetTradeSkillInfo(itemIndex);
1360 local cooldown,reagents;
1361 if(skillDifficulty=="header" and skillName~="" and isExpanded) then
1362 skillHeader=skillName;
1363 structProf[skillLineName][skillHeader]={};
1364 rpgoCPstate["Professions"][skillLineName]=rpgoCPstate["Professions"][skillLineName]+1;
1365 elseif(skillDifficulty=="header" and not isExpanded) then
1366 skillHeader=nil;
1367 elseif(skillHeader and skillName and skillName~="" ) then
1368 local skillIcon=GetTradeSkillIcon(itemIndex);
1369 if(not skillIcon) then skillIcon=""; end
1370 local Color,_,Link,_=rpgo_GetItemInfo(GetTradeSkillItemLink(itemIndex));
1371 structProf[skillLineName][skillHeader][skillName]={};
1372 structProf[skillLineName][skillHeader][skillName]["Texture"]=skillIcon;
1373 structProf[skillLineName][skillHeader][skillName]["Difficulty"]=TradeSkillCode[skillDifficulty];
1374 structProf[skillLineName][skillHeader][skillName]["Color"]=Color;
1375 structProf[skillLineName][skillHeader][skillName]["Item"]=Link;
1376 rpgoCPtooltip:SetTradeSkillItem(itemIndex);
1377 if(GetTradeSkillCooldown(itemIndex)) then
1378 structProf[skillLineName][skillHeader][skillName]["Cooldown"]=GetTradeSkillCooldown(itemIndex);
1379 structProf[skillLineName][skillHeader][skillName]["DateUTC"]=date("!%m/%d/%y %H:%M:%S");
1380 rpgoCPtooltip:AddLine(COOLDOWN_REMAINING.." "..SecondsToTime(structProf[skillLineName][skillHeader][skillName]["Cooldown"]));
1381 elseif(structProf[skillLineName][skillHeader][skillName]["Cooldown"]) then
1382 structProf[skillLineName][skillHeader][skillName]["Cooldown"]=nil;
1383 end
1384 structProf[skillLineName][skillHeader][skillName]["Tooltip"]=rpgo_TooltipScan();
1385 local numReagents=GetTradeSkillNumReagents(itemIndex);
1386 if(rpgoCPpref["reagenthtml"]) then
1387 reagents="";
1388 else
1389 reagents={};
1390 end
1391 for reagentIndex=1,numReagents,1 do
1392 local reagentName,reagentTexture,reagentCount,playerReagentCount=GetTradeSkillReagentInfo(itemIndex,reagentIndex);
1393 if(not reagentTexture) then reagentTexture=""; end
1394 if(not reagentName) then reagentName=UNKNOWN; reagentsUnknown=1; end
1395 if(rpgoCPpref["reagenthtml"]) then
1396 if(reagentIndex==numReagents) then
1397 reagents=reagents .. reagentName .. " x" .. reagentCount;
1398 else
1399 reagents=reagents .. reagentName .. " x" .. reagentCount .. "<br>";
1400 end
1401 else
1402 local _,itemID,_ = rpgo_GetItemID(GetTradeSkillReagentItemLink(itemIndex,reagentIndex));
1403 reagents[reagentIndex]={};
1404 reagents[reagentIndex]["Name"]=reagentName;
1405 reagents[reagentIndex]["Count"]=reagentCount;
1406 reagents[reagentIndex]["itemID"]=itemID;
1407 end
1408 end
1409 structProf[skillLineName][skillHeader][skillName]["Reagents"]=reagents;
1410 rpgoCPstate["Professions"][skillLineName]=rpgoCPstate["Professions"][skillLineName]+1;
1411 end
1412 end
1413 if(rpgoCPstate["Professions"][skillLineName]==0) then
1414 _skillError=1;
1415 structProf[skillLineName]=TradeSkillTemp;
1416 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": "..skillLineName..rpgo_ColorizeMsg(rpgoColorRed," not scanned, rescanning or open again"));
1417 rpgoCPtrade:Show();
1418 elseif(reagentsUnknown) then
1419 _skillError=1
1420 structProf[skillLineName]=TradeSkillTemp;
1421 rpgoCPstate["Professions"][skillLineName]=0;
1422 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": "..skillLineName..rpgo_ColorizeMsg(rpgoColorRed," reagents not scanned, rescanning or open again"));
1423 rpgoCPtrade:Show();
1424 else
1425 if(_skillError) then
1426 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": "..skillLineName.." rescanned successfully");
1427 _skillError=nil;
1428 end
1429 rpgoCPtrade:Hide();
1430 end
1431 TradeSkillTemp=nil;
1432 end
1433 rpgoCP_TidyProfessions();
1434 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
1435 myProfile[rpgoCPserver][rpgoCPplayer]["Professions"]=nil;
1436 rpgoCPstate["Professions"]={};
1437 end
1438 end
1439  
1440 function rpgoCP_GetCraft()
1441 if(rpgoCPpref["scan"]["professions"]) then
1442 local reagentsUnknown=nil;
1443 local skillLineName,skillLineRank,skillLineMaxRank=GetCraftDisplaySkillLine();
1444 if(not skillLineName) then
1445 return;
1446 elseif ( (skillLineName=="") or (skillLineName==UNKNOWN) ) then
1447 return;
1448 end
1449 -- get the number of recipes and loop through each one
1450 local numCrafts=GetNumCrafts();
1451 if ( not myProfile[rpgoCPserver][rpgoCPplayer]["Professions"] ) then
1452 myProfile[rpgoCPserver][rpgoCPplayer]["Professions"]={};
1453 end
1454 local structProf=myProfile[rpgoCPserver][rpgoCPplayer]["Professions"];
1455 local skillHeader=nil;
1456 if(numCrafts>0 and (not rpgoCPstate["Professions"][skillLineName] or numCrafts~=rpgoCPstate["Professions"][skillLineName]) ) then
1457 local TradeSkillTemp=nil;
1458 if(not structProf[skillLineName]) then
1459 structProf[skillLineName]={};
1460 elseif(structProf[skillLineName]) then
1461 TradeSkillTemp=structProf[skillLineName];
1462 structProf[skillLineName]={};
1463 end
1464 rpgoCPstate["Professions"][skillLineName]=0;
1465 skillHeader=skillLineName;
1466 for itemIndex=1,numCrafts,1 do
1467 local skillName,craftSubSpellName,skillDifficulty,numAvailable,isExpanded=GetCraftInfo(itemIndex);
1468 if( skillDifficulty=="header" and skillName~="" ) then
1469 skillHeader=skillName;
1470 structProf[skillLineName][skillHeader]={};
1471 rpgoCPstate["Professions"][skillLineName]=rpgoCPstate["Professions"][skillLineName]+1;
1472 elseif( skillHeader and skillName and skillName~="" ) then
1473 if(not structProf[skillLineName][skillHeader]) then
1474 structProf[skillLineName][skillHeader]={};
1475 end
1476 local skillIcon=GetCraftIcon(itemIndex);
1477 if(not skillIcon) then skillIcon=""; end
1478 local Color,_,Link,_=rpgo_GetItemInfo(GetTradeSkillItemLink(itemIndex));
1479 local numReagents=GetCraftNumReagents(itemIndex);
1480 local reagents="";
1481 structProf[skillLineName][skillHeader][skillName]={};
1482 structProf[skillLineName][skillHeader][skillName]["Texture"]=skillIcon;
1483 structProf[skillLineName][skillHeader][skillName]["Difficulty"]=TradeSkillCode[skillDifficulty];
1484 structProf[skillLineName][skillHeader][skillName]["Color"]=Color;
1485 structProf[skillLineName][skillHeader][skillName]["Item"]=Link;
1486 structProf[skillLineName][skillHeader][skillName]["Tooltip"]=GetCraftDescription(itemIndex);
1487 if(rpgoCPpref["reagenthtml"]) then
1488 reagents="";
1489 else
1490 reagents={};
1491 end
1492 for reagentIndex=1,numReagents,1 do
1493 local reagentName,reagentTexture,reagentCount,playerReagentCount=GetCraftReagentInfo(itemIndex,reagentIndex);
1494 if(not reagentTexture) then reagentTexture=""; end
1495 if(not reagentName) then reagentName=UNKNOWN; reagentsUnknown=1; end
1496 if(rpgoCPpref["reagenthtml"]) then
1497 if(reagentIndex==numReagents) then
1498 reagents=reagents .. reagentName .. " x" .. reagentCount;
1499 else
1500 reagents=reagents .. reagentName .. " x" .. reagentCount .. "<br>";
1501 end
1502 else
1503 local _,itemID,_ = rpgo_GetItemID(GetCraftReagentItemLink(itemIndex,reagentIndex));
1504 reagents[reagentIndex]={};
1505 reagents[reagentIndex]["Name"]=reagentName;
1506 reagents[reagentIndex]["Count"]=reagentCount;
1507 reagents[reagentIndex]["itemID"]=itemID;
1508 end
1509 end
1510 structProf[skillLineName][skillHeader][skillName]["Reagents"]=reagents;
1511 rpgoCPstate["Professions"][skillLineName]=rpgoCPstate["Professions"][skillLineName]+1;
1512 end
1513 end
1514 if(rpgoCPstate["Professions"][skillLineName]==0) then
1515 _skillError=1;
1516 structProf[skillLineName]=TradeSkillTemp;
1517 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": "..skillLineName..rpgo_ColorizeMsg(rpgoColorRed," not scanned, rescanning or open again"));
1518 rpgoCPcraft:Show();
1519 elseif(reagentsUnknown) then
1520 _skillError=1;
1521 structProf[skillLineName]=TradeSkillTemp;
1522 rpgoCPstate["Professions"][skillLineName]=0;
1523 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": "..skillLineName..rpgo_ColorizeMsg(rpgoColorRed," reagents not scanned, rescanning or open again"));
1524 rpgoCPcraft:Show();
1525 else
1526 if(_skillError) then
1527 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": "..skillLineName.." rescanned successfully");
1528 _skillError=nil;
1529 end
1530 rpgoCPcraft:Hide();
1531 end
1532 TradeSkillTemp=nil;
1533 end
1534 rpgoCP_TidyProfessions();
1535 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
1536 myProfile[rpgoCPserver][rpgoCPplayer]["Professions"]=nil;
1537 rpgoCPstate["Professions"]={};
1538 end
1539 end
1540  
1541 function rpgoCP_TidyProfessions()
1542 if(rpgoCPstate["_loaded"]) then
1543 for skillName,_ in myProfile[rpgoCPserver][rpgoCPplayer]["Professions"] do
1544 if(not rpgoCPstate["_skills"][skillName]) then
1545 myProfile[rpgoCPserver][rpgoCPplayer]["Professions"][skillName]=nil;
1546 end
1547 end
1548 end
1549 end
1550  
1551 function rpgoCP_GetSpellBook()
1552 if(rpgoCPpref["scan"]["spells"]) then
1553 if ( not myProfile[rpgoCPserver][rpgoCPplayer]["SpellBook"] ) then
1554 myProfile[rpgoCPserver][rpgoCPplayer]["SpellBook"]={};
1555 end
1556 local structSpell=myProfile[rpgoCPserver][rpgoCPplayer]["SpellBook"];
1557 for spelltab=1,GetNumSpellTabs(),1 do
1558 local spelltabname,spelltabtexture,offset,numSpells=GetSpellTabInfo(spelltab);
1559 if(not rpgoCPstate["SpellBook"][spelltabname] or rpgoCPstate["SpellBook"][spelltabname]~=numSpells) then
1560 if ( not structSpell[spelltabname] ) then
1561 structSpell[spelltabname]={};
1562 end
1563 structSpell[spelltabname]["Texture"]=spelltabtexture;
1564 if ( not structSpell[spelltabname]["Spells"] ) then
1565 structSpell[spelltabname]["Spells"]={};
1566 end
1567 rpgoCPstate["SpellBook"][spelltabname]=0;
1568 for spellId=offset + 1,numSpells + offset,1 do
1569 spellName,spellRank=GetSpellName( spellId,BOOKTYPE_SPELL );
1570 spellTexture=GetSpellTexture( spellId,spelltab );
1571 if ( not structSpell[spelltabname]["Spells"][spellName] ) then
1572 structSpell[spelltabname]["Spells"][spellName]={};
1573 end
1574 structSpell[spelltabname]["Spells"][spellName]["Rank"]=spellRank;
1575 structSpell[spelltabname]["Spells"][spellName]["Texture"]=spellTexture;
1576 rpgoCPtooltip:SetSpell(spellId,BOOKTYPE_SPELL);
1577 structSpell[spelltabname]["Spells"][spellName]["Tooltip"]=rpgo_TooltipScan();
1578 rpgoCPstate["SpellBook"][spelltabname]=rpgoCPstate["SpellBook"][spelltabname]+1;
1579 end
1580 structSpell[spelltabname]["Count"]=numSpells;
1581 end
1582 end
1583 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
1584 myProfile[rpgoCPserver][rpgoCPplayer]["SpellBook"]=nil;
1585 rpgoCPstate["SpellBook"]={};
1586 end
1587 end
1588  
1589 function rpgoCP_ScanPetInit(name)
1590 if(not myProfile[rpgoCPserver][rpgoCPplayer]["Pets"]) then
1591 myProfile[rpgoCPserver][rpgoCPplayer]["Pets"]={};
1592 end
1593 if(not myProfile[rpgoCPserver][rpgoCPplayer]["Pets"][name]) then
1594 myProfile[rpgoCPserver][rpgoCPplayer]["Pets"][name]={};
1595 end
1596 end
1597  
1598 function rpgoCP_ScanPetStable()
1599 if(rpgoCPpref["scan"]["pet"] and (rpgoCPclass=="HUNTER" and UnitLevel("player")>9)) then
1600 local structPets;
1601 for petIndex=0,GetNumStableSlots(),1 do
1602 local petIcon,petName,petLevel,petType,petLoyalty=GetStablePetInfo(petIndex);
1603 if(petName) then
1604 rpgoCP_ScanPetInit(petName);
1605 structPets=myProfile[rpgoCPserver][rpgoCPplayer]["Pets"];
1606 structPets[petName]["Slot"]=petIndex;
1607 structPets[petName]["Icon"]=petIcon;
1608 structPets[petName]["Name"]=petName;
1609 structPets[petName]["Level"]=petLevel;
1610 structPets[petName]["Type"]=petType;
1611 structPets[petName]["Loyalty"]=petLoyalty;
1612 end
1613 rpgoCPstate["Stable"][petIndex]=petName;
1614 end
1615 rpgoCP_ScanPetInfo();
1616 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
1617 myProfile[rpgoCPserver][rpgoCPplayer]["Pets"]=nil;
1618 rpgoCPstate["Pets"]={};
1619 end
1620 end
1621  
1622 function rpgoCP_ScanPetInfo()
1623 if(rpgoCPpref["scan"]["pet"]) then
1624 if(HasPetUI()) then
1625 petName=UnitName("pet");
1626 rpgoCP_ScanPetInit(petName);
1627 local structPet=myProfile[rpgoCPserver][rpgoCPplayer]["Pets"][petName];
1628 structPet["Name"]=petName;
1629 structPet["Type"]=UnitCreatureFamily("pet");
1630 structPet["TalentPoints"],structPet["TalentPointsUsed"]=GetPetTrainingPoints();
1631 local currXP,nextXP=GetPetExperience();
1632 structPet["Experience"]=currXP..":"..nextXP;
1633  
1634 rpgoCP_GetStats(structPet,"pet");
1635 rpgoCP_GetAttackRating(structPet,"pet");
1636 rpgoCP_GetBuffs(structPet,"pet");
1637 rpgoCP_GetPetSpellBook();
1638 rpgoCPstate["Pets"][petName]=1;
1639 end
1640 elseif(myProfile[rpgoCPserver][rpgoCPplayer]) then
1641 myProfile[rpgoCPserver][rpgoCPplayer]["Pets"]=nil;
1642 rpgoCPstate["Pets"]={};
1643 end
1644 end
1645  
1646 function rpgoCP_GetPetSpellBook()
1647 if(rpgoCPpref["scan"]["spells"]) then
1648 numSpells,_=HasPetSpells();
1649 petName=UnitName("pet");
1650 if(numSpells) then
1651 rpgoCP_ScanPetInit(petName);
1652 if (not myProfile[rpgoCPserver][rpgoCPplayer]["Pets"][petName]["SpellBook"]) then
1653 myProfile[rpgoCPserver][rpgoCPplayer]["Pets"][petName]["SpellBook"]={};
1654 end
1655 local structPetSpell=myProfile[rpgoCPserver][rpgoCPplayer]["Pets"][petName]["SpellBook"];
1656 for petSpellId=1,numSpells,1 do
1657 local spellName,spellRank=GetSpellName(petSpellId,BOOKTYPE_PET);
1658 local spellTexture=GetSpellTexture(petSpellId,BOOKTYPE_PET);
1659 if (spellName==nil) then break; end
1660 if (not structPetSpell["Spells"]) then
1661 structPetSpell["Spells"]={};
1662 end
1663 structPetSpell["Spells"][spellName]={};
1664 structPetSpell["Spells"][spellName]["Rank"]=spellRank;
1665 structPetSpell["Spells"][spellName]["Texture"]=spellTexture;
1666 structPetSpell["Count"]=petSpellId;
1667 end
1668 rpgoCPstate["PetSpell"][petName]=numSpells;
1669 end
1670 end
1671 end
1672  
1673 function rpgoCP_TradeTimer(event,arg1)
1674 local skill;
1675 if(not rpgoCPstate["ProfTimer"]) then rpgoCPstate["ProfTimer"]={}; end
1676 if(event=="CRAFT_UPDATE") then
1677 skill=GetCraftDisplaySkillLine();
1678 elseif(event=="TRADE_SKILL_UPDATE") then
1679 skill=GetTradeSkillLine();
1680 end
1681 if(skill) then
1682 if( (not arg1) or (not rpgoCPstate["ProfTimer"][skill]) ) then
1683 rpgoCPstate["ProfTimer"][skill]=0;
1684 elseif(tonumber(arg1)) then
1685 rpgoCPstate["ProfTimer"][skill]=rpgoCPstate["ProfTimer"][skill]+arg1;
1686 end
1687 if(rpgoCPstate["ProfTimer"][skill] > 1) then
1688 rpgoCPstate["ProfTimer"][skill]=nil;
1689 rpgoCP_EventHandler(string.gsub(event,'_UPDATE','_SHOW'),arg1);
1690 end
1691 end
1692 end
1693  
1694 function rpgoCP_ScanMCattune(arg1,arg2)
1695 if(not myProfile[rpgoCPserver][rpgoCPplayer]["Info"]) then
1696 myProfile[rpgoCPserver][rpgoCPplayer]["Info"]={};
1697 end
1698 end
1699  
1700 function rpgoCP_UpdatePlayed(arg1,arg2)
1701 if(arg1 and arg2) then timePlayed=arg1; timeLevelPlayed=arg2; end
1702 if(rpgoCPstate["_loaded"] and myProfile[rpgoCPserver][rpgoCPplayer]) then
1703 myProfile[rpgoCPserver][rpgoCPplayer]["TimePlayed"]=timePlayed;
1704 myProfile[rpgoCPserver][rpgoCPplayer]["TimeLevelPlayed"]=timeLevelPlayed;
1705 end
1706 end
1707  
1708 function rpgoCP_UpdateZone()
1709 myProfile[rpgoCPserver][rpgoCPplayer]["Zone"]=GetZoneText();
1710 myProfile[rpgoCPserver][rpgoCPplayer]["SubZone"]=GetSubZoneText();
1711 end
1712  
1713 function rpgoCP_UpdateBagScan(arg1)
1714 if(arg1 and rpgoCPstate["Bag"][arg1]) then
1715 local x=0;
1716 rpgoCPstate["Bag"][arg1]=nil;
1717 for i,j in rpgoCPstate["Bag"] do x=1;break; end
1718 if(x==0) then
1719 rpgoCPstate["_bagevent"]=nil;
1720 this:UnregisterEvent("BAG_UPDATE");
1721 end
1722 end
1723 end
1724  
1725 function rpgoCP_UpdateDate()
1726 myProfile[rpgoCPserver][rpgoCPplayer]["Date"]=date();
1727 myProfile[rpgoCPserver][rpgoCPplayer]["DateUTC"]=date("!%m/%d/%y %H:%M:%S");
1728 local currHour,currMinute=GetGameTime();
1729 myProfile[rpgoCPserver][rpgoCPplayer]["ServerTime"]=format("%02d:%02d",currHour,currMinute);
1730 --toRemove
1731 myProfile[rpgoCPserver][rpgoCPplayer]["DateUpdated"]=myProfile[rpgoCPserver][rpgoCPplayer]["Date"];
1732 end
1733  
1734 --[[//////////////////////////////////////////////
1735 -- general functions
1736 -- ////////////////////////////////////////////]]
1737 function rpgoCP_ScanItemInfo(itemlink,itemtexture,itemcount,itemtooltip)
1738 local itemColor,itemLink,itemID,itemName=rpgo_GetItemInfo(itemlink);
1739 --local itemName,itemLink,itemRarity,itemMinLeveL,itemType,itemSubType,itemStackCount,itemEquipLoc=GetItemInfo(itemLink);
1740 local itemBlock={};
1741 itemBlock["Name"]=itemName;
1742 itemBlock["Item"]=itemID;
1743 itemBlock["Color"]=itemColor;
1744 itemBlock["Quantity"]=itemcount;
1745 itemBlock["Texture"]=itemtexture;
1746 itemBlock["Tooltip"]=itemtooltip;
1747 return itemBlock;
1748 end
1749  
1750 function rpgoCP_ScanBagInfo(bagindex,baglink,bagtexture,bagtooltip)
1751 local itemColor,bagLink,itemID,itemName=rpgo_GetItemInfo(baglink);
1752 local itemName,itemLink,itemRarity,itemMinLeveL,itemType,itemSubType,itemStackCount,itemEquipLoc=GetItemInfo(bagLink);
1753 local bagBlock={};
1754 bagBlock["Name"]=GetBagName(bagindex);
1755 bagBlock["Slots"]=rpgoCP_GetContainerNumSlots(bagindex);
1756 bagBlock["Item"]=itemID;
1757 bagBlock["Color"]=itemColor;
1758 bagBlock["Texture"]=bagtexture;
1759 bagBlock["Tooltip"]=bagtooltip;
1760 bagContainerText=itemType;
1761 return bagBlock;
1762 end
1763  
1764 function rpgoCP_GetBagKey(bag)
1765 local key,slot;
1766 key=0;
1767 for slot=1,rpgoCP_GetContainerNumSlots(bag) do
1768 local _,itemCount,_,quality=GetContainerItemInfo(bag,slot);
1769 if(itemCount and quality) then key=key+rpgoCP_CalcItemKey(itemCount,quality,slot); end
1770 end
1771 return(key);
1772 end
1773  
1774 function rpgoCP_GetEQKey()
1775 local link,id,index,key;
1776 key=0;
1777 for index in UnitSlots do
1778 id=nil;
1779 if(index==0) then
1780 link=GetInventoryItemTexture("player",index);
1781 if(link) then id=1; end
1782 else
1783 link=GetInventoryItemLink("player",index);
1784 if(link) then _,id,_=rpgo_GetItemID(link); end
1785 end
1786 if(id) then key=key+id; end
1787 end
1788 return(key);
1789 end
1790  
1791 function rpgoCP_CalcItemKey(c,q,s) return((c*q)+s); end
1792  
1793 --[function] msg:string
1794 function rpgoCP_debug(msg)
1795 if (rpgoCPpref and rpgoCPpref["debug"]) then
1796 if(rpgoDebug) then rpgoDebug(rpgoCP_ABBR,msg);
1797 else rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": ".."[" .. msg .. "]",1,0,0); end end
1798 end
1799  
1800 --[function] rpgoCP_myAddons
1801 function rpgoCP_myAddons()
1802 if(myAddOnsFrame_Register) then
1803 rpgoCP_debug("myAddons: init");
1804 local rpgoAddonsInfoCP={
1805 name=rpgoCP_TITLE,
1806 version=rpgoCP_VERSION,
1807 releaseDate=rpgoCP_DATE,
1808 author=rpgoCP_AUTHOR,
1809 email=rpgoCP_EMAIL,
1810 website=rpgoCP_URL,
1811 category=MYADDONS_CATEGORY_OTHERS,
1812 frame="rpgoCPframe",
1813 };
1814 local rpgoAddonsUsageCP={};
1815 if(rpgoCP_Usage) then
1816 table.insert(rpgoAddonsUsageCP,rpgoCP_PROVIDER.."-"..rpgoCP_ABBR.." Usage (slash commands)");
1817 for index=1,table.getn(rpgoCP_Usage),1 do
1818 table.insert(rpgoAddonsUsageCP,rpgo_AssempleHelp(rpgoCP_Usage[index]));
1819 end
1820 end
1821 local rpgoAddonsHelpCP={
1822 "CharacterProfiler is an addon that extracts character info including stats, equipment, inventory, trade skills, spellbook. This information can then be uploaded to your website to display your character info.\n\n"..table.concat(rpgoAddonsUsageCP,"\n"),
1823 };
1824 myAddOnsFrame_Register(rpgoAddonsInfoCP,rpgoAddonsHelpCP);
1825 end
1826 end
1827  
1828 --[[// general rpgo functions: unit
1829 -- ////////////////////////////////////////////]]
1830 --[function] arg1:unit
1831 function rpgo_UnitSexString(arg1)
1832 local version,buildnum,builddate = GetBuildInfo();
1833 local _,_,vVersion,vMajor,vMinor=string.find(version,"(%d+).(%d+).(%d+)");
1834 vVersion=tonumber(vVersion);
1835 vMajor=tonumber(vMajor);
1836 if ( vVersion == 1 and vMajor >= 11 ) then
1837 local UnitSexLabel={UNKNOWN,MALE,FEMALE};
1838 return UnitSexLabel[UnitSex(arg1)];
1839 else
1840 local UnitSexLabel={MALE,FEMALE,UNKNOWN};
1841 return UnitSexLabel[UnitSex(arg1)+1];
1842 end
1843 return UNKNOWN;
1844 end
1845  
1846  
1847 --[function] rpgo_GetMoney()
1848 function rpgo_GetMoney()
1849 local money=GetMoney();
1850 local gold,silver,copper;
1851 local CopperPerGold=COPPER_PER_SILVER * SILVER_PER_GOLD;
1852 gold=floor(money/CopperPerGold);
1853 money=mod(money,CopperPerGold);
1854 silver=floor(money/COPPER_PER_SILVER);
1855 money=mod(money,CopperPerGold);
1856 copper=mod(money,COPPER_PER_SILVER);
1857 return gold,silver,copper;
1858 end
1859  
1860 --[[// general rpgo functions: item
1861 -- ////////////////////////////////////////////]]
1862 --[function] itemlink
1863 function rpgo_GetItemID(itemlink)
1864 local item,id,rid;
1865 if(itemlink) then _,_,item,id,rid=string.find(itemlink,"item:((%d+):%d+:(%d+):%d+)|"); end
1866 return item,id,rid;
1867 end
1868 --[function] itemlink
1869 function rpgo_GetItemInfo(itemlink)
1870 local c,l,i,n;
1871 if(itemlink) then _,_,c,l,i,n=string.find(itemlink,"|c(%x+)|H(item:(%d+:%d+:%d+:%d+))|h%[(.-)%]|h|r"); end
1872 return c,l,i,n;
1873 end
1874 --[function] tooltip iteminfo
1875 function rpgo_GetItemInfoTT(tooltipName)
1876 local nTT,cTT,r,g,b;
1877 if(tooltipName==nil) then tooltipName="rpgoCPtooltip"; end
1878 ttText=getglobal(tooltipName.."TextLeft1");
1879 nTT=ttText:GetText();
1880 if(nTT) then r,g,b=ttText:GetTextColor(); cTT=string.format("ff%x%x%x",r*256,g*256,b*256); end
1881 return nTT,cTT;
1882 end
1883  
1884 --[[// general rpgo functions: tooltip
1885 -- ////////////////////////////////////////////]]
1886 --[function] tooltipName
1887 function rpgo_TooltipScan(tooltipName)
1888 if(tooltipName==nil) then tooltipName=rpgoCP_TOOLTIP; end
1889 tooltipFrame=getglobal(tooltipName);
1890 local ttTextScan={};
1891 for idx=1,tooltipFrame:NumLines() do
1892 local ttTextBuff=nil;
1893 ttText=getglobal(tooltipName.."TextLeft"..idx);
1894 if(ttText and ttText:IsShown()) then
1895 ttTextBuff=ttText:GetText();
1896 if (ttText) then
1897 ttTextBuff=string.gsub(ttTextBuff,"\n","<br>");
1898 ttTextBuff=string.gsub(ttTextBuff,"\r","");
1899 end
1900 end
1901 ttText=getglobal(tooltipName.."TextRight"..idx);
1902 if(ttText and ttText:IsShown()) then
1903 if (ttText) then
1904 ttTextBuff=ttTextBuff.."\t"..ttText:GetText();
1905 end
1906 end
1907 if(ttTextBuff) then table.insert(ttTextScan,ttTextBuff); end
1908 end
1909 tooltipFrame:ClearLines();
1910 if(rpgoCPpref["tooltipshtml"]) then return table.concat(ttTextScan,"<br>");
1911 else return ttTextScan; end
1912 end
1913  
1914 --[[//////////////////////////////////////////////
1915 -- general rpgo functions (shared)
1916 -- ////////////////////////////////////////////]]
1917 --[function] str
1918 function rpgo_Str2Ary(str)
1919 local tab={n=0};
1920 local function S2Ahelper(word) table.insert(tab,word) end
1921 if not string.find(string.gsub(str,"%w+",S2Ahelper),"%S") then return tab end end
1922 --[function] str
1923 function rpgo_Str2Abbr(str)
1924 local abbr='';
1925 local function S2Ahelper(word) abbr=abbr..string.sub(word,1,1) end
1926 if not string.find(string.gsub(str,"%w+",S2Ahelper),"%S") then return abbr end end
1927 --[function] arg:key1,key2,val1,val2
1928 function rpgo_Arg2Tab(...)
1929 local tab={};
1930 local split=floor(arg.n/2);
1931 for i=1,split,1 do tab[arg[i]]=arg[i+split]; end
1932 return tab; end
1933 --[function] arg:arg1,arg2...
1934 function rpgo_Arg2Ary(...)
1935 local tab={};
1936 for i=1,arg.n,1 do tab[i]=arg[i]; end
1937 return tab; end
1938 --[function]
1939 function rpgo_SetTooltip()
1940 GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT"); end
1941 --[function] pref
1942 function rpgo_LiteScan(pref)
1943 if(not pref) then return false; end
1944 if(pref) then
1945 local msg;
1946 if(UnitInRaid("player")) then msg="raid";
1947 elseif(rpgo_IsInInstance()) then msg="instance"; end
1948 if(msg) then
1949 if(not rpgoCPstate["_litemsg"]) then
1950 rpgoCPstate["_litemsg"]=true;
1951 rpgo_VerboseMsg(rpgo_ColorizeTitle(rpgoCP_PROVIDER,rpgoCP_ABBR)..": scan skipped: character is in "..msg);
1952 end return 1; end end
1953 return nil; end
1954 --[function]
1955 function rpgo_IsInInstance()
1956 SetMapToCurrentZone();
1957 a,b=GetPlayerMapPosition("player");
1958 if(a==0 and b==0) then return 1; else return nil; end end
1959 --[function] msg
1960 function rpgo_VerboseMsg(msg)
1961 DEFAULT_CHAT_FRAME:AddMessage(msg); end
1962 --[function] pref
1963 function rpgo_ColorizePref(pref)
1964 if(pref) then return rpgo_ColorizeMsg(rpgoColorGreen,"on|r")
1965 else return rpgo_ColorizeMsg(rpgoColorRed,"off|r") end end
1966 --[function] helpline
1967 function rpgo_AssempleHelp(helpline)
1968 local msg; if(type(helpline)=="table") then
1969 msg=" |cff"..rpgoColorTitle..helpline[1].."|r "..helpline[2];
1970 if(helpline[3]) then msg=msg.."\n "..helpline[3]; end
1971 else msg=helpline; end
1972 return msg; end
1973 --[function] structPref,structDefault
1974 function rpgo_InitPref(structPref,structDefault)
1975 for pref,val in structDefault do
1976 if(type(structDefault[pref])=="table") then if(not structPref[pref]) then structPref[pref]={}; end rpgo_InitPref(structPref[pref],structDefault[pref]);
1977 elseif(structPref[pref] == nil) then structPref[pref]=val; end end end
1978 --[function] structPref,structDefault
1979 function rpgo_TidyPref(structPref,structDefault)
1980 for pref,val in structPref do
1981 if(type(structDefault[pref])=="table") then rpgo_TidyPref(structPref[pref],structDefault[pref]);
1982 elseif(structDefault[pref] == nil) then structPref[pref]=nil; end end end
1983 --[function] structPref
1984 function rpgoCP_ConvertPrefSub(structPref,structPrefConv)
1985 local valNew,prefNew;
1986 for pref,val in structPref do
1987 prefNew=strlower(pref);
1988 if(type(structPref[pref])=="table") then
1989 if(not structPrefConv[pref]) then structPrefConv[pref]={}; end
1990 rpgoCP_ConvertPrefSub(structPref[pref],structPrefConv[pref]);
1991 structPrefConv[prefNew]=structPrefConv[pref];
1992 structPrefConv[pref]=nil;
1993 else
1994 if(val==1) then valNew=true;
1995 elseif(val==0) then valNew=false; end
1996 structPrefConv[prefNew]=valNew;
1997 end
1998 end
1999 end
2000 --[function] provider,title
2001 function rpgo_ColorizeTitle(provider,title)
2002 if(provider and title) then return rpgo_ColorizeMsg(rpgoColorTitle,provider.."-"..title); end end
2003 --[function] color,msg
2004 function rpgo_ColorizeMsg(color,msg)
2005 if(color and msg) then return "|cff"..color..msg.."|r"; end end