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 addon.minimum_profit = 50000
|
Asa@19
|
40
|
Asa@19
|
41 local function calculateQAThreshold(copper)
|
Asa@19
|
42 if copper == 0 then
|
Asa@19
|
43 copper = 1
|
Asa@19
|
44 end
|
Asa@19
|
45
|
Asa@19
|
46 -- add my minimum profit margin
|
Asa@19
|
47 copper = copper * addon.profit_margin
|
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@18
|
88
|
Asa@18
|
89 for i = 1, GetNumTradeSkills() do
|
Asa@18
|
90 local itemLink = GetTradeSkillItemLink(i)
|
Asa@18
|
91 local itemId = Skillet:GetItemIDFromLink(itemLink)
|
Asa@18
|
92
|
Asa@18
|
93 --Figure out if its an enchant or not
|
Asa@18
|
94 _, _, _, _, altVerb = GetTradeSkillInfo(i)
|
Asa@18
|
95 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then
|
Asa@18
|
96 -- Ask LSW for the correct scroll
|
Asa@18
|
97 itemId = LSW.scrollData[itemId]["scrollID"]
|
Asa@18
|
98 end
|
Asa@18
|
99
|
Asa@18
|
100 local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(i)
|
Asa@18
|
101 local recipeLink = GetTradeSkillRecipeLink(i)
|
Asa@19
|
102 local stackSize = 1
|
Asa@18
|
103 if recipeLink ~= nil then
|
Asa@18
|
104 _, itemLink= GetItemInfo(itemId)
|
Asa@18
|
105 local QAGroup = QAAPI:GetItemGroup(itemLink)
|
Asa@18
|
106 if QAGroup ~= nil then
|
Asa@18
|
107 stackSize = QAAPI:GetGroupPostCap(QAGroup) * QAAPI:GetGroupPerAuction(QAGroup)
|
Asa@18
|
108 stackSize = stackSize / GetTradeSkillNumMade(i)
|
Asa@19
|
109
|
Asa@19
|
110 -- bonus
|
Asa@19
|
111 stackSize = ceil(stackSize *1.25)
|
Asa@18
|
112 end
|
Asa@18
|
113
|
Asa@18
|
114 local count = Altoholic:GetItemCount(itemId)
|
Asa@18
|
115
|
Asa@19
|
116 if count < stackSize and itemLink ~= nil then
|
Asa@18
|
117 local found, _, skillString = string.find(recipeLink, "^|%x+|H(.+)|h%[.+%]")
|
Asa@18
|
118 local _, skillId = strsplit(":", skillString )
|
Asa@18
|
119
|
Asa@19
|
120 local toQueue = stackSize - count
|
Asa@19
|
121 local newCost = 0
|
Asa@18
|
122 for reagentId = 1, GetTradeSkillNumReagents(i) do
|
Asa@18
|
123 _, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId);
|
Asa@18
|
124 reagentLink = GetTradeSkillReagentItemLink(i, reagentId)
|
Asa@19
|
125 newCost = newCost + addon:GetReagentCost(reagentLink, reagentCount)
|
Asa@18
|
126 end
|
Asa@18
|
127
|
Asa@19
|
128 local currentInvested, _, currentCount = addon:GetItemCost(itemLink)
|
Asa@19
|
129 local newThreshold = (newCost + currentInvested) / (currentCount + toQueue)
|
Asa@19
|
130
|
Asa@19
|
131
|
Asa@19
|
132 newThreshold = calculateQAThreshold(newThreshold)
|
Asa@18
|
133 local currentPrice = GetAuctionBuyout(itemLink) or 0
|
Asa@18
|
134
|
Asa@19
|
135
|
Asa@18
|
136 -- bonus?
|
Asa@18
|
137
|
Asa@19
|
138 if newThreshold < currentPrice and (currentPrice - newThreshold) > addon.minimum_profit then
|
Asa@19
|
139 self:Debug(format("Adding %s x%s to skillet queue. Profit: %s",
|
Asa@19
|
140 itemLink,
|
Asa@19
|
141 toQueue,
|
Asa@19
|
142 addon:FormatMoney(currentPrice - newThreshold)
|
Asa@19
|
143 ))
|
Asa@18
|
144 self:AddToQueue(skillId,i, toQueue)
|
Asa@18
|
145 else
|
Asa@19
|
146 self:Debug(format("Skipping %s x%s. Would lose %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newThreshold)))
|
Asa@18
|
147 end
|
Asa@18
|
148 end
|
Asa@18
|
149 end
|
Asa@18
|
150 end
|
Asa@18
|
151
|
Asa@18
|
152
|
Asa@18
|
153 end
|
Asa@18
|
154
|
Asa@18
|
155 function addon:GetReagentCost(link, total)
|
Asa@18
|
156 local totalCost = 0
|
Asa@19
|
157
|
Asa@19
|
158 if Skillet:VendorSellsReagent(link) then
|
Asa@19
|
159 local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link);
|
Asa@19
|
160 totalCost = itemVendorPrice * total
|
Asa@19
|
161 total = 0
|
Asa@19
|
162 end
|
Asa@19
|
163
|
Asa@19
|
164
|
Asa@18
|
165 local investedTotal, investedPerItem, count = addon:GetItemCost(link)
|
Asa@18
|
166
|
Asa@18
|
167 if count > 0 then
|
Asa@18
|
168 if total <= count then
|
Asa@18
|
169 totalCost = investedPerItem * total
|
Asa@18
|
170 total = 0
|
Asa@18
|
171 else
|
Asa@18
|
172 totalCost = investedTotal
|
Asa@18
|
173 total = total - count
|
Asa@18
|
174 end
|
Asa@18
|
175 end
|
Asa@18
|
176
|
Asa@18
|
177 -- If there is none on the auction house, this uses a large enough number
|
Asa@18
|
178 -- to prevent us from trying to make the item.
|
Asa@18
|
179 local ahPrice = (GetAuctionBuyout(link) or 99990000)
|
Asa@18
|
180
|
Asa@18
|
181 return totalCost + (ahPrice * total)
|
Asa@18
|
182 end
|
Asa@18
|
183
|
Asa@18
|
184 function addon:AddToQueue(skillId,skillIndex, toQueue)
|
Asa@18
|
185 if Skillet == nil then
|
Asa@18
|
186 self:Print("Skillet not loaded")
|
Asa@18
|
187 end
|
Asa@18
|
188 if Skillet.QueueCommandIterate ~= nil then
|
Asa@18
|
189 local queueCommand = Skillet:QueueCommandIterate(tonumber(skillId), toQueue)
|
Asa@18
|
190 Skillet:AddToQueue(queueCommand)
|
Asa@18
|
191 else
|
Asa@18
|
192 Skillet.stitch:AddToQueue(skillIndex, toQueue)
|
Asa@18
|
193 end
|
Asa@18
|
194 end
|