annotate CensusPlus.lua @ 8:c4f065a2b520

push error resolve
author EmFor
date Fri, 10 Dec 2010 17:18:56 +0100
parents 10c85be19b56
children 663f782bd903
rev   line source
EmFor@0 1 --[[
EmFor@0 2 CensusPlus for World of Warcraft(tm).
EmFor@0 3
EmFor@0 4 Copyright 2005 - 2007 Cooper Sellers and WarcraftRealms.com
EmFor@0 5
EmFor@0 6 License:
EmFor@0 7 This program is free software; you can redistribute it and/or
EmFor@0 8 modify it under the terms of the GNU General Public License
EmFor@0 9 as published by the Free Software Foundation; either version 2
EmFor@0 10 of the License, or (at your option) any later version.
EmFor@0 11
EmFor@0 12 This program is distributed in the hope that it will be useful,
EmFor@0 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
EmFor@0 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
EmFor@0 15 GNU General Public License for more details.
EmFor@0 16
EmFor@0 17 You should have received a copy of the GNU General Public License
EmFor@0 18 along with this program(see GLP.txt); if not, write to the Free Software
EmFor@0 19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
EmFor@0 20 ]]
EmFor@0 21
EmFor@0 22
EmFor@0 23 ------------------------------------------------------------------------------------
EmFor@0 24 --
EmFor@0 25 -- CensusPlus
EmFor@0 26 -- A WoW UI customization by Cooper Sellers
EmFor@0 27 --
EmFor@0 28 --
EmFor@0 29 ------------------------------------------------------------------------------------
EmFor@0 30
EmFor@0 31 ----------------------------------------------------------------------------------
EmFor@0 32 --
EmFor@0 33 -- EURO vs US localization problem workaround for common server names
EmFor@0 34 --
EmFor@0 35 ---------------------------------------------------------------------------------
EmFor@6 36 local g_InterfaceVersion = 40000;
EmFor@0 37 g_CensusPlusLocale = "N/A"; -- Must read either US or EU
EmFor@0 38 g_CensusPlusTZOffset = -999;
EmFor@0 39 local g_LocaleSet = false;
EmFor@0 40 local g_TZWarningSent = false;
EmFor@0 41
EmFor@0 42
EmFor@0 43 ----------------------------------------------------------------------------------
EmFor@0 44 --
EmFor@0 45 -- Constants
EmFor@0 46 --rm
EmFor@6 47 -- Special guild to search
EmFor@6 48 --local CensusPlus_MYGUILD = "The Last Journey";
EmFor@6 49 local CensusPlus_MYGUILD = "Worgengrauen";
EmFor@0 50 ---------------------------------------------------------------------------------
EmFor@6 51 local CensusPlus_VERSION = "4.3.2"; -- version
EmFor@0 52 local CensusPlus_MAXBARHEIGHT = 128; -- Length of blue bars
EmFor@0 53 local CensusPlus_NUMGUILDBUTTONS = 10; -- How many guild buttons are on the UI?
EmFor@6 54 local MAX_CHARACTER_LEVEL = 85; -- Maximum level a PC can attain
EmFor@0 55 --rm
EmFor@0 56 local MAX_LEVEL_DISPLAY = 255; -- Maximum level a PC can attain
EmFor@6 57 local MAX_WHO_RESULTS = 48; -- Maximum number of who results the server will return
EmFor@0 58 CensusPlus_GUILDBUTTONSIZEY = 16;
EmFor@0 59 local CensusPlus_UPDATEDELAY = 5; -- Delay time between /who messages
EmFor@0 60 local CP_MAX_TIMES = 50;
EmFor@0 61
EmFor@0 62 local g_ServerPrefix = ""; -- US VERSION!!
EmFor@0 63 --local g_ServerPrefix = "EU-"; -- EU VERSION!!
EmFor@0 64
EmFor@0 65 local wholib
EmFor@0 66 ----------------------------------------------------------------------------------
EmFor@0 67 --
EmFor@0 68 -- Print a string to the chat frame
EmFor@0 69 -- msg - message to print
EmFor@0 70 --
EmFor@0 71 ---------------------------------------------------------------------------------
EmFor@0 72 function CensusPlus_Msg(msg)
EmFor@0 73 if( msg == nil ) then
EmFor@0 74 msg = " NIL ";
EmFor@0 75 end
EmFor@0 76 ChatFrame1:AddMessage("Census+: "..msg, 1.0, 1.0, 0.5);
EmFor@0 77 end
EmFor@0 78
EmFor@0 79 function CensusPlus_WhoMsg(msg)
EmFor@0 80 if( msg == nil ) then
EmFor@0 81 msg = " NIL ";
EmFor@0 82 end
EmFor@0 83 ChatFrame1:AddMessage("Census+ Who: "..msg, 0.8, 0.8, 0.1);
EmFor@0 84 end
EmFor@0 85
EmFor@0 86 local function CensusPlus_Msg2( msg )
EmFor@0 87 if( msg == nil ) then
EmFor@0 88 msg = " NIL ";
EmFor@0 89 end
EmFor@0 90 ChatFrame2:AddMessage("Census+: "..msg, 0.5, 1.0, 1.0);
EmFor@0 91 end
EmFor@0 92
EmFor@0 93 ----------------------------------------------------------------------------------
EmFor@0 94 --
EmFor@0 95 -- Global scope variables
EmFor@0 96 --
EmFor@0 97 ---------------------------------------------------------------------------------
EmFor@0 98 CensusPlus_Database = {}; -- Database of all CensusPlus results
EmFor@0 99 CensusPlus_BGInfo = {}; -- Battleground info
EmFor@0 100 CensusPlus_PerCharInfo = {}; -- Per character settings
EmFor@0 101 CensusPlus_Unhandled = {};
EmFor@0 102 local g_TrackUnhandled = false;
EmFor@0 103
EmFor@0 104 ----------------------------------------------------------------------------------
EmFor@0 105 --
EmFor@0 106 -- File scope variables
EmFor@0 107 --
EmFor@0 108 ---------------------------------------------------------------------------------
EmFor@0 109 local g_CensusPlusInitialized; -- Is CensusPlus initialized?
EmFor@0 110 local g_JobQueue = {}; -- The queue of pending jobs
EmFor@0 111 local g_CurrentJob = {}; -- Current job being executed
EmFor@0 112 g_IsCensusPlusInProgress = false; -- Is a CensusPlus in progress?
EmFor@0 113 g_CensusPlusPaused = false; -- Is CensusPlus in progress paused?
EmFor@0 114 g_CensusPlusManuallyPaused = false; -- Is CensusPlus in progress manually paused?
EmFor@0 115 local g_WhoAutoClose = 0; -- AutoClose who window?
EmFor@0 116
EmFor@0 117 local g_NumNewCharacters = 0; -- How many new characters found this CensusPlus
EmFor@0 118 local g_NumUpdatedCharacters = 0; -- How many characters were updated during this CensusPlus
EmFor@0 119
EmFor@0 120 local g_MobXPByLevel = {}; -- XP earned for killing
EmFor@0 121 local g_CharacterXPByLevel = {}; -- XP required to advance through the given level
EmFor@0 122 local g_TotalCharacterXPPerLevel = {}; -- Total XP required to attain the given level
EmFor@0 123
EmFor@0 124 CensusPlus_Guilds = {}; -- All known guild
EmFor@0 125
EmFor@0 126 local g_TotalCharacterXP = 0; -- Total character XP for currently selected search
EmFor@0 127 local g_TotalCount = 0; -- Total number of characters which meet search criteria
EmFor@0 128 local g_RaceCount = {}; -- Totals for each race given search criteria
EmFor@0 129 local g_ClassCount = {}; -- Totals for each class given search criteria
EmFor@0 130 local g_LevelCount = {}; -- Totals for each level given search criteria
EmFor@0 131 local g_TempCount = {};
EmFor@0 132 local g_TempZoneCount = {};
EmFor@0 133
EmFor@0 134 g_GuildSelected = nil; -- Search criteria: Currently selected guild, 0 indicates none
EmFor@0 135 g_RaceSelected = 0; -- Search criteria: Currently selected race, 0 indicates none
EmFor@0 136 g_ClassSelected = 0; -- Search criteria: Currently selected class, 0 indicates none
EmFor@0 137 g_LevelSelected = 0;
EmFor@0 138
EmFor@0 139 local g_LastOnUpdateTime = 0; -- Last time OnUpdate was called
EmFor@0 140 local g_WaitingForWhoUpdate = false; -- Are we waiting for a who update event?
EmFor@0 141
EmFor@0 142 local g_WhoAttempts = 0; -- Counter for detecting stuck who results
EmFor@0 143 local g_MiniOnStart = 1; -- Flag to have the mini-censusP displayed on startup
EmFor@0 144
EmFor@0 145 local g_CompleteCensusStarted = false; -- Flag for counter
EmFor@0 146 local g_TakeHour = 0; -- Our timing hour
EmFor@0 147 local g_TimeDatabase = {}; -- Time database
EmFor@0 148 local g_ResetHour = true; -- Rest hour
EmFor@0 149 local g_VariablesLoaded = false; -- flag to tell us if vars are loaded
EmFor@0 150 local g_FirstRun = true;
EmFor@0 151 local g_LastCensusRun = time() - 1500; -- timer used if auto census is turned on
EmFor@0 152
EmFor@0 153 local g_Pre_FriendsFrameOnHideOverride = nil; -- override for friend's frame to stop the close window sound
EmFor@0 154 local g_Pre_FriendsFrameOnShowOverride = nil; -- override for friend's frame to stop the close window sound
EmFor@0 155 local g_Pre_WhoList_UpdateOverride = nil; -- override for friend's frame to stop the close window sound
EmFor@0 156 local g_Pre_WhoHandler = nil; -- override for submiting a who
EmFor@0 157 local CP_Pre_OnEvent = nil;
EmFor@0 158 local g_Pre_FriendsFrame_Update = nil;
EmFor@0 159 local g_SetItemRef_Override = nil;
EmFor@0 160 local CP_updatingGuild = nil;
EmFor@0 161 g_CensusPlusLastTarget = nil;
EmFor@0 162 g_CensusPlusLastTargetName = nil;
EmFor@0 163 local g_CurrentlyInBG = false;
EmFor@0 164 local g_CurrentlyInBG_Msg = false;
EmFor@0 165 local g_InternalSearchName = nil;
EmFor@0 166 local g_InternalSearchLevel = nil;
EmFor@0 167 local g_InternalSearchCount = 0;
EmFor@0 168 CensusPlus_EnableProfiling = false;
EmFor@0 169 local g_CensusPlus_StartTime = 0;
EmFor@0 170 local g_CensusWhoOverrideMsg = nil;
EmFor@0 171 local g_WaitingForOverrideUpdate = false;
EmFor@0 172 local g_ProblematicMessageShown = false;
EmFor@0 173 local g_WhoLibLoaded = false;
EmFor@0 174 local g_PratLoaded = false;
EmFor@0 175 local g_WhoLibSubvert = nil;
EmFor@0 176 local g_WhoLibSendWhoSubvert = nil;
EmFor@0 177 local g_whoLibResultSubvert = nil;
EmFor@0 178 local g_WhoLibChatSubvert = nil;
EmFor@0 179 local g_WhoLibAskWhoSubvert = nil;
EmFor@0 180
EmFor@0 181 -- Battleground info
EmFor@0 182 CENSUSPLUS_CURRENT_BATTLEFIELD_QUEUES = {};
EmFor@0 183
EmFor@0 184 local g_AccumulatedPruneData = {};
EmFor@0 185
EmFor@0 186 g_RaceClassList = { }; -- Used to pick the right icon
EmFor@0 187 g_RaceClassList[CENSUSPlus_DRUID] = 10;
EmFor@0 188 g_RaceClassList[CENSUSPlus_HUNTER] = 11;
EmFor@0 189 g_RaceClassList[CENSUSPlus_MAGE] = 12;
EmFor@0 190 g_RaceClassList[CENSUSPlus_PRIEST] = 13;
EmFor@0 191 g_RaceClassList[CENSUSPlus_ROGUE] = 14;
EmFor@0 192 g_RaceClassList[CENSUSPlus_WARLOCK] = 15;
EmFor@0 193 g_RaceClassList[CENSUSPlus_WARRIOR] = 16;
EmFor@0 194 g_RaceClassList[CENSUSPlus_SHAMAN] = 17;
EmFor@0 195 g_RaceClassList[CENSUSPlus_PALADIN] = 18;
EmFor@0 196 g_RaceClassList[CENSUSPlus_DEATHKNIGHT] = 30;
EmFor@0 197
EmFor@0 198 g_RaceClassList[CENSUSPlus_DWARF] = 20;
EmFor@0 199 g_RaceClassList[CENSUSPlus_GNOME] = 21;
EmFor@0 200 g_RaceClassList[CENSUSPlus_HUMAN] = 22;
EmFor@0 201 g_RaceClassList[CENSUSPlus_NIGHTELF] = 23;
EmFor@0 202 g_RaceClassList[CENSUSPlus_ORC] = 24;
EmFor@0 203 g_RaceClassList[CENSUSPlus_TAUREN] = 25;
EmFor@0 204 g_RaceClassList[CENSUSPlus_TROLL] = 26;
EmFor@0 205 g_RaceClassList[CENSUSPlus_UNDEAD] = 27;
EmFor@0 206 g_RaceClassList[CENSUSPlus_DRAENEI] = 28;
EmFor@0 207 g_RaceClassList[CENSUSPlus_BLOODELF] = 29;
EmFor@6 208 g_RaceClassList[CENSUSPlus_WORGEN] = 31;
EmFor@6 209 g_RaceClassList[CENSUSPlus_GOBLIN] = 32;
EmFor@0 210
EmFor@0 211 g_TimeDatabase[CENSUSPlus_DRUID] = 0;
EmFor@0 212 g_TimeDatabase[CENSUSPlus_HUNTER] = 0;
EmFor@0 213 g_TimeDatabase[CENSUSPlus_MAGE] = 0;
EmFor@0 214 g_TimeDatabase[CENSUSPlus_PRIEST] = 0;
EmFor@0 215 g_TimeDatabase[CENSUSPlus_ROGUE] = 0;
EmFor@0 216 g_TimeDatabase[CENSUSPlus_WARLOCK] = 0;
EmFor@0 217 g_TimeDatabase[CENSUSPlus_WARRIOR] = 0;
EmFor@0 218 g_TimeDatabase[CENSUSPlus_SHAMAN] = 0;
EmFor@0 219 g_TimeDatabase[CENSUSPlus_PALADIN] = 0;
EmFor@0 220 g_TimeDatabase[CENSUSPlus_DEATHKNIGHT] = 0;
EmFor@0 221 g_TimeDatabase[CENSUSPlus_WarsongGulch] = 0;
EmFor@0 222 g_TimeDatabase[CENSUSPlus_AlteracValley] = 0;
EmFor@0 223 g_TimeDatabase[CENSUSPlus_ArathiBasin] = 0;
EmFor@0 224
EmFor@0 225 -- These two DO NOT need to be localized
EmFor@0 226 local CENSUSPlus_HORDE = "Horde";
EmFor@0 227 local CENSUSPlus_ALLIANCE = "Alliance";
EmFor@0 228
EmFor@0 229
EmFor@0 230 local g_FactionCheck = {};
EmFor@0 231 g_FactionCheck[CENSUSPlus_ORC] = CENSUSPlus_HORDE;
EmFor@0 232 g_FactionCheck[CENSUSPlus_TAUREN] = CENSUSPlus_HORDE;
EmFor@0 233 g_FactionCheck[CENSUSPlus_TROLL] = CENSUSPlus_HORDE;
EmFor@0 234 g_FactionCheck[CENSUSPlus_UNDEAD] = CENSUSPlus_HORDE;
EmFor@0 235 g_FactionCheck[CENSUSPlus_BLOODELF] = CENSUSPlus_HORDE;
EmFor@6 236 g_FactionCheck[CENSUSPlus_GOBLIN] = CENSUSPlus_HORDE;
EmFor@0 237
EmFor@0 238 g_FactionCheck[CENSUSPlus_DWARF] = CENSUSPlus_ALLIANCE;
EmFor@0 239 g_FactionCheck[CENSUSPlus_GNOME] = CENSUSPlus_ALLIANCE;
EmFor@0 240 g_FactionCheck[CENSUSPlus_HUMAN] = CENSUSPlus_ALLIANCE;
EmFor@0 241 g_FactionCheck[CENSUSPlus_NIGHTELF] = CENSUSPlus_ALLIANCE;
EmFor@0 242 g_FactionCheck[CENSUSPlus_DRAENEI] = CENSUSPlus_ALLIANCE;
EmFor@6 243 g_FactionCheck[CENSUSPlus_WORGEN] = CENSUSPlus_ALLIANCE;
EmFor@0 244 local g_ReturnedZero = false;
EmFor@0 245
EmFor@0 246 do
EmFor@0 247 -- HACK
EmFor@0 248 --[[
EmFor@0 249 seeing as Blizzard improperly coded GuildControlPopupFrame_OnEvent to mess up when GUILD_ROSTER_EVENT is dispatched,
EmFor@0 250 and there is no real harm in removing the handler entirely, that's what's happening. If and when Blizzard decides to fix it, this should be removed.
EmFor@0 251 Thanks to ckknight of wowace for this
EmFor@0 252 ]]
EmFor@6 253 -- GuildControlPopupFrame:SetScript("OnEvent", nil)
EmFor@0 254 end
EmFor@0 255
EmFor@0 256
EmFor@0 257 ----------------------------------------------------------------------------------
EmFor@0 258 --
EmFor@0 259 -- Set up confirmation boxes
EmFor@0 260 --
EmFor@0 261 ---------------------------------------------------------------------------------
EmFor@0 262 StaticPopupDialogs["CP_PURGE_CONFIRM"] = {
EmFor@0 263 text = CENSUSPlus_PURGE_LOCAL_CONFIRM,
EmFor@0 264 button1 = CENSUSPlus_YES,
EmFor@0 265 button2 = CENSUSPlus_NO,
EmFor@0 266 OnAccept = function()
EmFor@0 267 CensusPlus_DoPurge();
EmFor@0 268 end,
EmFor@0 269 sound = "levelup2",
EmFor@0 270 timeout = 0,
EmFor@0 271 whileDead = 1,
EmFor@0 272 hideOnEscape = 1,
EmFor@0 273 showAlert = 1
EmFor@0 274 };
EmFor@0 275
EmFor@0 276 ----------------------------------------------------------------------------------
EmFor@0 277 --
EmFor@0 278 -- Set up Continue after override box
EmFor@0 279 --
EmFor@0 280 ---------------------------------------------------------------------------------
EmFor@0 281 StaticPopupDialogs["CP_CONTINUE_CENSUS"] = {
EmFor@0 282 text = CENSUSPlus_OVERRIDE_COMPLET_PAUSED,
EmFor@0 283 button1 = CENSUSPlus_CONTINUE,
EmFor@0 284 OnAccept = function()
EmFor@0 285 g_CensusPlusManuallyPaused = false;
EmFor@0 286 CensusPlusTakeButton:SetText( CENSUSPlus_PAUSE );
EmFor@0 287 end,
EmFor@0 288 sound = "levelup2",
EmFor@0 289 timeout = 0,
EmFor@0 290 whileDead = 1,
EmFor@0 291 hideOnEscape = 1,
EmFor@0 292 showAlert = 1
EmFor@0 293 };
EmFor@0 294
EmFor@0 295 ----------------------------------------------------------------------------------
EmFor@0 296 --
EmFor@0 297 -- Chat msg hook
EmFor@0 298 --
EmFor@0 299 ---------------------------------------------------------------------------------
EmFor@0 300 local function CP_HookAddMessage(frame)
EmFor@0 301 local AddMessage = frame.AddMessage;
EmFor@0 302 -- Create a closure to cleanly hook the AddMessage routine.
EmFor@0 303 frame.AddMessage =
EmFor@0 304 function (this, msg, r, g, b, id)
EmFor@0 305 if( ( g_TrackUnhandled or g_IsCensusPlusInProgress ) and msg ) then
EmFor@0 306 local s, e;
EmFor@0 307 local results = { };
EmFor@0 308 local whoMsg = false;
EmFor@0 309 --CensusPlus_Msg2( "Something : " .. msg );
EmFor@0 310
EmFor@0 311 --
EmFor@0 312 -- We don't need to process results from chat, we can get it straight from the who window (DUHH!)
EmFor@0 313 -- So, we just need to see if we have a match, and suppress the output if so
EmFor@0 314 --
EmFor@0 315
EmFor@0 316 -- results = CensusPlus_GatherSingleReturn( msg );
EmFor@0 317 -- if( results["NAME"] ~= nil ) then
EmFor@0 318 results = { };
EmFor@0 319 s, e = strmatch(msg, CENSUS_SINGLE_MATCH_PATTERN);
EmFor@0 320 if( s ~= nil ) then
EmFor@0 321 -- CensusPlus_Msg2( " Name : " .. results["NAME"] .. " L: " .. results["LEVEL"] .. " R: " .. results["RACE"] .. " C: " .. results["CLASS"].. " G: " .. results["GUILD"].. " Z: " .. results["ZONE"] );
EmFor@0 322 whoMsg = true;
EmFor@0 323 -- WR_ProcessSingleEntry( results["NAME"], results["LEVEL"], results["RACE"], results["CLASS"], results["GUILD"], results["ZONE"] );
EmFor@0 324 else
EmFor@0 325 if( g_TrackUnhandled ) then
EmFor@0 326 CensusPlus_Unhandled[msg] = 1;
EmFor@0 327 end
EmFor@0 328 end
EmFor@0 329
EmFor@0 330 results = { };
EmFor@0 331 s, e = strmatch(msg, WHO_NUM_RESULTS);
EmFor@0 332 if( s ~= nil ) then
EmFor@0 333 -- We got a match, now just need to determine if it's 0 or not, so we'll use a bit more lax check
EmFor@0 334 whoMsg = true;
EmFor@0 335
EmFor@0 336 local result;
EmFor@0 337 s, e, result = string.find( msg, "(%d+).*" );
EmFor@0 338 if( result == "0" ) then
EmFor@0 339 g_ReteurnedZero = true;
EmFor@0 340 end
EmFor@0 341
EmFor@0 342 CensusPlus_ProcessWhoResults();
EmFor@0 343 end
EmFor@0 344
EmFor@0 345
EmFor@0 346 if( whoMsg ) then
EmFor@0 347 --
EmFor@0 348 -- Also bail out of an override if in place
EmFor@0 349 --
EmFor@0 350 if( g_CensusWhoOverrideMsg ~= nil and g_WaitingForOverrideUpdate == true ) then
EmFor@0 351 --
EmFor@0 352 -- Allow the who to act normally
EmFor@0 353 --
EmFor@0 354 g_CensusWhoOverrideMsg = nil;
EmFor@0 355 g_WaitingForOverrideUpdate = false;
EmFor@0 356 CensusPlus_Msg( CENSUSPlus_OVERRIDE_COMPLETE );
EmFor@0 357 return AddMessage(this, msg, r, g, b, id)
EmFor@0 358 elseif( CensusPlus_PerCharInfo["Verbose"] ~= true and
EmFor@0 359 not g_CensusPlusPaused and
EmFor@0 360 not g_CensusPlusManuallyPaused ) then
EmFor@0 361 return;
EmFor@0 362
EmFor@0 363 end
EmFor@0 364
EmFor@0 365 g_WaitingForWhoUpdate = false;
EmFor@0 366 end
EmFor@0 367
EmFor@0 368 return AddMessage(this, msg, r, g, b, id)
EmFor@0 369 else
EmFor@0 370 return AddMessage(this, msg, r, g, b, id)
EmFor@0 371 end
EmFor@0 372 end
EmFor@0 373 end
EmFor@0 374
EmFor@0 375
EmFor@0 376
EmFor@0 377 -----------------------------------------------------------------------------------
EmFor@0 378 --
EmFor@0 379 -- Insert a job at the end of the job queue
EmFor@0 380 --
EmFor@0 381 -----------------------------------------------------------------------------------
EmFor@0 382 local function InsertJobIntoQueue(job)
EmFor@0 383 --CensusPlus_DumpJob( job );
EmFor@0 384 table.insert(g_JobQueue, job);
EmFor@0 385 end
EmFor@0 386
EmFor@0 387 -----------------------------------------------------------------------------------
EmFor@0 388 --
EmFor@0 389 -- Initialize the tables of constants for XP calculations
EmFor@0 390 --
EmFor@0 391 -----------------------------------------------------------------------------------
EmFor@0 392 local function InitConstantTables()
EmFor@0 393 --
EmFor@0 394 -- XP earned for killing
EmFor@0 395 --
EmFor@0 396 --rm
EmFor@0 397 for i = 1, MAX_LEVEL_DISPLAY, 1 do
EmFor@0 398 g_MobXPByLevel[i] = i;
EmFor@0 399 end
EmFor@0 400
EmFor@0 401 --
EmFor@0 402 -- XP required to advance through the given level
EmFor@0 403 --
EmFor@0 404 for i = 1, MAX_LEVEL_DISPLAY, 1 do
EmFor@0 405 g_CharacterXPByLevel[i] = ((8 * i * g_MobXPByLevel[i]) / 100) * 100;
EmFor@0 406 end
EmFor@0 407
EmFor@0 408 --
EmFor@0 409 -- Total XP required to attain the given level
EmFor@0 410 --
EmFor@0 411 local totalCharacterXP = 0;
EmFor@0 412 for i = 1, MAX_LEVEL_DISPLAY, 1 do
EmFor@0 413 -- g_TotalCharacterXPPerLevel[i] = totalCharacterXP;
EmFor@0 414 --totalCharacterXP = totalCharacterXP + g_CharacterXPByLevel[i];
EmFor@0 415 val = (i*5)/MAX_LEVEL_DISPLAY;
EmFor@0 416 g_TotalCharacterXPPerLevel[i] = math.exp(val);
EmFor@0 417 end
EmFor@0 418
EmFor@0 419 end
EmFor@0 420
EmFor@0 421 -----------------------------------------------------------------------------------
EmFor@0 422 --
EmFor@0 423 -- Return a table of races for the input faction
EmFor@0 424 --
EmFor@0 425 -----------------------------------------------------------------------------------
EmFor@0 426 function CensusPlus_GetFactionRaces(faction)
EmFor@0 427 local ret = {};
EmFor@0 428 if (faction == CENSUSPlus_HORDE) then
EmFor@6 429 ret = {CENSUSPlus_ORC, CENSUSPlus_TAUREN, CENSUSPlus_TROLL, CENSUSPlus_UNDEAD, CENSUSPlus_BLOODELF, CENSUSPlus_GOBLIN};
EmFor@0 430 elseif (faction == CENSUSPlus_ALLIANCE) then
EmFor@6 431 ret = {CENSUSPlus_DWARF, CENSUSPlus_GNOME, CENSUSPlus_HUMAN, CENSUSPlus_NIGHTELF, CENSUSPlus_DRAENEI, CENSUSPlus_WORGEN};
EmFor@0 432 end
EmFor@0 433 return ret;
EmFor@0 434 end
EmFor@0 435
EmFor@0 436 -----------------------------------------------------------------------------------
EmFor@0 437 --
EmFor@0 438 -- Return a table of classes for the input faction
EmFor@0 439 --
EmFor@0 440 -----------------------------------------------------------------------------------
EmFor@0 441 function CensusPlus_GetFactionClasses(faction)
EmFor@0 442 local ret = {};
EmFor@0 443 if (faction == CENSUSPlus_HORDE) then
EmFor@0 444 ret = {CENSUSPlus_DRUID, CENSUSPlus_HUNTER, CENSUSPlus_MAGE, CENSUSPlus_PRIEST, CENSUSPlus_ROGUE, CENSUSPlus_WARLOCK, CENSUSPlus_WARRIOR, CENSUSPlus_PALADIN, CENSUSPlus_SHAMAN, CENSUSPlus_DEATHKNIGHT};
EmFor@0 445 elseif (faction == CENSUSPlus_ALLIANCE) then
EmFor@0 446 ret = {CENSUSPlus_DRUID, CENSUSPlus_HUNTER, CENSUSPlus_MAGE, CENSUSPlus_PRIEST, CENSUSPlus_ROGUE, CENSUSPlus_WARLOCK, CENSUSPlus_WARRIOR, CENSUSPlus_PALADIN, CENSUSPlus_SHAMAN, CENSUSPlus_DEATHKNIGHT};
EmFor@0 447 end
EmFor@0 448 return ret;
EmFor@0 449 end
EmFor@0 450
EmFor@0 451 -----------------------------------------------------------------------------------
EmFor@0 452 --
EmFor@0 453 -- Return a table of classes for the input race
EmFor@0 454 --
EmFor@0 455 -----------------------------------------------------------------------------------
EmFor@0 456 local function GetRaceClasses(race)
EmFor@0 457 local ret = {};
EmFor@0 458 if (race == CENSUSPlus_ORC) then
EmFor@6 459 ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_ROGUE, CENSUSPlus_MAGE, CENSUSPlus_SHAMAN, CENSUSPlus_WARLOCK, CENSUSPlus_DEATHKNIGHT};
EmFor@0 460 elseif (race == CENSUSPlus_TAUREN) then
EmFor@6 461 ret = {CENSUSPlus_PALADIN, CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_SHAMAN, CENSUSPlus_PRIEST, CENSUSPlus_DRUID, CENSUSPlus_DEATHKNIGHT};
EmFor@0 462 elseif (race == CENSUSPlus_TROLL) then
EmFor@6 463 ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_ROGUE, CENSUSPlus_PRIEST, CENSUSPlus_SHAMAN, CENSUSPlus_MAGE, CENSUSPlus_DRUID, CENSUSPlus_DEATHKNIGHT};
EmFor@0 464 elseif (race == CENSUSPlus_UNDEAD) then
EmFor@6 465 ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_ROGUE, CENSUSPlus_PRIEST, CENSUSPlus_MAGE, CENSUSPlus_WARLOCK, CENSUSPlus_DEATHKNIGHT};
EmFor@0 466 elseif (race == CENSUSPlus_DWARF) then
EmFor@6 467 ret = {CENSUSPlus_WARRIOR, CENSUSPlus_PALADIN, CENSUSPlus_HUNTER, CENSUSPlus_ROGUE, CENSUSPlus_MAGE, CENSUSPlus_PRIEST, CENSUSPlus_SHAMAN, CENSUSPlus_DEATHKNIGHT};
EmFor@0 468 elseif (race == CENSUSPlus_GNOME) then
EmFor@6 469 ret = {CENSUSPlus_WARRIOR, CENSUSPlus_ROGUE, CENSUSPlus_MAGE, CENSUSPlus_PRIEST, CENSUSPlus_WARLOCK, CENSUSPlus_DEATHKNIGHT};
EmFor@0 470 elseif (race == CENSUSPlus_HUMAN) then
EmFor@6 471 ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_PALADIN, CENSUSPlus_ROGUE, CENSUSPlus_PRIEST, CENSUSPlus_MAGE, CENSUSPlus_WARLOCK, CENSUSPlus_DEATHKNIGHT};
EmFor@0 472 elseif (race == CENSUSPlus_NIGHTELF) then
EmFor@6 473 ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_MAGE, CENSUSPlus_ROGUE, CENSUSPlus_PRIEST, CENSUSPlus_DRUID, CENSUSPlus_DEATHKNIGHT};
EmFor@0 474 elseif (race == CENSUSPlus_BLOODELF) then
EmFor@6 475 ret = {CENSUSPlus_WARRIOR, CENSUSPlus_PALADIN, CENSUSPlus_HUNTER, CENSUSPlus_ROGUE, CENSUSPlus_PRIEST, CENSUSPlus_MAGE, CENSUSPlus_WARLOCK, CENSUSPlus_DEATHKNIGHT};
EmFor@0 476 elseif (race == CENSUSPlus_DRAENEI) then
EmFor@0 477 ret = {CENSUSPlus_WARRIOR, CENSUSPlus_PALADIN, CENSUSPlus_HUNTER, CENSUSPlus_PRIEST, CENSUSPlus_SHAMAN, CENSUSPlus_MAGE, CENSUSPlus_DEATHKNIGHT};
EmFor@6 478 elseif (race == CENSUSPlus_WORGEN) then
EmFor@6 479 ret = {CENSUSPlus_DEATHKNIGHT, CENSUSPlus_DRUID, CENSUSPlus_HUNTER, CENSUSPlus_MAGE, CENSUSPlus_PRIEST, CENSUSPlus_ROGUE, CENSUSPlus_WARLOCK, CENSUSPlus_WARRIOR};
EmFor@6 480 elseif (race == CENSUSPlus_GOBLIN) then
EmFor@6 481 ret = {CENSUSPlus_DEATHKNIGHT, CENSUSPlus_HUNTER, CENSUSPlus_MAGE, CENSUSPlus_PRIEST, CENSUSPlus_ROGUE, CENSUSPlus_SHAMAN, CENSUSPlus_WARLOCK, CENSUSPlus_WARRIOR};
EmFor@0 482 end
EmFor@0 483 return ret;
EmFor@0 484 end
EmFor@0 485
EmFor@0 486 -----------------------------------------------------------------------------------
EmFor@0 487 --
EmFor@0 488 -- Return common letters found in zone names
EmFor@0 489 --
EmFor@0 490 -----------------------------------------------------------------------------------
EmFor@0 491 local function GetZoneLetters()
EmFor@0 492 return {"t", "d", "g", "f", "h", "b", "x", "gulch", "valley", "basin" };
EmFor@0 493 end
EmFor@0 494
EmFor@0 495 -----------------------------------------------------------------------------------
EmFor@0 496 --
EmFor@0 497 -- Return common letters found in names, may override this for other languages
EmFor@0 498 -- Worst case scenario is to do it for every letter in the alphabet
EmFor@0 499 --
EmFor@0 500 -----------------------------------------------------------------------------------
EmFor@0 501 local function GetNameLetters()
EmFor@0 502 --rm
EmFor@0 503 -- return { "a", "b", "c", "d", "e", "f", "g", "i", "o", "p", "r", "s", "t", "u", "y" };
EmFor@0 504 -- return { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\195\134", "\195\164", "\195\182", "\195\188", "\195\152" };
EmFor@0 505 return { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\195\134", "\195\164", "\195\182", "\195\188", "\195\152", "\195\184" };
EmFor@0 506 end
EmFor@0 507
EmFor@0 508 ---------------------------------------------------------------------------------
EmFor@0 509 --
EmFor@0 510 -- Register with Cosmos UI
EmFor@0 511 --
EmFor@0 512 ---------------------------------------------------------------------------------
EmFor@0 513 local function CensusPlus_RegisterCosmos()
EmFor@0 514 --
EmFor@0 515 -- If Cosmos is installed, add a button to the Cosmos page to activate CensusPlus
EmFor@0 516 --
EmFor@0 517 if ( EarthFeature_AddButton ) then
EmFor@0 518 EarthFeature_AddButton(
EmFor@0 519 {
EmFor@0 520 id = "CensusPlus";
EmFor@0 521 name = CENSUSPlus_BUTTON_TEXT;
EmFor@0 522 subtext = CENSUSPlus_BUTTON_SUBTEXT;
EmFor@0 523 tooltip = CENSUSPlus_BUTTON_TIP;
EmFor@0 524 icon = "Interface\\AddOns\\CensusPlus\\Skin\\CensusPlus_Icon";
EmFor@0 525 callback = CensusPlus_Toggle;
EmFor@0 526 }
EmFor@0 527 );
EmFor@0 528 elseif ( Cosmos_RegisterButton ) then
EmFor@0 529 Cosmos_RegisterButton(CENSUSPlus_BUTTON_TEXT, CENSUSPlus_BUTTON_SUBTEXT, CENSUSPlus_BUTTON_TIP, "Interface\\AddOns\\CensusPlus\\Skin\\CensusPlus_Icon", CensusPlus_Toggle);
EmFor@0 530 end
EmFor@0 531 end
EmFor@0 532
EmFor@0 533
EmFor@0 534 ----------------------------------------------------------------------------------
EmFor@0 535 --
EmFor@0 536 -- Called when the main window is shown
EmFor@0 537 --
EmFor@0 538 ---------------------------------------------------------------------------------
EmFor@0 539 function CensusPlus_OnShow()
EmFor@0 540 -- Initialize if this is the first OnShow event
EmFor@0 541 if (g_CensusPlusInitialized == false) then
EmFor@0 542 g_CensusPlusInitialized = true;
EmFor@0 543 end
EmFor@0 544 CensusPlus_UpdateView();
EmFor@0 545 end
EmFor@0 546
EmFor@0 547 ----------------------------------------------------------------------------------
EmFor@0 548 --
EmFor@0 549 -- Toggle hidden status
EmFor@0 550 --
EmFor@0 551 ---------------------------------------------------------------------------------
EmFor@0 552 function CensusPlus_Toggle()
EmFor@0 553 if ( CensusPlus:IsVisible() ) then
EmFor@0 554 CensusPlus:Hide();
EmFor@0 555 else
EmFor@0 556 CensusPlus:Show();
EmFor@0 557 end
EmFor@0 558 end
EmFor@0 559
EmFor@0 560 ----------------------------------------------------------------------------------
EmFor@0 561 --
EmFor@0 562 -- Toggle options pane
EmFor@0 563 --
EmFor@0 564 ---------------------------------------------------------------------------------
EmFor@0 565 function CensusPlus_ToggleOptions()
EmFor@0 566 if ( CP_OptionsWindow:IsVisible() ) then
EmFor@0 567 CP_OptionsWindow:Hide();
EmFor@0 568 else
EmFor@0 569 CP_OptionsWindow:Show();
EmFor@0 570 end
EmFor@0 571 end
EmFor@0 572
EmFor@0 573 -----------------------------------------------------------------------------------
EmFor@0 574 --
EmFor@0 575 -- Called once on load
EmFor@0 576 --
EmFor@0 577 -----------------------------------------------------------------------------------
EmFor@6 578 function CensusPlus_OnLoad( this )
EmFor@0 579 --
EmFor@0 580 -- Update the version number
EmFor@0 581 --
EmFor@0 582 CensusPlusText:SetText("Census+ EmSpe\195\167ial v"..CensusPlus_VERSION .. " " .. g_CensusPlusLocale );
EmFor@0 583 CensusPlusText2:SetText( CENSUSPlus_UPLOAD );
EmFor@0 584
EmFor@0 585 --
EmFor@0 586 -- Init constant tables
EmFor@0 587 --
EmFor@0 588 InitConstantTables();
EmFor@0 589
EmFor@0 590 --
EmFor@0 591 -- Register with Cosmos, if it is installed
EmFor@0 592 --
EmFor@0 593 CensusPlus_RegisterCosmos();
EmFor@0 594
EmFor@0 595 --
EmFor@0 596 -- Register for events
EmFor@0 597 --
EmFor@0 598 this:RegisterEvent("VARIABLES_LOADED");
EmFor@0 599 -- this:RegisterEvent("WHO_LIST_UPDATE");
EmFor@0 600
EmFor@0 601
EmFor@0 602 this:RegisterEvent("CHAT_MSG_SYSTEM");
EmFor@0 603
EmFor@0 604
EmFor@0 605 this:RegisterEvent("ZONE_CHANGED_NEW_AREA");
EmFor@0 606
EmFor@0 607 --
EmFor@0 608 -- Register a slash command
EmFor@0 609 --
EmFor@0 610 SLASH_CensusPlusCMD1 = "/CensusPlus";
EmFor@0 611 SLASH_CensusPlusCMD2 = "/Census+";
EmFor@0 612 SLASH_CensusPlusCMD3 = "/Census";
EmFor@0 613 SlashCmdList["CensusPlusCMD"] = CensusPlus_Command;
EmFor@0 614
EmFor@0 615 SLASH_CensusPlusVerbose1 = "/censusverbose";
EmFor@0 616 SlashCmdList["CensusPlusVerbose"] = CensusPlus_Verbose;
EmFor@0 617
EmFor@0 618 --
EmFor@0 619 -- Set the auto close to true
EmFor@0 620 --
EmFor@0 621 CensusPlus_AutoCloseWho( 1 );
EmFor@0 622 --AutoClose:SetChecked( 1 );
EmFor@0 623
EmFor@0 624 -- g_Pre_FriendsFrameOnHideOverride = FriendsFrame_OnHide;
EmFor@0 625 -- FriendsFrame_OnHide = CensusPlus_FriendsFrame_OnHide;
EmFor@0 626
EmFor@0 627 -- g_Pre_FriendsFrameOnShowOverride = FriendsFrame_OnShow;
EmFor@0 628 -- FriendsFrame_OnShow = CensusPlus_FriendsFrame_OnShow;
EmFor@0 629
EmFor@0 630 -- g_Pre_WhoList_UpdateOverride = WhoList_Update;
EmFor@0 631 -- WhoList_Update = CensusPlus_WhoList_Update;
EmFor@0 632
EmFor@0 633 -- g_Pre_FriendsFrame_Update = FriendsFrame_Update;
EmFor@0 634 -- FriendsFrame_Update = CensusPlus_FriendsFrame_Update;
EmFor@0 635
EmFor@0 636 g_SetItemRef_Override = SetItemRef;
EmFor@0 637 SetItemRef = CensusPlus_SetItemRef;
EmFor@0 638
EmFor@0 639 CP_Pre_OnEvent = FriendsFrame_OnEvent;
EmFor@0 640 FriendsFrame_OnEvent = CensusPlus_FriendsFrame_OnEvent;
EmFor@0 641
EmFor@0 642 g_Pre_WhoHandler = SlashCmdList["WHO"];
EmFor@0 643 SlashCmdList["WHO"] = CensusPlus_WhoHandler;
EmFor@0 644
EmFor@0 645 CensusPlus_CheckForBattleground();
EmFor@0 646
EmFor@0 647 -- Hook the default chat frame's AddMessage method.
EmFor@0 648 CP_HookAddMessage(ChatFrame1);
EmFor@0 649
EmFor@0 650 --
EmFor@0 651 -- Set up an empty frame to do updates
EmFor@0 652 --
EmFor@0 653 local updateFrame = CreateFrame("Frame");
EmFor@0 654 updateFrame:SetScript("OnUpdate", CensusPlus_OnUpdate);
EmFor@0 655 CensusPlusTakeGuildButton:SetText( CENSUSPlus_TAKEGUILD.." \""..CensusPlus_MYGUILD.."\"" );
EmFor@0 656 end
EmFor@0 657
EmFor@6 658 function CensusPlus_FriendsFrame_OnEvent(self, event, ...)
EmFor@0 659
EmFor@0 660 -- CensusPlus_Msg( "CP_FF_OE Message =>" .. event );
EmFor@0 661
EmFor@0 662 if(wholib == nil and
EmFor@0 663 event == "WHO_LIST_UPDATE" and g_IsCensusPlusInProgress and g_WaitingForWhoUpdate ) then
EmFor@0 664 --
EmFor@0 665 -- First check for an override
EmFor@0 666 --
EmFor@0 667 if( g_CensusWhoOverrideMsg ~= nil and g_WaitingForOverrideUpdate == true ) then
EmFor@0 668 --
EmFor@0 669 -- Allow the who to act normally
EmFor@0 670 --
EmFor@0 671 g_CensusWhoOverrideMsg = nil;
EmFor@0 672 g_WaitingForOverrideUpdate = false;
EmFor@0 673 CensusPlus_Msg( CENSUSPlus_OVERRIDE_COMPLETE_BUT_PAUSED );
EmFor@0 674 -- g_Pre_WhoList_UpdateOverride();
EmFor@0 675
EmFor@0 676
EmFor@0 677 g_WaitingForWhoUpdate = false;
EmFor@0 678 CP_Pre_OnEvent(...);
EmFor@6 679
EmFor@0 680 --
EmFor@0 681 -- If we opened the who window, do a manual pause and open a dialog
EmFor@0 682 --
EmFor@0 683 g_CensusPlusManuallyPaused = true;
EmFor@0 684 CensusPlusTakeButton:SetText( CENSUSPlus_UNPAUSE );
EmFor@0 685
EmFor@0 686 StaticPopup_Show ("CP_CONTINUE_CENSUS");
EmFor@0 687
EmFor@0 688 elseif ( g_IsCensusPlusInProgress ) then
EmFor@0 689 --
EmFor@0 690 -- Only process who results if a CensusPlus is in progress
EmFor@0 691 --
EmFor@0 692
EmFor@0 693 CP_ProcessWhoEvent()
EmFor@0 694
EmFor@0 695
EmFor@0 696 else
EmFor@0 697 --
EmFor@0 698 -- This is just a random /who done by the player
EmFor@0 699 --
EmFor@0 700 CensusPlus_ProcessWhoResults();
EmFor@0 701 end
EmFor@0 702 --
EmFor@0 703 -- We got the who update
EmFor@0 704 --
EmFor@0 705 g_WaitingForWhoUpdate = false;
EmFor@0 706
EmFor@0 707 return;
EmFor@0 708
EmFor@0 709 end
EmFor@0 710
EmFor@6 711 CP_Pre_OnEvent(self, event, ...);
EmFor@0 712
EmFor@0 713 end
EmFor@0 714
EmFor@0 715 function CP_ProcessWhoEvent(query, ...)
EmFor@0 716 local numWhoResults = GetNumWhoResults();
EmFor@0 717 if( numWhoResults == 0 ) then
EmFor@0 718 return;
EmFor@0 719 end
EmFor@0 720
EmFor@0 721 CensusPlus_ProcessWhoResults();
EmFor@0 722 if (numWhoResults > MAX_WHO_RESULTS) then
EmFor@0 723 --
EmFor@0 724 -- Who list is overflowed, split the query to make the return smaller
EmFor@0 725 --
EmFor@0 726 local minLevel = g_CurrentJob.m_MinLevel;
EmFor@0 727 local maxLevel = g_CurrentJob.m_MaxLevel;
EmFor@0 728 local race = g_CurrentJob.m_Race;
EmFor@0 729 local class = g_CurrentJob.m_Class;
EmFor@0 730 local zoneLetter = g_CurrentJob.m_zoneLetter;
EmFor@0 731 local letter = g_CurrentJob.m_Letter;
EmFor@0 732 --rmg
EmFor@0 733 local guild = g_CurrentJob.m_Guild;
EmFor@0 734
EmFor@0 735 if (minLevel ~= maxLevel) then
EmFor@0 736
EmFor@0 737 --
EmFor@0 738 -- The level range is greater than a single level, so split it in half and submit the two jobs
EmFor@0 739 --
EmFor@0 740 local pivot = floor((minLevel + maxLevel) / 2);
EmFor@0 741 local jobLower = CensusPlus_CreateJob( minLevel, pivot, nil, nil, nil , guild );
EmFor@0 742 InsertJobIntoQueue(jobLower);
EmFor@0 743 local jobUpper = CensusPlus_CreateJob( pivot + 1, maxLevel, nil, nil, nil , guild );
EmFor@0 744 InsertJobIntoQueue(jobUpper);
EmFor@0 745 else
EmFor@0 746 --
EmFor@0 747 -- We cannot split the level range any more
EmFor@0 748 --
EmFor@0 749 local factionGroup = UnitFactionGroup("player");
EmFor@0 750 local level = minLevel;
EmFor@0 751 if (race == nil) then
EmFor@0 752 --
EmFor@0 753 -- This job does not specify race, so split it that way, making four new jobs
EmFor@0 754 --
EmFor@0 755 local thisFactionRaces = CensusPlus_GetFactionRaces(factionGroup);
EmFor@0 756 local numRaces = table.getn(thisFactionRaces);
EmFor@0 757 for i = 1, numRaces, 1 do
EmFor@0 758 local job = CensusPlus_CreateJob( level, level, thisFactionRaces[i], nil, nil , guild );
EmFor@0 759 InsertJobIntoQueue(job);
EmFor@0 760 end
EmFor@0 761 else
EmFor@0 762 if (class == nil) then
EmFor@0 763 --
EmFor@0 764 -- This job does not specify class, so split it that way, making more jobs
EmFor@0 765 --
EmFor@0 766 local thisRaceClasses = GetRaceClasses(race);
EmFor@0 767 local numClasses = table.getn(thisRaceClasses);
EmFor@0 768 for i = 1, numClasses, 1 do
EmFor@0 769 local job = CensusPlus_CreateJob( level, level, race, thisRaceClasses[i], nil , guild );
EmFor@0 770 InsertJobIntoQueue(job);
EmFor@0 771 end
EmFor@0 772 else
EmFor@0 773 if( letter == nil ) then
EmFor@0 774 -- There are too many characters with a single level, class and race
EmFor@0 775 -- The work around we are going to pursue is to check by name for a,e,i,o,r,s,t,u
EmFor@0 776 local letters = GetNameLetters();
EmFor@0 777 for i=1, table.getn( letters ), 1 do
EmFor@0 778 local job = CensusPlus_CreateJob( level, level, race, class, letters[i] , guild );
EmFor@0 779 InsertJobIntoQueue(job);
EmFor@0 780 end
EmFor@0 781 else
EmFor@0 782 -- There are too many characters with a single level, class, race and letter, give up
EmFor@0 783 local whoText = CensusPlus_CreateWhoText(g_CurrentJob);
EmFor@0 784 CensusPlus_Msg(format(CENSUSPlus_TOOMANY, whoText));
EmFor@0 785 end
EmFor@0 786 end
EmFor@0 787 end
EmFor@0 788 end
EmFor@0 789 end
EmFor@0 790
EmFor@0 791 local whoText = CensusPlus_CreateWhoText(g_CurrentJob);
EmFor@0 792
EmFor@0 793 if whoText == query then
EmFor@0 794 g_WaitingForWhoUpdate = false
EmFor@0 795 end
EmFor@0 796 end
EmFor@0 797
EmFor@0 798 -----------------------------------------------------------------------------------
EmFor@0 799 --
EmFor@0 800 -- Load Handler for options box
EmFor@0 801 --
EmFor@0 802 -----------------------------------------------------------------------------------
EmFor@0 803 function CP_OptionsOnShow()
EmFor@0 804 CP_OptionAutoClose:SetChecked(g_WhoAutoClose);
EmFor@0 805 CP_OptionAutoStartButton:SetChecked(g_MiniOnStart);
EmFor@0 806 CP_OptionVerboseButton:SetChecked(CensusPlus_PerCharInfo["Verbose"]);
EmFor@0 807 CP_OptionAutoCensusButton:SetChecked( CensusPlus_Database["Info"]["AutoCensus"] );
EmFor@0 808 -- CP_OptionProcessCharProfileButton:SetChecked( CensusPlus_DoThisCharacter );
EmFor@0 809 end
EmFor@0 810
EmFor@0 811 -----------------------------------------------------------------------------------
EmFor@0 812 --
EmFor@0 813 -- CensusPlus Friends Frame override to stop the window close sound
EmFor@0 814 --
EmFor@0 815 -----------------------------------------------------------------------------------
EmFor@0 816 function CensusPlus_FriendsFrame_OnHide()
EmFor@0 817 g_Pre_FriendsFrameOnHideOverride();
EmFor@0 818 end
EmFor@0 819
EmFor@0 820 -----------------------------------------------------------------------------------
EmFor@0 821 --
EmFor@0 822 -- CensusPlus Friends Frame override to stop the window close sound
EmFor@0 823 --
EmFor@0 824 -----------------------------------------------------------------------------------
EmFor@0 825 function CensusPlus_FriendsFrame_OnShow()
EmFor@0 826 g_Pre_FriendsFrameOnShowOverride();
EmFor@0 827 end
EmFor@0 828
EmFor@0 829 -----------------------------------------------------------------------------------
EmFor@0 830 --
EmFor@0 831 -- CensusPlus_WhoList_Update
EmFor@0 832 --
EmFor@0 833 -----------------------------------------------------------------------------------
EmFor@0 834 function CensusPlus_WhoList_Update()
EmFor@0 835 --InCombatLockdown() == false
EmFor@0 836 if( g_IsCensusPlusInProgress == true and g_WhoAutoClose ) then
EmFor@0 837 local numWhos, totalCount = GetNumWhoResults();
EmFor@0 838 local name, guild, level, race, class, zone, group;
EmFor@0 839 local button;
EmFor@0 840 local columnTable;
EmFor@0 841 local whoOffset = FauxScrollFrame_GetOffset(WhoListScrollFrame);
EmFor@0 842 local whoIndex;
EmFor@0 843 local showScrollBar = nil;
EmFor@0 844 if ( numWhos > WHOS_TO_DISPLAY ) then
EmFor@0 845 showScrollBar = 1;
EmFor@0 846 end
EmFor@0 847 local displayedText = "";
EmFor@0 848 if ( totalCount > MAX_WHOS_FROM_SERVER ) then
EmFor@0 849 displayedText = format(WHO_FRAME_SHOWN_TEMPLATE, MAX_WHOS_FROM_SERVER);
EmFor@0 850 end
EmFor@0 851 WhoFrameTotals:SetText(format(GetText("WHO_FRAME_TOTAL_TEMPLATE", nil, totalCount), totalCount).." "..displayedText);
EmFor@0 852 for i=1, WHOS_TO_DISPLAY, 1 do
EmFor@0 853 whoIndex = whoOffset + i;
EmFor@0 854 button = getglobal("WhoFrameButton"..i);
EmFor@0 855 button.whoIndex = whoIndex;
EmFor@0 856 name, guild, level, race, class, zone, group = GetWhoInfo(whoIndex);
EmFor@0 857 columnTable = { zone, guild, race };
EmFor@0 858 getglobal("WhoFrameButton"..i.."Name"):SetText(name);
EmFor@0 859 getglobal("WhoFrameButton"..i.."Level"):SetText(level);
EmFor@0 860 getglobal("WhoFrameButton"..i.."Class"):SetText(class);
EmFor@0 861 local variableText = getglobal("WhoFrameButton"..i.."Variable");
EmFor@0 862 variableText:SetText(columnTable[UIDropDownMenu_GetSelectedID(WhoFrameDropDown)]);
EmFor@0 863 if ( not group ) then
EmFor@0 864 group = "";
EmFor@0 865 end
EmFor@0 866 --getglobal("WhoFrameButton"..i.."Group"):SetText(getglobal(strupper(group)));
EmFor@0 867
EmFor@0 868 -- If need scrollbar resize columns
EmFor@0 869 if ( showScrollBar ) then
EmFor@0 870 variableText:SetWidth(95);
EmFor@0 871 else
EmFor@0 872 variableText:SetWidth(110);
EmFor@0 873 end
EmFor@0 874
EmFor@0 875 -- Highlight the correct who
EmFor@0 876 if ( WhoFrame.selectedWho == whoIndex ) then
EmFor@0 877 button:LockHighlight();
EmFor@0 878 else
EmFor@0 879 button:UnlockHighlight();
EmFor@0 880 end
EmFor@0 881
EmFor@0 882 if ( whoIndex > numWhos ) then
EmFor@0 883 button:Hide();
EmFor@0 884 else
EmFor@0 885 button:Show();
EmFor@0 886 end
EmFor@0 887 end
EmFor@0 888
EmFor@0 889 if ( not WhoFrame.selectedWho ) then
EmFor@0 890 WhoFrameGroupInviteButton:Disable();
EmFor@0 891 WhoFrameAddFriendButton:Disable();
EmFor@0 892 else
EmFor@0 893 WhoFrameGroupInviteButton:Enable();
EmFor@0 894 WhoFrameAddFriendButton:Enable();
EmFor@0 895 WhoFrame.selectedName = GetWhoInfo(WhoFrame.selectedWho);
EmFor@0 896 end
EmFor@0 897
EmFor@0 898 -- If need scrollbar resize columns
EmFor@0 899 if ( showScrollBar ) then
EmFor@0 900 WhoFrameColumn_SetWidth(WhoFrameColumnHeader2, 105);
EmFor@0 901 UIDropDownMenu_SetWidth(WhoFrameDropDown, 80);
EmFor@0 902 else
EmFor@0 903 WhoFrameColumn_SetWidth(WhoFrameColumnHeader2, 120);
EmFor@0 904 UIDropDownMenu_SetWidth(WhoFrameDropDown, 95);
EmFor@0 905 end
EmFor@0 906
EmFor@0 907 -- ScrollFrame update
EmFor@0 908 FauxScrollFrame_Update(WhoListScrollFrame, numWhos, WHOS_TO_DISPLAY, FRIENDS_FRAME_WHO_HEIGHT );
EmFor@0 909
EmFor@0 910 else
EmFor@0 911 g_Pre_WhoList_UpdateOverride();
EmFor@0 912 end
EmFor@0 913 end
EmFor@0 914
EmFor@0 915
EmFor@0 916 -----------------------------------------------------------------------------------
EmFor@0 917 --
EmFor@0 918 -- CensusPlus_FriendsFrame_Update
EmFor@0 919 --
EmFor@0 920 -----------------------------------------------------------------------------------
EmFor@0 921 function CensusPlus_FriendsFrame_Update()
EmFor@0 922 if ( FriendsFrame.selectedTab == 3 and g_IsCensusPlusInProgress == true and g_WhoAutoClose ) then
EmFor@0 923 FriendsFrameTopLeft:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-TopLeft");
EmFor@0 924 FriendsFrameTopRight:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-TopRight");
EmFor@0 925 FriendsFrameBottomLeft:SetTexture("Interface\\FriendsFrame\\GuildFrame-BotLeft");
EmFor@0 926 FriendsFrameBottomRight:SetTexture("Interface\\FriendsFrame\\GuildFrame-BotRight");
EmFor@0 927 local guildName, title, rank = GetGuildInfo("player");
EmFor@0 928 if ( guildName ) then
EmFor@0 929 FriendsFrameTitleText:SetText(format(GUILD_TITLE_TEMPLATE, title, guildName));
EmFor@0 930 else
EmFor@0 931 FriendsFrameTitleText:SetText("");
EmFor@0 932 end
EmFor@0 933 --GuildStatus_Update();
EmFor@0 934 FriendsFrameTitleText:SetText(guildName);
EmFor@0 935 FriendsFrame_ShowSubFrame("GuildFrame");
EmFor@0 936 else
EmFor@0 937 g_Pre_FriendsFrame_Update();
EmFor@0 938 end
EmFor@0 939 end
EmFor@0 940
EmFor@0 941 -----------------------------------------------------------------------------------
EmFor@0 942 --
EmFor@0 943 -- CensusPlus Who Handler
EmFor@0 944 --
EmFor@0 945 -----------------------------------------------------------------------------------
EmFor@0 946 function CensusPlus_WhoHandler( msg )
EmFor@0 947 if( g_IsCensusPlusInProgress == true ) then
EmFor@0 948 CensusPlus_Msg( "Census Who Handler" );
EmFor@0 949 if ( msg == "" ) then
EmFor@0 950 msg = WhoFrame_GetDefaultWhoCommand();
EmFor@0 951 ShowWhoPanel();
EmFor@0 952 elseif ( msg == "cheat" ) then
EmFor@0 953 -- Remove the "cheat" part later!
EmFor@0 954 ShowWhoPanel();
EmFor@0 955 end
EmFor@0 956
EmFor@0 957 --
EmFor@0 958 -- Queue up the command to run next
EmFor@0 959 --
EmFor@0 960 g_CensusWhoOverrideMsg = msg;
EmFor@0 961 CensusPlus_Msg( CENSUSPlus_OVERRIDE );
EmFor@0 962 -- CensusPlus_SendWho(msg);
EmFor@0 963 else
EmFor@0 964 g_Pre_WhoHandler(msg);
EmFor@0 965 end
EmFor@0 966 end
EmFor@0 967
EmFor@0 968 -----------------------------------------------------------------------------------
EmFor@0 969 --
EmFor@0 970 -- CensusPlus command
EmFor@0 971 --
EmFor@0 972 -----------------------------------------------------------------------------------
EmFor@0 973 function CensusPlus_Command( param )
EmFor@0 974
EmFor@0 975 local i,j, command, value = string.find(param, "^([^ ]+) (.+)$");
EmFor@0 976
EmFor@0 977 -- local firsti, lasti, command, value = string.find (param, "(%w+) (%w+) (%w+)") ;
EmFor@0 978
EmFor@0 979 -- if( string.lower(param) == "locale" ) then
EmFor@0 980 -- CP_EU_US_Version:Show();
EmFor@0 981 -- else
EmFor@0 982 if( string.lower(param) == "options" ) then
EmFor@0 983 CP_OptionsWindow:Show();
EmFor@0 984 -- elseif( string.lower(param) == "tz" ) then
EmFor@0 985 -- CensusPlus_DetermineServerDate();
EmFor@0 986 elseif( command ~= nil and string.lower(command) == "prune" ) then
EmFor@0 987 if( value ~= nil ) then
EmFor@0 988 CensusPlus_PruneData( value, nil );
EmFor@0 989 else
EmFor@0 990 CensusPlus_PruneData( 30, nil );
EmFor@0 991 end
EmFor@0 992 elseif( command ~= nil and string.lower(command) == "timer" ) then
EmFor@0 993 if( value ~= nil ) then
EmFor@0 994 CensusPlus_Database["Info"]["AutoCensusTimer"] = value * 60;
EmFor@0 995 CensusPlus_Msg( "Set autocensus timer to " .. value .. " minutes" );
EmFor@0 996 else
EmFor@0 997 CensusPlus_Database["Info"]["AutoCensusTimer"] = 1800;
EmFor@0 998 CensusPlus_Msg( "Set autocensus timer to 30 minutes" );
EmFor@0 999 end
EmFor@0 1000 elseif( string.lower(param) == "serverprune" ) then
EmFor@0 1001 CensusPlus_PruneData( 0, 1 );
EmFor@0 1002 elseif( string.lower(param) == "bufftest" ) then
EmFor@0 1003 showAllUnitBuffs("player");
EmFor@0 1004 elseif( string.lower(param) == "verbose" ) then
EmFor@0 1005 CensusPlus_Verbose();
EmFor@0 1006 elseif( string.lower(param) == "take" ) then
EmFor@0 1007 CensusPlus_Take_OnClick();
EmFor@0 1008 elseif( string.lower(param) == "stop" ) then
EmFor@0 1009 CensusPlus_StopCensus();
EmFor@0 1010 elseif( string.lower(param) == "track" ) then
EmFor@0 1011 if( g_TrackUnhandled ) then
EmFor@0 1012 CensusPlus_Msg( "Tracking disabled!" );
EmFor@0 1013 g_TrackUnhandled = false;
EmFor@0 1014 else
EmFor@0 1015 CensusPlus_Msg( "TRACKING ALL CHAT!" );
EmFor@0 1016 g_TrackUnhandled = true;
EmFor@0 1017 end
EmFor@0 1018 elseif( command ~= nil and string.lower(command) == "who" ) then
EmFor@0 1019 local m,n, check, level = string.find(value, "(%w+) (%w+)");
EmFor@0 1020 if( check ~= nil ) then
EmFor@0 1021 CensusPlus_InternalWho( string.lower(check), level );
EmFor@0 1022 else
EmFor@0 1023 CensusPlus_InternalWho( string.lower(value), nil );
EmFor@0 1024 end
EmFor@0 1025 elseif( command ~= nil and string.lower(command) == "test" ) then
EmFor@0 1026 if( value ~= nil ) then
EmFor@0 1027 CensusPlus_Test( value );
EmFor@0 1028 else
EmFor@0 1029 CensusPlus_Test( 1 );
EmFor@0 1030 end
EmFor@0 1031 else
EmFor@0 1032 CensusPlus_DisplayUsage();
EmFor@0 1033 end
EmFor@0 1034 end
EmFor@0 1035
EmFor@0 1036 -----------------------------------------------------------------------------------
EmFor@0 1037 --
EmFor@0 1038 -- CensusPlus Display Usage
EmFor@0 1039 --
EmFor@0 1040 -----------------------------------------------------------------------------------
EmFor@0 1041 function CensusPlus_DisplayUsage()
EmFor@0 1042 local text;
EmFor@0 1043
EmFor@0 1044 CensusPlus:Show();
EmFor@0 1045
EmFor@0 1046 CensusPlus_Msg("Usage:\n /CensusPlus");
EmFor@0 1047 CensusPlus_Msg(" /censusPlus verbose Toggle verbose mode off/on");
EmFor@0 1048 -- CensusPlus_Msg(" /CensusPlus locale Bring up the locale selection dialog - (WARNING -- CHANGING YOUR LOCALE WILL PURGE YOUR DATABASE)");
EmFor@0 1049 CensusPlus_Msg(" /CensusPlus options Bring up the Option window");
EmFor@0 1050 CensusPlus_Msg(" /CensusPlus take Start a Census snapshot");
EmFor@0 1051 CensusPlus_Msg(" /CensusPlus stop Stop a Census snapshot");
EmFor@0 1052 CensusPlus_Msg(" /CensusPlus prune X Prune the database by removing characters not seen in X days");
EmFor@0 1053 CensusPlus_Msg(" /CensusPlus serverprune Prune the database by removing all data from servers other than the one you are currently on.");
EmFor@0 1054 CensusPlus_Msg(" /CensusPlus who XXX Will display info that matches names or guilds.");
EmFor@0 1055 CensusPlus_Msg(" /CensusPlus who unguilded ## Will list unguilded characters of that level.");
EmFor@0 1056 CensusPlus_Msg(" /CensusPlus timer X ## Will set the autocensus timer (in minutes).");
EmFor@0 1057 end
EmFor@0 1058
EmFor@0 1059 -----------------------------------------------------------------------------------
EmFor@0 1060 --
EmFor@0 1061 -- CensusPlus_InternalWho - will go through our local database and see if we have
EmFor@0 1062 -- any info on this person
EmFor@0 1063 --
EmFor@0 1064 -----------------------------------------------------------------------------------
EmFor@0 1065 function CensusPlus_InternalWho( search, level )
EmFor@0 1066
EmFor@0 1067 if( g_CensusPlusLocale == "N/A" ) then
EmFor@0 1068 return;
EmFor@0 1069 end
EmFor@0 1070
EmFor@0 1071 g_InternalSearchName = search;
EmFor@0 1072 g_InternalSearchLevel = level;
EmFor@0 1073 g_InternalSearchCount = 0;
EmFor@0 1074 local realmName = g_CensusPlusLocale .. GetCVar("realmName");
EmFor@0 1075 CensusPlus_ForAllCharacters( realmName, UnitFactionGroup("player"), nil, nil, nil, nil, CensusPlus_InternalWhoResult)
EmFor@0 1076
EmFor@0 1077 CensusPlus_WhoMsg( "Found " .. g_InternalSearchCount .. " players." );
EmFor@0 1078 end
EmFor@0 1079
EmFor@0 1080 function CensusPlus_InternalWhoResult(name, level, guild, race, class, lastSeen )
EmFor@0 1081 lowerName = string.lower( name );
EmFor@0 1082 level = string.lower( level );
EmFor@0 1083 lowerGuild = string.lower( CensusPlus_SafeCheck( guild ) );
EmFor@0 1084
EmFor@0 1085 if( g_InternalSearchName == "unguilded" ) then
EmFor@0 1086 if( guild == "" ) then
EmFor@0 1087 local doit = 1;
EmFor@0 1088 if( g_InternalSearchLevel ~= nil ) then
EmFor@0 1089 if( g_InternalSearchLevel ~= level ) then
EmFor@0 1090 doit = 0;
EmFor@0 1091 end
EmFor@0 1092 end
EmFor@0 1093 if( doit == 1 ) then
EmFor@0 1094 local out = name .. " : Level " .. level .. " " .. race .. " " .. " " .. class;
EmFor@0 1095 out = out .. " Last Seen: " .. lastSeen;
EmFor@0 1096 CensusPlus_WhoMsg( out );
EmFor@0 1097 g_InternalSearchCount = g_InternalSearchCount + 1;
EmFor@0 1098 end
EmFor@0 1099 end
EmFor@0 1100 elseif( string.find( lowerName, g_InternalSearchName ) or string.find( lowerGuild, g_InternalSearchName ) ) then
EmFor@0 1101 -- found someone!
EmFor@0 1102 local out = name .. " : Level " .. level .. " " .. race .. " " .. " " .. class;
EmFor@0 1103 if( guild ~= "" ) then
EmFor@0 1104 out = out .. " <" .. guild .. ">";
EmFor@0 1105 end
EmFor@0 1106 out = out .. " Last Seen: " .. lastSeen;
EmFor@0 1107 CensusPlus_WhoMsg( out );
EmFor@0 1108 g_InternalSearchCount = g_InternalSearchCount + 1;
EmFor@0 1109 end
EmFor@0 1110 end
EmFor@0 1111
EmFor@0 1112 -----------------------------------------------------------------------------------
EmFor@0 1113 --
EmFor@0 1114 -- CensusPlus Verbose option
EmFor@0 1115 --
EmFor@0 1116 -----------------------------------------------------------------------------------
EmFor@0 1117 function CensusPlus_Verbose()
EmFor@0 1118 if( CensusPlus_PerCharInfo["Verbose"] == true ) then
EmFor@0 1119 CensusPlus_Msg( "Verbose Mode : OFF" );
EmFor@0 1120 CensusPlus_PerCharInfo["Verbose"] = false;
EmFor@0 1121 else
EmFor@0 1122 CensusPlus_Msg( "Verbose Mode : ON" );
EmFor@0 1123 CensusPlus_PerCharInfo["Verbose"] = true;
EmFor@0 1124 end
EmFor@0 1125 end
EmFor@0 1126
EmFor@0 1127 -----------------------------------------------------------------------------------
EmFor@0 1128 --
EmFor@0 1129 -- CensusPlus Auto Census set flag
EmFor@0 1130 --
EmFor@0 1131 -----------------------------------------------------------------------------------
EmFor@0 1132 function CensusPlus_SetAutoCensus( flag )
EmFor@0 1133 if( flag == 1 ) then
EmFor@0 1134 CensusPlus_Database["Info"]["AutoCensus"] = true;
EmFor@0 1135 else
EmFor@0 1136 CensusPlus_Database["Info"]["AutoCensus"] = false;
EmFor@0 1137 end
EmFor@0 1138 end
EmFor@0 1139
EmFor@0 1140 -----------------------------------------------------------------------------------
EmFor@0 1141 --
EmFor@0 1142 -- Minimize the window
EmFor@0 1143 --
EmFor@0 1144 -----------------------------------------------------------------------------------
EmFor@0 1145 function CensusPlus_OnClickMinimize()
EmFor@0 1146 if( CensusPlus:IsVisible() ) then
EmFor@0 1147 -- MiniCensusPlus:Show();
EmFor@0 1148 CensusPlus:Hide();
EmFor@0 1149 end
EmFor@0 1150 end
EmFor@0 1151
EmFor@0 1152 -----------------------------------------------------------------------------------
EmFor@0 1153 --
EmFor@0 1154 -- Minimize the window
EmFor@0 1155 --
EmFor@0 1156 -----------------------------------------------------------------------------------
EmFor@0 1157 function CensusPlus_OnClickMaximize()
EmFor@0 1158 if( MiniCensusPlus:IsVisible() ) then
EmFor@0 1159 MiniCensusPlus:Hide();
EmFor@0 1160 CensusPlus:Show();
EmFor@0 1161 end
EmFor@0 1162 end
EmFor@0 1163
EmFor@0 1164 -----------------------------------------------------------------------------------
EmFor@0 1165 --
EmFor@0 1166 -- Take or pause a census depending on current status
EmFor@0 1167 --
EmFor@0 1168 -----------------------------------------------------------------------------------
EmFor@0 1169 function CensusPlus_Take_OnClick()
EmFor@0 1170 if (g_IsCensusPlusInProgress) then
EmFor@0 1171 CensusPlus_TogglePause();
EmFor@0 1172 else
EmFor@0 1173 CensusPlus_StartCensus();
EmFor@0 1174 end
EmFor@0 1175 end
EmFor@0 1176
EmFor@0 1177 --rm
EmFor@0 1178 -----------------------------------------------------------------------------------
EmFor@0 1179 -- Take or pause a census depending on current status
EmFor@0 1180 -----------------------------------------------------------------------------------
EmFor@0 1181 function CensusPlus_TakeGuild_OnClick()
EmFor@0 1182 if (g_IsCensusPlusInProgress) then
EmFor@0 1183 CensusPlus_TogglePause();
EmFor@0 1184 else
EmFor@0 1185 CensusPlus_StartGuildCensus();
EmFor@0 1186 end
EmFor@0 1187 end
EmFor@0 1188
EmFor@0 1189 -----------------------------------------------------------------------------------
EmFor@0 1190 --
EmFor@0 1191 -- Display a tooltip for the take button
EmFor@0 1192 --
EmFor@0 1193 -----------------------------------------------------------------------------------
EmFor@6 1194 function CensusPlus_Take_OnEnter( this )
EmFor@0 1195 if (g_IsCensusPlusInProgress) then
EmFor@0 1196 if (g_CensusPlusManuallyPaused) then
EmFor@0 1197 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
EmFor@0 1198 GameTooltip:SetText(CENSUSPlus_UNPAUSECENSUS, 1.0, 1.0, 1.0);
EmFor@0 1199 GameTooltip:Show();
EmFor@0 1200 else
EmFor@0 1201 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
EmFor@0 1202 GameTooltip:SetText(CENSUSPlus_PAUSECENSUS, 1.0, 1.0, 1.0);
EmFor@0 1203 GameTooltip:Show();
EmFor@0 1204 end
EmFor@0 1205 else
EmFor@0 1206 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
EmFor@0 1207 GameTooltip:SetText(CENSUSPlus_TAKECENSUS, 1.0, 1.0, 1.0);
EmFor@0 1208 GameTooltip:Show();
EmFor@0 1209 end
EmFor@0 1210 end
EmFor@0 1211
EmFor@0 1212 --rm
EmFor@0 1213 -----------------------------------------------------------------------------------
EmFor@0 1214 -- Display a tooltip for the take guild button
EmFor@0 1215 -----------------------------------------------------------------------------------
EmFor@6 1216 function CensusPlus_TakeGuild_OnEnter( this )
EmFor@0 1217 if (g_IsCensusPlusInProgress) then
EmFor@0 1218 if (g_CensusPlusManuallyPaused) then
EmFor@0 1219 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
EmFor@0 1220 GameTooltip:SetText(CENSUSPlus_UNPAUSECENSUS, 1.0, 1.0, 1.0);
EmFor@0 1221 GameTooltip:Show();
EmFor@0 1222 else
EmFor@0 1223 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
EmFor@0 1224 GameTooltip:SetText(CENSUSPlus_PAUSECENSUS, 1.0, 1.0, 1.0);
EmFor@0 1225 GameTooltip:Show();
EmFor@0 1226 end
EmFor@0 1227 else
EmFor@0 1228 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
EmFor@0 1229 GameTooltip:SetText(CENSUSPlus_TAKEGUILDCENSUS, 1.0, 1.0, 1.0);
EmFor@0 1230 GameTooltip:Show();
EmFor@0 1231 end
EmFor@0 1232 end
EmFor@0 1233
EmFor@0 1234 -----------------------------------------------------------------------------------
EmFor@0 1235 --
EmFor@0 1236 -- Pause the current census
EmFor@0 1237 --
EmFor@0 1238 -----------------------------------------------------------------------------------
EmFor@0 1239 function CensusPlus_TogglePause()
EmFor@0 1240 if (g_IsCensusPlusInProgress == true) then
EmFor@0 1241 if( g_CensusPlusManuallyPaused == true ) then
EmFor@0 1242 CensusPlusTakeButton:SetText( CENSUSPlus_PAUSE );
EmFor@0 1243 g_CensusPlusManuallyPaused = false;
EmFor@0 1244 else
EmFor@0 1245 CensusPlusTakeButton:SetText( CENSUSPlus_UNPAUSE );
EmFor@0 1246 g_CensusPlusManuallyPaused = true;
EmFor@0 1247 end
EmFor@0 1248 end
EmFor@0 1249 end
EmFor@0 1250
EmFor@0 1251 -----------------------------------------------------------------------------------
EmFor@0 1252 --
EmFor@0 1253 -- Purge the database for this realm and faction
EmFor@0 1254 --
EmFor@0 1255 -----------------------------------------------------------------------------------
EmFor@0 1256 function CensusPlus_Purge()
EmFor@0 1257 StaticPopup_Show ("CP_PURGE_CONFIRM");
EmFor@0 1258 end
EmFor@0 1259
EmFor@0 1260 -----------------------------------------------------------------------------------
EmFor@0 1261 --
EmFor@0 1262 -- CensusPlus_DoPurge
EmFor@0 1263 --
EmFor@0 1264 -----------------------------------------------------------------------------------
EmFor@0 1265 function CensusPlus_DoPurge()
EmFor@0 1266 if( CensusPlus_Database["Servers"] ~= nil ) then
EmFor@0 1267 CensusPlus_Database["Servers"] = nil;
EmFor@0 1268 end
EmFor@0 1269 CensusPlus_Database["Servers"] = {};
EmFor@0 1270 CensusPlus_UpdateView();
EmFor@0 1271 CensusPlus_Msg(CENSUSPlus_PURGEMSG);
EmFor@0 1272
EmFor@0 1273 if( CensusPlus_Database["Guilds"] ~= nil ) then
EmFor@0 1274 CensusPlus_Database["Guilds"] = nil;
EmFor@0 1275 end
EmFor@0 1276 CensusPlus_Database["Guilds"] = {};
EmFor@0 1277
EmFor@0 1278 if( CensusPlus_Database["TimesPlus"] ~= nil ) then
EmFor@0 1279 CensusPlus_Database["TimesPlus"] = nil;
EmFor@0 1280 end
EmFor@0 1281 CensusPlus_Database["TimesPlus"] = {};
EmFor@0 1282
EmFor@0 1283 if( CensusPlus_Profile ~= nil ) then
EmFor@0 1284 CensusPlus_Profile = nil;
EmFor@0 1285 end
EmFor@0 1286 CensusPlus_Profile = {};
EmFor@0 1287
EmFor@0 1288 if( CensusPlus_BGInfo ~= nil ) then
EmFor@0 1289 CensusPlus_BGInfo = nil;
EmFor@0 1290 end
EmFor@0 1291 CensusPlus_BGInfo = {};
EmFor@0 1292
EmFor@0 1293 CensusPlus_Msg( "Data Purged" );
EmFor@0 1294 end
EmFor@0 1295
EmFor@0 1296 -----------------------------------------------------------------------------------
EmFor@0 1297 --
EmFor@0 1298 -- Handler for auto close checkbox
EmFor@0 1299 --
EmFor@0 1300 -----------------------------------------------------------------------------------
EmFor@0 1301 function CensusPlus_AutoCloseWho(close)
EmFor@0 1302 g_WhoAutoClose = close;
EmFor@0 1303 end
EmFor@0 1304
EmFor@0 1305 --function CensusPlus_WhoLibEvent(event, query, ...)
EmFor@0 1306 -- CensusPlus_Msg( event )
EmFor@0 1307 --end
EmFor@0 1308
EmFor@0 1309 --rm
EmFor@0 1310 -----------------------------------------------------------------------------------
EmFor@0 1311 -- Take a guild CensusPlus
EmFor@0 1312 -----------------------------------------------------------------------------------
EmFor@0 1313 function CensusPlus_StartGuildCensus()
EmFor@0 1314 if (g_IsCensusPlusInProgress) then
EmFor@0 1315 -- Do not initiate a new CensusPlus while one is in progress
EmFor@0 1316 CensusPlus_Msg(CENSUSPlus_ISINPROGRESS);
EmFor@0 1317 elseif( g_CurrentlyInBG ) then
EmFor@0 1318 g_LastCensusRun = time()-600;
EmFor@0 1319 if( not g_CurrentlyInBG_Msg ) then
EmFor@0 1320 CensusPlus_Msg(CENSUSPlus_ISINBG);
EmFor@0 1321 g_CurrentlyInBG_Msg = true;
EmFor@0 1322 end
EmFor@0 1323 else
EmFor@0 1324 -- Set a timer
EmFor@0 1325 g_CensusPlus_StartTime = time();
EmFor@0 1326 -- Initialize the job queue and counters
EmFor@0 1327 CensusPlus_Msg(CENSUSPlus_TAKINGONLINE);
EmFor@0 1328 g_NumNewCharacters = 0;
EmFor@0 1329 g_NumUpdatedCharacters = 0;
EmFor@0 1330 g_JobQueue = {};
EmFor@0 1331 g_TempCount = nil;
EmFor@0 1332 g_TempCount = {};
EmFor@0 1333 g_TempZoneCount = nil;
EmFor@0 1334 g_TempZoneCount = {};
EmFor@0 1335 -- The Job List Works as LIFO; last in, first out
EmFor@0 1336 -- for Cataclysm, ... and GM's :) after all following Jobs
EmFor@0 1337 local job = CensusPlus_CreateJob( ( MAX_CHARACTER_LEVEL + 1 ) , MAX_LEVEL_DISPLAY, nil, nil, nil , CensusPlus_MYGUILD );
EmFor@0 1338 InsertJobIntoQueue(job);
EmFor@0 1339 -- ending with lvl MAX_CHARACTER_LEVEL
EmFor@0 1340 local counter = MAX_CHARACTER_LEVEL;
EmFor@0 1341 local LowCounter = counter;
EmFor@0 1342 local LowCharDetailLevel = 3;
EmFor@0 1343 local LevelStep = 10;
EmFor@0 1344
EmFor@0 1345 local job = CensusPlus_CreateJob( counter, counter, nil, nil, nil , CensusPlus_MYGUILD );
EmFor@0 1346 InsertJobIntoQueue(job);
EmFor@0 1347 counter = counter - 1;
EmFor@0 1348 while (counter > LowCharDetailLevel) do
EmFor@0 1349 LowCounter = counter - LevelStep + 1 ;
EmFor@0 1350 if (LowCounter <= LowCharDetailLevel) then
EmFor@0 1351 LowCounter = LowCharDetailLevel +1 ;
EmFor@0 1352 end
EmFor@0 1353 local job = CensusPlus_CreateJob( LowCounter, counter, nil, nil, nil , CensusPlus_MYGUILD );
EmFor@0 1354 InsertJobIntoQueue(job);
EmFor@0 1355 counter = LowCounter - 1 ;
EmFor@0 1356 end
EmFor@0 1357 while (counter > 0) do
EmFor@0 1358 LowCounter = counter ;
EmFor@0 1359 local job = CensusPlus_CreateJob( LowCounter, counter, nil, nil, nil , CensusPlus_MYGUILD );
EmFor@0 1360 InsertJobIntoQueue(job);
EmFor@0 1361 counter = LowCounter - 1 ;
EmFor@0 1362 end
EmFor@0 1363 ------------------
EmFor@0 1364 -- Test inserts
EmFor@0 1365 -- local job = CensusPlus_CreateJob( 11, 12, "Troll", nil, nil , CensusPlus_MYGUILD );
EmFor@0 1366 -- InsertJobIntoQueue(job);
EmFor@0 1367 g_IsCensusPlusInProgress = true;
EmFor@0 1368 g_WaitingForWhoUpdate = false;
EmFor@0 1369 g_CensusPlusManuallyPaused = false;
EmFor@0 1370 local hour, minute = GetGameTime();
EmFor@0 1371 g_TakeHour = hour;
EmFor@0 1372 g_ResetHour = true;
EmFor@0 1373 wholib = wholib or LibStub:GetLibrary("LibWho-2.0", true);
EmFor@0 1374 -- Subvert WhoLib
EmFor@0 1375 if( wholib ) then
EmFor@0 1376 CensusPlus_Msg( "Using WhoLib" );
EmFor@0 1377 end
EmFor@0 1378 end
EmFor@0 1379 CensusPlusTakeButton:SetText( CENSUSPlus_PAUSE );
EmFor@0 1380 CensusPlusTakeGuildButton:SetText( CENSUSPlus_TAKINGGUILD.." \""..CensusPlus_MYGUILD.."\"" );
EmFor@0 1381 end
EmFor@0 1382
EmFor@0 1383
EmFor@0 1384 -----------------------------------------------------------------------------------
EmFor@0 1385 --
EmFor@0 1386 -- Take a CensusPlus
EmFor@0 1387 --
EmFor@0 1388 -----------------------------------------------------------------------------------
EmFor@0 1389 function CensusPlus_StartCensus()
EmFor@0 1390
EmFor@0 1391 if (g_IsCensusPlusInProgress) then
EmFor@0 1392 if( g_CensusPlusManuallyPaused == true ) then
EmFor@0 1393 g_CensusPlusManuallyPaused = false;
EmFor@0 1394 CensusPlusPauseButton:SetText( CENSUSPlus_PAUSE );
EmFor@0 1395 else
EmFor@0 1396 -- Do not initiate a new CensusPlus while one is in progress
EmFor@0 1397 CensusPlus_Msg(CENSUSPlus_ISINPROGRESS);
EmFor@0 1398 end
EmFor@0 1399 elseif( g_CurrentlyInBG ) then
EmFor@0 1400 g_LastCensusRun = time()-600;
EmFor@0 1401 if( not g_CurrentlyInBG_Msg ) then
EmFor@0 1402 CensusPlus_Msg(CENSUSPlus_ISINBG);
EmFor@0 1403 g_CurrentlyInBG_Msg = true;
EmFor@0 1404 end
EmFor@0 1405 else
EmFor@0 1406 --
EmFor@0 1407 -- Set a timer
EmFor@0 1408 --
EmFor@0 1409 g_CensusPlus_StartTime = time();
EmFor@0 1410
EmFor@0 1411 --
EmFor@0 1412 -- Initialize the job queue and counters
EmFor@0 1413 --
EmFor@0 1414 CensusPlus_Msg(CENSUSPlus_TAKINGONLINE);
EmFor@0 1415 g_NumNewCharacters = 0;
EmFor@0 1416 g_NumUpdatedCharacters = 0;
EmFor@0 1417 g_JobQueue = {};
EmFor@0 1418
EmFor@0 1419 g_TempCount = nil;
EmFor@0 1420 g_TempCount = {};
EmFor@0 1421
EmFor@0 1422 g_TempZoneCount = nil;
EmFor@0 1423 g_TempZoneCount = {};
EmFor@0 1424 --
EmFor@0 1425 -- First job covers all characters by searching all levels
EmFor@0 1426 --
EmFor@0 1427 -- The Job List Works as LIFO; last in, first out
EmFor@0 1428 -- local job = {m_MinLevel = 1, m_MaxLevel = MAX_CHARACTER_LEVEL};
EmFor@0 1429 -- InsertJobIntoQueue(job);
EmFor@0 1430 --rm
EmFor@0 1431 -- for Cataclysm, ... and GM's :) after all following Jobs
EmFor@0 1432 local job = CensusPlus_CreateJob( ( MAX_CHARACTER_LEVEL + 1 ) , MAX_LEVEL_DISPLAY, nil, nil, nil , nil );
EmFor@0 1433 InsertJobIntoQueue(job);
EmFor@0 1434 ---- ending with lvl 1-10
EmFor@0 1435 -- local counter = 0;
EmFor@0 1436 -- for counter = 0, 6, 1 do
EmFor@0 1437 -- local job = CensusPlus_CreateJob( counter*10 + 1, counter*10+10, nil, nil, nil , nil );
EmFor@0 1438 -- InsertJobIntoQueue(job);
EmFor@0 1439 -- end
EmFor@0 1440 ---- do 71-79 before the above jobs
EmFor@0 1441 -- job = CensusPlus_CreateJob( 71, 79, nil, nil, nil , nil );
EmFor@0 1442 -- InsertJobIntoQueue(job);
EmFor@0 1443 ---- do 80-80 before the above jobs
EmFor@0 1444 -- job = CensusPlus_CreateJob( 80, 80, nil, nil, nil , nil );
EmFor@0 1445 -- InsertJobIntoQueue(job);
EmFor@0 1446
EmFor@0 1447 -- ending with lvl MAX_CHARACTER_LEVEL
EmFor@0 1448 local counter = MAX_CHARACTER_LEVEL;
EmFor@0 1449 local LowCounter = counter;
EmFor@0 1450 local LowCharDetailLevel = 3;
EmFor@0 1451 local LevelStep = 10;
EmFor@0 1452
EmFor@0 1453
EmFor@0 1454 local job = CensusPlus_CreateJob( counter, counter, nil, nil, nil , nil );
EmFor@0 1455 InsertJobIntoQueue(job);
EmFor@0 1456 counter = counter - 1;
EmFor@0 1457 while (counter > LowCharDetailLevel) do
EmFor@0 1458 LowCounter = counter - LevelStep + 1 ;
EmFor@0 1459 if (LowCounter <= LowCharDetailLevel) then
EmFor@0 1460 LowCounter = LowCharDetailLevel +1 ;
EmFor@0 1461 end
EmFor@0 1462 local job = CensusPlus_CreateJob( LowCounter, counter, nil, nil, nil , nil );
EmFor@0 1463 InsertJobIntoQueue(job);
EmFor@0 1464 counter = LowCounter - 1 ;
EmFor@0 1465 end
EmFor@0 1466 while (counter > 0) do
EmFor@0 1467 LowCounter = counter ;
EmFor@0 1468 local job = CensusPlus_CreateJob( LowCounter, counter, nil, nil, nil , nil );
EmFor@0 1469 InsertJobIntoQueue(job);
EmFor@0 1470 counter = LowCounter - 1 ;
EmFor@0 1471 end
EmFor@0 1472 ------------------
EmFor@0 1473
EmFor@0 1474
EmFor@0 1475 -- for counter = 60, MAX_CHARACTER_LEVEL, 1 do
EmFor@0 1476 -- local job = CensusPlus_CreateJob( counter, counter, nil, nil, nil , nil );
EmFor@0 1477 -- InsertJobIntoQueue(job);
EmFor@0 1478 -- end
EmFor@0 1479
EmFor@0 1480 -- Test inserts
EmFor@0 1481 -- local job = CensusPlus_CreateJob( 11, 12, "Troll", nil, nil , nil );
EmFor@0 1482 -- InsertJobIntoQueue(job);
EmFor@0 1483 g_IsCensusPlusInProgress = true;
EmFor@0 1484 g_WaitingForWhoUpdate = false;
EmFor@0 1485 g_CensusPlusManuallyPaused = false;
EmFor@0 1486
EmFor@0 1487 local hour, minute = GetGameTime();
EmFor@0 1488 g_TakeHour = hour;
EmFor@0 1489 g_ResetHour = true;
EmFor@0 1490
EmFor@0 1491 wholib = wholib or LibStub:GetLibrary("LibWho-2.0", true);
EmFor@0 1492 --
EmFor@0 1493 -- Subvert WhoLib
EmFor@0 1494 --
EmFor@0 1495 if( wholib ) then
EmFor@0 1496 --
EmFor@0 1497 -- Be prepared to subvert the WhoLib mechanic
EmFor@0 1498 --
EmFor@0 1499 -- g_WhoLibSubvert = SlashCmdList["WHO"];
EmFor@0 1500 -- SlashCmdList["WHO"] = CensusPlus_WhoHandler;
EmFor@0 1501 --
EmFor@0 1502 -- g_WhoLibSendWhoSubvert = SendWho;
EmFor@0 1503 -- SendWho = WhoLibByALeX.hooks.SendWho;
EmFor@0 1504 --
EmFor@0 1505 -- g_WhoLibResultSubvert = WhoLibByALeX.WHO_LIST_UPDATE;
EmFor@0 1506 -- g_WhoLibChatSubvert = WhoLibByALeX.CHAT_MSG_SYSTEM;
EmFor@0 1507 -- g_WhoLibAskWhoSubvert = WhoLibByALeX.AskWho;
EmFor@0 1508 --
EmFor@0 1509 -- WhoLibByALeX.WHO_LIST_UPDATE = function( args ) end
EmFor@0 1510 -- WhoLibByALeX.CHAT_MSG_SYSTEM = function( args ) end
EmFor@0 1511 -- WhoLibByALeX.AskWho = function( args ) end
EmFor@0 1512
EmFor@0 1513 CensusPlus_Msg( "Using WhoLib" );
EmFor@0 1514
EmFor@0 1515
EmFor@0 1516 --wholib.RegisterCallback("CensusPlus", "WHOLIB_QUERY_RESULT", CensusPlus_WhoLibEvent)
EmFor@0 1517
EmFor@0 1518 end
EmFor@0 1519 end
EmFor@0 1520 CensusPlusTakeButton:SetText( CENSUSPlus_PAUSE );
EmFor@0 1521 end
EmFor@0 1522
EmFor@0 1523 -----------------------------------------------------------------------------------
EmFor@0 1524 --
EmFor@0 1525 -- Stop a CensusPlus
EmFor@0 1526 --
EmFor@0 1527 -----------------------------------------------------------------------------------
EmFor@0 1528 function CensusPlus_StopCensus( )
EmFor@0 1529 if (g_IsCensusPlusInProgress) then
EmFor@0 1530 CensusPlusTakeButton:SetText( CENSUSPlus_TAKE );
EmFor@0 1531 CensusPlusTakeGuildButton:SetText( CENSUSPlus_TAKEGUILD.." \""..CensusPlus_MYGUILD.."\"" ); CensusPlusTakeGuildButton:SetText( CENSUSPlus_TAKEGUILD.." \""..CensusPlus_MYGUILD.."\"" );
EmFor@0 1532 g_CensusPlusManuallyPaused = false;
EmFor@0 1533
EmFor@0 1534 CensusPlusScanProgress:SetText( CENSUSPlus_SCAN_PROGRESS_0 );
EmFor@0 1535
EmFor@0 1536 g_JobQueue = {};
EmFor@0 1537 g_JobQueue = nil;
EmFor@0 1538 g_JobQueue = {};
EmFor@0 1539
EmFor@0 1540 CensusPlus_DisplayResults( );
EmFor@0 1541
EmFor@0 1542 -- Clean up the times
EmFor@0 1543 CensusPlus_PruneTimes();
EmFor@0 1544
EmFor@0 1545 -- if( wholib ) then
EmFor@0 1546 -- SlashCmdList["WHO"] = g_WhoLibSubvert;
EmFor@0 1547 --
EmFor@0 1548 -- SendWho = g_WhoLibSendWhoSubvert;
EmFor@0 1549 -- WhoLibByALeX.WHO_LIST_UPDATE = g_WhoLibResultSubvert;
EmFor@0 1550 -- WhoLibByALeX.CHAT_MSG_SYSTEM = g_WhoLibChatSubvert;
EmFor@0 1551 -- WhoLibByALeX.AskWho = g_WhoLibAskWhoSubvert;
EmFor@0 1552
EmFor@0 1553
EmFor@0 1554 -- CensusPlus_Msg( "Unregistering with WhoLib" );
EmFor@0 1555
EmFor@0 1556 --wholib.UnregisterAllCallbacks("CensusPlus")
EmFor@0 1557 -- end
EmFor@0 1558
EmFor@0 1559 else
EmFor@0 1560 CensusPlus_Msg(CENSUSPlus_NOCENSUS);
EmFor@0 1561 end
EmFor@0 1562 end
EmFor@0 1563
EmFor@0 1564 -----------------------------------------------------------------------------------
EmFor@0 1565 --
EmFor@0 1566 -- Display Census results
EmFor@0 1567 --
EmFor@0 1568 -----------------------------------------------------------------------------------
EmFor@0 1569 function CensusPlus_DisplayResults( )
EmFor@0 1570 --
EmFor@0 1571 -- We are all done, report our results
EmFor@0 1572 --
EmFor@0 1573 g_IsCensusPlusInProgress = false;
EmFor@0 1574
EmFor@0 1575
EmFor@0 1576 --
EmFor@0 1577 -- Finish our timer
EmFor@0 1578 --
EmFor@0 1579 local total_time = time() - g_CensusPlus_StartTime;
EmFor@0 1580
EmFor@0 1581 CensusPlus_Msg(format(CENSUSPlus_FINISHED, g_NumNewCharacters, g_NumUpdatedCharacters, SecondsToTime( total_time )));
EmFor@0 1582 ChatFrame1:AddMessage(CENSUSPlus_UPLOAD, 0.5, 1.0, 1.0);
EmFor@0 1583
EmFor@0 1584 CensusPlus_UpdateView();
EmFor@0 1585 g_LastCensusRun = time();
EmFor@0 1586
EmFor@0 1587 CensusPlusTakeButton:SetText( CENSUSPlus_TAKE );
EmFor@0 1588 CensusPlusTakeGuildButton:SetText( CENSUSPlus_TAKEGUILD.." \""..CensusPlus_MYGUILD.."\"" );
EmFor@0 1589 end
EmFor@0 1590
EmFor@0 1591 -----------------------------------------------------------------------------------
EmFor@0 1592 --
EmFor@0 1593 -- Create a who command text for the input job
EmFor@0 1594 --
EmFor@0 1595 -----------------------------------------------------------------------------------
EmFor@0 1596 function CensusPlus_CreateWhoText(job)
EmFor@0 1597 local whoText = "";
EmFor@0 1598 local race = job.m_Race;
EmFor@0 1599 if (race ~= nil) then
EmFor@0 1600 whoText = whoText.." r-\""..race.."\"";
EmFor@0 1601 end
EmFor@0 1602
EmFor@0 1603 local class = job.m_Class;
EmFor@0 1604 if (class ~= nil) then
EmFor@0 1605 whoText = whoText.." c-\""..class.."\"";
EmFor@0 1606 end
EmFor@0 1607
EmFor@0 1608 local minLevel = tostring( job.m_MinLevel );
EmFor@0 1609 if (minLevel == nil) then
EmFor@0 1610 minLevel = 1;
EmFor@0 1611 end
EmFor@0 1612 local maxLevel = job.m_MaxLevel;
EmFor@0 1613 if (maxLevel == nil) then
EmFor@0 1614 maxLevel = MAX_CHARACTER_LEVEL;
EmFor@0 1615 end
EmFor@0 1616 whoText = whoText.." ".. minLevel .."-".. maxLevel;
EmFor@0 1617
EmFor@0 1618 local zoneLetter = job.m_zoneLetter;
EmFor@0 1619 if ( zoneLetter ~= nil) then
EmFor@0 1620 whoText = whoText.." z-"..zoneLetter;
EmFor@0 1621 end
EmFor@0 1622
EmFor@0 1623 local letter = job.m_Letter;
EmFor@0 1624 if( letter ~= nil ) then
EmFor@0 1625 whoText = whoText.." n-"..letter;
EmFor@0 1626 end
EmFor@0 1627 --rmg
EmFor@0 1628 local guild = job.m_Guild;
EmFor@0 1629 if( guild ~= nil ) then
EmFor@0 1630 whoText = whoText.." g-\""..guild.."\"";
EmFor@0 1631 end
EmFor@0 1632
EmFor@0 1633 return whoText;
EmFor@0 1634 end
EmFor@0 1635
EmFor@0 1636 -----------------------------------------------------------------------------------
EmFor@0 1637 --
EmFor@0 1638 -- Create a job
EmFor@0 1639 --
EmFor@0 1640 -----------------------------------------------------------------------------------
EmFor@0 1641 function CensusPlus_CreateJob( minLevel, maxLevel, race, class, letter, guild )
EmFor@0 1642 local job = {};
EmFor@0 1643 job.m_MinLevel = minLevel;
EmFor@0 1644 job.m_MaxLevel = maxLevel;
EmFor@0 1645 job.m_Race = race;
EmFor@0 1646 job.m_Class = class;
EmFor@0 1647 job.m_Letter = letter;
EmFor@0 1648 job.m_Guild = guild;
EmFor@0 1649
EmFor@0 1650 CensusPlus_DumpJob( job );
EmFor@0 1651
EmFor@0 1652 return job;
EmFor@0 1653 end
EmFor@0 1654
EmFor@0 1655 -----------------------------------------------------------------------------------
EmFor@0 1656 --
EmFor@0 1657 -- Debug function do dump a job
EmFor@0 1658 --
EmFor@0 1659 -----------------------------------------------------------------------------------
EmFor@0 1660 function CensusPlus_DumpJob( job )
EmFor@0 1661 local whoText = "";
EmFor@0 1662 local race = job.m_Race;
EmFor@0 1663 if (race ~= nil) then
EmFor@0 1664 whoText = whoText.." R: "..race;
EmFor@0 1665 end
EmFor@0 1666
EmFor@0 1667 local class = job.m_Class;
EmFor@0 1668 if (class ~= nil) then
EmFor@0 1669 whoText = whoText.." C: "..class;
EmFor@0 1670 end
EmFor@0 1671
EmFor@0 1672 local minLevel = job.m_MinLevel;
EmFor@0 1673 if (minLevel ~= nil) then
EmFor@0 1674 whoText = whoText.." min: ".. minLevel;
EmFor@0 1675 end
EmFor@0 1676
EmFor@0 1677 local maxLevel = job.m_MaxLevel;
EmFor@0 1678 if (maxLevel ~= nil) then
EmFor@0 1679 whoText = whoText.." max: ".. maxLevel;
EmFor@0 1680 end
EmFor@0 1681
EmFor@0 1682 local zoneLetter = job.m_zoneLetter;
EmFor@0 1683 if ( zoneLetter ~= nil) then
EmFor@0 1684 whoText = whoText.." Z: "..zoneLetter;
EmFor@0 1685 end
EmFor@0 1686
EmFor@0 1687 local letter = job.m_Letter;
EmFor@0 1688 if( letter ~= nil ) then
EmFor@0 1689 whoText = whoText.." N: "..letter;
EmFor@0 1690 end
EmFor@0 1691 --rmg
EmFor@0 1692 local guild = job.m_Guild;
EmFor@0 1693 if( guild ~= nil ) then
EmFor@0 1694 whoText = whoText.." G: \""..guild.."\"";
EmFor@0 1695 end
EmFor@0 1696
EmFor@0 1697 --CensusPlus_Msg( "JOB DUMP: " .. whoText );
EmFor@0 1698 end
EmFor@0 1699
EmFor@0 1700 -----------------------------------------------------------------------------------
EmFor@0 1701 --
EmFor@0 1702 -- Called on events
EmFor@0 1703 --
EmFor@0 1704 -----------------------------------------------------------------------------------
EmFor@0 1705 function CensusPlus_OnEvent(event,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
EmFor@0 1706
EmFor@0 1707 if( arg1 == nil ) then
EmFor@0 1708 arg1 = "nil"
EmFor@0 1709 end
EmFor@0 1710 if( arg2 == nil ) then
EmFor@0 1711 arg2 = "nil"
EmFor@0 1712 end
EmFor@0 1713 if( arg3 == nil ) then
EmFor@0 1714 arg3 = "nil"
EmFor@0 1715 end
EmFor@0 1716 if( arg4 == nil ) then
EmFor@0 1717 arg4 = "nil"
EmFor@0 1718 end
EmFor@0 1719
EmFor@0 1720 --
EmFor@0 1721 -- If we have not been initialized, do nothing
EmFor@0 1722 --
EmFor@0 1723 if (g_CensusPlusInitialized == false) then
EmFor@0 1724 return
EmFor@0 1725 end
EmFor@0 1726
EmFor@0 1727 -- CensusPlus_Msg( "Message =>" .. event );
EmFor@0 1728
EmFor@0 1729 --
EmFor@0 1730 -- WHO_LIST_UPDATE
EmFor@0 1731 --
EmFor@0 1732 if( event == "TRAINER_SHOW" or event == "MERCHANT_SHOW" or event == "TRADE_SHOW" or event == "GUILD_REGISTRAR_SHOW"
EmFor@0 1733 or event == "AUCTION_HOUSE_SHOW" or event == "BANKFRAME_OPENED" or event == "QUEST_DETAIL" ) then
EmFor@0 1734 if( g_IsCensusPlusInProgress ) then
EmFor@0 1735 g_CensusPlusPaused = true;
EmFor@0 1736 end
EmFor@0 1737 elseif( event == "TRAINER_CLOSED" or event == "MERCHANT_CLOSED" or event == "TRADE_CLOSED" or event == "GUILD_REGISTRAR_CLOSED"
EmFor@0 1738 or event == "AUCTION_HOUSE_CLOSED" or event == "BANKFRAME_CLOSED" or event == "QUEST_FINISHED" ) then
EmFor@0 1739 if( g_IsCensusPlusInProgress ) then
EmFor@0 1740 g_CensusPlusPaused = false;
EmFor@0 1741 end
EmFor@0 1742 elseif (event == "GUILD_ROSTER_SHOW") then
EmFor@0 1743 --
EmFor@0 1744 -- Process Guild info
EmFor@0 1745 --
EmFor@0 1746 --CensusPlus_Msg( " SHOW GUILD " );
EmFor@0 1747 CensusPlus_ProcessGuildResults();
EmFor@0 1748
EmFor@0 1749 elseif (event == "GUILD_ROSTER_UPDATE") then
EmFor@0 1750 --
EmFor@0 1751 -- Process Guild info
EmFor@0 1752 --
EmFor@0 1753 --CensusPlus_Msg( " UPDATE GUILD " );
EmFor@0 1754 if(not CP_updatingGuild ) then
EmFor@0 1755 CP_updatingGuild = 1;
EmFor@0 1756 CensusPlus_ProcessGuildResults();
EmFor@0 1757 CP_updatingGuild = nil;
EmFor@0 1758 end
EmFor@0 1759
EmFor@0 1760
EmFor@0 1761 elseif ( event == "VARIABLES_LOADED" ) then
EmFor@0 1762 --
EmFor@0 1763 -- Initialize our variables
EmFor@0 1764 --
EmFor@0 1765 CensusPlus_InitializeVariables();
EmFor@0 1766 elseif( event == "ZONE_CHANGED_NEW_AREA" ) then
EmFor@0 1767 --
EmFor@0 1768 -- We need to check to see if we entered a battleground
EmFor@0 1769 --
EmFor@0 1770 CensusPlus_CheckForBattleground();
EmFor@0 1771 elseif( event == "UPDATE_BATTLEFIELD_STATUS" ) then
EmFor@0 1772 CensusPlus_UpdateBattleGroundInfo();
EmFor@0 1773 end
EmFor@0 1774 end
EmFor@0 1775
EmFor@0 1776 -----------------------------------------------------------------------------------
EmFor@0 1777 --
EmFor@0 1778 -- ProcessTarget -- called when UNIT_FOCUS event is fired
EmFor@0 1779 --
EmFor@0 1780 -----------------------------------------------------------------------------------
EmFor@0 1781 function CensusPlus_ProcessTarget( unit )
EmFor@0 1782 -- have to totally disable this due to X-server bg's
EmFor@0 1783 if( true ) then
EmFor@0 1784 return;
EmFor@0 1785 end
EmFor@0 1786
EmFor@0 1787 if ( UnitIsPlayer(unit) == nil or (not UnitIsPlayer(unit)) or unit == "player" or unit == nil ) then
EmFor@0 1788 return;
EmFor@0 1789 end
EmFor@0 1790
EmFor@0 1791 local sightingData = CensusPlus_CollectSightingData( unit );
EmFor@0 1792 if( sightingData == nil or sightingData.faction == nil ) then
EmFor@0 1793 return
EmFor@0 1794 end
EmFor@0 1795
EmFor@0 1796 if (sightingData ~= nil and (sightingData.faction == "Alliance" or sightingData.faction == "Horde")) then
EmFor@0 1797
EmFor@0 1798 --
EmFor@0 1799 -- Do a quick check to see if this is an MC'd person
EmFor@0 1800 --
EmFor@0 1801 if( sightingData.faction ~= g_FactionCheck[sightingData.race] ) then
EmFor@0 1802 return;
EmFor@0 1803 end
EmFor@0 1804
EmFor@0 1805
EmFor@0 1806 if( sightingData.guild == nil ) then
EmFor@0 1807 sightingData.guild = "";
EmFor@0 1808 end
EmFor@0 1809 --
EmFor@0 1810 -- Get the portion of the database for this server
EmFor@0 1811 --
EmFor@0 1812 local realmName = g_CensusPlusLocale .. GetCVar("realmName");
EmFor@0 1813 local realmDatabase = CensusPlus_Database["Servers"][realmName];
EmFor@0 1814 if (realmDatabase == nil) then
EmFor@0 1815 CensusPlus_Database["Servers"][realmName] = {};
EmFor@0 1816 realmDatabase = CensusPlus_Database["Servers"][realmName];
EmFor@0 1817 end
EmFor@0 1818
EmFor@0 1819 --
EmFor@0 1820 -- Get the portion of the database for this faction
EmFor@0 1821 --
EmFor@0 1822 local factionDatabase = realmDatabase[sightingData.faction];
EmFor@0 1823 if (factionDatabase == nil) then
EmFor@0 1824 realmDatabase[sightingData.faction] = {};
EmFor@0 1825 factionDatabase = realmDatabase[sightingData.faction];
EmFor@0 1826 end
EmFor@0 1827
EmFor@0 1828 --
EmFor@0 1829 -- Get racial database
EmFor@0 1830 --
EmFor@0 1831 local raceDatabase = factionDatabase[sightingData.race];
EmFor@0 1832 if (raceDatabase == nil) then
EmFor@0 1833 factionDatabase[sightingData.race] = {};
EmFor@0 1834 raceDatabase = factionDatabase[sightingData.race];
EmFor@0 1835 end
EmFor@0 1836
EmFor@0 1837 --
EmFor@0 1838 -- Get class database
EmFor@0 1839 --
EmFor@0 1840 local classDatabase = raceDatabase[sightingData.class];
EmFor@0 1841 if (classDatabase == nil) then
EmFor@0 1842 raceDatabase[sightingData.class] = {};
EmFor@0 1843 classDatabase = raceDatabase[sightingData.class];
EmFor@0 1844 end
EmFor@0 1845
EmFor@0 1846 --
EmFor@0 1847 -- Get this player's entry
EmFor@0 1848 --
EmFor@0 1849 local entry = classDatabase[sightingData.name];
EmFor@0 1850 if (entry == nil) then
EmFor@0 1851 classDatabase[sightingData.name] = {};
EmFor@0 1852 entry = classDatabase[sightingData.name];
EmFor@0 1853 end
EmFor@0 1854
EmFor@0 1855 --
EmFor@0 1856 -- Update the information
EmFor@0 1857 --
EmFor@0 1858 entry[1] = sightingData.level;
EmFor@0 1859 entry[2] = sightingData.guild;
EmFor@0 1860 entry[3] = CensusPlus_DetermineServerDate() .. "";
EmFor@0 1861
EmFor@0 1862 entry[7] = CensusPlus_DetermineServerDate() .. "";
EmFor@0 1863
EmFor@0 1864 --
EmFor@0 1865 -- Update their rank info
EmFor@0 1866 --
EmFor@0 1867 rankNumber = UnitPVPRank(unit);
EmFor@0 1868 if( rankNumber ~= 0 ) then
EmFor@0 1869 -- rankName= GetPVPRankInfo( rankNumber )
EmFor@0 1870 entry[8] = rankNumber; -- slot 8 will be current rank
EmFor@0 1871 else
EmFor@0 1872 entry[8] = 0; -- slot 8 will be current rank
EmFor@0 1873 end
EmFor@0 1874
EmFor@0 1875 --
EmFor@0 1876 -- Trigger an update on the inspect honor frame to get honor information
EmFor@0 1877 --
EmFor@0 1878 if ( UnitIsPlayer( unit ) and sightingData.level >= 30
EmFor@0 1879 and CheckInteractDistance( unit, 1)
EmFor@0 1880 and not UnitIsUnit("player", unit) and unit == "target"
EmFor@0 1881 and g_CensusPlusLastTarget == nil
EmFor@0 1882 and g_CensusPlusLastTargetName == nil
EmFor@0 1883 and CensusPlus_IsInspectLoaded() ) then
EmFor@0 1884 NotifyInspect(unit);
EmFor@0 1885 InspectFrame.unit = unit;
EmFor@0 1886 if ( not HasInspectHonorData() ) then
EmFor@0 1887 g_CensusPlusLastTarget = entry;
EmFor@0 1888 g_CensusPlusLastTargetName = sightingData.name;
EmFor@0 1889 RequestInspectHonorData();
EmFor@0 1890 else
EmFor@0 1891 InspectHonorFrame_Update();
EmFor@0 1892 end
EmFor@0 1893 end
EmFor@0 1894 end
EmFor@0 1895 end
EmFor@0 1896
EmFor@0 1897
EmFor@0 1898 -----------------------------------------------------------------------------------
EmFor@0 1899 --
EmFor@0 1900 -- Gather targeting data
EmFor@0 1901 --
EmFor@0 1902 -----------------------------------------------------------------------------------
EmFor@0 1903 function CensusPlus_CollectSightingData(unit)
EmFor@0 1904 if ( UnitIsPlayer(unit) and UnitName(unit) ~= "Unknown Entity" ) then
EmFor@0 1905 return {
EmFor@0 1906 name=UnitName(unit),
EmFor@0 1907 level=UnitLevel(unit),
EmFor@0 1908 sex=UnitSex(unit),
EmFor@0 1909 race=UnitRace(unit),
EmFor@0 1910 class=UnitClass(unit),
EmFor@0 1911 guild=GetGuildInfo(unit),
EmFor@0 1912 faction=UnitFactionGroup(unit)
EmFor@0 1913 };
EmFor@0 1914 else
EmFor@0 1915 return nil;
EmFor@0 1916 end
EmFor@0 1917 end
EmFor@0 1918
EmFor@0 1919
EmFor@0 1920 -----------------------------------------------------------------------------------
EmFor@0 1921 --
EmFor@0 1922 -- Initialize our primary save variables -- called when VARIABLES_LOADED event is fired
EmFor@0 1923 --
EmFor@0 1924 -----------------------------------------------------------------------------------
EmFor@0 1925 function CensusPlus_InitializeVariables()
EmFor@0 1926
EmFor@0 1927 if( CensusPlus_Database["Servers"] == nil ) then
EmFor@0 1928 CensusPlus_Database["Servers"] = {};
EmFor@0 1929 end
EmFor@0 1930
EmFor@0 1931 if( CensusPlus_Database["Times"] ~= nil ) then
EmFor@0 1932 CensusPlus_Database["Times"] = nil;
EmFor@0 1933 end
EmFor@0 1934
EmFor@0 1935 if( CensusPlus_Database["TimesPlus"] == nil ) then
EmFor@0 1936 CensusPlus_Database["TimesPlus"] = {};
EmFor@0 1937 end
EmFor@0 1938
EmFor@0 1939 if( CensusPlus_BGInfo == nil ) then
EmFor@0 1940 CensusPlus_BGInfo = {};
EmFor@0 1941 end
EmFor@0 1942
EmFor@0 1943 --
EmFor@0 1944 -- Make sure info is last so it will be first in the output so we can grab the version number
EmFor@0 1945 --
EmFor@0 1946 if( CensusPlus_Database["Info"] == nil ) then
EmFor@0 1947 CensusPlus_Database["Info"] = {};
EmFor@0 1948 end
EmFor@0 1949 CensusPlus_Database["Info"]["Version"] = CensusPlus_VERSION;
EmFor@0 1950 CensusPlus_Database["Info"]["ClientLocale"] = GetLocale();
EmFor@0 1951 if( CensusPlus_Database["Info"]["ClientLocale"] == "enUS" and GetCVar("realmList") == "eu.logon.worldofwarcraft.com" ) then
EmFor@0 1952 CensusPlus_Database["Info"]["ClientLocale"] = "enGB";
EmFor@0 1953 end
EmFor@0 1954 if( CensusPlus_Database["Info"]["LoginServer"] ~= nil ) then
EmFor@0 1955 -- already present, make sure it equals, and if
EmFor@0 1956 -- not, force a purge
EmFor@0 1957 if( CensusPlus_Database["Info"]["LoginServer"] ~= GetCVar("realmList") ) then
EmFor@0 1958 --
EmFor@0 1959 -- We have to nuke the data in the case that someone is playing on both
EmFor@0 1960 -- US and EU servers
EmFor@0 1961 --
EmFor@0 1962 CensusPlus_DoPurge()
EmFor@0 1963 end
EmFor@0 1964 end
EmFor@0 1965 CensusPlus_Database["Info"]["LoginServer"] = GetCVar("realmList");
EmFor@0 1966
EmFor@0 1967 local firstVersionRun = CensusPlus_Database["Info"][g_InterfaceVersion];
EmFor@0 1968 local localeSetting = CensusPlus_Database["Info"]["Locale"];
EmFor@0 1969 if( localeSetting == "??" ) then
EmFor@0 1970 -- We had problems previously.. we must purge =(
EmFor@0 1971 CensusPlus_DoPurge();
EmFor@0 1972 localeSetting = nil;
EmFor@0 1973 end
EmFor@0 1974
EmFor@0 1975 --
EmFor@0 1976 -- Have a new way to detect locale, yay!
EmFor@0 1977 --
EmFor@0 1978 if( CensusPlus_Database["Info"]["ClientLocale"] == "enUS" ) then
EmFor@0 1979 CensusPlus_VerifyLocale( "US" );
EmFor@0 1980 CensusPlus_Database["Info"]["Locale"] = "US";
EmFor@0 1981 elseif( CensusPlus_Database["Info"]["ClientLocale"] == "enGB" or
EmFor@0 1982 CensusPlus_Database["Info"]["ClientLocale"] == "frFR" or
EmFor@0 1983 CensusPlus_Database["Info"]["ClientLocale"] == "deDE" or
EmFor@0 1984 CensusPlus_Database["Info"]["ClientLocale"] == "esES" ) then
EmFor@0 1985 CensusPlus_VerifyLocale( "EU" );
EmFor@0 1986 CensusPlus_Database["Info"]["Locale"] = "EU";
EmFor@0 1987 else
EmFor@0 1988 CensusPlus_VerifyLocale( "??" );
EmFor@0 1989 CensusPlus_Database["Info"]["Locale"] = "??";
EmFor@0 1990 end
EmFor@0 1991
EmFor@0 1992 if( firstVersionRun == nil and g_InterfaceVersion == 21000 ) then
EmFor@0 1993 --
EmFor@0 1994 -- Clean out all character entries that are irregular
EmFor@0 1995 --
EmFor@0 1996 CensusPlus_CleanChars();
EmFor@0 1997 CensusPlus_Database["Info"][g_InterfaceVersion] = true;
EmFor@0 1998 end
EmFor@0 1999
EmFor@0 2000 local locale = CensusPlus_Database["Info"]["Locale"];
EmFor@0 2001 CensusPlus_SelectLocale( CensusPlus_Database["Info"]["Locale"], true );
EmFor@0 2002
EmFor@0 2003 local miniStart = CensusPlus_Database["Info"]["MiniStart"];
EmFor@0 2004 if( miniStart == nil ) then
EmFor@0 2005 miniStart = 0;
EmFor@0 2006 end
EmFor@0 2007
EmFor@0 2008 if( CensusPlus_Database["Info"]["AutoCensus"] == nil ) then
EmFor@0 2009 CensusPlus_Database["Info"]["AutoCensus"] = false;
EmFor@0 2010 end
EmFor@0 2011
EmFor@0 2012 if( CensusPlus_Database["Info"]["AutoCensusTimer"] == nil ) then
EmFor@0 2013 CensusPlus_Database["Info"]["AutoCensusTimer"] = 1800;
EmFor@0 2014 end
EmFor@0 2015
EmFor@0 2016 if( CensusPlus_Database["Info"]["CensusButtonPosition"] == nil ) then
EmFor@0 2017 CensusPlus_Database["Info"]["CensusButtonPosition"] = 370;
EmFor@0 2018 end
EmFor@0 2019
EmFor@0 2020 if( CensusPlus_Database["Info"]["CensusButtonShown"] == nil ) then
EmFor@0 2021 CensusPlus_Database["Info"]["CensusButtonShown"] = 1;
EmFor@0 2022 end
EmFor@0 2023
EmFor@0 2024 if( CensusPlus_Database["Info"]["CensusButtonShown"] == 1 ) then
EmFor@0 2025 CensusButtonFrame:Show();
EmFor@0 2026 else
EmFor@0 2027 CensusButtonFrame:Hide();
EmFor@0 2028 end
EmFor@0 2029
EmFor@0 2030 if( CensusPlus_Database["Info"]["UseLogBars"] == nil ) then
EmFor@0 2031 CensusPlus_Database["Info"]["UseLogBars"] = 1;
EmFor@0 2032 end
EmFor@0 2033 CP_OptionUseLogarithmicBars:SetChecked( CensusPlus_Database["Info"]["UseLogBars"] );
EmFor@0 2034
EmFor@0 2035 CensusPlus_AutoStart(miniStart);
EmFor@0 2036
EmFor@0 2037 if( miniStart ) and (not Khaos) then
EmFor@0 2038 CensusPlus_Msg(" V"..CensusPlus_VERSION..CENSUSPlus_MSG1);
EmFor@0 2039 end
EmFor@0 2040
EmFor@0 2041 g_VariablesLoaded = true;
EmFor@0 2042
EmFor@0 2043 CensusPlus_CheckTZ();
EmFor@0 2044
EmFor@0 2045 InitConstantTables();
EmFor@0 2046
EmFor@0 2047 CP_OptionAutoShowMinimapButton:SetChecked(CensusPlus_Database["Info"]["CensusButtonShown"]);
EmFor@0 2048 -- CP_SliderButtonPos:SetValue(CensusPlus_Database["Info"]["CensusButtonPosition"]);
EmFor@0 2049
EmFor@0 2050 if( CensusPlus_PerCharInfo["PlayFinishSound"] == nil ) then
EmFor@0 2051 CensusPlus_PerCharInfo["PlayFinishSound"] = true;
EmFor@0 2052 end
EmFor@0 2053
EmFor@0 2054 CP_OptionPlaySoundOnCompleteButton:SetChecked( CensusPlus_PerCharInfo["PlayFinishSound"] );
EmFor@0 2055
EmFor@0 2056 if( CensusPlus_PerCharInfo["Verbose"] == nil ) then
EmFor@0 2057 CensusPlus_PerCharInfo["Verbose"] = false;
EmFor@0 2058 end
EmFor@0 2059
EmFor@0 2060
EmFor@0 2061 --
EmFor@0 2062 -- If we are in a guild, attempt to gather the guild roster data
EmFor@0 2063 --
EmFor@0 2064 if (IsInGuild()) then
EmFor@0 2065 GuildRoster();
EmFor@0 2066 end
EmFor@0 2067
EmFor@0 2068 --
EmFor@0 2069 -- Prune times if we have too many
EmFor@0 2070 --
EmFor@0 2071 CensusPlus_PruneTimes();
EmFor@0 2072
EmFor@0 2073 --
EmFor@0 2074 -- Prune BG info if we have too many
EmFor@0 2075 --
EmFor@0 2076 CensusPlus_PruneBGInfo();
EmFor@0 2077
EmFor@0 2078 --
EmFor@0 2079 -- Check for WhoLib since it does not play nice with C+
EmFor@0 2080 --
EmFor@0 2081 CensusPlus_CheckForWhoLib();
EmFor@0 2082 CensusPlus_CheckForPrat();
EmFor@0 2083
EmFor@0 2084 CensusPlus_Unhandled = nil;
EmFor@0 2085 CensusPlus_Unhandled = {};
EmFor@0 2086 end
EmFor@0 2087
EmFor@0 2088 function CensusPlus_CheckForWhoLib()
EmFor@0 2089 if( WhoLibByALeX and WhoLibByALeX.AskWho ) then
EmFor@0 2090 g_WhoLibLoaded = true;
EmFor@0 2091 CensusPlus_Msg( "ACE WhoLib detected - WhoLib does not play nice with other mods and as such, some WhoLib functionality must be disabled while a Census scan is in progress." );
EmFor@0 2092 end
EmFor@0 2093 end
EmFor@0 2094
EmFor@0 2095 function CensusPlus_CheckForPrat()
EmFor@0 2096 if( Prat ) then
EmFor@0 2097 g_PratLoaded = true;
EmFor@0 2098 CensusPlus_Msg( "Prat detected. CensusPlus will attempt to capture the 3 or less /who results that are displayed in chat, but may be unsuccessful." );
EmFor@0 2099 end
EmFor@0 2100 end
EmFor@0 2101 -----------------------------------------------------------------------------------
EmFor@0 2102 --
EmFor@0 2103 -- Call on the update event
EmFor@0 2104 --
EmFor@0 2105 -----------------------------------------------------------------------------------
EmFor@0 2106 function CensusPlus_OnUpdate()
EmFor@0 2107 if( g_VariablesLoaded and g_IsCensusPlusInProgress == false and CensusPlus_Database["Info"]["AutoCensus"] == true and g_LastCensusRun < time() - CensusPlus_Database["Info"]["AutoCensusTimer"] ) then
EmFor@0 2108 CensusPlus_Take_OnClick();
EmFor@0 2109 end
EmFor@0 2110
EmFor@0 2111 if (g_IsCensusPlusInProgress == true and g_CensusPlusPaused == false and g_CensusPlusManuallyPaused == false ) then
EmFor@0 2112
EmFor@0 2113 --
EmFor@0 2114 -- update our progress
EmFor@0 2115 --
EmFor@0 2116 local numJobs = table.getn(g_JobQueue);
EmFor@0 2117 if( numJobs > 0 ) then
EmFor@0 2118 CensusPlusScanProgress:SetText(format(CENSUSPlus_SCAN_PROGRESS, numJobs, CensusPlus_CreateWhoText( g_JobQueue[numJobs] ) ));
EmFor@0 2119 end
EmFor@0 2120
EmFor@0 2121 if( g_ReturnedZero == true ) then
EmFor@0 2122 g_ReturnedZero = false;
EmFor@0 2123 --
EmFor@0 2124 -- Determine if there is any more work to do
EmFor@0 2125 --
EmFor@0 2126 if (numJobs > 0) then
EmFor@0 2127 --
EmFor@0 2128 -- Remove the top job from the queue and send it
EmFor@0 2129 --
EmFor@0 2130 local job = g_JobQueue[numJobs];
EmFor@0 2131 table.remove(g_JobQueue);
EmFor@0 2132 local whoText = CensusPlus_CreateWhoText(job);
EmFor@0 2133
EmFor@0 2134 --
EmFor@0 2135 -- Zap our current job
EmFor@0 2136 --
EmFor@0 2137 g_CurrentJob = nil;
EmFor@0 2138
EmFor@0 2139 g_CurrentJob = job;
EmFor@0 2140 g_WaitingForWhoUpdate = true;
EmFor@0 2141
EmFor@0 2142 CensusPlus_SendWho(whoText);
EmFor@0 2143 g_WhoAttempts = 0;
EmFor@0 2144 else
EmFor@0 2145 --
EmFor@0 2146 -- We are all done, hide the friends frame and report our results
EmFor@0 2147 --
EmFor@0 2148 if( CensusPlus_PerCharInfo["PlayFinishSound"] ) then
EmFor@0 2149 PlaySoundFile("Interface\\AddOns\\CensusPlus\\Sounds\\CensusComplete.ogg")
EmFor@0 2150 end
EmFor@0 2151
EmFor@0 2152 CensusPlus_DoTimeCounts();
EmFor@0 2153 CensusPlus_DisplayResults();
EmFor@0 2154 end
EmFor@0 2155 end
EmFor@0 2156
EmFor@0 2157 local now = GetTime();
EmFor@0 2158 local delta = now - g_LastOnUpdateTime;
EmFor@0 2159 if (not g_WaitingForWhoUpdate or delta > CensusPlus_UPDATEDELAY) then
EmFor@0 2160 g_LastOnUpdateTime = now;
EmFor@0 2161 if (g_WaitingForWhoUpdate == true ) then
EmFor@0 2162
EmFor@0 2163 --
EmFor@0 2164 -- First check to see if we are waiting for an override
EmFor@0 2165 --
EmFor@0 2166 if( g_WaitingForOverrideUpdate == true ) then
EmFor@0 2167 CensusPlus_SendWho( g_CensusWhoOverrideMsg );
EmFor@0 2168 else
EmFor@0 2169 --
EmFor@0 2170 -- Resend /who command
EmFor@0 2171 --
EmFor@0 2172 g_WhoAttempts = g_WhoAttempts + 1;
EmFor@0 2173 local whoText = CensusPlus_CreateWhoText(g_CurrentJob);
EmFor@0 2174 if( CensusPlus_PerCharInfo["Verbose"] == true ) then
EmFor@0 2175 CensusPlus_Msg(CENSUSPlus_WAITING);
EmFor@0 2176 end
EmFor@0 2177 if( g_WhoAttempts < 2 ) then
EmFor@0 2178 CensusPlus_SendWho(whoText);
EmFor@0 2179 else
EmFor@0 2180 g_WaitingForWhoUpdate = false;
EmFor@0 2181 end
EmFor@0 2182 end
EmFor@0 2183 else
EmFor@0 2184
EmFor@0 2185 --
EmFor@0 2186 -- Check to see if we have an override waiting
EmFor@0 2187 --
EmFor@0 2188 if( g_CensusWhoOverrideMsg ~= nil ) then
EmFor@0 2189 CensusPlus_SendWho( g_CensusWhoOverrideMsg );
EmFor@0 2190 g_WaitingForOverrideUpdate = true;
EmFor@0 2191 g_WaitingForWhoUpdate = true;
EmFor@0 2192 else
EmFor@0 2193 --
EmFor@0 2194 -- Determine if there is any more work to do
EmFor@0 2195 --
EmFor@0 2196 local numJobs = table.getn(g_JobQueue);
EmFor@0 2197 if (numJobs > 0) then
EmFor@0 2198 --
EmFor@0 2199 -- Remove the top job from the queue and send it
EmFor@0 2200 --
EmFor@0 2201 local job = g_JobQueue[numJobs];
EmFor@0 2202 table.remove(g_JobQueue);
EmFor@0 2203 local whoText = CensusPlus_CreateWhoText(job);
EmFor@0 2204 g_CurrentJob = nil;
EmFor@0 2205 g_CurrentJob = job;
EmFor@0 2206 g_WaitingForWhoUpdate = true;
EmFor@0 2207 CensusPlus_SendWho(whoText);
EmFor@0 2208 g_WaitingForWhoUpdate = true;
EmFor@0 2209 g_WhoAttempts = 0;
EmFor@0 2210 else
EmFor@0 2211 --
EmFor@0 2212 -- We are all done, hide the friends frame and report our results
EmFor@0 2213 --
EmFor@0 2214 if( CensusPlus_PerCharInfo["PlayFinishSound"] ) then
EmFor@0 2215 PlaySoundFile("Interface\\AddOns\\CensusPlus\\Sounds\\CensusComplete.ogg")
EmFor@0 2216 end
EmFor@0 2217
EmFor@0 2218 CensusPlus_DoTimeCounts();
EmFor@0 2219 CensusPlus_DisplayResults();
EmFor@0 2220 end
EmFor@0 2221 end
EmFor@0 2222 end
EmFor@0 2223 end
EmFor@0 2224 end
EmFor@0 2225 end
EmFor@0 2226
EmFor@0 2227 -----------------------------------------------------------------------------------
EmFor@0 2228 --
EmFor@0 2229 -- Take final tally
EmFor@0 2230 --
EmFor@0 2231 -----------------------------------------------------------------------------------
EmFor@0 2232 function CensusPlus_DoTimeCounts()
EmFor@0 2233
EmFor@0 2234 if( g_CensusPlusLocale == "N/A" ) then
EmFor@0 2235 return;
EmFor@0 2236 end
EmFor@0 2237
EmFor@0 2238 -- Zero out the times
EmFor@0 2239 g_TimeDatabase[CENSUSPlus_DRUID] = 0;
EmFor@0 2240 g_TimeDatabase[CENSUSPlus_HUNTER] = 0;
EmFor@0 2241 g_TimeDatabase[CENSUSPlus_MAGE] = 0;
EmFor@0 2242 g_TimeDatabase[CENSUSPlus_PRIEST] = 0;
EmFor@0 2243 g_TimeDatabase[CENSUSPlus_ROGUE] = 0;
EmFor@0 2244 g_TimeDatabase[CENSUSPlus_WARLOCK] = 0;
EmFor@0 2245 g_TimeDatabase[CENSUSPlus_WARRIOR] = 0;
EmFor@0 2246 g_TimeDatabase[CENSUSPlus_SHAMAN] = 0;
EmFor@0 2247 g_TimeDatabase[CENSUSPlus_PALADIN] = 0;
EmFor@0 2248 g_TimeDatabase[CENSUSPlus_DEATHKNIGHT] = 0;
EmFor@0 2249 g_TimeDatabase[CENSUSPlus_WarsongGulch] = 0;
EmFor@0 2250 g_TimeDatabase[CENSUSPlus_AlteracValley]= 0;
EmFor@0 2251 g_TimeDatabase[CENSUSPlus_ArathiBasin] = 0;
EmFor@0 2252
EmFor@0 2253 g_NumUpdatedCharacters = 0;
EmFor@0 2254
EmFor@0 2255 for charName, charClass in pairs(g_TempCount) do
EmFor@0 2256 if (CENSUSPlusFemale[charClass] ~= nil) then
EmFor@0 2257 charClass = CENSUSPlusFemale[charClass];
EmFor@0 2258 end
EmFor@0 2259 g_TimeDatabase[charClass] = g_TimeDatabase[charClass] + 1;
EmFor@0 2260 g_NumUpdatedCharacters = g_NumUpdatedCharacters + 1;
EmFor@0 2261 end
EmFor@0 2262
EmFor@0 2263 -- Collect some zone info
EmFor@0 2264 for charName, charZone in pairs(g_TempZoneCount) do
EmFor@0 2265 if( charZone == CENSUSPlus_WarsongGulch or charZone == CENSUSPlus_AlteracValley or charZone == CENSUSPlus_ArathiBasin ) then
EmFor@0 2266 g_TimeDatabase[charZone] = g_TimeDatabase[charZone] + 1;
EmFor@0 2267 end
EmFor@0 2268 end
EmFor@0 2269
EmFor@0 2270
EmFor@0 2271 local realmName = g_CensusPlusLocale .. GetCVar("realmName");
EmFor@0 2272 if( CensusPlus_Database["TimesPlus"][realmName] == nil ) then
EmFor@0 2273 CensusPlus_Database["TimesPlus"][realmName]= {};
EmFor@0 2274 end
EmFor@0 2275
EmFor@0 2276 if( CensusPlus_Database["TimesPlus"][realmName][UnitFactionGroup("player")] == nil ) then
EmFor@0 2277 CensusPlus_Database["TimesPlus"][realmName][UnitFactionGroup("player")] = {};
EmFor@0 2278 end
EmFor@0 2279
EmFor@0 2280 local hour, minute = GetGameTime();
EmFor@0 2281 -- CensusPlus_Database["TimesPlus"][realmName][UnitFactionGroup("player")]["" .. hour .. ""] = g_TimeDatabase;
EmFor@0 2282 CensusPlus_Database["TimesPlus"][realmName][UnitFactionGroup("player")][CensusPlus_DetermineServerDate() .. "&" .. hour .. ":" .. minute .. ":00"] =
EmFor@0 2283 g_TimeDatabase[CENSUSPlus_DRUID] .. "&" ..
EmFor@0 2284 g_TimeDatabase[CENSUSPlus_HUNTER] .. "&" ..
EmFor@0 2285 g_TimeDatabase[CENSUSPlus_MAGE] .. "&" ..
EmFor@0 2286 g_TimeDatabase[CENSUSPlus_PRIEST] .. "&" ..
EmFor@0 2287 g_TimeDatabase[CENSUSPlus_ROGUE] .. "&" ..
EmFor@0 2288 g_TimeDatabase[CENSUSPlus_WARLOCK] .. "&" ..
EmFor@0 2289 g_TimeDatabase[CENSUSPlus_WARRIOR] .. "&" ..
EmFor@0 2290 g_TimeDatabase[CENSUSPlus_SHAMAN] .. "&" ..
EmFor@0 2291 g_TimeDatabase[CENSUSPlus_PALADIN] .. "&" ..
EmFor@0 2292 g_TimeDatabase[CENSUSPlus_DEATHKNIGHT] .. "&" ..
EmFor@0 2293 g_TimeDatabase[CENSUSPlus_WarsongGulch] .. "&" ..
EmFor@0 2294 g_TimeDatabase[CENSUSPlus_AlteracValley] .. "&" ..
EmFor@0 2295 g_TimeDatabase[CENSUSPlus_ArathiBasin];
EmFor@0 2296 end
EmFor@0 2297
EmFor@0 2298 -----------------------------------------------------------------------------------
EmFor@0 2299 --
EmFor@0 2300 -- Add the contents of the guild results to the database
EmFor@0 2301 --
EmFor@0 2302 -----------------------------------------------------------------------------------
EmFor@0 2303 function CensusPlus_ProcessGuildResults()
EmFor@0 2304
EmFor@0 2305 if( g_VariablesLoaded == false ) then
EmFor@0 2306 return;
EmFor@0 2307 end
EmFor@0 2308
EmFor@0 2309 if( CensusPlus_Database["Info"]["Locale"] == nil ) then
EmFor@0 2310 return;
EmFor@0 2311 end
EmFor@0 2312
EmFor@0 2313 if( g_CensusPlusLocale == "N/A" ) then
EmFor@0 2314 return;
EmFor@0 2315 end
EmFor@0 2316
EmFor@0 2317
EmFor@0 2318 --
EmFor@0 2319 -- Grab temp var
EmFor@0 2320 --
EmFor@0 2321 local showOfflineTemp = GetGuildRosterShowOffline();
EmFor@0 2322 SetGuildRosterShowOffline(1);
EmFor@0 2323
EmFor@0 2324
EmFor@0 2325 --
EmFor@0 2326 -- Walk through the guild info
EmFor@0 2327 --
EmFor@0 2328 local numGuildMembers = GetNumGuildMembers();
EmFor@0 2329 -- CensusPlus_Msg("Processing "..numGuildMembers.." guild members.");
EmFor@0 2330
EmFor@0 2331 local realmName = g_CensusPlusLocale .. GetCVar("realmName");
EmFor@0 2332 CensusPlus_Database["Guilds"] = nil;
EmFor@0 2333 if( CensusPlus_Database["Guilds"] == nil ) then
EmFor@0 2334 CensusPlus_Database["Guilds"] = {};
EmFor@0 2335 end
EmFor@0 2336
EmFor@0 2337 if (CensusPlus_Database["Guilds"][realmName] == nil) then
EmFor@0 2338 CensusPlus_Database["Guilds"][realmName] = {};
EmFor@0 2339 end
EmFor@0 2340
EmFor@0 2341 local guildRealmDatabase = CensusPlus_Database["Guilds"][realmName];
EmFor@0 2342 if (guildRealmDatabase == nil) then
EmFor@0 2343 CensusPlus_Database["Guilds"][realmName] = {};
EmFor@0 2344 guildRealmDatabase = CensusPlus_Database["Guilds"][realmName];
EmFor@0 2345 end
EmFor@0 2346
EmFor@0 2347 local factionGroup = UnitFactionGroup("player");
EmFor@0 2348 if( factionGroup == nil ) then
EmFor@0 2349 CensusPlus_Database["Guilds"] = nil;
EmFor@0 2350 SetGuildRosterShowOffline(showOfflineTemp);
EmFor@0 2351 return;
EmFor@0 2352 end
EmFor@0 2353
EmFor@0 2354 local factionDatabase = guildRealmDatabase[factionGroup];
EmFor@0 2355 if (factionDatabase == nil) then
EmFor@0 2356 guildRealmDatabase[factionGroup] = {};
EmFor@0 2357 factionDatabase = guildRealmDatabase[factionGroup];
EmFor@0 2358 end
EmFor@0 2359
EmFor@0 2360 CensusPlus_Database["Guilds"][realmName][factionGroup] = nil;
EmFor@0 2361 CensusPlus_Database["Guilds"][realmName][factionGroup] = {};
EmFor@0 2362
EmFor@0 2363 factionDatabase = CensusPlus_Database["Guilds"][realmName][factionGroup];
EmFor@0 2364
EmFor@0 2365 local Ginfo = GetGuildInfo("player");
EmFor@0 2366 if( Ginfo == nil ) then
EmFor@0 2367 CensusPlus_Database["Guilds"] = nil;
EmFor@0 2368 SetGuildRosterShowOffline(showOfflineTemp);
EmFor@0 2369 return;
EmFor@0 2370 end
EmFor@0 2371 local guildDatabase = factionDatabase[Ginfo];
EmFor@0 2372 if (guildDatabase == nil) then
EmFor@0 2373 factionDatabase[Ginfo] = {};
EmFor@0 2374 guildDatabase = factionDatabase[Ginfo];
EmFor@0 2375 end
EmFor@0 2376
EmFor@0 2377 local info = guildDatabase["GuildInfo"];
EmFor@0 2378 if (info == nil) then
EmFor@0 2379 guildDatabase["GuildInfo"] = {};
EmFor@0 2380 info = guildDatabase["GuildInfo"];
EmFor@0 2381 end
EmFor@0 2382
EmFor@0 2383 info["Update"] = date( "%m-%d-%Y", time()) .. "";
EmFor@0 2384 info["ShowOnline"] = 1; -- Variable comes from FriendsFrame
EmFor@0 2385
EmFor@0 2386 guildDatabase["Members"] = nil;
EmFor@0 2387 guildDatabase["Members"] = {};
EmFor@0 2388
EmFor@0 2389 local members = guildDatabase["Members"];
EmFor@0 2390
EmFor@0 2391 for index = 1, numGuildMembers, 1 do
EmFor@0 2392 local name, rank, rankIndex, level, class, zone, note, officernote, online, status = GetGuildRosterInfo(index);
EmFor@0 2393
EmFor@0 2394 if( members[name] == nil ) then
EmFor@0 2395 members[name] = {};
EmFor@0 2396 end
EmFor@0 2397
EmFor@0 2398 -- CensusPlus_Msg( "Name =>" .. name );
EmFor@0 2399 -- CensusPlus_Msg( "rank =>" .. rank );
EmFor@0 2400 -- CensusPlus_Msg( "rankIndex =>" .. rankIndex );
EmFor@0 2401 -- CensusPlus_Msg( "level =>" .. level );
EmFor@0 2402 -- CensusPlus_Msg( "class =>" .. class );
EmFor@0 2403 members[name]["Rank"] = rank;
EmFor@0 2404 members[name]["RankIndex"] = rankIndex;
EmFor@0 2405 members[name]["Level"]= level;
EmFor@0 2406 members[name]["Class"]= class;
EmFor@0 2407 -- members[name]["Zone"]= zone;
EmFor@0 2408 -- members[name]["Note"]= CensusPlus_SafeSet( note );
EmFor@0 2409 -- members[name]["OfficerNote"]= CensusPlus_SafeSet( officernote );
EmFor@0 2410 -- members[name]["Online"]= online;
EmFor@0 2411 -- members[name]["Status"]= CensusPlus_SafeSet( status );
EmFor@0 2412 end
EmFor@0 2413
EmFor@0 2414 SetGuildRosterShowOffline(showOfflineTemp);
EmFor@0 2415 end
EmFor@0 2416
EmFor@0 2417 function CensusPlus_SafeCheck( param )
EmFor@0 2418 if( param == nil ) then
EmFor@0 2419 return "nil";
EmFor@0 2420 else
EmFor@0 2421 return param;
EmFor@0 2422 end
EmFor@0 2423 end
EmFor@0 2424
EmFor@0 2425 -----------------------------------------------------------------------------------
EmFor@0 2426 --
EmFor@0 2427 -- Add the contents of the who results to the database
EmFor@0 2428 --
EmFor@0 2429 -----------------------------------------------------------------------------------
EmFor@0 2430 function CensusPlus_ProcessWhoResults()
EmFor@0 2431
EmFor@0 2432 --
EmFor@0 2433 -- If we are in a BG then stop a census
EmFor@0 2434 --
EmFor@0 2435 if( g_CurrentlyInBG and g_IsCensusPlusInProgress ) then
EmFor@0 2436 g_LastCensusRun = time()-600;
EmFor@0 2437 CensusPlus_Msg(CENSUSPlus_ISINBG);
EmFor@0 2438 CensusPlus_StopCensus( );
EmFor@0 2439 end
EmFor@0 2440
EmFor@0 2441 if( g_CensusPlusLocale == "N/A" ) then
EmFor@0 2442 return;
EmFor@0 2443 end
EmFor@0 2444
EmFor@0 2445 --
EmFor@0 2446 -- Get the portion of the database for this server
EmFor@0 2447 --
EmFor@0 2448 local realmName = g_CensusPlusLocale .. GetCVar("realmName");
EmFor@0 2449 local realmDatabase = CensusPlus_Database["Servers"][realmName];
EmFor@0 2450 if (realmDatabase == nil) then
EmFor@0 2451 CensusPlus_Database["Servers"][realmName] = {};
EmFor@0 2452 realmDatabase = CensusPlus_Database["Servers"][realmName];
EmFor@0 2453 end
EmFor@0 2454
EmFor@0 2455 --
EmFor@0 2456 -- Get the portion of the database for this faction
EmFor@0 2457 --
EmFor@0 2458 local factionGroup = UnitFactionGroup("player");
EmFor@0 2459 if( factionGroup == nil ) then
EmFor@0 2460 return
EmFor@0 2461 end
EmFor@0 2462
EmFor@0 2463 local factionDatabase = realmDatabase[factionGroup];
EmFor@0 2464 if (factionDatabase == nil) then
EmFor@0 2465 realmDatabase[factionGroup] = {};
EmFor@0 2466 factionDatabase = realmDatabase[factionGroup];
EmFor@0 2467 end
EmFor@0 2468
EmFor@0 2469 --
EmFor@0 2470 -- Walk through all the who results
EmFor@0 2471 --
EmFor@0 2472 local numWhoResults = GetNumWhoResults();
EmFor@0 2473 if( CensusPlus_PerCharInfo["Verbose"] == true ) then
EmFor@0 2474 CensusPlus_Msg(format(CENSUSPlus_PROCESSING, numWhoResults));
EmFor@0 2475 end
EmFor@0 2476 for i = 1, numWhoResults, 1 do
EmFor@0 2477 --
EmFor@0 2478 -- Get who result entry
EmFor@0 2479 --
EmFor@0 2480 local name, guild, level, race, class, zone, group = GetWhoInfo(i);
EmFor@0 2481
EmFor@0 2482 if (CENSUSPlusFemale[race] ~= nil) then
EmFor@0 2483 race = CENSUSPlusFemale[race];
EmFor@0 2484 end
EmFor@0 2485
EmFor@0 2486 if (CENSUSPlusFemale[class] ~= nil) then
EmFor@0 2487 class = CENSUSPlusFemale[class];
EmFor@0 2488 end
EmFor@0 2489
EmFor@0 2490 --
EmFor@0 2491 -- Test the name for possible color coding
EmFor@0 2492 --
EmFor@0 2493 -- for example |cffff0000Rollie|r
EmFor@0 2494 local karma_check = string.find( name, "|cff" );
EmFor@0 2495 if( karma_check ~= nil ) then
EmFor@0 2496 name = string.sub( name, 11, -3 );
EmFor@0 2497 end
EmFor@0 2498
EmFor@0 2499 --
EmFor@0 2500 -- Further check for problematic chars
EmFor@0 2501 --
EmFor@0 2502 local pattern = "[0-9\| -]";
EmFor@0 2503 if( string.find( name, pattern ) ~= nil ) then
EmFor@0 2504 if( not g_ProblematicMessageShown ) then
EmFor@0 2505 CensusPlus_Msg( "This name is problematic => " .. name .. ", name skipped. This message will only be shown once." );
EmFor@0 2506 g_ProblematicMessageShown = true;
EmFor@0 2507 end
EmFor@0 2508 return;
EmFor@0 2509 end
EmFor@0 2510
EmFor@0 2511
EmFor@0 2512 --
EmFor@0 2513 -- Get racial database
EmFor@0 2514 --
EmFor@0 2515 local raceDatabase = factionDatabase[race];
EmFor@0 2516 if (raceDatabase == nil) then
EmFor@0 2517 factionDatabase[race] = {};
EmFor@0 2518 raceDatabase = factionDatabase[race];
EmFor@0 2519 end
EmFor@0 2520
EmFor@0 2521 --
EmFor@0 2522 -- Get class database
EmFor@0 2523 --
EmFor@0 2524 local classDatabase = raceDatabase[class];
EmFor@0 2525 if (classDatabase == nil) then
EmFor@0 2526 raceDatabase[class] = {};
EmFor@0 2527 classDatabase = raceDatabase[class];
EmFor@0 2528 end
EmFor@0 2529
EmFor@0 2530 --
EmFor@0 2531 -- Get this player's entry
EmFor@0 2532 --
EmFor@0 2533 local entry = classDatabase[name];
EmFor@0 2534 if (entry == nil) then
EmFor@0 2535 classDatabase[name] = {};
EmFor@0 2536 entry = classDatabase[name];
EmFor@0 2537 g_NumNewCharacters = g_NumNewCharacters + 1;
EmFor@0 2538 end
EmFor@0 2539
EmFor@0 2540 --
EmFor@0 2541 -- Update the information
EmFor@0 2542 --
EmFor@0 2543 entry[1] = level;
EmFor@0 2544 entry[2] = guild;
EmFor@0 2545 -- local hour, minute = GetGameTime();
EmFor@0 2546 entry[3] = CensusPlus_DetermineServerDate() .. "";
EmFor@0 2547
EmFor@0 2548 g_TempCount[name] = class;
EmFor@0 2549 g_TempZoneCount[name] = zone;
EmFor@0 2550
EmFor@0 2551 end
EmFor@0 2552 -- CensusPlus_UpdateView();
EmFor@0 2553 end
EmFor@0 2554
EmFor@0 2555
EmFor@0 2556 ----------------------------------------------------------------------------------
EmFor@0 2557 --
EmFor@0 2558 -- Process a single entry
EmFor@0 2559 --
EmFor@0 2560 ---------------------------------------------------------------------------------
EmFor@0 2561 function WR_ProcessSingleEntry( name, level, race, class, guild, zone )
EmFor@0 2562
EmFor@0 2563 CensusPlus_Msg2( "Processing " .. name );
EmFor@0 2564
EmFor@0 2565 if( g_CensusPlusLocale == "N/A" ) then
EmFor@0 2566 return;
EmFor@0 2567 end
EmFor@0 2568
EmFor@0 2569 if (CENSUSPlusFemale[race] ~= nil) then
EmFor@0 2570 race = CENSUSPlusFemale[race];
EmFor@0 2571 end
EmFor@0 2572
EmFor@0 2573 if (CENSUSPlusFemale[class] ~= nil) then
EmFor@0 2574 class = CENSUSPlusFemale[class];
EmFor@0 2575 end
EmFor@0 2576
EmFor@0 2577 --
EmFor@0 2578 -- Get the portion of the database for this server
EmFor@0 2579 --
EmFor@0 2580 local realmName = g_CensusPlusLocale .. GetCVar("realmName");
EmFor@0 2581 local realmDatabase = CensusPlus_Database["Servers"][realmName];
EmFor@0 2582 if (realmDatabase == nil) then
EmFor@0 2583 CensusPlus_Database["Servers"][realmName] = {};
EmFor@0 2584 realmDatabase = CensusPlus_Database["Servers"][realmName];
EmFor@0 2585 end
EmFor@0 2586
EmFor@0 2587 --
EmFor@0 2588 -- Get the portion of the database for this faction
EmFor@0 2589 --
EmFor@0 2590 local factionGroup = UnitFactionGroup("player");
EmFor@0 2591 if( factionGroup == nil ) then
EmFor@0 2592 return
EmFor@0 2593 end
EmFor@0 2594
EmFor@0 2595 local factionDatabase = realmDatabase[factionGroup];
EmFor@0 2596 if (factionDatabase == nil) then
EmFor@0 2597 realmDatabase[factionGroup] = {};
EmFor@0 2598 factionDatabase = realmDatabase[factionGroup];
EmFor@0 2599 end
EmFor@0 2600
EmFor@0 2601 --
EmFor@0 2602 -- Remove the trailing ] that I can't remove through patterns
EmFor@0 2603 --
EmFor@0 2604 -- local oldname = name;
EmFor@0 2605 -- name = string.sub( oldname, 1, string.len(oldname) - 3 );
EmFor@0 2606
EmFor@0 2607 level = tonumber( level );
EmFor@0 2608
EmFor@0 2609 --
EmFor@0 2610 -- Test the name for possible color coding
EmFor@0 2611 --
EmFor@0 2612 -- for example |cffff0000Rollie|r
EmFor@0 2613 local karma_check = string.find( name, "|cff" );
EmFor@0 2614 if( karma_check ~= nil ) then
EmFor@0 2615 name = string.sub( name, 11, -3 );
EmFor@0 2616 end
EmFor@0 2617
EmFor@0 2618 local pattern = "[0-9\| :]";
EmFor@0 2619 if( string.find( name, pattern ) ~= nil ) then
EmFor@0 2620 if( not g_ProblematicMessageShown ) then
EmFor@0 2621 CensusPlus_Msg( "This name is problematic => " .. name .. ", name skipped. This message will only be shown once." );
EmFor@0 2622 end
EmFor@0 2623 return;
EmFor@0 2624 end
EmFor@0 2625
EmFor@0 2626 --
EmFor@0 2627 -- Do a race check just to be sure this is working
EmFor@0 2628 --
EmFor@0 2629 if( g_FactionCheck[race] == nil ) then
EmFor@0 2630 CensusPlus_Msg( "Found an unknown race (" .. race .. "), please tell Rollie at WarcraftRealms.com" );
EmFor@0 2631 return;
EmFor@0 2632 end
EmFor@0 2633
EmFor@0 2634 --
EmFor@0 2635 -- Get racial database
EmFor@0 2636 --
EmFor@0 2637 local raceDatabase = factionDatabase[race];
EmFor@0 2638 if (raceDatabase == nil) then
EmFor@0 2639 factionDatabase[race] = {};
EmFor@0 2640 raceDatabase = factionDatabase[race];
EmFor@0 2641 end
EmFor@0 2642
EmFor@0 2643 --
EmFor@0 2644 -- Get class database
EmFor@0 2645 --
EmFor@0 2646 local classDatabase = raceDatabase[class];
EmFor@0 2647 if (classDatabase == nil) then
EmFor@0 2648 raceDatabase[class] = {};
EmFor@0 2649 classDatabase = raceDatabase[class];
EmFor@0 2650 end
EmFor@0 2651
EmFor@0 2652 --
EmFor@0 2653 -- Get this player's entry
EmFor@0 2654 --
EmFor@0 2655 local entry = classDatabase[name];
EmFor@0 2656 if (entry == nil) then
EmFor@0 2657 classDatabase[name] = {};
EmFor@0 2658 entry = classDatabase[name];
EmFor@0 2659 g_NumNewCharacters = g_NumNewCharacters + 1;
EmFor@0 2660 end
EmFor@0 2661
EmFor@0 2662 --
EmFor@0 2663 -- Update the information
EmFor@0 2664 --
EmFor@0 2665 entry[1] = level;
EmFor@0 2666 entry[2] = guild;
EmFor@0 2667 -- local hour, minute = GetGameTime();
EmFor@0 2668 entry[3] = CensusPlus_DetermineServerDate() .. "";
EmFor@0 2669
EmFor@0 2670 g_TempCount[name] = class;
EmFor@0 2671 g_TempZoneCount[name] = zone;
EmFor@0 2672
EmFor@0 2673 -- CensusPlus_Msg2( "Processed " .. name );
EmFor@0 2674 end
EmFor@0 2675
EmFor@0 2676 ----------------------------------------------------------------------------------
EmFor@0 2677 --
EmFor@0 2678 -- Find a guild in the CensusPlus_Guilds array by name
EmFor@0 2679 --
EmFor@0 2680 ---------------------------------------------------------------------------------
EmFor@0 2681 local function FindGuildByName(name)
EmFor@0 2682 local i;
EmFor@0 2683 local size = table.getn(CensusPlus_Guilds);
EmFor@0 2684 for i = 1, size, 1 do
EmFor@0 2685 local entry = CensusPlus_Guilds[i];
EmFor@0 2686 if (entry.m_Name == name) then
EmFor@0 2687 return i;
EmFor@0 2688 end
EmFor@0 2689 end
EmFor@0 2690 return nil;
EmFor@0 2691 end
EmFor@0 2692
EmFor@0 2693 ----------------------------------------------------------------------------------
EmFor@0 2694 --
EmFor@0 2695 -- Add up the total character XP and count
EmFor@0 2696 --
EmFor@0 2697 ---------------------------------------------------------------------------------
EmFor@0 2698 local g_AccumulateGuildTotals = true;
EmFor@0 2699 local function TotalsAccumulator(name, level, guild)
EmFor@0 2700 --
EmFor@0 2701 -- Add character to our player list
EmFor@0 2702 --
EmFor@0 2703 CensusPlus_AddPlayerToList( name, level, guild );
EmFor@0 2704
EmFor@0 2705 if( g_TotalCharacterXPPerLevel[level] ) then
EmFor@0 2706 InitConstantTables();
EmFor@0 2707 end
EmFor@0 2708
EmFor@0 2709 local totalCharacterXP = g_TotalCharacterXPPerLevel[level];
EmFor@0 2710 if( totalCharacterXP == nil ) then
EmFor@0 2711 totalCharacterXP = 0;
EmFor@0 2712 end
EmFor@0 2713 if( g_TotalCharacterXP == nil ) then
EmFor@0 2714 g_TotalCharacterXP = 0;
EmFor@0 2715 end
EmFor@0 2716 g_TotalCharacterXP = g_TotalCharacterXP + totalCharacterXP;
EmFor@0 2717 g_TotalCount = g_TotalCount + 1;
EmFor@0 2718 if (g_AccumulateGuildTotals and (guild ~= nil)) then
EmFor@0 2719 local index = FindGuildByName(guild);
EmFor@0 2720 if (index == nil) then
EmFor@0 2721 local size = table.getn(CensusPlus_Guilds);
EmFor@0 2722 index = size + 1;
EmFor@0 2723 CensusPlus_Guilds[index] = {m_Name = guild, m_TotalCharacterXP = 0, m_Count = 0};
EmFor@0 2724 end
EmFor@0 2725 local entry = CensusPlus_Guilds[index];
EmFor@0 2726 entry.m_TotalCharacterXP = entry.m_TotalCharacterXP + totalCharacterXP;
EmFor@0 2727 entry.m_Count = entry.m_Count + 1;
EmFor@0 2728 end
EmFor@0 2729 end
EmFor@0 2730
EmFor@0 2731 ----------------------------------------------------------------------------------
EmFor@0 2732 --
EmFor@0 2733 -- Predicate function which can be used to compare two guilds for sorting
EmFor@0 2734 --
EmFor@0 2735 ---------------------------------------------------------------------------------
EmFor@0 2736 local function GuildPredicate(lhs, rhs)
EmFor@0 2737 --
EmFor@0 2738 -- nil references are always less than
EmFor@0 2739 --
EmFor@0 2740 if (lhs == nil) then
EmFor@0 2741 if (rhs == nil) then
EmFor@0 2742 return false;
EmFor@0 2743 else
EmFor@0 2744 return true;
EmFor@0 2745 end
EmFor@0 2746 elseif (rhs == nil) then
EmFor@0 2747 return false;
EmFor@0 2748 end
EmFor@0 2749 --
EmFor@0 2750 -- Sort by total XP first
EmFor@0 2751 --
EmFor@0 2752 if (rhs.m_TotalCharacterXP < lhs.m_TotalCharacterXP) then
EmFor@0 2753 return true;
EmFor@0 2754 elseif (lhs.m_TotalCharacterXP < rhs.m_TotalCharacterXP) then
EmFor@0 2755 return false;
EmFor@0 2756 end
EmFor@0 2757 --
EmFor@0 2758 -- Sort by name
EmFor@0 2759 --
EmFor@0 2760 if (lhs.m_Name < rhs.m_Name) then
EmFor@0 2761 return true;
EmFor@0 2762 elseif (rhs.m_Name < lhs.m_Name) then
EmFor@0 2763 return false;
EmFor@0 2764 end
EmFor@0 2765
EmFor@0 2766 --
EmFor@0 2767 -- identical
EmFor@0 2768 --
EmFor@0 2769 return false;
EmFor@0 2770 end
EmFor@0 2771
EmFor@0 2772
EmFor@0 2773 ----------------------------------------------------------------------------------
EmFor@0 2774 --
EmFor@0 2775 -- Another accumulator for adding up XP and counts
EmFor@0 2776 --
EmFor@0 2777 ---------------------------------------------------------------------------------
EmFor@0 2778 local g_AccumulatorCount = 0;
EmFor@0 2779 local g_AccumulatorXPTotal = 0;
EmFor@0 2780 local function CensusPlus_Accumulator(name, level, guild)
EmFor@0 2781 if( g_TotalCharacterXPPerLevel[level] == nil ) then
EmFor@0 2782 InitConstantTables();
EmFor@0 2783 end
EmFor@0 2784 local totalCharacterXP = g_TotalCharacterXPPerLevel[level];
EmFor@0 2785 if( totalCharacterXP == nil or g_TotalCharacterXPPerLevel[level] == nil ) then
EmFor@0 2786 return;
EmFor@0 2787 end
EmFor@0 2788 g_AccumulatorXPTotal = g_AccumulatorXPTotal + totalCharacterXP;
EmFor@0 2789 g_AccumulatorCount = g_AccumulatorCount + 1;
EmFor@0 2790 end
EmFor@0 2791
EmFor@0 2792 ----------------------------------------------------------------------------------
EmFor@0 2793 --
EmFor@0 2794 -- Reset the above accumulator
EmFor@0 2795 --
EmFor@0 2796 ---------------------------------------------------------------------------------
EmFor@0 2797 function CensusPlus_ResetAccumulator()
EmFor@0 2798 g_AccumulatorCount = 0;
EmFor@0 2799 g_AccumulatorXPTotal = 0;
EmFor@0 2800 end
EmFor@0 2801
EmFor@0 2802
EmFor@0 2803 ----------------------------------------------------------------------------------
EmFor@0 2804 --
EmFor@0 2805 -- Search the character database using the search criteria and update display
EmFor@0 2806 --
EmFor@0 2807 ---------------------------------------------------------------------------------
EmFor@0 2808 function CensusPlus_UpdateView()
EmFor@0 2809
EmFor@0 2810 --
EmFor@0 2811 -- No need to do anything if the window is not open
EmFor@0 2812 --
EmFor@0 2813 if( not CensusPlus:IsVisible() ) then
EmFor@0 2814 return;
EmFor@0 2815 end
EmFor@0 2816
EmFor@0 2817 if( g_CensusPlusLocale == "N/A" ) then
EmFor@0 2818 return;
EmFor@0 2819 end
EmFor@0 2820
EmFor@0 2821 --
EmFor@0 2822 -- Get realm and faction
EmFor@0 2823 --
EmFor@0 2824 local realmName = g_CensusPlusLocale .. GetCVar("realmName");
EmFor@0 2825 if( realmName == nil ) then
EmFor@0 2826 return;
EmFor@0 2827 end
EmFor@0 2828 CensusPlusRealmName:SetText(format(CENSUSPlus_REALMNAME, realmName));
EmFor@0 2829
EmFor@0 2830 local factionGroup = UnitFactionGroup("player");
EmFor@0 2831 if( factionGroup == nil ) then
EmFor@0 2832 return;
EmFor@0 2833 end
EmFor@0 2834
EmFor@0 2835 CensusPlusFactionName:SetText(format(CENSUSPlus_FACTION, factionGroup));
EmFor@0 2836
EmFor@0 2837 if( CensusPlus_Database["Info"]["Locale"] ~= nil ) then
EmFor@0 2838 CensusPlusLocaleName:SetText(format(CENSUSPlus_LOCALE, CensusPlus_Database["Info"]["Locale"]));
EmFor@0 2839 end
EmFor@0 2840
EmFor@0 2841 local guildKey = nil;
EmFor@0 2842 local raceKey = nil;
EmFor@0 2843 local classKey = nil;
EmFor@0 2844 local levelKey = nil;
EmFor@0 2845 g_TotalCharacterXP = 0;
EmFor@0 2846 g_TotalCount = 0;
EmFor@0 2847
EmFor@0 2848 --
EmFor@0 2849 -- Has the user selected a guild?
EmFor@0 2850 --
EmFor@0 2851 if (g_GuildSelected ~= nil ) then
EmFor@0 2852 guildKey = g_GuildSelected;
EmFor@0 2853 end
EmFor@0 2854 if (g_RaceSelected > 0) then
EmFor@0 2855 local thisFactionRaces = CensusPlus_GetFactionRaces(factionGroup);
EmFor@0 2856 raceKey = thisFactionRaces[g_RaceSelected];
EmFor@0 2857 end
EmFor@0 2858 if (g_ClassSelected > 0) then
EmFor@0 2859 local thisFactionClasses = CensusPlus_GetFactionClasses(factionGroup);
EmFor@0 2860 classKey = thisFactionClasses[g_ClassSelected];
EmFor@0 2861 end
EmFor@0 2862 if (g_LevelSelected > 0 or g_LevelSelected < 0) then
EmFor@0 2863 levelKey = g_LevelSelected;
EmFor@0 2864 end
EmFor@0 2865
EmFor@0 2866 debugprofilestart();
EmFor@0 2867
EmFor@0 2868 --
EmFor@0 2869 -- Has the user added any search criteria?
EmFor@0 2870 --
EmFor@0 2871 if ((guildKey ~= nil) or (raceKey ~= nil) or (classKey ~= nil) or (levelKey ~= nil)) then
EmFor@0 2872 --
EmFor@0 2873 -- Get totals for this criteria
EmFor@0 2874 --
EmFor@0 2875 CensusPlus_Guilds = {};
EmFor@0 2876 g_AccumulateGuildTotals = true;
EmFor@0 2877 CensusPlus_ForAllCharacters(realmName, factionGroup, raceKey, classKey, guildKey, levelKey, TotalsAccumulator);
EmFor@0 2878
EmFor@0 2879 if( CensusPlus_EnableProfiling ) then
EmFor@0 2880 CensusPlus_Msg( "PROFILE: Time to do calcs 1 " .. debugprofilestop() / 1000000000 );
EmFor@0 2881 debugprofilestart();
EmFor@0 2882 end
EmFor@0 2883
EmFor@0 2884 else
EmFor@0 2885 --
EmFor@0 2886 -- Get the overall totals and find guild information
EmFor@0 2887 --
EmFor@0 2888 CensusPlus_Guilds = {};
EmFor@0 2889 g_AccumulateGuildTotals = true;
EmFor@0 2890 CensusPlus_ForAllCharacters(realmName, factionGroup, nil, nil, nil, nil, TotalsAccumulator);
EmFor@0 2891
EmFor@0 2892 if( CensusPlus_EnableProfiling ) then
EmFor@0 2893 CensusPlus_Msg( "PROFILE: Time to do calcs 1 " .. debugprofilestop() / 1000000000 );
EmFor@0 2894 debugprofilestart();
EmFor@0 2895 end
EmFor@0 2896
EmFor@0 2897 local size = table.getn(CensusPlus_Guilds);
EmFor@0 2898 if (size) then
EmFor@0 2899 table.sort(CensusPlus_Guilds, GuildPredicate);
EmFor@0 2900 end
EmFor@0 2901
EmFor@0 2902 if( CensusPlus_EnableProfiling ) then
EmFor@0 2903 CensusPlus_Msg( "PROFILE: Time to sort guilds " .. debugprofilestop() / 1000000000 );
EmFor@0 2904 debugprofilestart();
EmFor@0 2905 end
EmFor@0 2906 end
EmFor@0 2907
EmFor@0 2908 local levelSearch = nil;
EmFor@0 2909 if (levelKey ~= nil) then
EmFor@0 2910 levelSearch = " ("..CENSUSPlus_LEVEL..": ";
EmFor@0 2911 local level = levelKey;
EmFor@0 2912 if (levelKey < 0) then
EmFor@0 2913 levelSearch = levelSearch.."!";
EmFor@0 2914 level = 0 - levelKey;
EmFor@0 2915 end
EmFor@0 2916 levelSearch = levelSearch..level..")";
EmFor@0 2917 end
EmFor@0 2918
EmFor@0 2919 local totalCharactersText = nil;
EmFor@0 2920 if (levelSearch ~= nil) then
EmFor@0 2921 totalCharactersText = format(CENSUSPlus_TOTALCHAR, g_TotalCount)..levelSearch;
EmFor@0 2922 else
EmFor@0 2923 totalCharactersText = format(CENSUSPlus_TOTALCHAR, g_TotalCount);
EmFor@0 2924 end
EmFor@0 2925 CensusPlusTotalCharacters:SetText(totalCharactersText);
EmFor@0 2926 CensusPlusTotalCharacterXP:SetText(format(CENSUSPlus_TOTALCHARXP, g_TotalCharacterXP));
EmFor@0 2927 CensusPlus_UpdateGuildButtons();
EmFor@0 2928
EmFor@0 2929 if( CensusPlus_EnableProfiling ) then
EmFor@0 2930 CensusPlus_Msg( "PROFILE: Update Guilds " .. debugprofilestop() / 1000000000 );
EmFor@0 2931 debugprofilestart();
EmFor@0 2932 end
EmFor@0 2933
EmFor@0 2934 --
EmFor@0 2935 -- Accumulate totals for each race
EmFor@0 2936 --
EmFor@0 2937 local maxCount = 0;
EmFor@0 2938 local thisFactionRaces = CensusPlus_GetFactionRaces(factionGroup);
EmFor@0 2939 local numRaces = table.getn(thisFactionRaces);
EmFor@0 2940 for i = 1, numRaces, 1 do
EmFor@0 2941 local race = thisFactionRaces[i];
EmFor@0 2942 CensusPlus_ResetAccumulator();
EmFor@0 2943 if ((raceKey == nil) or (raceKey == race)) then
EmFor@0 2944 CensusPlus_ForAllCharacters(realmName, factionGroup, race, classKey, guildKey, levelKey, CensusPlus_Accumulator);
EmFor@0 2945 end
EmFor@0 2946 if (g_AccumulatorCount > maxCount) then
EmFor@0 2947 maxCount = g_AccumulatorCount;
EmFor@0 2948 end
EmFor@0 2949 g_RaceCount[i] = g_AccumulatorCount;
EmFor@0 2950 end
EmFor@0 2951
EmFor@0 2952 --
EmFor@0 2953 -- Update race bars
EmFor@0 2954 --
EmFor@0 2955 for i = 1, numRaces, 1 do
EmFor@0 2956 local race = thisFactionRaces[i];
EmFor@0 2957 local buttonName = "CensusPlusRaceBar"..i;
EmFor@0 2958 local button = getglobal(buttonName);
EmFor@0 2959 local thisCount = g_RaceCount[i];
EmFor@0 2960 if ((thisCount ~= nil) and (thisCount > 0) and (maxCount > 0)) then
EmFor@0 2961 local height = floor((thisCount * CensusPlus_MAXBARHEIGHT / maxCount) );
EmFor@0 2962 if (height < 2 or height == nil ) then height = 2; end
EmFor@0 2963 button:SetHeight(height);
EmFor@0 2964 button:Show();
EmFor@0 2965 else
EmFor@0 2966 button:Hide();
EmFor@0 2967 end
EmFor@0 2968 local normalTextureName="Interface\\AddOns\\CensusPlus\\Skin\\CensusPlus_"..g_RaceClassList[race];
EmFor@0 2969 local legendName = "CensusPlusRaceLegend"..i;
EmFor@0 2970 local legend = getglobal(legendName);
EmFor@0 2971 legend:SetNormalTexture(normalTextureName);
EmFor@0 2972 if (g_RaceSelected == i) then
EmFor@0 2973 legend:LockHighlight();
EmFor@0 2974 else
EmFor@0 2975 legend:UnlockHighlight();
EmFor@0 2976 end
EmFor@0 2977 end
EmFor@0 2978
EmFor@0 2979 if( CensusPlus_EnableProfiling ) then
EmFor@0 2980 CensusPlus_Msg( "PROFILE: Update Races " .. debugprofilestop() / 1000000000 );
EmFor@0 2981 debugprofilestart();
EmFor@0 2982 end
EmFor@0 2983
EmFor@0 2984 --
EmFor@0 2985 -- Accumulate totals for each class
EmFor@0 2986 --
EmFor@0 2987 local maxCount = 0;
EmFor@0 2988 local thisFactionClasss = CensusPlus_GetFactionClasses(factionGroup);
EmFor@0 2989 local numClasses = table.getn(thisFactionClasss);
EmFor@0 2990 for i = 1, numClasses, 1 do
EmFor@0 2991 local class = thisFactionClasss[i];
EmFor@0 2992 CensusPlus_ResetAccumulator();
EmFor@0 2993 if ((classKey == nil) or (classKey == class)) then
EmFor@0 2994 CensusPlus_ForAllCharacters(realmName, factionGroup, raceKey, class, guildKey, levelKey, CensusPlus_Accumulator);
EmFor@0 2995 end
EmFor@0 2996 if (g_AccumulatorCount > maxCount) then
EmFor@0 2997 maxCount = g_AccumulatorCount;
EmFor@0 2998 end
EmFor@0 2999 g_ClassCount[i] = g_AccumulatorCount;
EmFor@0 3000 end
EmFor@0 3001
EmFor@0 3002 --
EmFor@0 3003 -- Update class bars
EmFor@0 3004 --
EmFor@0 3005 for i = 1, numClasses, 1 do
EmFor@0 3006 local class = thisFactionClasss[i];
EmFor@0 3007
EmFor@0 3008 local buttonName = "CensusPlusClassBar"..i;
EmFor@0 3009 local button = getglobal(buttonName);
EmFor@0 3010 local thisCount = g_ClassCount[i];
EmFor@0 3011 if ((thisCount ~= nil) and (thisCount > 0) and (maxCount > 0)) then
EmFor@0 3012 local height = floor((thisCount * CensusPlus_MAXBARHEIGHT / maxCount) );
EmFor@0 3013 if (height < 2 or height == nil ) then height = 2; end
EmFor@0 3014 button:SetHeight(height);
EmFor@0 3015 button:Show();
EmFor@0 3016 else
EmFor@0 3017 button:Hide();
EmFor@0 3018 end
EmFor@0 3019
EmFor@0 3020 local normalTextureName="Interface\\AddOns\\CensusPlus\\Skin\\CensusPlus_"..g_RaceClassList[class];
EmFor@0 3021 local legendName = "CensusPlusClassLegend"..i;
EmFor@0 3022 local legend = getglobal(legendName);
EmFor@0 3023 legend:SetNormalTexture(normalTextureName);
EmFor@0 3024 if (g_ClassSelected == i) then
EmFor@0 3025 legend:LockHighlight();
EmFor@0 3026 else
EmFor@0 3027 legend:UnlockHighlight();
EmFor@0 3028 end
EmFor@0 3029 end
EmFor@0 3030
EmFor@0 3031 if( CensusPlus_EnableProfiling ) then
EmFor@0 3032 CensusPlus_Msg( "PROFILE: Update Classes " .. debugprofilestop() / 1000000000 );
EmFor@0 3033 debugprofilestart();
EmFor@0 3034 end
EmFor@0 3035
EmFor@0 3036 --
EmFor@0 3037 -- Accumulate totals for each level
EmFor@0 3038 --
EmFor@0 3039 local maxCount = 0;
EmFor@0 3040 for i = 1, MAX_CHARACTER_LEVEL, 1 do
EmFor@0 3041 if ((levelKey == nil) or (levelKey == i) or (levelKey < 0 and levelKey + i ~= 0)) then
EmFor@0 3042 CensusPlus_ResetAccumulator();
EmFor@0 3043 CensusPlus_ForAllCharacters(realmName, factionGroup, raceKey, classKey, guildKey, i, CensusPlus_Accumulator);
EmFor@0 3044 if (g_AccumulatorCount > maxCount) then
EmFor@0 3045 maxCount = g_AccumulatorCount;
EmFor@0 3046 end
EmFor@0 3047 g_LevelCount[i] = g_AccumulatorCount;
EmFor@0 3048 else
EmFor@0 3049 g_LevelCount[i] = 0;
EmFor@0 3050 end
EmFor@0 3051 end
EmFor@0 3052 local logMaxCount = math.log( maxCount / 3 + 1 );
EmFor@0 3053
EmFor@0 3054 --
EmFor@0 3055 -- To make the data easier to use, we need to massage it a bit for levels
EmFor@0 3056 --
EmFor@0 3057
EmFor@0 3058
EmFor@0 3059 --
EmFor@0 3060 -- Update level bars
EmFor@0 3061 --
EmFor@0 3062 for i = 1, MAX_CHARACTER_LEVEL, 1 do
EmFor@0 3063 local buttonName = "CensusPlusLevelBar"..i;
EmFor@0 3064 local buttonEmptyName = "CensusPlusLevelBarEmpty"..i;
EmFor@0 3065 local button = getglobal(buttonName);
EmFor@0 3066 local emptyButton = getglobal(buttonEmptyName);
EmFor@0 3067 local thisCount = g_LevelCount[i];
EmFor@0 3068 if ((thisCount ~= nil) and (thisCount > 0) and (maxCount > 0)) then
EmFor@0 3069 local height = floor(( math.log(thisCount / 3 + 1) * CensusPlus_MAXBARHEIGHT / logMaxCount) );
EmFor@0 3070 if( CensusPlus_Database["Info"]["UseLogBars"] == 0 ) then
EmFor@0 3071 height = floor(( CensusPlus_MAXBARHEIGHT * (thisCount) / maxCount) );
EmFor@0 3072 end
EmFor@0 3073
EmFor@0 3074 if (height < 2 or height == nil ) then height = 2; end
EmFor@0 3075 button:SetHeight(height);
EmFor@0 3076 button:Show();
EmFor@0 3077 if (emptyButton ~= nil) then
EmFor@0 3078 emptyButton:Hide();
EmFor@0 3079 end
EmFor@0 3080 else
EmFor@0 3081 button:Hide();
EmFor@0 3082 if (emptyButton ~= nil) then
EmFor@0 3083 emptyButton:SetHeight(CensusPlus_MAXBARHEIGHT);
EmFor@0 3084 emptyButton:Show();
EmFor@0 3085 end
EmFor@0 3086 end
EmFor@0 3087 end
EmFor@0 3088
EmFor@0 3089 if( CensusPlus_EnableProfiling ) then
EmFor@0 3090 CensusPlus_Msg( "PROFILE: Update Levels " .. debugprofilestop() / 1000000000 );
EmFor@0 3091 debugprofilestart();
EmFor@0 3092 end
EmFor@0 3093
EmFor@0 3094 if( CP_PlayerListWindow:IsVisible() ) then
EmFor@0 3095 CensusPlus_PlayerListOnShow();
EmFor@0 3096 end
EmFor@0 3097
EmFor@0 3098
EmFor@0 3099 debugprofilestop();
EmFor@0 3100
EmFor@0 3101 end
EmFor@0 3102
EmFor@0 3103 ----------------------------------------------------------------------------------
EmFor@0 3104 --
EmFor@0 3105 -- Walk the character database and call the callback function for every entry that matches the search criteria
EmFor@0 3106 --
EmFor@0 3107 ---------------------------------------------------------------------------------
EmFor@0 3108 function CensusPlus_ForAllCharacters(realmKey, factionKey, raceKey, classKey, guildKey, levelKey, callback)
EmFor@0 3109 for realmName, realmDatabase in pairs(CensusPlus_Database["Servers"]) do
EmFor@0 3110 if ((realmKey == nil) or (realmKey == realmName)) then
EmFor@0 3111 for factionName, factionDatabase in pairs(realmDatabase) do
EmFor@0 3112 if ((factionKey == nil) or (factionKey == factionName)) then
EmFor@0 3113 for raceName, raceDatabase in pairs(factionDatabase) do
EmFor@0 3114 if ((raceKey == nil) or (raceKey == raceName)) then
EmFor@0 3115 for className, classDatabase in pairs(raceDatabase) do
EmFor@0 3116 if ((classKey == nil) or (classKey == className)) then
EmFor@0 3117 for characterName, character in pairs(classDatabase) do
EmFor@0 3118 local characterGuild = character[2];
EmFor@0 3119 if ((guildKey == nil) or (guildKey == characterGuild)) then
EmFor@0 3120 local characterLevel = character[1];
EmFor@0 3121 if( characterLevel == nil ) then
EmFor@0 3122 characterLevel = 0;
EmFor@0 3123 end
EmFor@0 3124 if ((levelKey == nil) or (levelKey == characterLevel) or (levelKey < 0 and levelKey + characterLevel ~= 0)) then
EmFor@0 3125 callback(characterName, characterLevel, characterGuild, raceName, className, character[3] );
EmFor@0 3126 end
EmFor@0 3127 end
EmFor@0 3128 end
EmFor@0 3129 end
EmFor@0 3130 end
EmFor@0 3131 end
EmFor@0 3132 end
EmFor@0 3133 end
EmFor@0 3134 end
EmFor@0 3135 end
EmFor@0 3136 end
EmFor@0 3137 end
EmFor@0 3138
EmFor@0 3139 ----------------------------------------------------------------------------------
EmFor@0 3140 --
EmFor@0 3141 -- Race legend clicked
EmFor@0 3142 --
EmFor@0 3143 ---------------------------------------------------------------------------------
EmFor@6 3144 function CensusPlus_OnClickRace( this )
EmFor@0 3145 local id = this:GetID();
EmFor@0 3146 if (id == g_RaceSelected) then
EmFor@0 3147 g_RaceSelected = 0;
EmFor@0 3148 else
EmFor@0 3149 g_RaceSelected = id;
EmFor@0 3150 end
EmFor@0 3151 CensusPlus_UpdateView();
EmFor@0 3152 end
EmFor@0 3153
EmFor@0 3154 ----------------------------------------------------------------------------------
EmFor@0 3155 --
EmFor@0 3156 -- Class legend clicked
EmFor@0 3157 --
EmFor@0 3158 ---------------------------------------------------------------------------------
EmFor@6 3159 function CensusPlus_OnClickClass( this )
EmFor@0 3160 local id = this:GetID();
EmFor@0 3161 if (id == g_ClassSelected) then
EmFor@0 3162 g_ClassSelected = 0;
EmFor@0 3163 else
EmFor@0 3164 g_ClassSelected = id;
EmFor@0 3165 end
EmFor@0 3166 CensusPlus_UpdateView();
EmFor@0 3167 end
EmFor@0 3168
EmFor@0 3169
EmFor@0 3170 ----------------------------------------------------------------------------------
EmFor@0 3171 --
EmFor@0 3172 -- Level bar loaded
EmFor@0 3173 --
EmFor@0 3174 ---------------------------------------------------------------------------------
EmFor@6 3175 function CensusPlus_OnLoadLevel( self )
EmFor@6 3176 self:RegisterForClicks("LeftButtonUp","RightButtonUp");
EmFor@0 3177 end
EmFor@0 3178
EmFor@0 3179 ----------------------------------------------------------------------------------
EmFor@0 3180 --
EmFor@0 3181 -- Level bar clicked
EmFor@0 3182 --
EmFor@0 3183 ---------------------------------------------------------------------------------
EmFor@6 3184 function CensusPlus_OnClickLevel(this, button)
EmFor@0 3185 local id = this:GetID();
EmFor@0 3186 if (((button == "LeftButton") and (id == g_LevelSelected)) or ((button == "RightButton") and (id + g_LevelSelected == 0))) then
EmFor@0 3187 g_LevelSelected = 0;
EmFor@0 3188 elseif (button == "RightButton") then
EmFor@0 3189 g_LevelSelected = 0 - id;
EmFor@0 3190 else
EmFor@0 3191 g_LevelSelected = id;
EmFor@0 3192 end
EmFor@0 3193 CensusPlus_UpdateView();
EmFor@0 3194 end
EmFor@0 3195
EmFor@0 3196 ----------------------------------------------------------------------------------
EmFor@0 3197 --
EmFor@0 3198 -- Race tooltip
EmFor@0 3199 --
EmFor@0 3200 ---------------------------------------------------------------------------------
EmFor@6 3201 function CensusPlus_OnEnterRace( this )
EmFor@0 3202 local factionGroup = UnitFactionGroup("player");
EmFor@0 3203 local thisFactionRaces = CensusPlus_GetFactionRaces(factionGroup);
EmFor@0 3204 local id = this:GetID();
EmFor@0 3205 local raceName = thisFactionRaces[id];
EmFor@0 3206 local count = g_RaceCount[id];
EmFor@0 3207 if (count ~= nil) then
EmFor@0 3208 local percent = floor((count / g_TotalCount) * 100);
EmFor@0 3209 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
EmFor@0 3210 GameTooltip:SetText(raceName.."\n"..count.."\n"..percent.."%", 1.0, 1.0, 1.0);
EmFor@0 3211 GameTooltip:Show();
EmFor@0 3212 end
EmFor@0 3213 end
EmFor@0 3214
EmFor@0 3215 ----------------------------------------------------------------------------------
EmFor@0 3216 --
EmFor@0 3217 -- Class tooltip
EmFor@0 3218 --
EmFor@0 3219 ---------------------------------------------------------------------------------
EmFor@6 3220 function CensusPlus_OnEnterClass( self )
EmFor@0 3221 local factionGroup = UnitFactionGroup("player");
EmFor@0 3222 local thisFactionClasses = CensusPlus_GetFactionClasses(factionGroup);
EmFor@6 3223 local id = self:GetID();
EmFor@0 3224 local className = thisFactionClasses[id];
EmFor@0 3225 local count = g_ClassCount[id];
EmFor@0 3226 if (count ~= nil) then
EmFor@0 3227 local percent = floor((count / g_TotalCount) * 100);
EmFor@6 3228 GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
EmFor@0 3229 GameTooltip:SetText(className.."\n"..count.."\n"..percent.."%", 1.0, 1.0, 1.0);
EmFor@0 3230 GameTooltip:Show();
EmFor@0 3231 end
EmFor@0 3232 end
EmFor@0 3233
EmFor@0 3234 ----------------------------------------------------------------------------------
EmFor@0 3235 --
EmFor@0 3236 -- Level tooltip
EmFor@0 3237 --
EmFor@0 3238 ---------------------------------------------------------------------------------
EmFor@6 3239 function CensusPlus_OnEnterLevel( this )
EmFor@0 3240 local id = this:GetID();
EmFor@0 3241 local count = g_LevelCount[id];
EmFor@0 3242 if (count ~= nil) then
EmFor@6 3243 local percent = floor((count / g_TotalCount) * 100);
EmFor@0 3244 GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
EmFor@0 3245 GameTooltip:SetText("Level "..id.."\n"..count.."\n"..percent.."%", 1.0, 1.0, 1.0);
EmFor@0 3246 GameTooltip:Show();
EmFor@0 3247 end
EmFor@0 3248 end
EmFor@0 3249
EmFor@0 3250 ----------------------------------------------------------------------------------
EmFor@0 3251 --
EmFor@0 3252 -- Clicked a guild button
EmFor@0 3253 --
EmFor@0 3254 ---------------------------------------------------------------------------------
EmFor@6 3255 function CensusPlus_GuildButton_OnClick( this )
EmFor@0 3256 local id = this:GetID();
EmFor@0 3257 local offset = FauxScrollFrame_GetOffset(CensusPlusGuildScrollFrame);
EmFor@0 3258 local newSelection = id + offset;
EmFor@0 3259 local guildKey = CensusPlus_Guilds[newSelection].m_Name;
EmFor@0 3260 if (g_GuildSelected ~= guildKey) then
EmFor@0 3261 g_GuildSelected = guildKey;
EmFor@0 3262 else
EmFor@0 3263 g_GuildSelected = nil;
EmFor@0 3264 end
EmFor@0 3265 CensusPlus_UpdateView();
EmFor@0 3266 end
EmFor@0 3267
EmFor@0 3268 ----------------------------------------------------------------------------------
EmFor@0 3269 --
EmFor@0 3270 -- Update the guild button contents
EmFor@0 3271 --
EmFor@0 3272 ---------------------------------------------------------------------------------
EmFor@0 3273 function CensusPlus_UpdateGuildButtons()
EmFor@0 3274 --
EmFor@0 3275 -- Determine where the scroll bar is
EmFor@0 3276 --
EmFor@0 3277 local offset = FauxScrollFrame_GetOffset(CensusPlusGuildScrollFrame);
EmFor@0 3278 --
EmFor@0 3279 -- Walk through all the rows in the frame
EmFor@0 3280 --
EmFor@0 3281 local size = table.getn(CensusPlus_Guilds);
EmFor@0 3282 local i = 1;
EmFor@0 3283 while (i <= CensusPlus_NUMGUILDBUTTONS) do
EmFor@0 3284 --
EmFor@0 3285 -- Get the index to the ad displayed in this row
EmFor@0 3286 --
EmFor@0 3287 local iGuild = i + offset;
EmFor@0 3288 --
EmFor@0 3289 -- Get the button on this row
EmFor@0 3290 --
EmFor@0 3291 local button = getglobal("CensusPlusGuildButton"..i);
EmFor@0 3292 --
EmFor@0 3293 -- Is there a valid guild on this row?
EmFor@0 3294 --
EmFor@0 3295 if (iGuild <= size) then
EmFor@0 3296 local guild = CensusPlus_Guilds[iGuild];
EmFor@0 3297 --
EmFor@0 3298 -- Update the button text
EmFor@0 3299 --
EmFor@0 3300 button:Show();
EmFor@0 3301 local textField = "CensusPlusGuildButton"..i.."Text";
EmFor@0 3302 if (guild.m_Name == "") then
EmFor@0 3303 getglobal(textField):SetText(CENSUSPlus_UNGUILDED);
EmFor@0 3304 else
EmFor@0 3305 getglobal(textField):SetText(guild.m_Name);
EmFor@0 3306 end
EmFor@0 3307 --
EmFor@0 3308 -- If this is the guild, highlight it
EmFor@0 3309 --
EmFor@0 3310 local guildName = CensusPlus_Guilds[iGuild].m_Name
EmFor@0 3311 if (g_GuildSelected == guildName) then
EmFor@0 3312 button:LockHighlight();
EmFor@0 3313 else
EmFor@0 3314 button:UnlockHighlight();
EmFor@0 3315 end
EmFor@0 3316 else
EmFor@0 3317 --
EmFor@0 3318 -- Hide the button
EmFor@0 3319 --
EmFor@0 3320 button:Hide();
EmFor@0 3321 end
EmFor@0 3322 --
EmFor@0 3323 -- Next row
EmFor@0 3324 --
EmFor@0 3325 i = i + 1;
EmFor@0 3326 end
EmFor@0 3327 --
EmFor@0 3328 -- Update the scroll bar
EmFor@0 3329 --
EmFor@0 3330 FauxScrollFrame_Update(CensusPlusGuildScrollFrame, size, CensusPlus_NUMGUILDBUTTONS, CensusPlus_GUILDBUTTONSIZEY);
EmFor@0 3331 end
EmFor@0 3332
EmFor@0 3333
EmFor@0 3334 ----------------------------------------------------------------------------------
EmFor@0 3335 --
EmFor@0 3336 -- Census_AutoStartOnLoad
EmFor@0 3337 --
EmFor@0 3338 ---------------------------------------------------------------------------------
EmFor@0 3339 function Census_AutoStartOnLoad( )
EmFor@0 3340 CP_OptionAutoStartButton:SetChecked(g_MiniOnStart);
EmFor@0 3341 if( g_MiniOnStart == 1 ) then
EmFor@0 3342 MiniCensusPlus:Show();
EmFor@0 3343 else
EmFor@0 3344 MiniCensusPlus:Hide();
EmFor@0 3345 end
EmFor@0 3346 MiniCensusPlus:Hide();
EmFor@0 3347 end
EmFor@0 3348
EmFor@0 3349 ----------------------------------------------------------------------------------
EmFor@0 3350 --
EmFor@0 3351 -- CensusPlus_AutoStart - Set the auto-start option
EmFor@0 3352 --
EmFor@0 3353 ---------------------------------------------------------------------------------
EmFor@0 3354 function CensusPlus_AutoStart( check )
EmFor@0 3355 g_MiniOnStart = check;
EmFor@0 3356 CensusPlus_Database["Info"]["MiniStart"] = g_MiniOnStart;
EmFor@0 3357 Census_AutoStartOnLoad();
EmFor@0 3358 end
EmFor@0 3359
EmFor@0 3360
EmFor@0 3361 ----------------------------------------------------------------------------------
EmFor@0 3362 --
EmFor@0 3363 -- CensusPlus_VerifyLocale - Set the locale (US or EU)
EmFor@0 3364 --
EmFor@0 3365 ---------------------------------------------------------------------------------
EmFor@0 3366 function CensusPlus_VerifyLocale( locale )
EmFor@0 3367 if( CensusPlus_Database["Info"]["Locale"] ~= locale ) then
EmFor@0 3368 --
EmFor@0 3369 -- Purge
EmFor@0 3370 --
EmFor@0 3371 CensusPlus_DoPurge()
EmFor@0 3372 end
EmFor@0 3373 end
EmFor@0 3374
EmFor@0 3375 ----------------------------------------------------------------------------------
EmFor@0 3376 --
EmFor@0 3377 -- CensusPlus_SelectLocale - Set the locale (US or EU)
EmFor@0 3378 --
EmFor@0 3379 ---------------------------------------------------------------------------------
EmFor@0 3380 function CensusPlus_SelectLocale( locale, auto )
EmFor@0 3381
EmFor@0 3382 if( not auto ) then
EmFor@0 3383 CensusPlus_Msg( "You have set your locale to " .. locale .. " from " .. g_CensusPlusLocale );
EmFor@0 3384 end
EmFor@0 3385
EmFor@0 3386 g_CensusPlusLocale = locale;
EmFor@0 3387 if( g_CensusPlusLocale == "EU" ) then
EmFor@0 3388 g_CensusPlusLocale = g_CensusPlusLocale .. "-";
EmFor@0 3389 else
EmFor@0 3390 g_CensusPlusLocale = "";
EmFor@0 3391 end
EmFor@0 3392
EmFor@0 3393
EmFor@0 3394 if( CensusPlus_Database["Info"]["Locale"] ~= locale ) then
EmFor@0 3395 if( not ( CensusPlus_Database["Info"]["Locale"] == nil and locale == "US" ) ) then
EmFor@0 3396 CensusPlus_Msg( "Locale differs from previous setting, purging database." );
EmFor@0 3397 CensusPlus_DoPurge();
EmFor@0 3398 CensusPlus_Database["Info"]["Locale"] = locale;
EmFor@0 3399 end
EmFor@0 3400 end
EmFor@0 3401 CensusPlus_Database["Info"]["Locale"] = locale;
EmFor@0 3402
EmFor@0 3403 textLine = getglobal("CensusPlusText");
EmFor@0 3404 textLine:SetText("Census+ EmSpe\195\167ial v"..CensusPlus_VERSION .. " " .. g_CensusPlusLocale );
EmFor@0 3405
EmFor@0 3406 if(( CENSUSPlus_DWARF == "Nain" or CENSUSPlus_DWARF == "Zwerg" ) and GetLocale() == "usEN") then
EmFor@0 3407 CensusPlus_Msg( "You appear to have a US Census version, yet your localization is set to French or German." );
EmFor@0 3408 CensusPlus_Msg( "Please do not upload stats to WarcraftRealms until this has been resolved." );
EmFor@0 3409 CensusPlus_Msg( "If this is incorrect, please let Rollie know at www.WarcraftRealms.com about your situation so he can make corrections." );
EmFor@0 3410 end
EmFor@0 3411
EmFor@0 3412 CP_EU_US_Version:Hide();
EmFor@0 3413
EmFor@0 3414 end
EmFor@0 3415
EmFor@0 3416 ----------------------------------------------------------------------------------
EmFor@0 3417 --
EmFor@0 3418 -- Walk the character database prune all characters entries that are older than 30 days
EmFor@0 3419 --
EmFor@0 3420 ---------------------------------------------------------------------------------
EmFor@0 3421 function CensusPlus_PruneData( nDays, sServer )
EmFor@0 3422
EmFor@0 3423 if( g_CensusPlusLocale == "N/A" ) then
EmFor@0 3424 return;
EmFor@0 3425 end
EmFor@0 3426
EmFor@0 3427
EmFor@0 3428 local thisRealmName = g_CensusPlusLocale .. GetCVar("realmName");
EmFor@0 3429
EmFor@0 3430 if( sServer == 1 ) then
EmFor@0 3431 nDays = 0;
EmFor@0 3432 end
EmFor@0 3433
EmFor@0 3434 local pruneTime = 24 * 60 * 60 * nDays;
EmFor@0 3435
EmFor@0 3436 for realmName, realmDatabase in pairs(CensusPlus_Database["Servers"]) do
EmFor@0 3437 if ((realmKey == nil) or (realmKey == realmName)) then
EmFor@0 3438 for factionName, factionDatabase in pairs(realmDatabase) do
EmFor@0 3439 if ((factionKey == nil) or (factionKey == factionName)) then
EmFor@0 3440 for raceName, raceDatabase in pairs(factionDatabase) do
EmFor@0 3441 if ((raceKey == nil) or (raceKey == raceName)) then
EmFor@0 3442 for className, classDatabase in pairs(raceDatabase) do
EmFor@0 3443 if ((classKey == nil) or (classKey == className)) then
EmFor@0 3444 for characterName, character in pairs(classDatabase) do
EmFor@0 3445 if( characterName ~= nil ) then
EmFor@0 3446 if( sServer == 1 ) then
EmFor@0 3447 if( realmName ~= thisRealmName ) then
EmFor@0 3448 CensusPlus_AccumulatePruneData( realmName, factionName, raceName, className, characterName );
EmFor@0 3449 end
EmFor@0 3450 else
EmFor@0 3451 local lastSeen = character[3]; -- 2005-05-02
EmFor@0 3452
EmFor@0 3453 local tYear, tMonth, tDay;
EmFor@0 3454 tYear = string.sub( lastSeen, 1, 4 );
EmFor@0 3455 tMonth = string.sub( lastSeen, 6, 7 );
EmFor@0 3456 tDay = string.sub( lastSeen, 9 );
EmFor@0 3457
EmFor@0 3458 local lastSeenTime = time( {year=tYear, month=tMonth, day=tDay, hour=0} );
EmFor@0 3459
EmFor@0 3460 if( time() - lastSeenTime > pruneTime ) then
EmFor@0 3461 CensusPlus_AccumulatePruneData( realmName, factionName, raceName, className, characterName );
EmFor@0 3462 end
EmFor@0 3463 end
EmFor@0 3464 end
EmFor@0 3465 end
EmFor@0 3466 end
EmFor@0 3467 end
EmFor@0 3468 end
EmFor@0 3469 end
EmFor@0 3470 end
EmFor@0 3471 end
EmFor@0 3472 end
EmFor@0 3473 end
EmFor@0 3474
EmFor@0 3475 CensusPlus_PruneTimes();
EmFor@0 3476 CensusPlus_UpdateView();
EmFor@0 3477 CensusPlus_PruneTheData();
EmFor@0 3478 end
EmFor@0 3479
EmFor@0 3480 -----------------------------------------------------------------------------------
EmFor@0 3481 --
EmFor@0 3482 -- Prune the accumulation
EmFor@0 3483 --
EmFor@0 3484 -----------------------------------------------------------------------------------
EmFor@0 3485 function CensusPlus_AccumulatePruneData( realm, faction, race, class, name )
EmFor@0 3486 local pruneData = {};
EmFor@0 3487 pruneData.realm = realm;
EmFor@0 3488 pruneData.faction = faction;
EmFor@0 3489 pruneData.race = race;
EmFor@0 3490 pruneData.class = class;
EmFor@0 3491 pruneData.name = name;
EmFor@0 3492
EmFor@0 3493 table.insert(g_AccumulatedPruneData, pruneData);
EmFor@0 3494 end
EmFor@0 3495 -----------------------------------------------------------------------------------
EmFor@0 3496 --
EmFor@0 3497 -- Prune the accumulation
EmFor@0 3498 --
EmFor@0 3499 -----------------------------------------------------------------------------------
EmFor@0 3500 function CensusPlus_PruneTheData()
EmFor@0 3501 local num = table.getn(g_AccumulatedPruneData);
EmFor@0 3502 CensusPlus_Msg( format(CENSUSPlus_PRUNEINFO, num ) );
EmFor@0 3503 while( num > 0 )do
EmFor@0 3504 --
EmFor@0 3505 -- Remove the top job from the queue and send it
EmFor@0 3506 --
EmFor@0 3507 local pruneData = g_AccumulatedPruneData[num];
EmFor@0 3508
EmFor@0 3509 CensusPlus_Database["Servers"][pruneData.realm][pruneData.faction][pruneData.race][pruneData.class][pruneData.name] = {};
EmFor@0 3510 CensusPlus_Database["Servers"][pruneData.realm][pruneData.faction][pruneData.race][pruneData.class][pruneData.name] = nil;
EmFor@0 3511
EmFor@0 3512 table.remove(g_AccumulatedPruneData);
EmFor@0 3513 num = table.getn(g_AccumulatedPruneData);
EmFor@0 3514 end
EmFor@0 3515 end
EmFor@0 3516
EmFor@0 3517 -----------------------------------------------------------------------------------
EmFor@0 3518 --
EmFor@0 3519 -- Prune time entries
EmFor@0 3520 --
EmFor@0 3521 -----------------------------------------------------------------------------------
EmFor@0 3522 function CensusPlus_PruneTimes()
EmFor@0 3523 local pruneDays = 60*60*24*21; -- num seconds
EmFor@0 3524
EmFor@0 3525 local accumTimesData = {};
EmFor@0 3526 for realmName, realmDatabase in pairs(CensusPlus_Database["TimesPlus"]) do
EmFor@0 3527 if (realmName ~= nil ) then
EmFor@0 3528 for factionName, factionDatabase in pairs(realmDatabase) do
EmFor@0 3529 if ( factionName ~= nil) then
EmFor@0 3530 for moment, count in pairs( factionDatabase ) do
EmFor@0 3531 -- Moment is in format of YYYY-MM-DD&HH:MM
EmFor@0 3532 local test = string.sub( moment, 1, 2 );
EmFor@0 3533 local tYear, tMonth, tDay;
EmFor@0 3534 tYear = string.sub( moment, 1, 4 );
EmFor@0 3535 tMonth = string.sub( moment, 6, 7 );
EmFor@0 3536 tDay = string.sub( moment, 9, 10 );
EmFor@0 3537 local momentTime = time( {year=tYear, month=tMonth, day=tDay, hour=0} );
EmFor@0 3538
EmFor@0 3539 if( time() - momentTime > pruneDays ) then
EmFor@0 3540 -- cull entry
EmFor@0 3541 local pruneData = {};
EmFor@0 3542 pruneData.realm = realmName;
EmFor@0 3543 pruneData.faction = factionName;
EmFor@0 3544 pruneData.entry = moment;
EmFor@0 3545 table.insert(accumTimesData, pruneData);
EmFor@0 3546 end
EmFor@0 3547 end
EmFor@0 3548 end
EmFor@0 3549 end
EmFor@0 3550 end
EmFor@0 3551 end
EmFor@0 3552
EmFor@0 3553 local num = table.getn(accumTimesData);
EmFor@0 3554 while( num > 0 )do
EmFor@0 3555 local pruneData = accumTimesData[num];
EmFor@0 3556
EmFor@0 3557 CensusPlus_Database["TimesPlus"][pruneData.realm][pruneData.faction][pruneData.entry] = {};
EmFor@0 3558 CensusPlus_Database["TimesPlus"][pruneData.realm][pruneData.faction][pruneData.entry] = nil;
EmFor@0 3559
EmFor@0 3560 table.remove(accumTimesData);
EmFor@0 3561 num = table.getn(accumTimesData);
EmFor@0 3562 end
EmFor@0 3563 end
EmFor@0 3564
EmFor@0 3565
EmFor@0 3566 function CensusPlus_CheckForBattleground()
EmFor@0 3567
EmFor@0 3568
EmFor@0 3569 -- CensusPlus_Msg( "Checking for BG" );
EmFor@0 3570 g_CurrentlyInBG_Msg = false;
EmFor@0 3571
EmFor@0 3572 local battlefieldTime = GetBattlefieldInstanceRunTime();
EmFor@0 3573 if( battlefieldTime > 0 ) then
EmFor@0 3574 --
EmFor@0 3575 -- We are in a battleground so cancel the current take
EmFor@0 3576 --
EmFor@0 3577 g_CurrentlyInBG = true;
EmFor@0 3578 else
EmFor@0 3579 if( GetBattlefieldStatInfo(1) ~= nil ) then
EmFor@0 3580 g_CurrentlyInBG = true;
EmFor@0 3581 else
EmFor@0 3582 g_CurrentlyInBG = false;
EmFor@0 3583 end
EmFor@0 3584 end
EmFor@0 3585
EmFor@0 3586 end
EmFor@0 3587
EmFor@0 3588 function CensusPlus_IsInspectLoaded()
EmFor@0 3589 if (IsAddOnLoaded("Blizzard_InspectUI")) then
EmFor@0 3590 --ChatFrame1:AddMessage("Inspect Loaded");
EmFor@0 3591 return true;
EmFor@0 3592 end
EmFor@0 3593
EmFor@0 3594 if (CensusPlus_Database["Info"]["LoadInspect"] ~= nil and CensusPlus_Database["Info"]["LoadInspect"] == true) then
EmFor@0 3595 --ChatFrame1:AddMessage("Loading Inspect Frame");
EmFor@0 3596 LoadAddOn("Blizzard_InspectUI");
EmFor@0 3597 end
EmFor@0 3598
EmFor@0 3599 --ChatFrame1:AddMessage("Inspect Not Loaded");
EmFor@0 3600 return false;
EmFor@0 3601 end
EmFor@0 3602
EmFor@0 3603 function CensusPlus_IsTalentLoaded()
EmFor@0 3604 if (IsAddOnLoaded("Blizzard_TalentUI")) then
EmFor@0 3605 --ChatFrame1:AddMessage("Talent Loaded");
EmFor@0 3606 return true;
EmFor@0 3607 end
EmFor@0 3608
EmFor@0 3609 if (CensusPlus_Database["Info"]["LoadTalent"] ~= nil and CensusPlus_Database["Info"]["LoadTalent"] == true) then
EmFor@0 3610 --ChatFrame1:AddMessage("Loading Talent Frame");
EmFor@0 3611 LoadAddOn("Blizzard_TalentUI");
EmFor@0 3612 end
EmFor@0 3613
EmFor@0 3614 --ChatFrame1:AddMessage("Talent Not Loaded");
EmFor@0 3615 return false;
EmFor@0 3616 end
EmFor@0 3617
EmFor@0 3618
EmFor@0 3619
EmFor@0 3620 function showAllUnitBuffs(sUnitname)
EmFor@0 3621 local iIterator = 1
EmFor@0 3622 DEFAULT_CHAT_FRAME:AddMessage(format("[%s] Buffs", sUnitname))
EmFor@0 3623 while (UnitBuff(sUnitname, iIterator)) do
EmFor@0 3624 DEFAULT_CHAT_FRAME:AddMessage(UnitBuff(sUnitname, iIterator), 1, 1, 0)
EmFor@0 3625 iIterator = iIterator + 1
EmFor@0 3626 end
EmFor@0 3627 DEFAULT_CHAT_FRAME:AddMessage("---", 1, 1, 0)
EmFor@0 3628 end
EmFor@0 3629
EmFor@0 3630 function CensusPlus_GetUTCDateTimeStr()
EmFor@0 3631 return date( "!%Y-%m-%d %H:%M", time() );
EmFor@0 3632 end
EmFor@0 3633
EmFor@0 3634 -----------------------------------------------------------------------------------
EmFor@0 3635 --
EmFor@0 3636 -- CensusPlus_DetermineServerDate
EmFor@0 3637 --
EmFor@0 3638 -----------------------------------------------------------------------------------
EmFor@0 3639 function CensusPlus_DetermineServerDate()
EmFor@0 3640
EmFor@0 3641 CensusPlus_CheckTZ();
EmFor@0 3642
EmFor@0 3643 local strDate;
EmFor@0 3644 local TZOffset = g_CensusPlusTZOffset;
EmFor@0 3645
EmFor@0 3646 --
EmFor@0 3647 -- Timezone offsets should fall into distinct numbers for now
EmFor@0 3648 -- And now that we know if they are playing on US or EU servers
EmFor@0 3649 -- we can be even better estimates
EmFor@0 3650 --
EmFor@0 3651
EmFor@0 3652 --
EmFor@0 3653 -- For US servers, the offset should be either -9 to -5 or 16/19 depending on DST for NA times
EmFor@0 3654 -- and for oceana it is +11/-13
EmFor@0 3655 -- EU servers are either +1 or 0 or -23 depending on DST
EmFor@0 3656 --
EmFor@0 3657
EmFor@0 3658 if( CensusPlus_Database["Info"]["Locale"] == "US" ) then
EmFor@0 3659 if( TZOffset > 12 ) then
EmFor@0 3660 -- NA server times but wrong day
EmFor@0 3661 TZOffset = TZOffset - 24;
EmFor@0 3662 elseif( TZOffset < -11 ) then
EmFor@0 3663 -- Oceana times but wrong day
EmFor@0 3664 TZOffset = 24 - TZOffset;
EmFor@0 3665 end
EmFor@0 3666 else
EmFor@0 3667 if( TZOffset == -23 ) then
EmFor@0 3668 TZOffset = 1;
EmFor@0 3669 end
EmFor@0 3670 end
EmFor@0 3671
EmFor@0 3672 -- Now, take the TZOffset and modify our time to give us server date
EmFor@0 3673 strDate = date( "!%Y-%m-%d", time() + (TZOffset * 3600 ) );
EmFor@0 3674
EmFor@0 3675 -- local strDate2 = date( "%Y-%m-%d : %H:%M", time() );
EmFor@0 3676 -- CensusPlus_Msg("Server date = " .. strDate .. " for TZOffset : " .. TZOffset .. " curr local: " .. strDate2 );
EmFor@0 3677
EmFor@0 3678 return strDate;
EmFor@0 3679 end
EmFor@0 3680
EmFor@0 3681 -----------------------------------------------------------------------------------
EmFor@0 3682 --
EmFor@0 3683 -- Check time zone
EmFor@0 3684 --
EmFor@0 3685 -----------------------------------------------------------------------------------
EmFor@0 3686 function CensusPlus_CheckTZ()
EmFor@0 3687
EmFor@0 3688 local UTCTimeHour = date( "!%H", time() );
EmFor@0 3689 local LocTimeHour = date( "%H", time() );
EmFor@0 3690 local hour, minute = GetGameTime();
EmFor@0 3691
EmFor@0 3692 local locDiff = LocTimeHour - UTCTimeHour;
EmFor@0 3693 local servDiff = hour - UTCTimeHour;
EmFor@0 3694 g_CensusPlusTZOffset = servDiff;
EmFor@0 3695 end
EmFor@0 3696
EmFor@0 3697
EmFor@0 3698 function CensusPlus_UpdateBattleGroundInfo()
EmFor@0 3699 local status, mapName, instanceID, lowestLevel, highestLevel;
EmFor@0 3700 local numberQueues = 0;
EmFor@0 3701 local waitTime, timeInQueue;
EmFor@0 3702 local map = {};
EmFor@0 3703
EmFor@0 3704 if( g_CensusPlusLocale == "N/A" ) then
EmFor@0 3705 return;
EmFor@0 3706 end
EmFor@0 3707
EmFor@0 3708 for i=1, MAX_BATTLEFIELD_QUEUES do
EmFor@0 3709 map = {};
EmFor@0 3710 status, mapName, instanceID, lowestLevel, highestLevel = GetBattlefieldStatus(i);
EmFor@0 3711
EmFor@0 3712 if ( status ~= "none" ) then
EmFor@0 3713 numberQueues = numberQueues+1;
EmFor@0 3714
EmFor@0 3715 if ( status == "queued" ) then
EmFor@0 3716 -- Update queue info
EmFor@0 3717 waitTime = GetBattlefieldEstimatedWaitTime(i)/1000;
EmFor@0 3718 timeInQueue = GetBattlefieldTimeWaited(i)/1000;
EmFor@0 3719
EmFor@0 3720 map[0] = waitTime;
EmFor@0 3721 map[1] = timeInQueue;
EmFor@0 3722 map[2] = mapName;
EmFor@0 3723 map[3] = "Inactive";
EmFor@0 3724
EmFor@0 3725 -- CensusPlus_Msg( "INSERT " .. mapName .. " : " .. map[2] .. " to " .. i );
EmFor@0 3726 CENSUSPLUS_CURRENT_BATTLEFIELD_QUEUES[i] = map;
EmFor@0 3727
EmFor@0 3728 elseif ( status == "confirm" ) then
EmFor@0 3729 -- In the battleground
EmFor@0 3730 -- Check to see if we know we've already entered, and if so, add info to
EmFor@0 3731 -- our database
EmFor@0 3732 map = CENSUSPLUS_CURRENT_BATTLEFIELD_QUEUES[i];
EmFor@0 3733
EmFor@0 3734 -- CensusPlus_Msg( "ACTIVE " .. mapName );
EmFor@0 3735 -- CensusPlus_Msg( map[2] );
EmFor@0 3736 if( map ~= nil and map[3] == "Inactive" ) then
EmFor@0 3737 map[3] = "Active";
EmFor@0 3738
EmFor@0 3739 CENSUSPLUS_CURRENT_BATTLEFIELD_QUEUES[i] = map;
EmFor@0 3740
EmFor@0 3741 -- Make an entry in our database
EmFor@0 3742
EmFor@0 3743 --
EmFor@0 3744 -- Get the portion of the database for this server
EmFor@0 3745 --
EmFor@0 3746 local realmName = g_CensusPlusLocale .. GetCVar("realmName");
EmFor@0 3747 if (CensusPlus_BGInfo[realmName] == nil) then
EmFor@0 3748 CensusPlus_BGInfo[realmName] = {};
EmFor@0 3749 end
EmFor@0 3750
EmFor@0 3751 --
EmFor@0 3752 -- Get the portion of the database for this faction
EmFor@0 3753 --
EmFor@0 3754 local factionGroup = UnitFactionGroup("player");
EmFor@0 3755 if( factionGroup ~= nil ) then
EmFor@0 3756 if (CensusPlus_BGInfo[realmName][factionGroup] == nil) then
EmFor@0 3757 CensusPlus_BGInfo[realmName][factionGroup] = {};
EmFor@0 3758 end
EmFor@0 3759
EmFor@0 3760 local playerLevel = UnitLevel( "player" );
EmFor@0 3761 if( playerLevel ~= nil ) then
EmFor@0 3762 if (CensusPlus_BGInfo[realmName][factionGroup][playerLevel] == nil) then
EmFor@0 3763 CensusPlus_BGInfo[realmName][factionGroup][playerLevel] = {};
EmFor@0 3764 end
EmFor@0 3765
EmFor@0 3766 local hour, minute = GetGameTime();
EmFor@0 3767 CensusPlus_BGInfo[realmName][factionGroup][playerLevel][CensusPlus_DetermineServerDate() .. "&" .. hour .. ":" .. minute .. ":00"] =
EmFor@0 3768 map[2] .. "&" .. map[0] .. "&" .. map[1] .. "&" .. lowestLevel .. "&" .. highestLevel;
EmFor@0 3769 end
EmFor@0 3770 end
EmFor@0 3771 end
EmFor@0 3772 end
EmFor@0 3773 end
EmFor@0 3774 end
EmFor@0 3775 end
EmFor@0 3776
EmFor@0 3777 function CensusPlus_PruneBGInfo()
EmFor@0 3778 local pruneDays = 60*60*24*21; -- num seconds
EmFor@0 3779
EmFor@0 3780 local accumData = {};
EmFor@0 3781 for realmName, realmDatabase in pairs(CensusPlus_BGInfo) do
EmFor@0 3782 if (realmName ~= nil and table.getn( realmDatabase ) > 0 ) then
EmFor@0 3783 for factionName, factionDatabase in pairs(realmDatabase) do
EmFor@0 3784 if ( factionName ~= nil and table.getn( factionDatabase ) > 0 ) then
EmFor@0 3785 for level, levelDatabase in pairs( factionDatabase ) do
EmFor@0 3786 if( level ~= nil and table.getn( levelDatabase ) > 0 ) then
EmFor@0 3787 for moment, data in pairs( levelDatabase ) do
EmFor@0 3788 -- Moment is in format of YYYY-MM-DD&HH:MM
EmFor@0 3789 local test = string.sub( moment, 1, 2 );
EmFor@0 3790 local tYear, tMonth, tDay;
EmFor@0 3791 tYear = string.sub( moment, 1, 4 );
EmFor@0 3792 tMonth = string.sub( moment, 6, 7 );
EmFor@0 3793 tDay = string.sub( moment, 9, 10 );
EmFor@0 3794 local momentTime = time( {year=tYear, month=tMonth, day=tDay, hour=0} );
EmFor@0 3795
EmFor@0 3796 if( time() - momentTime > pruneDays ) then
EmFor@0 3797 -- cull entry
EmFor@0 3798 local pruneData = {};
EmFor@0 3799 pruneData.realm = realmName;
EmFor@0 3800 pruneData.faction = factionName;
EmFor@0 3801 pruneData.level = level;
EmFor@0 3802 pruneData.entry = moment;
EmFor@0 3803 table.insert(accumData, pruneData);
EmFor@0 3804 end
EmFor@0 3805 end
EmFor@0 3806 end
EmFor@0 3807 end
EmFor@0 3808 end
EmFor@0 3809 end
EmFor@0 3810 end
EmFor@0 3811 end
EmFor@0 3812
EmFor@0 3813 local num = table.getn(accumData);
EmFor@0 3814 while( num > 0 )do
EmFor@0 3815 local pruneData = accumData[num];
EmFor@0 3816
EmFor@0 3817 CensusPlus_BGInfo[pruneData.realm][pruneData.faction][pruneData.level][pruneData.entry] = {};
EmFor@0 3818 CensusPlus_BGInfo[pruneData.realm][pruneData.faction][pruneData.level][pruneData.entry] = nil;
EmFor@0 3819
EmFor@0 3820 table.remove(accumData);
EmFor@0 3821 num = table.getn(accumData);
EmFor@0 3822 end
EmFor@0 3823 end
EmFor@0 3824
EmFor@0 3825 -----------------------------------------------------------------------------------
EmFor@0 3826 --
EmFor@0 3827 -- My Test function
EmFor@0 3828 --
EmFor@0 3829 -----------------------------------------------------------------------------------
EmFor@0 3830 function CensusPlus_Test( val )
EmFor@0 3831
EmFor@0 3832
EmFor@0 3833 -- local file = "Interface\\AddOns\\CensusPlus\\Sounds\\CensusComplete.ogg";
EmFor@0 3834 -- CensusPlus_Msg( "Play sound " .. file );
EmFor@0 3835 -- PlaySoundFile( file );
EmFor@0 3836
EmFor@0 3837 local test = {};
EmFor@0 3838 test[1] = "|Hplayer:Cdrom|h[Cdrom]|h: Level 60 Tauren Warrior <CSM AND NOVA SUX> - Hellfire Peninsula";
EmFor@0 3839 test[2] = "|Hplayer:Cdrom|h[Cdrom]|h: Level 60 Tauren Warrior - Hellfire Peninsula";
EmFor@0 3840 test[3] = "|Hplayer:Cdrom|h[Cdrom]|h: Level 60 Troll Death Knight <CSM AND NOVA SUX> - Hellfire Peninsula";
EmFor@0 3841 test[4] = "|Hplayer:Cdrom|h[Cdrom]|h: Level 60 Troll Death Knight - Hellfire Peninsula";
EmFor@0 3842 test[5] = "|Hplayer:Frostbiite|h[Frostbiite]|h: Level 61 Troll Death Knight - Hellfire Peninsula";
EmFor@0 3843 test[6] = "|Hplayer:Dynanite|h[Dynanite]|h: Level 60 Troll Death Knight - Hellfire Peninsula";
EmFor@0 3844 test[7] = "|Hplayer:Physco|h[Physco]|h: Level 61 Troll Death Knight - Hellfire Peninsula";
EmFor@0 3845 test[8] = "|Hplayer:Gordoom|h[Gordoom]|h: Level 60 Troll Death Knight <Hellfire Club> - Hellfire Peninsula";
EmFor@0 3846 test[9] = "|Hplayer:Seroa|h[Seroa]|h: Level 67 Blood Elf Death Knight <Carnage> - Nagrand";
EmFor@0 3847 test[10] = "|Hplayer:Seroa|h[Seroa]|h: Level 67 Night Elf Death Knight <Carnage> - Nagrand";
EmFor@0 3848 test[11] = "|Hplayer:Seroa|h[Seroa]|h: Level 67 Blood Elf Death Knight - Nagrand";
EmFor@0 3849 test[12] = "|Hplayer:Seroa|h[Seroa]|h: Level 67 Night Elf Death Knight - Nagrand";
EmFor@0 3850 test[13] = "|Hplayer:Seroa|h[Seroa]|h: Level 67 Blood Elf Paladin <Carnage> - Nagrand";
EmFor@0 3851 test[14] = "|Hplayer:Seroa|h[Seroa]|h: Level 67 Night Elf Paladin <Carnage> - Nagrand";
EmFor@0 3852 test[15] = "|Hplayer:Seroa|h[Seroa]|h: Level 67 Blood Elf Paladin - Nagrand";
EmFor@0 3853 test[16] = "|Hplayer:Seroa|h[Seroa]|h: Level 67 Night Elf Paladin - Nagrand";
EmFor@0 3854
EmFor@0 3855
EmFor@0 3856 for index, case in pairs(test) do
EmFor@0 3857 CensusPlus_Msg( "Checking : " .. case );
EmFor@0 3858 local t = CensusPlus_GatherSingleReturn( case );
EmFor@0 3859 if( t ~= nil ) then
EmFor@0 3860 CensusPlus_Msg( index .. " Name : " .. t["NAME"]
EmFor@0 3861 .. " L: " .. t["LEVEL"]
EmFor@0 3862 .. " R: " .. t["RACE"]
EmFor@0 3863 .. " C: " .. t["CLASS"]
EmFor@0 3864 .. " G: " .. t["GUILD"]
EmFor@0 3865 .. " Z: " .. t["ZONE"] );
EmFor@0 3866 end
EmFor@0 3867 end
EmFor@0 3868
EmFor@0 3869
EmFor@0 3870 --[[
EmFor@0 3871 local pattern = "[0-9\| ]";
EmFor@0 3872
EmFor@0 3873 local name = "11:58]|r |Hplayer:Azide|h[Azide";
EmFor@0 3874 if( string.find( name, pattern ) ~= nil ) then
EmFor@0 3875 CensusPlus_Msg( "This name is problematic => " .. name );
EmFor@0 3876 end
EmFor@0 3877
EmFor@0 3878 name = "Rollie";
EmFor@0 3879 if( string.find( name, pattern ) ~= nil ) then
EmFor@0 3880 CensusPlus_Msg( "This name is problematic => " .. name );
EmFor@0 3881 else
EmFor@0 3882 CensusPlus_Msg( "This name is NOT problematic => " .. name );
EmFor@0 3883 end
EmFor@0 3884 ]]--
EmFor@0 3885
EmFor@0 3886 end
EmFor@0 3887
EmFor@0 3888 function CensusPlus_GatherSingleReturn( line )
EmFor@0 3889 local t = {};
EmFor@0 3890 local s, e, name, level_text, level, rcg, zone, junk;
EmFor@0 3891 local RCG = {};
EmFor@0 3892 local presults = {};
EmFor@0 3893 local RCG_Pattern = "(.+) <(.+)>";
EmFor@0 3894 local possibles = {};
EmFor@0 3895 possibles[1] = "(" .. CENSUSPlus_NIGHTELF .. ")" .. " ([%a%s]+)";
EmFor@0 3896 possibles[2] = "(" .. CENSUSPlus_BLOODELF .. ")" .. " ([%a%s]+)";
EmFor@0 3897 possibles[3] = "(%a+) " .. "(" .. CENSUSPlus_DEATHKNIGHT .. ")";
EmFor@0 3898 possibles[4] = "(%a+) (%a+)";
EmFor@0 3899
EmFor@0 3900 --CensusPlus_Msg2( " CHECKING " .. line );
EmFor@0 3901
EmFor@0 3902 if( g_PratLoaded ) then
EmFor@0 3903 s, e, junk, junk, junk, name, junk, junk, level_text, level, rcg, zone = string.find(line, CENSUS_SINGLE_MATCH_PATTERN_PRAT );
EmFor@0 3904 else
EmFor@0 3905 s, e, junk, junk, name, level_text, level, rcg, zone = string.find(line, CENSUS_SINGLE_MATCH_PATTERN);
EmFor@0 3906 end
EmFor@0 3907 if( name ~= nil ) then
EmFor@0 3908 --
EmFor@0 3909 -- Now let's break out our race, class & guild
EmFor@0 3910 --
EmFor@0 3911 local race_class = rcg;
EmFor@0 3912 t["GUILD"] = '';
EmFor@0 3913 t["NAME"] = name;
EmFor@0 3914 t["LEVEL"] = level;
EmFor@0 3915 t["ZONE"] = zone;
EmFor@0 3916 s, e, RCG[0], RCG[1] = string.find(rcg, RCG_Pattern);
EmFor@0 3917 if( RCG[0] ~= nil ) then
EmFor@0 3918 race_class = RCG[0];
EmFor@0 3919 t["GUILD"] = RCG[1];
EmFor@0 3920 end
EmFor@0 3921
EmFor@0 3922 --
EmFor@0 3923 -- Now we need to figure out race/class
EmFor@0 3924 --
EmFor@0 3925 for pi, poss in pairs(possibles) do
EmFor@0 3926 s, e, presults[0], presults[1] = string.find(race_class, poss);
EmFor@0 3927 if( presults[0] ~= nil ) then
EmFor@0 3928 -- CensusPlus_Msg( pi .. " 0: " .. presults[0] .. " 1: " .. presults[1]);
EmFor@0 3929 t["RACE"] = presults[0];
EmFor@0 3930 t["CLASS"] = presults[1];
EmFor@0 3931 break;
EmFor@0 3932 end
EmFor@0 3933 end
EmFor@0 3934
EmFor@0 3935 -- CensusPlus_Msg2( " IN Fn Name : " .. t["NAME"] .. " L: " .. t["LEVEL"] .. " R: " .. t["RACE"] .. " C: " .. t["CLASS"].. " G: " .. t["GUILD"] .. " Z: " .. t["ZONE"] );
EmFor@0 3936 end
EmFor@0 3937
EmFor@0 3938 return t;
EmFor@0 3939 end
EmFor@0 3940
EmFor@0 3941
EmFor@0 3942 function CensusPlus_SetItemRef(link, text, button)
EmFor@0 3943 --
EmFor@0 3944 -- We only care about if they are sending a who, otherwise send on through
EmFor@0 3945 --
EmFor@0 3946 if ( g_IsCensusPlusInProgress and strsub(link, 1, 6) == "player" ) then
EmFor@0 3947 if ( strsub(link, 1, 6) == "player" ) then
EmFor@0 3948 local namelink = strsub(link, 8);
EmFor@0 3949 local name, lineid = strsplit(":", namelink);
EmFor@0 3950 if ( name and (strlen(name) > 0) ) then
EmFor@0 3951 name = gsub(name, "([^%s]*)%s+([^%s]*)%s+([^%s]*)", "%3");
EmFor@0 3952 name = gsub(name, "([^%s]*)%s+([^%s]*)", "%2");
EmFor@0 3953 if ( IsShiftKeyDown() ) then
EmFor@6 3954 if ( not ChatFrame1EditBox:IsVisible() ) then
EmFor@0 3955 --
EmFor@0 3956 -- This is the part we need to snag
EmFor@0 3957 --
EmFor@0 3958
EmFor@0 3959 --
EmFor@0 3960 -- Queue up the command to run next
EmFor@0 3961 --
EmFor@0 3962 g_CensusWhoOverrideMsg = "n-"..name;
EmFor@0 3963 CensusPlus_Msg( CENSUSPlus_OVERRIDE );
EmFor@0 3964
EmFor@0 3965 -- CensusPlus_SendWho("n-"..name);
EmFor@0 3966 return;
EmFor@0 3967 end
EmFor@0 3968 end
EmFor@0 3969 end
EmFor@0 3970 end
EmFor@0 3971 end
EmFor@0 3972
EmFor@0 3973 g_SetItemRef_Override( link, text, button );
EmFor@0 3974 end
EmFor@0 3975
EmFor@0 3976 function CensusPlus_CleanChars()
EmFor@0 3977
EmFor@0 3978 local pattern = "[0-9\| -]";
EmFor@0 3979 local count = 0;
EmFor@0 3980
EmFor@0 3981 for realmName, realmDatabase in pairs(CensusPlus_Database["Servers"]) do
EmFor@0 3982 if ((realmKey == nil) or (realmKey == realmName)) then
EmFor@0 3983 for factionName, factionDatabase in pairs(realmDatabase) do
EmFor@0 3984 if ((factionKey == nil) or (factionKey == factionName)) then
EmFor@0 3985 for raceName, raceDatabase in pairs(factionDatabase) do
EmFor@0 3986 if ((raceKey == nil) or (raceKey == raceName)) then
EmFor@0 3987 for className, classDatabase in pairs(raceDatabase) do
EmFor@0 3988 if ((classKey == nil) or (classKey == className)) then
EmFor@0 3989 for characterName, character in pairs(classDatabase) do
EmFor@0 3990 if( characterName ~= nil ) then
EmFor@0 3991 if( string.find( characterName, pattern ) ~= nil ) then
EmFor@0 3992 CensusPlus_AccumulatePruneData( realmName, factionName, raceName, className, characterName );
EmFor@0 3993 count = count + 1;
EmFor@0 3994 end
EmFor@0 3995 end
EmFor@0 3996 end
EmFor@0 3997 end
EmFor@0 3998 end
EmFor@0 3999 end
EmFor@0 4000 end
EmFor@0 4001 end
EmFor@0 4002 end
EmFor@0 4003 end
EmFor@0 4004 end
EmFor@0 4005
EmFor@0 4006 CensusPlus_PruneTheData();
EmFor@0 4007 CensusPlus_Msg( "Found " .. count .. " entries to remove" );
EmFor@0 4008 end
EmFor@0 4009
EmFor@0 4010 function CensusPlus_SendWho( msg )
EmFor@0 4011
EmFor@0 4012 if( CensusPlus_PerCharInfo["Verbose"] == true ) then
EmFor@0 4013 CensusPlus_Msg(format(CENSUSPlus_SENDING, msg));
EmFor@0 4014 end
EmFor@0 4015
EmFor@0 4016 if wholib then
EmFor@0 4017 wholib:AskWho({query = msg, queue = wholib.WHOLIB_QUEUE_QUIET, callback = CP_ProcessWhoEvent })
EmFor@0 4018 else
EmFor@0 4019 SendWho( msg );
EmFor@0 4020 end
EmFor@0 4021 end
EmFor@6 4022
EmFor@6 4023 function CensusPlus_Options_OnMouseUp(self,...)
EmFor@6 4024 CensusPlus_Msg('Mouse up');
EmFor@6 4025
EmFor@6 4026 if ( self.isMoving ) then
EmFor@6 4027 self:StopMovingOrSizing();
EmFor@6 4028 self.isMoving = false;
EmFor@6 4029 end
EmFor@6 4030 end
EmFor@6 4031
EmFor@6 4032 function CensusPlus_Options_OnMouseDown(self,arg1,arg2,arg3,...)
EmFor@6 4033 if ( ( ( not self.isLocked ) or ( self.isLocked == 0 ) ) and ( arg1 == "LeftButton" ) ) then
EmFor@6 4034 self:StartMoving();
EmFor@6 4035 self.isMoving = true;
EmFor@6 4036 end
EmFor@6 4037 end
EmFor@6 4038
EmFor@6 4039 function CensusPlus_Mini_OnMouseDown( self, arg1 )
EmFor@6 4040 if ( ( ( not self.isLocked ) or ( self.isLocked == 0 ) ) and ( arg1 == "LeftButton" ) ) then
EmFor@6 4041 self:StartMoving();
EmFor@6 4042 self.isMoving = true;
EmFor@6 4043 end
EmFor@6 4044 end
EmFor@6 4045
EmFor@6 4046 function CensusPlus_Census_OnMouseDown( self, arg1 )
EmFor@6 4047 if ( ( ( not self.isLocked ) or ( self.isLocked == 0 ) ) and ( arg1 == "LeftButton" ) ) then
EmFor@6 4048 self:StartMoving();
EmFor@6 4049 self.isMoving = true;
EmFor@6 4050 end
EmFor@6 4051 end