-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
369 lines (301 loc) · 10.5 KB
/
main.lua
File metadata and controls
369 lines (301 loc) · 10.5 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
local f = CreateFrame("Frame")
local function createDumpBox()
local CopyFrame = CreateFrame("Frame", "CopyFrame", UIParent)
CopyFrame:SetMovable(true)
CopyFrame:SetSize(700, 450)
CopyFrame:SetPoint("CENTER")
CopyFrame:SetBackdrop({bgFile = "Interface/DialogFrame/UI-DialogBox-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 5, right = 5, top = 5, bottom = 5 },
backdropColor = { r=0, g=0, b=0, a=1 }})
local CopyFrameButton = CreateFrame("Button", "CopyFrameButton", CopyFrame, "GameMenuButtonTemplate")
CopyFrameButton:SetText("Okay")
CopyFrameButton:SetPoint("BOTTOM", CopyFrame, "BOTTOM", 0, 10)
local CopyFrameScroll = CreateFrame("ScrollFrame", "CopyFrameScroll", CopyFrame, "UIPanelScrollFrameTemplate")
CopyFrameScroll:SetPoint("TOP", CopyFrame, "TOP", 5, -30)
CopyFrameScroll:SetPoint("BOTTOM", CopyFrameButton, "BOTTOM", 10, 30)
CopyFrameScroll:SetPoint("RIGHT", CopyFrame, "RIGHT", -40, 0)
local CopyFrameScrollText = CreateFrame("EditBox", "CopyFrameScrollText", CopyFrameScroll)
CopyFrameScrollText:SetMaxLetters(99999)
CopyFrameScrollText:SetMultiLine(true)
CopyFrameScrollText:SetAutoFocus(true)
CopyFrameScrollText:SetSize(630, 380)
CopyFrameScrollText:SetFontObject(ChatFontNormal)
CopyFrameScroll:SetScrollChild(CopyFrameScrollText)
CopyFrame.Button = CopyFrameButton
CopyFrame.Scroll = CopyFrameScroll
CopyFrame.ScrollText = CopyFrameScrollText
CopyFrameScrollText:SetScript("OnEscapePressed", function(self)
CopyFrame:Hide()
end)
CopyFrameButton:SetScript("OnClick", function(self)
CopyFrame:Hide()
end)
CopyFrame:Hide()
return CopyFrame
end
local function parseCSV(csvData)
for row in string.gmatch(csvData, "[^\n]+") do
local columnNr = 0
local loot = ""
local prios = {}
local isGroup = false
local group = ""
for column in string.gmatch(row, "[^,]+") do
if column:sub(1,1) == "\"" then
isGroup = true
end
if isGroup then
group = group .. "," .. column
if column:sub(#column, #column) == "\"" then
isGroup = false
column = group
end
end
if not isGroup then
columnNr = columnNr + 1
if columnNr == 1 then
loot = column
elseif columnNr > 3 and prios[#prios] ~= column then
table.insert(prios, column)
end
end
end
if loot ~= "Loot Name" and #prios > 0 then
DCSession[#DCSession]["reserves"][loot] = prios
end
end
print("Reserved import done!")
end
local function createImportBox()
local ImportFrame = CreateFrame("Frame", "ImportFrame", UIParent)
ImportFrame:SetMovable(true)
ImportFrame:SetSize(700, 450)
ImportFrame:SetPoint("CENTER")
ImportFrame:SetBackdrop({bgFile = "Interface/DialogFrame/UI-DialogBox-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 5, right = 5, top = 5, bottom = 5 },
backdropColor = { r=0, g=0, b=0, a=1 }})
local ImportFrameButton = CreateFrame("Button", "ImportFrameButton", ImportFrame, "GameMenuButtonTemplate")
ImportFrameButton:SetText("Okay")
ImportFrameButton:SetPoint("BOTTOM", ImportFrame, "BOTTOM", 0, 10)
local ImportFrameScroll = CreateFrame("ScrollFrame", "ImportFrameScroll", ImportFrame, "UIPanelScrollFrameTemplate")
ImportFrameScroll:SetPoint("TOP", ImportFrame, "TOP", 5, -30)
ImportFrameScroll:SetPoint("BOTTOM", ImportFrameButton, "BOTTOM", 10, 30)
ImportFrameScroll:SetPoint("RIGHT", ImportFrame, "RIGHT", -40, 0)
local ImportFrameScrollText = CreateFrame("EditBox", "ImportFrameScrollText", ImportFrameScroll)
ImportFrameScrollText:SetMaxLetters(99999)
ImportFrameScrollText:SetMultiLine(true)
ImportFrameScrollText:SetAutoFocus(true)
ImportFrameScrollText:SetSize(630, 380)
ImportFrameScrollText:SetFontObject(ChatFontNormal)
ImportFrameScroll:SetScrollChild(ImportFrameScrollText)
ImportFrame.Button = ImportFrameButton
ImportFrame.Scroll = ImportFrameScroll
ImportFrame.ScrollText = ImportFrameScrollText
ImportFrameScrollText:SetScript("OnEscapePressed", function(self)
ImportFrame:Hide()
end)
ImportFrameButton:SetScript("OnClick", function(self)
parseCSV(ImportFrameScrollText:GetText())
ImportFrame:Hide()
end)
ImportFrame:Hide()
return ImportFrame
end
local CopyFrame = createDumpBox()
local ImportFrame = createImportBox()
local activeSession = false
local trackRolls = false
local rolls = {}
local currentlyRolledLoot = ""
local function setup()
DCSession = _G["DCSession"] or {}
end
local function receivedLoot(playerName)
if not activeSession then
return 0
end
local lootReceived = 0;
for _,t in ipairs(DCSession[#DCSession]["looters"]) do
if playerName == t["player"] then
lootReceived = lootReceived + 1
end
end
return lootReceived
end
local function spairs(t, order)
-- collect the keys
local keys = {}
for k in pairs(t) do keys[#keys+1] = k end
-- if order function given, sort by it by passing the table and keys a, b,
-- otherwise just sort the keys
if order then
table.sort(keys, function(a,b) return order(t, a, b) end)
else
table.sort(keys)
end
-- return the iterator function
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
local function getPrios(lootName)
if DCSession[#DCSession]["reserves"][lootName] == nil then
return nil
end
local namesString = DCSession[#DCSession]["reserves"][lootName][1]
for i = 2, #DCSession[#DCSession]["reserves"][lootName] do
namesString = strjoin(" ", namesString, DCSession[#DCSession]["reserves"][lootName][i])
end
nameCount = #(DCSession[#DCSession]["reserves"][lootName])
prioInfo = {}
prioInfo["namesString"] = namesString
prioInfo["nameCount"] = nameCount
return prioInfo
end
local function DumpSession(index)
local dumpString = "Name;"..DCSession[index]["name"]..";"..(DCSession[index]["date"] or "").."\n"
dumpString = dumpString.."Looter;Loot\n"
for i = 1, #DCSession[index]["looters"] do
dumpString = dumpString..DCSession[index]["looters"][i]["player"]..";"..DCSession[index]["looters"][i]["loot"].."\n"
end
CopyFrame.ScrollText:SetText(dumpString)
CopyFrame.ScrollText:HighlightText()
CopyFrame:Show()
end
local function addLoot(player, loot)
table.insert(DCSession[#DCSession]["looters"], {["player"] = player, ["loot"] = loot})
print("Added "..loot.." to "..player)
end
StaticPopupDialogs["BIG_ADD_LOOT"] = {
text = "Is %s +1?",
button1 = "Yes",
button2 = "No",
OnAccept = function(_, player, item)
addLoot(player, item)
end,
timeout = 0,
whileDead = true,
preferredIndex = 3,
}
f:RegisterEvent("ADDON_LOADED")
f:RegisterEvent("CHAT_MSG_SYSTEM")
f:RegisterEvent("CHAT_MSG_LOOT")
f:SetScript("OnEvent", function (self, event, arg1, ...)
if event == "ADDON_LOADED" and arg1 == "DC-Roll" then
SLASH_BIG1 = '/big'
setup()
SlashCmdList.BIG = function (msg)
local msg_split = {}
for v in string.gmatch(msg, "[^ ]+") do
table.insert(msg_split, v)
end
if msg_split[1] == "startsession" then
if #msg_split < 2 then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00A59CBiG:|r ~ Missing session name ~")
return
end
local session = {["name"] = msg_split[2], ["looters"] = {}, ["date"] = date("%d/%m/%Y"), ["reserves"] = {}}
table.insert(DCSession,session)
activeSession = true
print("Session "..session["name"].." started")
elseif msg_split[1] == "endsession" then
if (activeSession) then
print("Session "..DCSession[#DCSession]["name"].." ended")
end
activeSession = false
elseif msg_split[1] == "add" then
if not activeSession then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00A59CBiG:|r ~ No active session ~")
return
end
local player = UnitName("target")
local loot = string.match(msg, "^add +(.+|r)")
addLoot(player, loot);
elseif msg_split[1] == "del" then
if not activeSession then
DEFAULT_CHAT_FRAME:AddMessage("|cFF00A59CBiG:|r ~ No active session ~")
return
end
local player = UnitName("target")
local loot = string.match(msg, "^del (.+)")
local index = 0;
for i = 1, #DCSession[#DCSession]["looters"] do
if DCSession[#DCSession]["looters"][i]["player"] == player and DCSession[#DCSession]["looters"][i]["loot"] == loot then
index = i
break
end
end
if index > 0 then
print("Deleted "..loot.." from "..player)
table.remove(DCSession[#DCSession]["looters"],index)
end
elseif msg_split[1] == "roll" then
local loot = string.match(msg, "^roll (.+)")
local lootName = string.match(loot, "%[(.+)%]")
currentlyRolledLoot = loot
local announceString = "Roll " .. loot
if activeSession then
local lootPrios = getPrios(lootName)
if (lootPrios) then
if(lootPrios["nameCount"] > 1) then
announceString = strjoin(" ", announceString, lootPrios["namesString"])
else
announceString = "GZ " .. currentlyRolledLoot .. " " .. lootPrios["namesString"] .. " softres"
end
end
end
SendChatMessage(announceString, "RAID_WARNING")
print("Roll started for "..loot)
trackRolls = true;
rolls = {}
elseif msg_split[1] == "endroll" then
trackRolls = false;
SendChatMessage("Rolls are now closed", "RAID");
DEFAULT_CHAT_FRAME:AddMessage("|cFF00A59CBiG:|r ~ Roll Results ~")
for p,r in spairs(rolls, function(t,a,b) return t[a] > t[b] end) do
DEFAULT_CHAT_FRAME:AddMessage(p.." : "..r)
end
elseif msg_split[1] == "export" then
local index = #DCSession
if (#msg_split > 1) then
local nr = tonumber(msg_split[2])
if (nr < #DCSession and nr > 0) then
index = nr
elseif (nr < 0 and index + nr > 0) then
index = index + nr
end
end
DumpSession(index)
elseif msg_split[1] == "import" then
ImportFrame.ScrollText:SetText("")
ImportFrame:Show()
end
end
elseif event == "CHAT_MSG_SYSTEM" then
local name, roll, range = string.match(arg1, "^([^ ]+) rolls (%d+) %((%d+-%d+)%)$")
if roll ~= nil and trackRolls and range == "1-100" then
if rolls[name] == nil then
rolls[name] = roll - (receivedLoot(name)*100)
end
end
elseif event == "CHAT_MSG_LOOT" and activeSession then
local player = select(4,...)
local item = string.match(arg1, "loot: (.+[^.])")
local itemName = string.match(item, "%[(.+)%]")
if item == currentlyRolledLoot and getPrios(itemName) == nil then
local dialog = StaticPopup_Show("BIG_ADD_LOOT", item);
if dialog then
dialog.data = player
dialog.data2 = item
end
end
end
end)