-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.lua
More file actions
591 lines (494 loc) · 21.1 KB
/
Main.lua
File metadata and controls
591 lines (494 loc) · 21.1 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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
local AutoRoll = LibStub("AceAddon-3.0"):NewAddon("AutoRoll3000", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0", "AceSerializer-3.0", "AceTimer-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("AutoRoll")
-- @todo: save this in AutoRoll, to not have dublications...
AutoRoll.rollOptions = {[0]=L["Pass"], [1]=L["Need"], [2]=L["Greed"]}
AutoRoll.itemQuality = {[2]="|cFF1eff00"..L["uncommon"].."|r", [3]="|cff0070dd"..L["rare"].."|r", [4]="|cffa335ee"..L["epic"].."|r", [5]="|cffff8000"..L["legendary"].."|r", [6]="|cffe6cc80"..L["artifact"].."|r"}
AutoRoll.conditionOperaters = {["=="]=L["equal"],[">="]=L["minimum"],["<="]=L["maximum"],[">"]=L["bigger then"],["<"]=L["lower then"]}
AutoRoll.dungeonList = {[309]=L["Zul'Gurub"],[249]=L["Ony"], [409]=L["MC"], [469]=L["BWL"], [389]="test instance"}
AutoRoll.conditionList = {["disenchanter"]=L["is disenchanter"], ["quality"]=L["Quality"], ["dungeon"]=L["Dungeon"], ["party_member"]=L["in group with"], ["lua"]="Lua",["disabled"]=L["disabled"],["deleted"]=L["deleted"],["item"]=L["item"]}
AutoRoll.trollTimerCount = 0
--wow api, tis will do a lot other addons, i'm not sure is it local a lot faster?
local GetLootRollItemInfo = GetLootRollItemInfo
local GetLootRollItemLink = GetLootRollItemLink
local GetItemInfoInstant = GetItemInfoInstant
local GetNumGroupMembers = GetNumGroupMembers
local GetPlayerInfo = C_LootHistory.GetPlayerInfo
local PLAYER_NAME = UnitName("player")
local dbDefaults = {
profile = {
enabled = true, -- the addon self is enabled per default
guildItemGroupsEnabled = true, -- use a group config to auto roll in a raid from a guild leader
--savedItemsEnabled = true, -- add the options to store
profileItemGroupsEnabled = false, -- on default it should not use any ItemGroups to auto roll.
disenchanter = false,
itemGroupsPointer = "itemGroups",
-- savedItems = { -- it will be possible to remember the decision on the roll frame. this is stored here
-- --[19698] = 0,
-- },
itemGroupsRaid = {
raidSize = nil, -- When i get a itemGroupsRaid ruleset for a raid store here the group size. when the group size will be smaler then 40% or less then 2 i know the raid is finish and the itemGroupsRaid will be deleted.
}, -- here are the groups stored you recive from raid lead
itemGroups = { -- When not stored in the savedItems it will check the items groups
--thank you lua for your ugly mixed aray hash disaster...
rolls = {}, -- data about current rolls with share function, when this rollId is finished we have to check do we have won the item. and update the itemgroup share data. rolls[rollId] = itemGroupId
share = {}, -- round robin data of all groups. e.g: share[itemGroupId].loot_counter
{
description = L["ZG coin desc"],
enabled = true,
share = {
enabled = true,
size = "raid"
},
rollOptionSuccsess = 2,
conditions = {
[1] = {
type = "item",
args = {"19698,19699,19700,19701,19702,19703,19704,19705,19706"},
}
},
},
{
description = L["ZG bijous desc"],
enabled = true,
share = {
enabled = true,
},
rollOptionSuccsess = 2,
conditions = {
[1] = {
type = "item",
args = {"19707,19708,19709,19710,19711,19712,19713,19714,19715"},
}
},
},
{ --
description = L["all items disenchanter"],
enabled = true,
share = {
enabled = false,
},
rollOptionSuccsess = 2,
conditions = {
[1] = {
type = "disenchanter",
args = {true},
}
},
},
{ --
description = L["all green items"],
enabled = false,
share = {
enabled = false,
},
rollOptionSuccsess = 0,
conditions = {
[1] = {
type = "quality",
args = {
"==",
2, --0 - Poor, 1 - Common, 2 - Uncommon, 3 - Rare, 4 - Epic, 5 - Legendary, 6 - Artifact, 7 - Heirloom, 8 - WoW Token
},
}
-- the following conditions are not implemented yet, and only a hint for me
-- dungeon = 309, -- condition work only in ZG
-- inGroupWith = {
-- "oneOf", "Player1,Player2,Player3",
-- "allOf", "Player1,Player2,Player3",
-- },
-- perhaps i add a lua solution to, we will see
},
},
},
},
}
function Copy_Table(src, dest)
for index, value in pairs(src) do
if type(value) == "table" then
dest[index] = {}
Copy_Table(value, dest[index])
else
dest[index] = value
end
end
end
function AutoRoll:OnInitialize()
-- Called when the addon is loaded
self:RegisterChatCommand("rl", function() ReloadUI() end)
self:loadDb()
self:refreshOptions()
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("AutoRoll3000", "AutoRoll3000")
self:RegisterChatCommand("ar3", "ChatCommand")
end
function AutoRoll:OnEnable()
-- Called when the addon is enabled
self:RegisterEvent("START_LOOT_ROLL")
self:RegisterEvent("LOOT_HISTORY_ROLL_COMPLETE")
-- @Todo: only use the comm "ar3" and "ar3_data" so it is possible to send on ar3 hei ther is a raid config with id xyz or delete raid config xyz and then send it on the data channel.
-- maybe after a client recive ther is a raid config xyz he has to send back i need the data and then wisper it back. and use the compression only on data
self:RegisterComm("ar3_rc") -- recive a confi
self:RegisterComm("ar3_rmc") -- remove the raid config
self:checkItemGroupPointer()
StaticPopupDialogs["CONFIRM_RECIVE_CONFIG_AR3"] = {
text = "%s "..L["send you a AutoRoll3000 config for this raid. install it?"],
button1 = L["Yes"],
button2 = L["No"],
OnAccept = function(self, config)
AutoRoll:ReciveItemGroupRaid(config)
end,
timeout = 20,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3, -- avoid some UI taint, see http://www.wowace.com/announcements/how-to-avoid-some-ui-taint/
};
StaticPopupDialogs["CONFIRM_REMOVE_CONFIG_AR3"] = {
text = "%s "..L["will remove your AutoRoll3000 Raid config. Remove it?"],
button1 = L["Yes"],
button2 = L["No"],
OnAccept = function(self)
AutoRoll:setItemGroupPointer("itemGroups")
end,
timeout = 20,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3, -- avoid some UI taint, see http://www.wowace.com/announcements/how-to-avoid-some-ui-taint/
};
-- Register AutoRoll db on Core addon, and set only the scope to this addon db. So profile reset works fine for all the addons.
--self.db = FdHrT:AddAddonDBDefaults(dbDefaults).profile.AutoRoll;
--LibStub("AceConfig-3.0"):RegisterOptionsTable("AutoRoll", options.args.ar, {"ar"})
end
function AutoRoll:loadDb()
self.db = LibStub("AceDB-3.0"):New("AutoRollDB", dbDefaults, true)
self.profilOptions = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
self.db.RegisterCallback(self, "OnProfileChanged", "refreshOptions")
self.db.RegisterCallback(self, "OnProfileCopied", "refreshOptions")
self.db.RegisterCallback(self, "OnProfileReset", "refreshOptions")
end
function AutoRoll:ChatCommand(input)
if not input or input:trim() == "" then
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
else
LibStub("AceConfigCmd-3.0"):HandleCommand("ar3", "AutoRoll3000", input)
end
end
function AutoRoll:GetRollIdData(rollId)
local itemInfo = {["rollId"] = rollId}
itemInfo.texture, itemInfo.name, itemInfo.count, itemInfo.quality, itemInfo.bindOnPickUp, itemInfo.canNeed, itemInfo.canGreed, itemInfo.canDisenchant, itemInfo.reasonNeed, itemInfo.reasonGreed, itemInfo.reasonDisenchant, itemInfo.deSkillRequired = GetLootRollItemInfo(rollId);
itemInfo.itemId, itemInfo.itemType, itemInfo.itemSubType, itemInfo.itemEquipLoc, itemInfo.icon, itemInfo.itemClassID, itemInfo.itemSubClassID = GetItemInfoInstant(GetLootRollItemLink(itemInfo.rollId));
itemInfo.itemLink = GetLootRollItemLink(itemInfo.rollId)
return itemInfo
end
-- Fake roll data used when you use the AutoRoll:troll function for a test roll
function AutoRoll:GetRollIdDataDebug(rollId, itemId)
local itemInfo = {
rollId = rollId,
count = 1,
itemId = itemId or 19698,
}
itemInfo.itemId, itemInfo.itemType, itemInfo.itemSubType, itemInfo.itemEquipLoc, itemInfo.icon, itemInfo.itemClassID, itemInfo.itemSubClassID = GetItemInfoInstant(itemInfo.itemId);
itemInfo.itemLink = select(2,GetItemInfo(itemInfo.itemId))
-- it is only possible to get a itemInfo when it is on cache from the client... when not it will return nil and request it on the server for later use...
-- so when i do not have it in cache i have to "sleep" some seconds
if itemInfo.itemLink == nil then
self.trollTimerCount = self.trollTimerCount +1
if self.trollTimerCount <= 6 then
self.trollTimer = itemInfo
self:ScheduleTimer("TrollLater", 0.5)
end
return nil
end
self.trollTimerCount = 0
self.trollTimer = {}
return itemInfo
end
function AutoRoll:TrollLater()
AutoRoll:troll(self.trollTimer.rollId,self.trollTimer.itemId)
end
-- Only for addon develop:
-- start a new roll for a ZG coin and rollId 1
-- /run AutoRoll:troll(1)
-- fake a win of the item from rollId 1
-- /run AutoRoll:rollItemWon(1)
-- start a new roll for item id 1234
-- /run AutoRoll:troll(1,1234)
-- Debug function to emulate a roll windows event
function AutoRoll:troll(rollId, itemId)
local itemInfo = self:GetRollIdDataDebug(rollId, itemId);
if itemInfo == nil then return end
self:CheckRoll(itemInfo)
end
function AutoRoll:START_LOOT_ROLL(event, rollId)
local itemInfo = self:GetRollIdData(rollId);
self:CheckRoll(itemInfo)
end
function AutoRoll:CheckRoll(itemInfo)
if self.db.profile.enabled == false then return false end
local currentItemGroupId
if
(self:getItemGroupPointer() == "itemGroupsRaid" and self.db.profile.guildItemGroupsEnabled) or
(self:getItemGroupPointer() == "itemGroups" and self.db.profile.profileItemGroupsEnabled) then
currentItemGroupId = self:findGroup(itemInfo,self.db.profile[self:getItemGroupPointer()]);
end
-- no active itemGroup found for this roll window, abort
if currentItemGroupId == nil then return false end
local currentItemGroup = self.db.profile[self:getItemGroupPointer()][currentItemGroupId]
if currentItemGroup.share.enabled then
-- round robin mode. only roll when player not have more then the other from currentItemGroupId.
self:CheckShare(itemInfo, currentItemGroupId, currentItemGroup)
else
-- auto roll
self:Print(L["roll"].." "..self.rollOptions[currentItemGroup.rollOptionSuccsess].." "..L["for"].." "..itemInfo.itemLink);
RollOnLoot(itemInfo.rollId, currentItemGroup.rollOptionSuccsess);
end
end
-- /ar3
-- /run AutoRoll:SendRaidConfig()
-- /run AutoRoll:installItemGroupRaidFromItemGroups()
-- /run AutoRoll:checkItemGroupPointer()
function AutoRoll:installItemGroupRaidFromItemGroups()
local itemGroupsRaid = {}
Copy_Table(self.db.profile.itemGroups, itemGroupsRaid)
itemGroupsRaid.raidSize = GetNumGroupMembers()
itemGroupsRaid.owner = PLAYER_NAME
self:installItemGroupRaid(itemGroupsRaid)
end
function AutoRoll:ReciveItemGroupRaid(itemGroupsRaidMessage)
local LibDeflate = LibStub:GetLibrary("LibDeflate")
local ctext = LibDeflate:DecodeForWoWAddonChannel(itemGroupsRaidMessage)
local text = LibDeflate:DecompressDeflate(ctext)
local _,itemGroupsRaid = self:Deserialize(text)
self:installItemGroupRaid(itemGroupsRaid)
end
function AutoRoll:installItemGroupRaid(itemGroupsRaid)
-- simulate a recive from a raid itemGroup
self.db.profile.itemGroupsRaid = itemGroupsRaid
-- share reset
self.db.profile.itemGroupsRaid.share = {}
-- switch to Raid config
self:setItemGroupPointer("itemGroupsRaid")
-- recive raid config when you are not in a group make no sence but better check it here
self:checkItemGroupPointer()
end
function AutoRoll:OnCommReceived(prefix, message, distribution, sender)
if sender == UnitName("player") then return end -- ignore mesage from my self
if self:getItemGroupPointer() == "itemGroupsRaid" and prefix == "ar3_rc" then return end -- when you allready has a raid config do not recive.
-- check should we do the command or is a user confirm required
-- @Todo: user GetGuildInfo to check is the sender in my guild
-- @Todo: check is it possible to fake the sender
if self.db.profile.guildItemGroupsEnabled and (UnitIsGroupAssistant(sender) or UnitIsGroupLeader(sender)) then
-- install/remove Raid Rules
if prefix == "ar3_rc" then
self:ReciveItemGroupRaid(message)
elseif prefix == "ar3_rmc" then
self:setItemGroupPointer("itemGroups")
end
else
-- user has to confirm before the Raid Rules will be installed/removed
if prefix == "ar3_rc" then
self:confirmRaidConfigRecive(message, sender)
elseif prefix == "ar3_rmc" then
self:confirmRemoveRaidConfig(sender)
end
end
end
function AutoRoll:confirmRemoveRaidConfig(playerName)
StaticPopup_Show("CONFIRM_REMOVE_CONFIG_AR3", playerName)
end
function AutoRoll:confirmRaidConfigRecive(itemGroups, playerName)
local dialog = StaticPopup_Show("CONFIRM_RECIVE_CONFIG_AR3", playerName)
dialog.data = itemGroups
end
function AutoRoll:SendRaidConfig()
if self:getItemGroupPointer() == "itemGroups" then
self:installItemGroupRaidFromItemGroups()
end
local LibDeflate = LibStub:GetLibrary("LibDeflate")
local s = self:Serialize(self.db.profile.itemGroupsRaid)
local cs = LibDeflate:CompressDeflate(s)
cs = LibDeflate:EncodeForWoWAddonChannel(cs)
self:SendCommMessage("ar3_rc", cs, "RAID", "", "BULK")
end
function AutoRoll:SendRaidConfigRemove()
self:setItemGroupPointer("itemGroups")
self:SendCommMessage("ar3_rmc", "remove raid config", "RAID", "", "BULK")
end
function AutoRoll:setItemGroupPointer(value)
if value == "itemGroupsRaid" then
self:Print(L["Raid Rules are now active"])
self:RegisterEvent("GROUP_ROSTER_UPDATE")
else
self:Print(L["Raid Rules are now not active"])
self:UnregisterEvent("GROUP_ROSTER_UPDATE")
end
self.db.profile.itemGroupsPointer = value
self:refreshOptions();
end
function AutoRoll:GROUP_ROSTER_UPDATE()
self:checkItemGroupPointer();
if self:getItemGroupPointer() == "itemGroupsRaid" and self.db.profile[self:getItemGroupPointer()].owner == PLAYER_NAME then
self:SendRaidConfig()
end
end
function AutoRoll:getItemGroupPointer()
return self.db.profile.itemGroupsPointer
end
function AutoRoll:checkItemGroupPointer()
local itemGroups = self:getItemGroupPointer()
if itemGroups == "itemGroups" then return end
if itemGroups == "itemGroupsRaid" then
-- Curent itemGroup is for a raid. check are we allready in this group
if self.db.profile[itemGroups].raidSize ~= nill and (self.db.profile[itemGroups].raidSize / 2) < GetNumGroupMembers() then
-- group looks ok for raid ruls
return
end
end
-- no working itemGroups detected. set to default
self:Print(L["switch to default rules"])
self:setItemGroupPointer("itemGroups")
end
-- Raid lead can shere a itemGroup to all raid members with this addon. this temporary itemGroup should work until the end of the dungeon.
-- function AutoRoll:isRaidItemGroup()
-- -- There are no dungeon session id, so i have to track self is it the same group
-- end
function AutoRoll:CheckConditions(itemInfo, itemGroup)
if itemGroup.conditions == nil then return false end
-- Check all Conditions
for ic, condition in pairs(itemGroup.conditions) do
if AutoRoll:CheckCondition(itemInfo, condition) == false then
-- Condition fails try next itemGroup
return false
end
end
-- All Conditions true, une this itemGroup
return true
end
function AutoRoll:CheckCondition(itemInfo, condition)
if condition.type == "item" then
return tContains({strsplit(",",condition.args[1])},tostring(itemInfo.itemId))
elseif condition.type == "disabled" then
return true
elseif condition.type == "disenchanter" then
return self.db.profile.disenchanter == condition.args[1]
elseif condition.type == "lua" then
return true
elseif condition.type == "party_member" then
for i,playerName in ipairs({strsplit(",",condition.args[2])}) do
if UnitInRaid(playerName) or UnitInParty(playerName) then
if condition.args[1] == "oneOf" then
return true
end
else
if condition.args[1] == "allOf" then
return false
end
end
end
if condition.args[1] == "oneOf" then
return false
else
return true
end
elseif condition.type == "dungeon" then
local instanceId = select(8,GetInstanceInfo())
return instanceId == condition.args[1]
elseif condition.type == "quality" then
-- Validate bevore use the evel loadstring function...
if self.conditionOperaters[condition.args[1]] == nil or self.itemQuality[condition.args[2]] == nil then return false end
local f = assert(loadstring("return "..itemInfo.quality.." "..condition.args[1].." "..condition.args[2]))
return f()
end
return true -- Condition type not known, ignore it
end
function AutoRoll:findGroup(itemInfo, itemGroups)
if itemGroups == nil then return nil end -- no itemGroups created
for i, itemGroup in ipairs(itemGroups) do
if itemGroup.enabled == true then
if self:CheckConditions(itemInfo, itemGroup) then
return i
end
end
end
return nil
end
-- a little bit messy at the moment,
function AutoRoll:CheckShare(itemInfo, currentItemGroupId)
self.db.profile[self:getItemGroupPointer()].rolls[itemInfo.rollId] = currentItemGroupId;
if self.db.profile[self:getItemGroupPointer()].share[currentItemGroupId] == nil then self:initShare(currentItemGroupId) end
local sharedata = self.db.profile[self:getItemGroupPointer()].share[currentItemGroupId];
sharedata.loot_counter = sharedata.loot_counter +1;
sharedata.party_member = GetNumGroupMembers(); -- it is possible that one of the group do not want any zg coins. so we need a option later to change the party_member size by hand...
-- print("vor würfeln. has_loot: "..has_loot)
if sharedata.has_loot < 1 then
--würfeln
self:Print(self.rollOptions[self.db.profile[self:getItemGroupPointer()][currentItemGroupId].rollOptionSuccsess].." "..L["for"].." "..itemInfo.itemLink.." "..sharedata.loot_counter.."/"..sharedata.party_member.." "..L["has one"]);
RollOnLoot(itemInfo.rollId, self.db.profile[self:getItemGroupPointer()][currentItemGroupId].rollOptionSuccsess);
else
self:Print(self.rollOptions[0].." "..L["for"].." "..itemInfo.itemLink.." "..sharedata.loot_counter.."/"..sharedata.party_member.." "..L["has one"]);
RollOnLoot(itemInfo.rollId, 0);
end
if sharedata.party_member <= sharedata.loot_counter then
sharedata.loot_counter = 0;
sharedata.has_loot = sharedata.has_loot -1;
sharedata.loot_round = sharedata.loot_round +1;
self:Print(L["All player has a"].." "..self.db.profile[self:getItemGroupPointer()][currentItemGroupId].description..". "..L["Start a new round"]);
end
end
function AutoRoll:initShare(currentItemGroupId)
self.db.profile[self:getItemGroupPointer()].share[currentItemGroupId] = {
loot_counter = 0,
has_loot = 0,
loot_round = 1,
has_won_total = 0,
}
end
-- -- This stupid event do not return the rollId!
-- -- so i will not store the item id to check it here... perhaps i will change my mind later
-- function AutoRoll:LOOT_ITEM_ROLL_WON(event, itemLink, rollQuntity, rollType, roll, upgraded)
-- self:Print("LOOT_ITEM_ROLL_WON entdeckt. item von rollid: "..rollId.." gewonnen")
-- self:rollItemWon(rollId)
-- end
-- /run AutoRoll:rollItemWon(1)
function AutoRoll:rollItemWon(rollId)
if self.db.profile[self:getItemGroupPointer()].rolls[rollId] then
local sharedata = self.db.profile[self:getItemGroupPointer()].share[self.db.profile[self:getItemGroupPointer()].rolls[rollId]]
sharedata.has_loot = sharedata.has_loot +1;
sharedata.has_won_total = sharedata.has_won_total +1;
end
end
-- LOOT_HISTORY_ROLL_COMPLETE is very complex i have to work with the complete roll history from wow.
-- At the moment i use only the info is the winner is me. This will be a lot easyser with LOOT_ITEM_ROLL_WON.
-- When I will track all winners this function should work:
function AutoRoll:LOOT_HISTORY_ROLL_COMPLETE()
local hid, rollId, players, done, _ = 1;
-- Any roll is done now. so loop over all the wow lootHistory data and check is ther a entry for a open rollid...
while true do
rollId, _, players, done = C_LootHistory.GetItem(hid);
if not rollId then
return
elseif done and self.db.profile[self:getItemGroupPointer()].rolls[rollId] then
-- found it...
--print(rollId.." abgeschlossen ");
break
end
hid = hid+1
end
-- There is no function to get the winner of the item. i have to loop over all players and get a lot of data about the history id of this player
for j=1, players do
local name, class, rtype, roll, is_winner, is_me = GetPlayerInfo(hid, j)
if is_winner then
-- print("gewinner von ".._.." ist: "..name.." class: "..class);
-- perhaps i will add here a loot history feature, but not at the moment.
if is_me then
self:rollItemWon(rollId)
end
-- /dump AutoRoll.db.profile["itemGroupsRaid"].share[4].data
local currentShare = self.db.profile[self:getItemGroupPointer()].share[self.db.profile[self:getItemGroupPointer()].rolls[rollId]]
if currentShare.data == nil then currentShare.data = {} end
if currentShare.data[name] == nil then currentShare.data[name] = 0 end
currentShare.data[name] = currentShare.data[name] + 1
break
end
end
self.db.profile[self:getItemGroupPointer()].rolls[rollId] = nil -- ignore this rollId in the history data next time
end