Mercurial > wow > ouroloot
diff core.lua @ 2:fe437e761ef8
More safety checks for itemfilter validity. Factor out DBM callbacks into semi-generalized boss mod registration (todo: selection gui).
author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
---|---|
date | Fri, 22 Apr 2011 01:34:47 +0000 |
parents | 822b6ca3ef89 |
children | 05caaf17b3ca |
line wrap: on
line diff
--- a/core.lua Sat Apr 16 06:03:29 2011 +0000 +++ b/core.lua Fri Apr 22 01:34:47 2011 +0000 @@ -52,6 +52,7 @@ ['no_tracking_wipes'] = false, ['snarky_boss'] = true, ['keybinding'] = false, + ['bossmod'] = "DBM", ['keybinding_text'] = 'CTRL-SHIFT-O', ['forum'] = { ['[url]'] = '[url=http://www.wowhead.com/?item=$I]$N[/url]$X - $T', @@ -128,7 +129,9 @@ -- Can change 'loot' to 'item' to trigger on, e.g., extracting stuff from mail. loot_pattern = "(%S+) receives? loot:.*|cff%x+|H(.-)|h.*|r(.*)%.$" - dbm_registered = nil + bossmod_registered = nil + bossmods = {} + requesting = nil -- for prompting for additional rebroadcasters thresholds, quality_hexes = {}, {} @@ -159,7 +162,7 @@ local pprint, tabledump = addon.pprint, flib.tabledump -- En masse forward decls of symbols defined inside local blocks -local _registerDBM -- break out into separate file +local _register_bossmod local makedate, create_new_cache, _init -- Hypertext support, inspired by DBM broadcast pizza timers @@ -378,8 +381,7 @@ if SetBindingClick(opts.keybinding_text, "OuroLootBindingOpen") then SaveBindings(GetCurrentBindingSet()) else - self:Print("Error registering '%s' as a keybinding, check spelling!", - opts.keybinding_text) + self:Print("Error registering '%s' as a keybinding, check spelling!", opts.keybinding_text) end end @@ -424,7 +426,7 @@ if event == "Activate" then -- dispatched manually from Activate self:RegisterEvent "CHAT_MSG_LOOT" - _registerDBM(self) + _register_bossmod(self) elseif event == "RAID_ROSTER_UPDATE" then -- event registration from onload, joined a raid, maybe show popup if opts.popup_on_join and not self.popped then @@ -638,7 +640,7 @@ self:RAID_ROSTER_UPDATE("Activate") elseif self.debug.notraid then self:RegisterEvent "CHAT_MSG_LOOT" - _registerDBM(self) + _register_bossmod(self) elseif g_restore_p then g_restore_p = nil if #g_loot == 0 then return end -- only saved texts, not worth verbage @@ -946,57 +948,50 @@ self.loot_clean = first or index-1 end - local GetRaidRosterInfo = GetRaidRosterInfo - function addon:DBMBossCallback (reason, mod, ...) - if (not self.rebroadcast) and (not self.enabled) then return end + function addon:register_boss_mod (name, registration_func, deregistration_func) + assert(type(name)=='string') + assert(type(registration_func)=='function') + if deregistration_func ~= nil then assert(type(deregistration_func)=='function') end + self.bossmods[#self.bossmods+1] = { + n = name, + r = registration_func, + d = deregistration_func, + } + end - local name - if mod.combatInfo and mod.combatInfo.name then - name = mod.combatInfo.name - elseif mod.id then - name = mod.id - else - name = "Unknown Boss" + function _register_bossmod (self, force_p) + local x = self.bossmod_registered and self.bossmods[self.bossmod_registered] + if x then + if x.n == opts.bossmod and not force_p then + -- trying to register with already-registered boss mod + return + else + -- deregister + if x.d then x.d(self) end + end end - local it = location or instance_tag() - location = nil - - local duration = 0 - if mod.combatInfo and mod.combatInfo.pull then - duration = math.floor (GetTime() - mod.combatInfo.pull) + x = nil + for k,v in ipairs(self.bossmods) do + if v.n == opts.bossmod then + x = k + break + end end - -- attendance: maybe put people in groups 6,7,8 into a "backup/standby" - -- list? probably too specific to guild practices. - local raiders = {} - for i = 1, GetNumRaidMembers() do - tinsert(raiders, (GetRaidRosterInfo(i))) + if not x then + self.status_text = "|cffff1010No boss-mod found!|r" + self:Print(self.status_text) + return end - table.sort(raiders) - return _do_boss (self, reason, name, it, duration, raiders) - end - - local callback = function(...) addon:DBMBossCallback(...) end - function _registerDBM(self) - if DBM then - if not self.dbm_registered then - local rev = tonumber(DBM.Revision) or 0 - if rev < 1503 then - self.status_text = "|cffff1010Deadly Boss Mods must be version 1.26 or newer to work with Ouro Loot.|r" - return - end - local r = DBM:RegisterCallback("kill", callback) - DBM:RegisterCallback("wipe", callback) - DBM:RegisterCallback("pull", function() location = instance_tag() end) - self.dbm_registered = r > 0 - end + if self.bossmods[x].r (self, _do_boss) then + self.bossmod_registered = x else - self.status_text = "|cffff1010Ouro Loot cannot find Deadly Boss Mods, loot will not be grouped by boss.|r" + self:Print("|cffff1010Boss mod registration failed|r") end end -end -- DBM tie-ins +end -- Adding entries to the loot record, and tracking the corresponding timestamp. do