Asa@18
|
1 local addonName, addonTable = ...;
|
Asa@18
|
2 local addon = _G[addonName]
|
Asa@18
|
3
|
Asa@18
|
4 function addon:IsQACompatible()
|
Asa@18
|
5 return (QAAPI ~= nil and QAAPI.GetGroups ~= nil)
|
Asa@18
|
6 end
|
Asa@18
|
7
|
Asa@18
|
8 function addon:IsQAEnabled()
|
Asa@18
|
9 return addon:IsQACompatible() and ItemAuditor.db.char.use_quick_auctions
|
Asa@18
|
10 end
|
Asa@18
|
11
|
Asa@18
|
12 function addon:IsQADisabled()
|
Asa@18
|
13 return not self:IsQAEnabled()
|
Asa@18
|
14 end
|
Asa@18
|
15
|
Asa@18
|
16 function addon:SetQAEnabled(info, value)
|
Asa@18
|
17 ItemAuditor.db.char.use_quick_auctions = value
|
Asa@18
|
18 end
|
Asa@18
|
19
|
Asa@18
|
20 function addon:RefreshQAGroups()
|
Asa@18
|
21 if not addon.IsQAEnabled() then
|
Asa@18
|
22 return
|
Asa@18
|
23 end
|
Asa@18
|
24 for groupName in pairs(QAAPI:GetGroups()) do
|
Asa@18
|
25 self:UpdateQAGroup(groupName)
|
Asa@18
|
26 end
|
Asa@18
|
27 end
|
Asa@18
|
28
|
Asa@18
|
29 function addon:UpdateQAThreshold(link)
|
Asa@18
|
30 if not addon.IsQAEnabled() then
|
Asa@18
|
31 return
|
Asa@18
|
32 end
|
Asa@18
|
33 _, link= GetItemInfo(link)
|
Asa@18
|
34
|
Asa@18
|
35 self:UpdateQAGroup(QAAPI:GetItemGroup(link))
|
Asa@18
|
36 end
|
Asa@18
|
37
|
Asa@19
|
38 addon.profit_margin = 1.15
|
Asa@19
|
39
|
Asa@19
|
40 local function calculateQAThreshold(copper)
|
Asa@19
|
41 if copper == 0 then
|
Asa@19
|
42 copper = 1
|
Asa@19
|
43 end
|
Asa@19
|
44
|
Asa@19
|
45 -- add my minimum profit margin
|
Asa@20
|
46 -- GetAuctionThreshold returns a percent as a whole number. This will convert 25 to 1.25
|
Asa@20
|
47 copper = copper * (1+addon:GetAuctionThreshold())
|
Asa@19
|
48
|
Asa@19
|
49 -- Adding the cost of mailing every item once.
|
Asa@19
|
50 copper = copper + 30
|
Asa@19
|
51
|
Asa@19
|
52 -- add AH Cut
|
Asa@19
|
53 local keep = 1 - addon:GetAHCut()
|
Asa@19
|
54 return copper/keep
|
Asa@19
|
55 end
|
Asa@19
|
56
|
Asa@18
|
57 function addon:UpdateQAGroup(groupName)
|
Asa@18
|
58 if not addon.IsQAEnabled() then
|
Asa@18
|
59 return
|
Asa@18
|
60 end
|
Asa@18
|
61 if groupName then
|
Asa@18
|
62 local threshold = 0
|
Asa@18
|
63
|
Asa@18
|
64 for link in pairs(QAAPI:GetItemsInGroup(groupName)) do
|
Asa@18
|
65 local _, itemCost= ItemAuditor:GetItemCost(link, 0)
|
Asa@18
|
66
|
Asa@18
|
67 threshold = max(threshold, itemCost)
|
Asa@18
|
68 end
|
Asa@18
|
69
|
Asa@19
|
70 threshold = calculateQAThreshold(threshold)
|
Asa@18
|
71
|
Asa@18
|
72 QAAPI:SetGroupThreshold(groupName, ceil(threshold))
|
Asa@18
|
73 end
|
Asa@18
|
74 end
|
Asa@18
|
75
|
Asa@18
|
76 --[[
|
Asa@18
|
77 This is based on KTQ
|
Asa@18
|
78 ]]
|
Asa@18
|
79 function addon:Queue()
|
Asa@18
|
80 if not addon.IsQAEnabled() then
|
Asa@18
|
81 self:Debug("Refusing to run :Queue() QA is disabled")
|
Asa@18
|
82 return
|
Asa@18
|
83 end
|
Asa@18
|
84 if LSW == nil then
|
Asa@18
|
85 self:Print("This feature requires LilSparky's Workshop.")
|
Asa@18
|
86 return
|
Asa@18
|
87 end
|
Asa@20
|
88 self:Debug(format("Auction Threshold: %d%%", self:GetAuctionThreshold()*100 ))
|
Asa@20
|
89 self:Debug(format("Crafting Threshold: %s", self:FormatMoney(self:GetCraftingThreshold())))
|
Asa@18
|
90
|
Asa@18
|
91 for i = 1, GetNumTradeSkills() do
|
Asa@18
|
92 local itemLink = GetTradeSkillItemLink(i)
|
Asa@18
|
93 local itemId = Skillet:GetItemIDFromLink(itemLink)
|
Asa@18
|
94
|
Asa@18
|
95 --Figure out if its an enchant or not
|
Asa@18
|
96 _, _, _, _, altVerb = GetTradeSkillInfo(i)
|
Asa@18
|
97 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then
|
Asa@18
|
98 -- Ask LSW for the correct scroll
|
Asa@18
|
99 itemId = LSW.scrollData[itemId]["scrollID"]
|
Asa@18
|
100 end
|
Asa@18
|
101
|
Asa@18
|
102 local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(i)
|
Asa@18
|
103 local recipeLink = GetTradeSkillRecipeLink(i)
|
Asa@19
|
104 local stackSize = 1
|
Asa@18
|
105 if recipeLink ~= nil then
|
Asa@18
|
106 _, itemLink= GetItemInfo(itemId)
|
Asa@18
|
107 local QAGroup = QAAPI:GetItemGroup(itemLink)
|
Asa@18
|
108 if QAGroup ~= nil then
|
Asa@18
|
109 stackSize = QAAPI:GetGroupPostCap(QAGroup) * QAAPI:GetGroupPerAuction(QAGroup)
|
Asa@18
|
110 stackSize = stackSize / GetTradeSkillNumMade(i)
|
Asa@19
|
111
|
Asa@19
|
112 -- bonus
|
Asa@19
|
113 stackSize = ceil(stackSize *1.25)
|
Asa@18
|
114 end
|
Asa@18
|
115
|
Asa@18
|
116 local count = Altoholic:GetItemCount(itemId)
|
Asa@18
|
117
|
Asa@19
|
118 if count < stackSize and itemLink ~= nil then
|
Asa@18
|
119 local found, _, skillString = string.find(recipeLink, "^|%x+|H(.+)|h%[.+%]")
|
Asa@18
|
120 local _, skillId = strsplit(":", skillString )
|
Asa@18
|
121
|
Asa@19
|
122 local toQueue = stackSize - count
|
Asa@19
|
123 local newCost = 0
|
Asa@18
|
124 for reagentId = 1, GetTradeSkillNumReagents(i) do
|
Asa@18
|
125 _, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId);
|
Asa@18
|
126 reagentLink = GetTradeSkillReagentItemLink(i, reagentId)
|
Asa@19
|
127 newCost = newCost + addon:GetReagentCost(reagentLink, reagentCount)
|
Asa@18
|
128 end
|
Asa@18
|
129
|
Asa@19
|
130 local currentInvested, _, currentCount = addon:GetItemCost(itemLink)
|
Asa@19
|
131 local newThreshold = (newCost + currentInvested) / (currentCount + toQueue)
|
Asa@19
|
132
|
Asa@19
|
133
|
Asa@19
|
134 newThreshold = calculateQAThreshold(newThreshold)
|
Asa@18
|
135 local currentPrice = GetAuctionBuyout(itemLink) or 0
|
Asa@18
|
136
|
Asa@19
|
137
|
Asa@18
|
138 -- bonus?
|
Asa@18
|
139
|
Asa@20
|
140 if newThreshold < currentPrice and (currentPrice - newCost) > self:GetCraftingThreshold() then
|
Asa@19
|
141 self:Debug(format("Adding %s x%s to skillet queue. Profit: %s",
|
Asa@19
|
142 itemLink,
|
Asa@19
|
143 toQueue,
|
Asa@19
|
144 addon:FormatMoney(currentPrice - newThreshold)
|
Asa@19
|
145 ))
|
Asa@18
|
146 self:AddToQueue(skillId,i, toQueue)
|
Asa@20
|
147 elseif ItemAuditor.db.profile.messages.queue_skip then
|
Asa@20
|
148 self:Debug(format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost)))
|
Asa@18
|
149 end
|
Asa@18
|
150 end
|
Asa@18
|
151 end
|
Asa@18
|
152 end
|
Asa@18
|
153
|
Asa@18
|
154
|
Asa@18
|
155 end
|
Asa@18
|
156
|
Asa@18
|
157 function addon:GetReagentCost(link, total)
|
Asa@18
|
158 local totalCost = 0
|
Asa@19
|
159
|
Asa@19
|
160 if Skillet:VendorSellsReagent(link) then
|
Asa@19
|
161 local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link);
|
Asa@19
|
162 totalCost = itemVendorPrice * total
|
Asa@19
|
163 total = 0
|
Asa@19
|
164 end
|
Asa@19
|
165
|
Asa@19
|
166
|
Asa@18
|
167 local investedTotal, investedPerItem, count = addon:GetItemCost(link)
|
Asa@18
|
168
|
Asa@18
|
169 if count > 0 then
|
Asa@18
|
170 if total <= count then
|
Asa@18
|
171 totalCost = investedPerItem * total
|
Asa@18
|
172 total = 0
|
Asa@18
|
173 else
|
Asa@18
|
174 totalCost = investedTotal
|
Asa@18
|
175 total = total - count
|
Asa@18
|
176 end
|
Asa@18
|
177 end
|
Asa@18
|
178
|
Asa@18
|
179 -- If there is none on the auction house, this uses a large enough number
|
Asa@18
|
180 -- to prevent us from trying to make the item.
|
Asa@18
|
181 local ahPrice = (GetAuctionBuyout(link) or 99990000)
|
Asa@18
|
182
|
Asa@18
|
183 return totalCost + (ahPrice * total)
|
Asa@18
|
184 end
|
Asa@18
|
185
|
Asa@18
|
186 function addon:AddToQueue(skillId,skillIndex, toQueue)
|
Asa@18
|
187 if Skillet == nil then
|
Asa@18
|
188 self:Print("Skillet not loaded")
|
Asa@18
|
189 end
|
Asa@18
|
190 if Skillet.QueueCommandIterate ~= nil then
|
Asa@18
|
191 local queueCommand = Skillet:QueueCommandIterate(tonumber(skillId), toQueue)
|
Asa@18
|
192 Skillet:AddToQueue(queueCommand)
|
Asa@18
|
193 else
|
Asa@18
|
194 Skillet.stitch:AddToQueue(skillIndex, toQueue)
|
Asa@18
|
195 end
|
Asa@18
|
196 end
|