vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 local locals = KC_ITEMS_LOCALS.modules.broker
2  
3 KC_Broker = KC_ItemsModule:new({
4 type = "broker",
5 name = locals.name,
6 desc = locals.description,
7 cmdOptions = locals.chat,
8 dependencies = {"common", "auction"},
9 optPath = {"Options"},
10 db = AceDatabase:new("KC_AuctionBrokerDB")
11 })
12  
13 KC_Items:Register(KC_Broker)
14  
15 function KC_Broker:Enable()
16 self:RegisterEvent("AUCTION_HOUSE_SHOW")
17 -- One Click Auctions
18 self:Hook("ContainerFrameItemButton_OnClick", "BagClick")
19 end
20  
21 function KC_Broker:Disable()
22 KC_ItemsModule.Disable(self)
23 if (not AuctionFrame) then return end
24 AuctionsItemText:SetText(self.AuctionsItemText or AuctionsItemText:GetText())
25 BrowseTitle:SetText(self.BrowseTitle or BrowseTitle:GetText())
26 end
27  
28 function KC_Broker:AUCTION_HOUSE_SHOW()
29 -- Data Caching
30 self.AuctionsItemText = AuctionsItemText:GetText()
31 self.BrowseTitle = BrowseTitle:GetText()
32 -- Autofill
33 _ = self:GetOpt(self.optPath, "autofill") and self:RegisterEvent("NEW_AUCTION_UPDATE", "AutoFill")
34 _ = self:GetOpt(self.optPath, "autofill") and self:Hook("StartAuction", "Remember")
35 -- Duration Memory
36 _ = self:GetOpt(self.optPath, "remduration") and self:Hook("AuctionsRadioButton_OnClick", "UpdateDuration")
37 _ = self:GetOpt(self.optPath, "remduration") and AuctionsRadioButton_OnClick(self:GetOpt(self.optPath, "duration"))
38 -- Coloration
39 if (self.app.auction and self:GetOpt(self.optPath, "ahcolor")) then
40 self:Hook("AuctionFrameBrowse_Update")
41 self:UpdateGuide()
42 BrowseTitle:SetPoint("TOP",35 , -18)
43 BrowseTitle:SetText( format("%s - %s", self.BrowseTitle, locals.labels.guide))
44 end
45 self:UnregisterEvent("AUCTION_HOUSE_SHOW")
46 end
47  
48 function KC_Broker:AutoFill()
49 local name, texture, qty, quality, canUse, price = GetAuctionSellItemInfo()
50  
51 if (not name) then return end
52  
53 local factionID = self.common:GetRealmFactionID()
54 local code = self.common:GetCodeFromInv(name, true)
55 local mode = self:GetOpt(self.optPath, "fillmode") or locals.modes.mixed
56 local cut = self:GetOpt(self.optPath, "cut") or 1
57 local skipmem = self:GetOpt(self.optPath, "skipmem")
58 local min, buy = 0, 0
59 local used = locals.modes.none
60  
61 if (mode == locals.modes.memory or (mode == locals.modes.mixed and not skipmem)) then
62 min, buy = self:GetLastPrices(code, factionID)
63 used = locals.modes.memory
64 end
65  
66 if ((mode == locals.modes.smart or (mode == locals.modes.mixed and min == 0)) and self.app.auction) then
67 _, _, min, _, _, _, buy = self.app.auction:GetItemData(code)
68 min = min and min * cut or 0
69 buy = buy and buy * cut or 0
70 used = locals.modes.smart
71 end
72  
73 if ((mode == locals.modes.vendor or (mode == locals.modes.mixed and min == 0)) and self.app.sellvalue) then
74 local vsell = self.common:GetItemPrices(code)
75 min = min > 0 and min or vsell * 2.5
76 buy = buy > 0 and buy or vsell * 3.5
77  
78 min = min < vsell and vsell * 1.1 or min
79  
80 min = buy < vsell and vsell * 1.5 or min
81 buy = buy < vsell and vsell * 1.8 or buy
82 used = locals.modes.vendor
83 end
84  
85 buy = buy < min and min * 1.1 or buy
86  
87 _ = min > 0 and MoneyInputFrame_SetCopper(StartPrice, floor(min * qty))
88 _ = buy < 1 and MoneyInputFrame_SetCopper(BuyoutPrice, floor(price * 2.5))
89 _ = buy > 0 and MoneyInputFrame_SetCopper(BuyoutPrice, floor(buy * qty))
90  
91 AuctionsItemText:SetText(format("%s - |cff00ff33Mode: %s", self.AuctionsItemText, used))
92 end
93  
94 function KC_Broker:GetLastPrices(code, factionID)
95 return self.common:Split(self.db:get({factionID}, code) or "0,0", ",")
96 end
97  
98 function KC_Broker:Remember(min, buy, dur)
99 local name, _, qty = GetAuctionSellItemInfo()
100 local factionID = self.common:GetRealmFactionID()
101 local code = self.common:GetCodeFromInv(name, true)
102  
103 self.db:set({factionID}, code, format("%s,%s", self.common:Round(min / qty,3), self.common:Round(buy / qty, 3)))
104  
105 self.Hooks["StartAuction"].orig(min, buy, dur)
106 end
107  
108 function KC_Broker:UpdateDuration(index)
109 self:SetOpt(self.optPath, "duration", index)
110 self.Hooks["AuctionsRadioButton_OnClick"].orig(index)
111 end
112  
113 function KC_Broker:BagClick(button, ignore)
114 if (AuctionFrame and AuctionFrame:IsVisible()) then
115 if (button == "LeftButton" and IsAltKeyDown()and GetContainerItemLink(this:GetParent():GetID(), this:GetID())) then
116 PickupContainerItem(this:GetParent():GetID(), this:GetID())
117 ClickAuctionSellItemButton()
118 self:AutoFill()
119 StartAuction(MoneyInputFrame_GetCopper(StartPrice), MoneyInputFrame_GetCopper(BuyoutPrice), AuctionFrameAuctions.duration)
120 elseif (button == "RightButton" and IsControlKeyDown()) then
121 local link = GetContainerItemLink(this:GetParent():GetID(),this:GetID())
122 if (not link) then return end
123 BrowseName:SetText(self.common:GetItemInfo(self.common:GetCode(link))["name"])
124 AuctionFrameBrowse_Search();
125 BrowseNoResultsText:SetText(BROWSE_NO_RESULTS);
126 BrowseName:ClearFocus();
127 elseif (button == "RightButton" and IsAltKeyDown()) then
128 self:SmartSplit()
129 else
130 self.Hooks["ContainerFrameItemButton_OnClick"].orig(button, ignore)
131 end
132 elseif (button == "RightButton" and IsAltKeyDown()) then
133 self:SmartSplit()
134 else
135 self.Hooks["ContainerFrameItemButton_OnClick"].orig(button, ignore)
136 end
137 end
138  
139 function KC_Broker:SmartSplit()
140 SplitContainerItem(this:GetParent():GetID(), this:GetID(), 1)
141 for bag=0,4 do
142 for slot=1, GetContainerNumSlots(bag) do
143 if (not GetContainerItemLink(bag, slot)) then
144 PickupContainerItem(bag, slot)
145 return
146 end
147 end
148 end
149 end
150  
151 function KC_Broker:AuctionFrameBrowse_Update()
152 self.Hooks["AuctionFrameBrowse_Update"].orig()
153 local offset = FauxScrollFrame_GetOffset(BrowseScrollFrame)
154  
155 local knownColor = {self.common:Explode(self:GetOpt(self.optPath, "knownColor") or ".1!.1!1", "!")}
156 local sellColor = {self.common:Explode(self:GetOpt(self.optPath, "sellColor") or "1!.5!.8", "!")}
157 local buyColor = {self.common:Explode(self:GetOpt(self.optPath, "buyColor") or "1!1!0", "!")}
158 local minColor = {self.common:Explode(self:GetOpt(self.optPath, "minColor") or "0!.8!1", "!")}
159  
160 for i=1, NUM_BROWSE_TO_DISPLAY do
161  
162 local code = self.common:GetCode(GetAuctionItemLink("list", i+offset), true);
163  
164 if (not code) then return; end
165  
166 local _, _, count, _, _, _, min, _, buy, bid, _, _ = GetAuctionItemInfo("list", i+offset);
167 local sSeen, sAvgStack, sMin, sBidcount, sBid, sBuycount, sBuy = self.app.auction:GetItemData(code);
168 local sell = self.common:GetItemPrices(code)
169  
170 local sellPass = sSeen and buy < (sell * count) and buy > 0
171 local buyPass = sBuy and buy / count < sBuy * .75 and buy > 0
172 local minPass = sMin and min / count < sMin * .75
173  
174 --FilterKnown Code
175 KCITooltip:SetAuctionItem("list", i+offset);
176 local text = format("%s %s %s", getglobal("KCITooltipTextLeft2"):GetText() or "", getglobal("KCITooltipTextLeft3"):GetText() or "", getglobal("KCITooltipTextLeft4"):GetText() or "");
177 local knownPass = strfind(text, ITEM_SPELL_KNOWN);
178  
179 if (knownPass) then
180 local iconTexture = getglobal("BrowseButton"..i.."ItemIconTexture");
181 iconTexture:SetVertexColor(unpack(knownColor));
182 elseif (sellPass) then
183 local iconTexture = getglobal("BrowseButton"..i.."ItemIconTexture");
184 iconTexture:SetVertexColor(unpack(sellColor));
185 elseif (buyPass) then
186 local iconTexture = getglobal("BrowseButton"..i.."ItemIconTexture");
187 iconTexture:SetVertexColor(unpack(buyColor));
188 elseif (minPass) then
189 local iconTexture = getglobal("BrowseButton"..i.."ItemIconTexture");
190 iconTexture:SetVertexColor(unpack(minColor));
191 end
192 end
193 KCITooltip:Hide()
194 end
195  
196 function KC_Broker:UpdateGuide()
197 local kc = {self.common:Explode(self:GetOpt(self.optPath, "knownColor") or ".1!.1!1", "!")}
198 local sc = {self.common:Explode(self:GetOpt(self.optPath, "sellColor") or "1!.5!.8", "!")}
199 local bc = {self.common:Explode(self:GetOpt(self.optPath, "buyColor") or "1!1!0", "!")}
200 local mc = {self.common:Explode(self:GetOpt(self.optPath, "minColor") or "0!.8!1", "!")}
201  
202 locals.labels.guide = format(locals.labels.guidebase, self.common:GetHexCode(kc[1], kc[2], kc[3], true), self.common:GetHexCode(sc[1], sc[2], sc[3], true), self.common:GetHexCode(bc[1], bc[2], bc[3], true),self.common:GetHexCode(mc[1], mc[2], mc[3], true))
203 end