comparison 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
comparison
equal deleted inserted replaced
19:f560cf82e7d3 20:d89aeb6b9f9e
80 ['artifact'] = 6, 80 ['artifact'] = 6,
81 --['heirloom'] = 7, 81 --['heirloom'] = 7,
82 } 82 }
83 local my_name = UnitName('player') 83 local my_name = UnitName('player')
84 local comm_cleanup_ttl = 5 -- seconds in the cache 84 local comm_cleanup_ttl = 5 -- seconds in the cache
85 local g_LOOT_ITEM_ss, g_LOOT_ITEM_MULTIPLE_sss, g_LOOT_ITEM_SELF_s, g_LOOT_ITEM_SELF_MULTIPLE_ss
85 86
86 87
87 ------ Addon member data 88 ------ Addon member data
88 local flib = LibStub("LibFarmbuyer") 89 local flib = LibStub("LibFarmbuyer")
89 addon.author_debug = flib.author_debug 90 addon.author_debug = flib.author_debug
139 popped = nil -- non-nil when reminder has been shown, actual value unimportant 140 popped = nil -- non-nil when reminder has been shown, actual value unimportant
140 141
141 -- This is an amalgamation of all four LOOT_ITEM_* patterns. 142 -- This is an amalgamation of all four LOOT_ITEM_* patterns.
142 -- Captures: 1 person/You, 2 itemstring, 3 rest of string after final |r until '.' 143 -- Captures: 1 person/You, 2 itemstring, 3 rest of string after final |r until '.'
143 -- Can change 'loot' to 'item' to trigger on, e.g., extracting stuff from mail. 144 -- Can change 'loot' to 'item' to trigger on, e.g., extracting stuff from mail.
144 loot_pattern = "(%S+) receives? loot:.*|cff%x+|H(.-)|h.*|r(.*)%.$" 145 --loot_pattern = "(%S+) receives? loot:.*|cff%x+|H(.-)|h.*|r(.*)%.$"
145 146
146 bossmod_registered = nil 147 bossmod_registered = nil
147 bossmods = {} 148 bossmods = {}
148 149
149 requesting = nil -- for prompting for additional rebroadcasters 150 requesting = nil -- for prompting for additional rebroadcasters
411 end 412 end
412 else 413 else
413 self:Print("Error registering '%s' as a keybinding, check spelling!", opts.keybinding_text) 414 self:Print("Error registering '%s' as a keybinding, check spelling!", opts.keybinding_text)
414 end 415 end
415 end 416 end
417
418 --[[
419 The four loot format patterns of interest, changed into relatively tight
420 string match patterns. Done at enable-time rather than load-time against
421 the slim chance that one of the non-US "delocalizers" needs to mess with
422 the global patterns before we transform them.
423
424 The SELF variants can be replaced with LOOT_ITEM_PUSHED_SELF[_MULTIPLE] to
425 trigger on 'receive item' instead, which would detect extracting stuff
426 from mail, or s/PUSHED/CREATED/ for things like healthstones and guild
427 cauldron flasks.
428 ]]
429
430 -- LOOT_ITEM = "%s receives loot: %s." --> (.+) receives loot: (.+)%.
431 g_LOOT_ITEM_ss = _G.LOOT_ITEM:gsub('%.$','%%.'):gsub('%%s','(.+)')
432
433 -- LOOT_ITEM_MULTIPLE = "%s receives loot: %sx%d." --> (.+) receives loot: (.+)(x%d+)%.
434 g_LOOT_ITEM_MULTIPLE_sss = _G.LOOT_ITEM_MULTIPLE:gsub('%.$','%%.'):gsub('%%s','(.+)'):gsub('x%%d','(x%%d+)')
435
436 -- LOOT_ITEM_SELF = "You receive loot: %s." --> You receive loot: (.+)%.
437 g_LOOT_ITEM_SELF_s = _G.LOOT_ITEM_SELF:gsub('%.$','%%.'):gsub('%%s','(.+)')
438
439 -- LOOT_ITEM_SELF_MULTIPLE = "You receive loot: %sx%d." --> You receive loot: (.+)(x%d+)%.
440 g_LOOT_ITEM_SELF_MULTIPLE_ss = _G.LOOT_ITEM_SELF_MULTIPLE:gsub('%.$','%%.'):gsub('%%s','(.+)'):gsub('x%%d','(x%%d+)')
416 441
417 if self.debug.flow then self:Print"is in control-flow debug mode." end 442 if self.debug.flow then self:Print"is in control-flow debug mode." end
418 end 443 end
419 --function addon:OnDisable() end 444 --function addon:OnDisable() end
420 445
665 itexture: inventory icon texture 690 itexture: inventory icon texture
666 ]] 691 ]]
667 692
668 if event == "CHAT_MSG_LOOT" then 693 if event == "CHAT_MSG_LOOT" then
669 local msg = ... 694 local msg = ...
670 --ChatFrame2:AddMessage("original string: >"..(msg:gsub("\124","\124\124")).."<") 695 local person, itemstring, count
671 local person, itemstring, remainder = msg:match(self.loot_pattern) 696 ChatFrame2:AddMessage("original string: >"..(msg:gsub("\124","\124\124")).."<")
672 self.dprint('loot', "CHAT_MSG_LOOT, person is", person, ", itemstring is", itemstring, ", rest is", remainder) 697 --local person, itemstring, remainder = msg:match(self.loot_pattern)
673 if not person then return end -- "So-and-So selected Greed", etc, not actual looting 698
674 local count = remainder and remainder:match(".*(x%d+)$") 699 -- test in most likely order: other people get more loot than "you" do
700 person, itemstring, count = msg:match(g_LOOT_ITEM_MULTIPLE_sss)
701 if not person then
702 person, itemstring = msg:match(g_LOOT_ITEM_ss)
703 end
704 if not person then
705 itemstring, count = msg:match(g_LOOT_ITEM_SELF_MULTIPLE_ss)
706 if not itemstring then
707 itemstring = msg:match(g_LOOT_ITEM_SELF_s)
708 end
709 end
710
711 --self.dprint('loot', "CHAT_MSG_LOOT, person is", person, ", itemstring is", itemstring, ", rest is", remainder)
712 self.dprint('loot', "CHAT_MSG_LOOT, person is", person, ", itemstring is", itemstring, ", count is", count)
713 if not itemstring then return end -- "So-and-So selected Greed", etc, not actual looting
714 --local count = remainder and remainder:match(".*(x%d+)$")
675 715
676 -- Name might be colorized, remove the highlighting 716 -- Name might be colorized, remove the highlighting
677 local p = person:match("|c%x%x%x%x%x%x%x%x(%S+)") 717 if person then
678 person = p or person 718 person = person:match("|c%x%x%x%x%x%x%x%x(%S+)") or person
679 person = (person == UNIT_YOU) and my_name or person 719 else
680 720 -- UNIT_YOU / You
681 local id = tonumber((select(2, strsplit(":", itemstring)))) 721 person = my_name
722 end
723
724 --local id = tonumber((select(2, strsplit(":", itemstring))))
725 local id = tonumber(itemstring:match('|Hitem:(%d+):'))
682 726
683 return self:_do_loot (false, person, id, count) 727 return self:_do_loot (false, person, id, count)
684 728
685 elseif event == "broadcast" then 729 elseif event == "broadcast" then
686 return self:_do_loot(false, ...) 730 return self:_do_loot(false, ...)