Mercurial > wow > ouroloot
comparison core.lua @ 10:67b8537e8432
More work on ML/EQDKP generator and its spawned subprojects.
| author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
|---|---|
| date | Tue, 28 Jun 2011 07:36:26 +0000 |
| parents | 30ba1f35e164 |
| children | 952c3ac0e783 |
comparison
equal
deleted
inserted
replaced
| 9:4fba9c6b5d3d | 10:67b8537e8432 |
|---|---|
| 156 local g_wafer_thin = nil -- for prompting for additional rebroadcasters | 156 local g_wafer_thin = nil -- for prompting for additional rebroadcasters |
| 157 local g_today = nil -- "today" entry in g_loot | 157 local g_today = nil -- "today" entry in g_loot |
| 158 local opts = nil | 158 local opts = nil |
| 159 | 159 |
| 160 local pairs, ipairs, tinsert, tremove, tonumber = pairs, ipairs, table.insert, table.remove, tonumber | 160 local pairs, ipairs, tinsert, tremove, tonumber = pairs, ipairs, table.insert, table.remove, tonumber |
| 161 | |
| 162 local pprint, tabledump = addon.pprint, flib.tabledump | 161 local pprint, tabledump = addon.pprint, flib.tabledump |
| 163 | 162 local GetNumRaidMembers = GetNumRaidMembers |
| 164 -- En masse forward decls of symbols defined inside local blocks | 163 -- En masse forward decls of symbols defined inside local blocks |
| 165 local _register_bossmod | 164 local _register_bossmod |
| 166 local makedate, create_new_cache, _init | 165 local makedate, create_new_cache, _init |
| 167 | 166 |
| 168 -- Hypertext support, inspired by DBM broadcast pizza timers | 167 -- Hypertext support, inspired by DBM broadcast pizza timers |
| 249 foo:test("blah") -- returns true | 248 foo:test("blah") -- returns true |
| 250 ]] | 249 ]] |
| 251 do | 250 do |
| 252 local caches = {} | 251 local caches = {} |
| 253 local cleanup_group = AnimTimerFrame:CreateAnimationGroup() | 252 local cleanup_group = AnimTimerFrame:CreateAnimationGroup() |
| 253 local time = _G.time | |
| 254 cleanup_group:SetLooping("REPEAT") | 254 cleanup_group:SetLooping("REPEAT") |
| 255 cleanup_group:SetScript("OnLoop", function(cg) | 255 cleanup_group:SetScript("OnLoop", function(cg) |
| 256 addon.dprint('cache',"OnLoop firing") | 256 addon.dprint('cache',"OnLoop firing") |
| 257 local now = GetTime() | 257 local now = time() |
| 258 local alldone = true | 258 local alldone = true |
| 259 -- this is ass-ugly | 259 -- this is ass-ugly |
| 260 for _,c in ipairs(caches) do | 260 for _,c in ipairs(caches) do |
| 261 while (#c > 0) and (now - c[1].t > c.ttl) do | 261 while (#c > 0) and (now - c[1].t > c.ttl) do |
| 262 addon.dprint('cache', c.name, "cache removing",c[1].t, c[1].m) | 262 addon.dprint('cache', c.name, "cache removing",c[1].t, c[1].m) |
| 273 end | 273 end |
| 274 addon.dprint('cache',"OnLoop done") | 274 addon.dprint('cache',"OnLoop done") |
| 275 end) | 275 end) |
| 276 | 276 |
| 277 local function _add (cache, x) | 277 local function _add (cache, x) |
| 278 tinsert(cache, {t=GetTime(),m=x}) | 278 tinsert(cache, {t=time(),m=x}) |
| 279 if not cleanup_group:IsPlaying() then | 279 if not cleanup_group:IsPlaying() then |
| 280 addon.dprint('cache', cache.name, "STARTING animation group") | 280 addon.dprint('cache', cache.name, "STARTING animation group") |
| 281 cache.cleanup:SetDuration(2) -- hmmm | 281 cache.cleanup:SetDuration(2) -- hmmm |
| 282 cleanup_group:Play() | 282 cleanup_group:Play() |
| 283 end | 283 end |
| 353 _init(self) | 353 _init(self) |
| 354 self.OnInitialize = nil | 354 self.OnInitialize = nil |
| 355 end | 355 end |
| 356 | 356 |
| 357 function addon:OnEnable() | 357 function addon:OnEnable() |
| 358 self:RegisterEvent "PLAYER_LOGOUT" | 358 self:RegisterEvent("PLAYER_LOGOUT") |
| 359 self:RegisterEvent "RAID_ROSTER_UPDATE" | 359 self:RegisterEvent("RAID_ROSTER_UPDATE") |
| 360 | 360 |
| 361 -- Cribbed from Talented. I like the way jerry thinks: the first argument | 361 -- Cribbed from Talented. I like the way jerry thinks: the first argument |
| 362 -- can be a format spec for the remainder of the arguments. (The new | 362 -- can be a format spec for the remainder of the arguments. (The new |
| 363 -- AceConsole:Printf isn't used because we can't specify a prefix without | 363 -- AceConsole:Printf isn't used because we can't specify a prefix without |
| 364 -- jumping through ridonkulous hoops.) The part about overriding :Print | 364 -- jumping through ridonkulous hoops.) The part about overriding :Print |
| 399 OuroLootSV_hist = nil | 399 OuroLootSV_hist = nil |
| 400 ReloadUI() | 400 ReloadUI() |
| 401 end | 401 end |
| 402 function addon:PLAYER_LOGOUT() | 402 function addon:PLAYER_LOGOUT() |
| 403 if (#g_loot > 0) or g_loot.saved | 403 if (#g_loot > 0) or g_loot.saved |
| 404 -- someday make this smarter | |
| 404 or (g_loot.forum and g_loot.forum ~= "") | 405 or (g_loot.forum and g_loot.forum ~= "") |
| 405 or (g_loot.attend and g_loot.attend ~= "") | 406 or (g_loot.attend and g_loot.attend ~= "") |
| 406 then | 407 then |
| 407 g_loot.autoshard = self.sharder | 408 g_loot.autoshard = self.sharder |
| 408 g_loot.threshold = self.threshold | 409 g_loot.threshold = self.threshold |
| 421 end | 422 end |
| 422 end end | 423 end end |
| 423 OuroLootSV_hist = self.history_all | 424 OuroLootSV_hist = self.history_all |
| 424 end | 425 end |
| 425 | 426 |
| 426 function addon:RAID_ROSTER_UPDATE (event) | 427 do |
| 427 if GetNumRaidMembers() > 0 then | 428 local IsInInstance, UnitName, UnitIsConnected, UnitClass, UnitRace, UnitSex, |
| 429 UnitLevel, UnitInRaid, UnitIsVisible, GetGuildInfo = | |
| 430 IsInInstance, UnitName, UnitIsConnected, UnitClass, UnitRace, UnitSex, | |
| 431 UnitLevel, UnitInRaid, UnitIsVisible, GetGuildInfo | |
| 432 local time, difftime = time, difftime | |
| 433 local R_ACTIVE, R_OFFLINE, R_LEFT = 1, 2, 3 | |
| 434 | |
| 435 local lastevent, now = 0, 0 | |
| 436 local timer_handle | |
| 437 | |
| 438 function addon:CheckRoster (leaving_p, now_a) | |
| 439 if not g_loot.raiders then return end -- bad transition | |
| 440 | |
| 441 now = now_a or time() | |
| 442 | |
| 443 if leaving_p then | |
| 444 for name,r in pairs(g_loot.raiders) do | |
| 445 r.leave = r.leave or now | |
| 446 end | |
| 447 return | |
| 448 end | |
| 449 | |
| 450 for name,r in pairs(g_loot.raiders) do | |
| 451 if r.online ~= R_LEFT and not UnitInRaid(name) then | |
| 452 r.online = R_LEFT | |
| 453 r.leave = now | |
| 454 end | |
| 455 end | |
| 456 | |
| 457 local redo = false | |
| 458 for i = 1, GetNumRaidMembers() do | |
| 459 local unit = 'raid'..i | |
| 460 local name = UnitName(unit) | |
| 461 -- No, that's not my typo, it really is "uknownbeing" in Blizzard's code. | |
| 462 if name and name ~= UNKNOWN and name ~= UNKNOWNOBJECT and name ~= UKNOWNBEING then | |
| 463 if not g_loot.raiders[name] then | |
| 464 g_loot.raiders[name] = { needinfo=true } | |
| 465 end | |
| 466 local r = g_loot.raiders[name] | |
| 467 if r.needinfo and UnitIsVisible(unit) then | |
| 468 r.needinfo = nil | |
| 469 r.class = select(2,UnitClass(unit)) | |
| 470 r.race = select(2,UnitRace(unit)) | |
| 471 r.sex = UnitSex(unit) | |
| 472 r.level = UnitLevel(unit) | |
| 473 r.guild = GetGuildInfo(unit) | |
| 474 end | |
| 475 local connected = UnitIsConnected(unit) | |
| 476 if connected and r.online ~= R_ACTIVE then | |
| 477 r.join = r.join or now | |
| 478 r.online = R_ACTIVE | |
| 479 elseif (not connected) and r.online ~= R_OFFLINE then | |
| 480 r.leave = now | |
| 481 r.online = R_OFFLINE | |
| 482 end | |
| 483 redo = redo or r.needinfo | |
| 484 end | |
| 485 end | |
| 486 if redo then | |
| 487 timer_handle = self:ScheduleRepeatingTimer("RAID_ROSTER_UPDATE", 60) | |
| 488 elseif timer_handle then | |
| 489 self:CancelTimer(timer_handle) | |
| 490 timer_handle = nil | |
| 491 end | |
| 492 end | |
| 493 | |
| 494 function addon:RAID_ROSTER_UPDATE (event) | |
| 495 if GetNumRaidMembers() == 0 then | |
| 496 -- Because of PLAYER_ENTERING_WORLD, this code also executes on load | |
| 497 -- screens while soloing and in regular groups. Take care. | |
| 498 if self.enabled then | |
| 499 self.popped = nil | |
| 500 self:UnregisterEvent("CHAT_MSG_LOOT") | |
| 501 self:CheckRoster(--[[leaving raid]]true) | |
| 502 end | |
| 503 return | |
| 504 end | |
| 505 | |
| 428 local inside,whatkind = IsInInstance() | 506 local inside,whatkind = IsInInstance() |
| 429 if inside and (whatkind == "pvp" or whatkind == "arena") then | 507 if inside and (whatkind == "pvp" or whatkind == "arena") then |
| 430 return self.dprint('flow', "got RRU event but in pvp zone, bailing") | 508 return self.dprint('flow', "got RRU event but in pvp zone, bailing") |
| 431 end | 509 end |
| 510 | |
| 511 local docheck = self.enabled | |
| 432 if event == "Activate" then | 512 if event == "Activate" then |
| 433 -- dispatched manually from Activate | 513 -- dispatched manually from Activate |
| 434 self:RegisterEvent "CHAT_MSG_LOOT" | 514 self:RegisterEvent("CHAT_MSG_LOOT") |
| 435 _register_bossmod(self) | 515 _register_bossmod(self) |
| 516 docheck = true | |
| 436 elseif event == "RAID_ROSTER_UPDATE" then | 517 elseif event == "RAID_ROSTER_UPDATE" then |
| 518 -- hot code path, be careful | |
| 519 | |
| 437 -- event registration from onload, joined a raid, maybe show popup | 520 -- event registration from onload, joined a raid, maybe show popup |
| 438 if opts.popup_on_join and not self.popped then | 521 if (not self.popped) and opts.popup_on_join then |
| 439 self.popped = StaticPopup_Show "OUROL_REMIND" | 522 self.popped = StaticPopup_Show "OUROL_REMIND" |
| 440 self.popped.data = self | 523 self.popped.data = self |
| 441 end | 524 return |
| 442 end | 525 end |
| 443 else | 526 end |
| 444 self:UnregisterEvent "CHAT_MSG_LOOT" | 527 if docheck and not InCombatLockdown() then |
| 445 self.popped = nil | 528 now = time() |
| 529 if difftime(now,lastevent) > 45 then | |
| 530 lastevent = now | |
| 531 self:CheckRoster(false,now) | |
| 532 end | |
| 533 end | |
| 446 end | 534 end |
| 447 end | 535 end |
| 448 | 536 |
| 449 -- helper for CHAT_MSG_LOOT handler | 537 -- helper for CHAT_MSG_LOOT handler |
| 450 do | 538 do |
| 643 end | 731 end |
| 644 | 732 |
| 645 | 733 |
| 646 ------ On/off | 734 ------ On/off |
| 647 function addon:Activate (opt_threshold, opt_bcast_only) | 735 function addon:Activate (opt_threshold, opt_bcast_only) |
| 648 self:RegisterEvent "RAID_ROSTER_UPDATE" | 736 self:RegisterEvent("RAID_ROSTER_UPDATE") |
| 737 self:RegisterEvent("PLAYER_ENTERING_WORLD","RAID_ROSTER_UPDATE") | |
| 649 self.popped = true | 738 self.popped = true |
| 650 if GetNumRaidMembers() > 0 then | 739 if GetNumRaidMembers() > 0 then |
| 651 self:RAID_ROSTER_UPDATE("Activate") | 740 self:RAID_ROSTER_UPDATE("Activate") |
| 652 elseif self.debug.notraid then | 741 elseif self.debug.notraid then |
| 653 self:RegisterEvent "CHAT_MSG_LOOT" | 742 self:RegisterEvent("CHAT_MSG_LOOT") |
| 654 _register_bossmod(self) | 743 _register_bossmod(self) |
| 655 elseif g_restore_p then | 744 elseif g_restore_p then |
| 656 g_restore_p = nil | 745 g_restore_p = nil |
| 657 if #g_loot == 0 then return end -- only saved texts, not worth verbage | 746 if #g_loot == 0 then return end -- only saved texts, not worth verbage |
| 658 self:Print("Ouro Raid Loot restored previous data, but not in a raid", | 747 self:Print("Ouro Raid Loot restored previous data, but not in a raid", |
| 675 -- Note: running '/loot off' will also avoid the popup reminder when | 764 -- Note: running '/loot off' will also avoid the popup reminder when |
| 676 -- joining a raid, but will not change the saved option setting. | 765 -- joining a raid, but will not change the saved option setting. |
| 677 function addon:Deactivate() | 766 function addon:Deactivate() |
| 678 self.enabled = false | 767 self.enabled = false |
| 679 self.rebroadcast = false | 768 self.rebroadcast = false |
| 680 self:UnregisterEvent "RAID_ROSTER_UPDATE" | 769 self:UnregisterEvent("RAID_ROSTER_UPDATE") |
| 681 self:UnregisterEvent "CHAT_MSG_LOOT" | 770 self:UnregisterEvent("PLAYER_ENTERING_WORLD") |
| 771 self:UnregisterEvent("CHAT_MSG_LOOT") | |
| 682 self:Print("Ouro Raid Loot deactivated.") | 772 self:Print("Ouro Raid Loot deactivated.") |
| 683 end | 773 end |
| 684 | 774 |
| 685 function addon:Clear(verbose_p) | 775 function addon:Clear(verbose_p) |
| 686 local repopup, st | 776 local repopup, st |
| 817 self.dprint('flow', "restoring", #g_loot, "entries") | 907 self.dprint('flow', "restoring", #g_loot, "entries") |
| 818 self:ScheduleTimer("Activate", 8, g_loot.threshold) | 908 self:ScheduleTimer("Activate", 8, g_loot.threshold) |
| 819 -- FIXME printed could be too large if entries were deleted, how much do we care? | 909 -- FIXME printed could be too large if entries were deleted, how much do we care? |
| 820 self.sharder = g_loot.autoshard | 910 self.sharder = g_loot.autoshard |
| 821 else | 911 else |
| 822 g_loot = { printed = {} } | 912 g_loot = { printed = {}, raiders = {} } |
| 823 g_loot.saved = g_saved_tmp; g_saved_tmp = nil -- potentially restore across a clear | 913 g_loot.saved = g_saved_tmp; g_saved_tmp = nil -- potentially restore across a clear |
| 824 end | 914 end |
| 825 | 915 |
| 826 self.threshold = g_loot.threshold or self.threshold -- in the case of restoring but not tracking | 916 self.threshold = g_loot.threshold or self.threshold -- in the case of restoring but not tracking |
| 827 self:gui_init(g_loot) | 917 self:gui_init(g_loot) |
| 1091 setmetatable(e,loot_entry_mt) | 1181 setmetatable(e,loot_entry_mt) |
| 1092 | 1182 |
| 1093 if not done_todays_date then do_todays_date() end | 1183 if not done_todays_date then do_todays_date() end |
| 1094 | 1184 |
| 1095 local h, m = GetGameTime() | 1185 local h, m = GetGameTime() |
| 1096 local localuptime = math.floor(GetTime()) | 1186 --local localuptime = math.floor(GetTime()) |
| 1187 local time_t = time() | |
| 1097 e.hour = h | 1188 e.hour = h |
| 1098 e.minute = m | 1189 e.minute = m |
| 1099 e.stamp = localuptime | 1190 e.stamp = time_t --localuptime |
| 1100 local index = #g_loot + 1 | 1191 local index = #g_loot + 1 |
| 1101 g_loot[index] = e | 1192 g_loot[index] = e |
| 1102 return index | 1193 return index |
| 1103 end | 1194 end |
| 1104 end | 1195 end |
| 1124 local n = #(g_loot.saved) + 1 | 1215 local n = #(g_loot.saved) + 1 |
| 1125 local save = { | 1216 local save = { |
| 1126 name = name, | 1217 name = name, |
| 1127 date = makedate(), | 1218 date = makedate(), |
| 1128 count = #g_loot, | 1219 count = #g_loot, |
| 1129 forum = g_loot.forum, | |
| 1130 attend = g_loot.attend, | |
| 1131 } | 1220 } |
| 1221 for text in self:registered_textgen_iter() do | |
| 1222 save[text] = g_loot[text] | |
| 1223 end | |
| 1132 self:Print("Saving current loot texts to #%d '%s'", n, name) | 1224 self:Print("Saving current loot texts to #%d '%s'", n, name) |
| 1133 g_loot.saved[n] = save | 1225 g_loot.saved[n] = save |
| 1134 return self:save_list() | 1226 return self:save_list() |
| 1135 end | 1227 end |
| 1136 | 1228 |
| 1142 local save = s[num] | 1234 local save = s[num] |
| 1143 self:Print("Overwriting current loot data with saved text #%d '%s'", num, save.name) | 1235 self:Print("Overwriting current loot data with saved text #%d '%s'", num, save.name) |
| 1144 self:Clear(--[[verbose_p=]]false) | 1236 self:Clear(--[[verbose_p=]]false) |
| 1145 -- Clear will already have displayed the window, and re-selected the first | 1237 -- Clear will already have displayed the window, and re-selected the first |
| 1146 -- tab. Set these up for when the text tabs are clicked. | 1238 -- tab. Set these up for when the text tabs are clicked. |
| 1147 g_loot.forum = save.forum | 1239 for text in self:registered_textgen_iter() do |
| 1148 g_loot.attend = save.attend | 1240 g_loot[text] = save[text] |
| 1241 end | |
| 1149 end | 1242 end |
| 1150 | 1243 |
| 1151 function addon:save_delete(num) | 1244 function addon:save_delete(num) |
| 1152 local s = self:check_saved_table(); if not s then return end; | 1245 local s = self:check_saved_table(); if not s then return end; |
| 1153 if (not num) or (num > #s) then | 1246 if (not num) or (num > #s) then |
