Mercurial > wow > ouroloot
diff core.lua @ 20:d89aeb6b9f9e
Put in slower but portable loot pattern matching, finally.
author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
---|---|
date | Thu, 01 Sep 2011 02:03:14 +0000 |
parents | f560cf82e7d3 |
children | 41e735c1b91f |
line wrap: on
line diff
--- a/core.lua Mon Aug 29 01:29:13 2011 +0000 +++ b/core.lua Thu Sep 01 02:03:14 2011 +0000 @@ -82,6 +82,7 @@ } local my_name = UnitName('player') local comm_cleanup_ttl = 5 -- seconds in the cache +local g_LOOT_ITEM_ss, g_LOOT_ITEM_MULTIPLE_sss, g_LOOT_ITEM_SELF_s, g_LOOT_ITEM_SELF_MULTIPLE_ss ------ Addon member data @@ -141,7 +142,7 @@ -- This is an amalgamation of all four LOOT_ITEM_* patterns. -- Captures: 1 person/You, 2 itemstring, 3 rest of string after final |r until '.' -- Can change 'loot' to 'item' to trigger on, e.g., extracting stuff from mail. - loot_pattern = "(%S+) receives? loot:.*|cff%x+|H(.-)|h.*|r(.*)%.$" + --loot_pattern = "(%S+) receives? loot:.*|cff%x+|H(.-)|h.*|r(.*)%.$" bossmod_registered = nil bossmods = {} @@ -414,6 +415,30 @@ end end + --[[ + The four loot format patterns of interest, changed into relatively tight + string match patterns. Done at enable-time rather than load-time against + the slim chance that one of the non-US "delocalizers" needs to mess with + the global patterns before we transform them. + + The SELF variants can be replaced with LOOT_ITEM_PUSHED_SELF[_MULTIPLE] to + trigger on 'receive item' instead, which would detect extracting stuff + from mail, or s/PUSHED/CREATED/ for things like healthstones and guild + cauldron flasks. + ]] + + -- LOOT_ITEM = "%s receives loot: %s." --> (.+) receives loot: (.+)%. + g_LOOT_ITEM_ss = _G.LOOT_ITEM:gsub('%.$','%%.'):gsub('%%s','(.+)') + + -- LOOT_ITEM_MULTIPLE = "%s receives loot: %sx%d." --> (.+) receives loot: (.+)(x%d+)%. + g_LOOT_ITEM_MULTIPLE_sss = _G.LOOT_ITEM_MULTIPLE:gsub('%.$','%%.'):gsub('%%s','(.+)'):gsub('x%%d','(x%%d+)') + + -- LOOT_ITEM_SELF = "You receive loot: %s." --> You receive loot: (.+)%. + g_LOOT_ITEM_SELF_s = _G.LOOT_ITEM_SELF:gsub('%.$','%%.'):gsub('%%s','(.+)') + + -- LOOT_ITEM_SELF_MULTIPLE = "You receive loot: %sx%d." --> You receive loot: (.+)(x%d+)%. + g_LOOT_ITEM_SELF_MULTIPLE_ss = _G.LOOT_ITEM_SELF_MULTIPLE:gsub('%.$','%%.'):gsub('%%s','(.+)'):gsub('x%%d','(x%%d+)') + if self.debug.flow then self:Print"is in control-flow debug mode." end end --function addon:OnDisable() end @@ -667,18 +692,37 @@ if event == "CHAT_MSG_LOOT" then local msg = ... - --ChatFrame2:AddMessage("original string: >"..(msg:gsub("\124","\124\124")).."<") - local person, itemstring, remainder = msg:match(self.loot_pattern) - self.dprint('loot', "CHAT_MSG_LOOT, person is", person, ", itemstring is", itemstring, ", rest is", remainder) - if not person then return end -- "So-and-So selected Greed", etc, not actual looting - local count = remainder and remainder:match(".*(x%d+)$") + local person, itemstring, count + ChatFrame2:AddMessage("original string: >"..(msg:gsub("\124","\124\124")).."<") + --local person, itemstring, remainder = msg:match(self.loot_pattern) + + -- test in most likely order: other people get more loot than "you" do + person, itemstring, count = msg:match(g_LOOT_ITEM_MULTIPLE_sss) + if not person then + person, itemstring = msg:match(g_LOOT_ITEM_ss) + end + if not person then + itemstring, count = msg:match(g_LOOT_ITEM_SELF_MULTIPLE_ss) + if not itemstring then + itemstring = msg:match(g_LOOT_ITEM_SELF_s) + end + end + + --self.dprint('loot', "CHAT_MSG_LOOT, person is", person, ", itemstring is", itemstring, ", rest is", remainder) + self.dprint('loot', "CHAT_MSG_LOOT, person is", person, ", itemstring is", itemstring, ", count is", count) + if not itemstring then return end -- "So-and-So selected Greed", etc, not actual looting + --local count = remainder and remainder:match(".*(x%d+)$") -- Name might be colorized, remove the highlighting - local p = person:match("|c%x%x%x%x%x%x%x%x(%S+)") - person = p or person - person = (person == UNIT_YOU) and my_name or person + if person then + person = person:match("|c%x%x%x%x%x%x%x%x(%S+)") or person + else + -- UNIT_YOU / You + person = my_name + end - local id = tonumber((select(2, strsplit(":", itemstring)))) + --local id = tonumber((select(2, strsplit(":", itemstring)))) + local id = tonumber(itemstring:match('|Hitem:(%d+):')) return self:_do_loot (false, person, id, count)