public
Description: WoW addon - Track down those needy and greedy party members
Homepage: http://www.tekkub.net
Clone URL: git://github.com/tekkub/greedbeacon.git
Click here to lend your support to: greedbeacon and make a donation at www.pledgie.com !
tekkub (author)
Sun Jun 01 17:21:49 -0700 2008
commit  bf53bb566a91516816d5a818af0f94eb9beba963
tree    b70bd0e454766fe80581e391fef156c9c6a0b747
parent  974a26a41729b30f0d734342b64b5c72285913d4
greedbeacon / GreedBeacon.lua
100644 128 lines (109 sloc) 4.843 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
local L = setmetatable(GetLocale() == "deDE" and {
  ["(.*) won: (.+)"] = "(.*) gewinnt: (.+)",
  ["%s|Hgreedbeacon:%d|h[%s roll]|h|r %s won %s "] = "%s|Hgreedbeacon:%d|h[%s roll]|h|r %s gewinnt: %s",
  ["(.*) has?v?e? selected (.+) for: (.+)"] = "(.+) hab?t f\195\188r (.+) '(.+)' ausgew\195\164hlt",
  ["(.+) Roll . (%d+) for (.+) by (.+)"] = "Wurf f\195\188r (.*): (%d+) f\195\188r (.*) von (.*)",
  [" passed on: "] = " w\195\188rfelt nicht f\195\188r: ",
  [" automatically passed on: "] = " passt automatisch bei ",
  ["You passed on: "] = "Ihr habt gepasst bei: ",
  ["Everyone passed on: "] = "Alle haben gepasst bei: ",
  ["Greed"] = GREED,
  ["Need"] = NEED,
} or {}, {__index = function(t,i) return i end})
 
local colorneed, colorgreed = "|cffff0000", "|cffffff00"
local coloredwords = {[L.Greed] = colorgreed..L.Greed, [L.Need] = colorneed..L.Need}
local rolls = {}
 
local function Print(...) ChatFrame1:AddMessage(string.join(" ", "|cFF33FF99GreedBeacon|r:", ...)) end
 
local debugf = tekDebug and tekDebug:GetFrame("GreedBeacon")
local function Debug(...) if debugf then debugf:AddMessage(string.join(", ", ...)) end end
 
 
local chatframes = {[ChatFrame1] = false, [ChatFrame2] = false, [ChatFrame3] = false, [ChatFrame4] = false, [ChatFrame5] = false, [ChatFrame6] = false, [ChatFrame7] = false}
for frame in pairs(chatframes) do
  for i,v in pairs(frame.messageTypeList) do
    if v == "LOOT" then
      chatframes[frame] = true
      Debug("Initializing", frame:GetName())
    end
  end
end
 
local origadd, origrem = ChatFrame_AddMessageGroup, ChatFrame_RemoveMessageGroup
ChatFrame_AddMessageGroup = function(frame, channel, ...)
  if channel == "LOOT" then
    chatframes[frame] = true
    Debug("ChatFrame_AddMessageGroup", frame:GetName())
  end
  return origadd(frame, channel, ...)
end
ChatFrame_RemoveMessageGroup = function(frame, channel, ...)
  if channel == "LOOT" then
    chatframes[frame] = false
    Debug("ChatFrame_RemoveMessageGroup", frame:GetName())
  end
  return origrem(frame, channel, ...)
end
 
 
local function FindRoll(link, player, hasselected)
  for i,roll in ipairs(rolls) do
    if roll._link == link and not roll._winner and (not roll[player] or hasselected) then return roll end
  end
  Debug("New roll started", link)
  local newroll = {_link = link}
  table.insert(rolls, newroll)
  return newroll
end
 
 
local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_LOOT")
f:SetScript("OnEvent", function(self, event, msg)
  local rolltype, rollval, link, player = msg:match(L["(.+) Roll . (%d+) for (.+) by (.+)"])
  if player then
    local roll = FindRoll(link, player, true)
    Debug("Roll detected", player, rolltype, rollval, link)
    roll[player] = (rolltype == "Need" and colorneed or colorgreed)..rollval
    roll._type = rolltype
    return
  end
 
  local player, selection, link = msg:match(L["(.*) has?v?e? selected (.+) for: (.+)"])
  if player and player ~= "" then
    player = player == YOU and UnitName("player") or player
    Debug("Selection detected", player, selection, link)
    FindRoll(link, player)[player] = coloredwords[selection]
    return
  end
 
  local player, link = msg:match(L["(.*) won: (.+)"])
  if player then
    player = player == YOU and UnitName("player") or player
    for i,roll in ipairs(rolls) do
      if roll._link == link and roll[player] and not roll._printed then
        roll._printed = true
        roll._winner = player
        Debug("Roll completed", roll._type or "nil", i, player, link)
        local msg = string.format(L["%s|Hgreedbeacon:%d|h[%s roll]|h|r %s won %s "], roll._type == L.Need and colorneed or colorgreed, i, roll._type or "???", player, link)
        for frame,val in pairs(chatframes) do if val then frame:AddMessage(msg) end end
        return
      end
    end
    Print("No match found for", msg)
    return
  end
end)
 
 
local function filter(msg)
  if msg:match(L["(.*) won: (.+)"]) or msg:match(L["(.*) has?v?e? selected (.+) for: (.+)"]) or msg:match(L["(.+) Roll . (%d+) for (.+) by (.+)"])
    or msg:match(L["You passed on: "]) or msg:match(L[" automatically passed on: "]) or (msg:match(L[" passed on: "]) and not msg:match(L["Everyone passed on: "])) then
    Debug("Supressing chat message", msg)
    return true
  end
end
ChatFrame_AddMessageEventFilter("CHAT_MSG_LOOT", filter)
 
 
local orig2 = SetItemRef
function SetItemRef(link, text, button)
  local id = link:match("greedbeacon:(%d+)")
  if id then
    ShowUIPanel(ItemRefTooltip)
    if not ItemRefTooltip:IsShown() then ItemRefTooltip:SetOwner(UIParent, "ANCHOR_PRESERVE") end
 
    local i = tonumber(id)
    local val = rolls[i]
    ItemRefTooltip:ClearLines()
    ItemRefTooltip:AddLine(coloredwords[val._type].." roll|r - "..val._link)
    ItemRefTooltip:AddDoubleLine("Winner:", "|cffffffff"..val._winner)
    for i,v in pairs(val) do if string.sub(i, 1, 1) ~= "_" then ItemRefTooltip:AddDoubleLine(i, v) end end
    ItemRefTooltip:Show()
  else return orig2(link, text, button) end
end