forked from Pierre-Sassoulas/grey-handling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HandleMutuallyBeneficialTrades.lua
54 lines (50 loc) · 2.25 KB
/
HandleMutuallyBeneficialTrades.lua
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
local A, GreyHandling = ...
function GreyHandling.loot_frame:OnLoot(event, chat_message, player_name_retail, a, b, player_name_classic, d, e, f, g,
h, line_number, player_id, k, l, m, n, o)
-- print(event, "-", chat_message, "-", player_name_retail, "-", a, "-", b, "-", player_name_classic, "-", d,
-- "-", e, "-", f, "-", g, "-", h, "-", line_number, "-", player_id, "-", k, "-", l, "-", m, "-", n, "-", o)
if GreyHandling.IS_CLASSIC then
GreyHandling.functions.handleChatMessageLoot(chat_message, player_name_classic, line_number, player_id, k, l, m, n, o)
else
GreyHandling.functions.handleChatMessageLoot(chat_message, player_name_retail, line_number, player_id, k, l, m, n, o)
end
end
function GreyHandling.member_leave_frame:OnLeave(event, addon, text, channel, sender, target, zoneChannelID, localID, name, instanceID)
local playerNames = {}
for raidIndex = 1, GetNumGroupMembers() do
local name = GetRaidRosterInfo(raidIndex)
playerNames[name] = true
end
GreyHandling.db.removePlayerThatLeft(playerNames)
end
function GreyHandling.functions.GetBagAndSlot(itemLink, ourCount)
for bagID = 0, NUM_BAG_SLOTS do
for bagSlot = 1, GetContainerNumSlots(bagID) do
local _, testedItemCount, _, _, _, _, testedItemLink = GetContainerItemInfo(bagID, bagSlot)
if testedItemLink == itemLink and ourCount == testedItemCount then
-- print(itemLink, testedItemLink, ourCount, testedItemCount)
return bagID, bagSlot
end
end
end
end
function GreyHandling.functions.HandleMutuallyBeneficialTrades(foundSomething)
local bestExchanges = GreyHandling.functions.GetBestExchanges()
local foundExchange = nil
for i, exchange in pairs(bestExchanges) do
if exchange.itemGiven and exchange.itemTaken then
foundExchange = true
foundSomething = true
local bag, slot = GreyHandling.functions.GetBagAndSlot(exchange.itemGiven, exchange.ourCount)
if bag and slot then
GreyHandling.functions.SetBagItemGlow(bag, slot, 0.1, 1, 0.1)
end
GreyHandling.print(GreyHandling.functions.DisplayMutuallyBeneficialTradeInChat(exchange))
-- SendChatMessage(msg)
end
end
if not foundExchange then
GreyHandling.print("|cff"..GreyHandling.redPrint..GreyHandling["No mutually beneficial trade found."].."|r")
end
return foundSomething
end