forked from tg123/RaidLedger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trade.lua
113 lines (90 loc) · 3.07 KB
/
trade.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
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
local _, ADDONSELF = ...
local L = ADDONSELF.L
local GUI = ADDONSELF.gui
local Database = ADDONSELF.db
local Print = ADDONSELF.print
local RegEvent = ADDONSELF.regevent
local f = CreateFrame("Frame", nil, TradeFrame)
f:SetWidth(172)
f:SetHeight(40)
f:SetBackdrop({
-- bgFile = "Interface\\FrameGeneral\\UI-Background-Marble",
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true,
tileEdge = true,
tileSize = 16,
edgeSize = 24,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
f:SetPoint("TOPRIGHT", TradeFrame, "BOTTOMRIGHT", 0, 0)
f:SetToplevel(true)
f:EnableMouse(true)
f:SetFrameLevel(TradeFrame:GetFrameLevel() + 1)
local addtoCheckbtn = nil
do
local b = CreateFrame("CheckButton", nil, f, "UICheckButtonTemplate")
b.text = b:CreateFontString(nil, "OVERLAY", "GameFontNormal")
b.text:SetPoint("LEFT", b, "RIGHT", 0, 1)
b:SetPoint("LEFT", f, 5, 0)
b.text:SetText(L["Add to"] .. " " .. L["Raid Ledger"])
f:SetWidth(b.text:GetStringWidth() + 50)
addtoCheckbtn = b
end
local currTrade = nil
-- local function UpdateCheckButton()
-- -- print(1)
-- end
-- RegEvent("TRADE_SHOW", function()
-- addtoCheckbtn:SetChecked(UnitInRaid("player"))
-- end)
-- RegEvent("TRADE_UPDATE", UpdateCheckButton)
-- RegEvent("TRADE_PLAYER_ITEM_CHANGED", UpdateCheckButton)
-- RegEvent("TRADE_MONEY_CHANGED", UpdateCheckButton)
RegEvent("TRADE_ACCEPT_UPDATE", function(p, t)
currTrade = {
target = GetUnitName("NPC", true),
targetmoney = GetTargetTradeMoney(),
playermoney = GetPlayerTradeMoney(),
targetitems = {},
playeritems = {},
}
for i = 1, 6 do
local t = GetTradeTargetItemLink(i)
if t then
table.insert(currTrade.targetitems, {
item = t,
count = select(3, GetTradeTargetItemInfo(i)),
})
end
local p = GetTradePlayerItemLink(i)
if p then
table.insert(currTrade.playeritems, {
item = p,
count = select(3, GetTradePlayerItemInfo(i)),
})
end
end
end)
local function AddLootFromTrade(beneficiary, cost, items)
if cost == 0 then
return
end
for i, item in ipairs(items) do
if i > 1 then
cost = 0
end
Database:AddOrUpdateLoot(item.item, item.count, beneficiary, cost / 10000)
Print(L["Item added"] .. " " .. item.item .. " " .. L["Beneficiary"] .. " " .. beneficiary .. " " .. GetMoneyString(cost))
end
end
RegEvent("UI_INFO_MESSAGE", function(_, text)
if text == ERR_TRADE_COMPLETE then
if not addtoCheckbtn:GetChecked() then
return
end
AddLootFromTrade(currTrade.target, currTrade.targetmoney, currTrade.playeritems)
AddLootFromTrade(UnitName("player"), currTrade.playermoney, currTrade.targetitems)
end
currTrade = nil
end)