Mercurial > wow > ouroloot
comparison 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 |
comparison
equal
deleted
inserted
replaced
1:822b6ca3ef89 | 2:fe437e761ef8 |
---|---|
50 ['scroll_to_bottom'] = true, | 50 ['scroll_to_bottom'] = true, |
51 ['chatty_on_kill'] = false, | 51 ['chatty_on_kill'] = false, |
52 ['no_tracking_wipes'] = false, | 52 ['no_tracking_wipes'] = false, |
53 ['snarky_boss'] = true, | 53 ['snarky_boss'] = true, |
54 ['keybinding'] = false, | 54 ['keybinding'] = false, |
55 ['bossmod'] = "DBM", | |
55 ['keybinding_text'] = 'CTRL-SHIFT-O', | 56 ['keybinding_text'] = 'CTRL-SHIFT-O', |
56 ['forum'] = { | 57 ['forum'] = { |
57 ['[url]'] = '[url=http://www.wowhead.com/?item=$I]$N[/url]$X - $T', | 58 ['[url]'] = '[url=http://www.wowhead.com/?item=$I]$N[/url]$X - $T', |
58 ['[item] by name'] = '[item]$N[/item]$X - $T', | 59 ['[item] by name'] = '[item]$N[/item]$X - $T', |
59 ['[item] by ID'] = '[item]$I[/item]$X - $T', | 60 ['[item] by ID'] = '[item]$I[/item]$X - $T', |
126 -- This is an amalgamation of all four LOOT_ITEM_* patterns. | 127 -- This is an amalgamation of all four LOOT_ITEM_* patterns. |
127 -- Captures: 1 person/You, 2 itemstring, 3 rest of string after final |r until '.' | 128 -- Captures: 1 person/You, 2 itemstring, 3 rest of string after final |r until '.' |
128 -- Can change 'loot' to 'item' to trigger on, e.g., extracting stuff from mail. | 129 -- Can change 'loot' to 'item' to trigger on, e.g., extracting stuff from mail. |
129 loot_pattern = "(%S+) receives? loot:.*|cff%x+|H(.-)|h.*|r(.*)%.$" | 130 loot_pattern = "(%S+) receives? loot:.*|cff%x+|H(.-)|h.*|r(.*)%.$" |
130 | 131 |
131 dbm_registered = nil | 132 bossmod_registered = nil |
133 bossmods = {} | |
134 | |
132 requesting = nil -- for prompting for additional rebroadcasters | 135 requesting = nil -- for prompting for additional rebroadcasters |
133 | 136 |
134 thresholds, quality_hexes = {}, {} | 137 thresholds, quality_hexes = {}, {} |
135 for i = 0,6 do | 138 for i = 0,6 do |
136 local hex = _G.select(4,_G.GetItemQualityColor(i)) | 139 local hex = _G.select(4,_G.GetItemQualityColor(i)) |
157 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 |
158 | 161 |
159 local pprint, tabledump = addon.pprint, flib.tabledump | 162 local pprint, tabledump = addon.pprint, flib.tabledump |
160 | 163 |
161 -- En masse forward decls of symbols defined inside local blocks | 164 -- En masse forward decls of symbols defined inside local blocks |
162 local _registerDBM -- break out into separate file | 165 local _register_bossmod |
163 local makedate, create_new_cache, _init | 166 local makedate, create_new_cache, _init |
164 | 167 |
165 -- Hypertext support, inspired by DBM broadcast pizza timers | 168 -- Hypertext support, inspired by DBM broadcast pizza timers |
166 do | 169 do |
167 local hypertext_format_str = "|HOuroRaid:%s|h%s[%s]|r|h" | 170 local hypertext_format_str = "|HOuroRaid:%s|h%s[%s]|r|h" |
376 btn:SetAttribute("type", "macro") | 379 btn:SetAttribute("type", "macro") |
377 btn:SetAttribute("macrotext", "/ouroloot toggle") | 380 btn:SetAttribute("macrotext", "/ouroloot toggle") |
378 if SetBindingClick(opts.keybinding_text, "OuroLootBindingOpen") then | 381 if SetBindingClick(opts.keybinding_text, "OuroLootBindingOpen") then |
379 SaveBindings(GetCurrentBindingSet()) | 382 SaveBindings(GetCurrentBindingSet()) |
380 else | 383 else |
381 self:Print("Error registering '%s' as a keybinding, check spelling!", | 384 self:Print("Error registering '%s' as a keybinding, check spelling!", opts.keybinding_text) |
382 opts.keybinding_text) | |
383 end | 385 end |
384 end | 386 end |
385 | 387 |
386 if self.debug.flow then self:Print"is in control-flow debug mode." end | 388 if self.debug.flow then self:Print"is in control-flow debug mode." end |
387 end | 389 end |
422 return self.dprint('flow', "got RRU event but in pvp zone, bailing") | 424 return self.dprint('flow', "got RRU event but in pvp zone, bailing") |
423 end | 425 end |
424 if event == "Activate" then | 426 if event == "Activate" then |
425 -- dispatched manually from Activate | 427 -- dispatched manually from Activate |
426 self:RegisterEvent "CHAT_MSG_LOOT" | 428 self:RegisterEvent "CHAT_MSG_LOOT" |
427 _registerDBM(self) | 429 _register_bossmod(self) |
428 elseif event == "RAID_ROSTER_UPDATE" then | 430 elseif event == "RAID_ROSTER_UPDATE" then |
429 -- event registration from onload, joined a raid, maybe show popup | 431 -- event registration from onload, joined a raid, maybe show popup |
430 if opts.popup_on_join and not self.popped then | 432 if opts.popup_on_join and not self.popped then |
431 self.popped = StaticPopup_Show "OUROL_REMIND" | 433 self.popped = StaticPopup_Show "OUROL_REMIND" |
432 self.popped.data = self | 434 self.popped.data = self |
636 self.popped = true | 638 self.popped = true |
637 if GetNumRaidMembers() > 0 then | 639 if GetNumRaidMembers() > 0 then |
638 self:RAID_ROSTER_UPDATE("Activate") | 640 self:RAID_ROSTER_UPDATE("Activate") |
639 elseif self.debug.notraid then | 641 elseif self.debug.notraid then |
640 self:RegisterEvent "CHAT_MSG_LOOT" | 642 self:RegisterEvent "CHAT_MSG_LOOT" |
641 _registerDBM(self) | 643 _register_bossmod(self) |
642 elseif g_restore_p then | 644 elseif g_restore_p then |
643 g_restore_p = nil | 645 g_restore_p = nil |
644 if #g_loot == 0 then return end -- only saved texts, not worth verbage | 646 if #g_loot == 0 then return end -- only saved texts, not worth verbage |
645 self:Print("Ouro Raid Loot restored previous data, but not in a raid", | 647 self:Print("Ouro Raid Loot restored previous data, but not in a raid", |
646 "and 5-person mode not active. |cffff0505NOT tracking loot|r;", | 648 "and 5-person mode not active. |cffff0505NOT tracking loot|r;", |
944 e.reason = 'kill' | 946 e.reason = 'kill' |
945 e.attempts = attempts | 947 e.attempts = attempts |
946 self.loot_clean = first or index-1 | 948 self.loot_clean = first or index-1 |
947 end | 949 end |
948 | 950 |
949 local GetRaidRosterInfo = GetRaidRosterInfo | 951 function addon:register_boss_mod (name, registration_func, deregistration_func) |
950 function addon:DBMBossCallback (reason, mod, ...) | 952 assert(type(name)=='string') |
951 if (not self.rebroadcast) and (not self.enabled) then return end | 953 assert(type(registration_func)=='function') |
952 | 954 if deregistration_func ~= nil then assert(type(deregistration_func)=='function') end |
953 local name | 955 self.bossmods[#self.bossmods+1] = { |
954 if mod.combatInfo and mod.combatInfo.name then | 956 n = name, |
955 name = mod.combatInfo.name | 957 r = registration_func, |
956 elseif mod.id then | 958 d = deregistration_func, |
957 name = mod.id | 959 } |
960 end | |
961 | |
962 function _register_bossmod (self, force_p) | |
963 local x = self.bossmod_registered and self.bossmods[self.bossmod_registered] | |
964 if x then | |
965 if x.n == opts.bossmod and not force_p then | |
966 -- trying to register with already-registered boss mod | |
967 return | |
968 else | |
969 -- deregister | |
970 if x.d then x.d(self) end | |
971 end | |
972 end | |
973 | |
974 x = nil | |
975 for k,v in ipairs(self.bossmods) do | |
976 if v.n == opts.bossmod then | |
977 x = k | |
978 break | |
979 end | |
980 end | |
981 | |
982 if not x then | |
983 self.status_text = "|cffff1010No boss-mod found!|r" | |
984 self:Print(self.status_text) | |
985 return | |
986 end | |
987 | |
988 if self.bossmods[x].r (self, _do_boss) then | |
989 self.bossmod_registered = x | |
958 else | 990 else |
959 name = "Unknown Boss" | 991 self:Print("|cffff1010Boss mod registration failed|r") |
960 end | 992 end |
961 | 993 end |
962 local it = location or instance_tag() | 994 end |
963 location = nil | |
964 | |
965 local duration = 0 | |
966 if mod.combatInfo and mod.combatInfo.pull then | |
967 duration = math.floor (GetTime() - mod.combatInfo.pull) | |
968 end | |
969 | |
970 -- attendance: maybe put people in groups 6,7,8 into a "backup/standby" | |
971 -- list? probably too specific to guild practices. | |
972 local raiders = {} | |
973 for i = 1, GetNumRaidMembers() do | |
974 tinsert(raiders, (GetRaidRosterInfo(i))) | |
975 end | |
976 table.sort(raiders) | |
977 | |
978 return _do_boss (self, reason, name, it, duration, raiders) | |
979 end | |
980 | |
981 local callback = function(...) addon:DBMBossCallback(...) end | |
982 function _registerDBM(self) | |
983 if DBM then | |
984 if not self.dbm_registered then | |
985 local rev = tonumber(DBM.Revision) or 0 | |
986 if rev < 1503 then | |
987 self.status_text = "|cffff1010Deadly Boss Mods must be version 1.26 or newer to work with Ouro Loot.|r" | |
988 return | |
989 end | |
990 local r = DBM:RegisterCallback("kill", callback) | |
991 DBM:RegisterCallback("wipe", callback) | |
992 DBM:RegisterCallback("pull", function() location = instance_tag() end) | |
993 self.dbm_registered = r > 0 | |
994 end | |
995 else | |
996 self.status_text = "|cffff1010Ouro Loot cannot find Deadly Boss Mods, loot will not be grouped by boss.|r" | |
997 end | |
998 end | |
999 end -- DBM tie-ins | |
1000 | 995 |
1001 -- Adding entries to the loot record, and tracking the corresponding timestamp. | 996 -- Adding entries to the loot record, and tracking the corresponding timestamp. |
1002 do | 997 do |
1003 -- This shouldn't be required. /sadface | 998 -- This shouldn't be required. /sadface |
1004 local loot_entry_mt = { | 999 local loot_entry_mt = { |