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