Asa@18: local addonName, addonTable = ...; Asa@18: local addon = _G[addonName] Asa@18: Asa@18: function addon:IsQACompatible() Asa@18: return (QAAPI ~= nil and QAAPI.GetGroups ~= nil) Asa@18: end Asa@18: Asa@18: function addon:IsQAEnabled() Asa@18: return addon:IsQACompatible() and ItemAuditor.db.char.use_quick_auctions Asa@18: end Asa@18: Asa@18: function addon:IsQADisabled() Asa@18: return not self:IsQAEnabled() Asa@18: end Asa@18: Asa@18: function addon:SetQAEnabled(info, value) Asa@18: ItemAuditor.db.char.use_quick_auctions = value Asa@18: end Asa@18: Asa@18: function addon:RefreshQAGroups() Asa@18: if not addon.IsQAEnabled() then Asa@18: return Asa@18: end Asa@18: for groupName in pairs(QAAPI:GetGroups()) do Asa@18: self:UpdateQAGroup(groupName) Asa@18: end Asa@18: end Asa@18: Asa@18: function addon:UpdateQAThreshold(link) Asa@18: if not addon.IsQAEnabled() then Asa@18: return Asa@18: end Asa@18: _, link= GetItemInfo(link) Asa@18: Asa@18: self:UpdateQAGroup(QAAPI:GetItemGroup(link)) Asa@18: end Asa@18: Asa@19: addon.profit_margin = 1.15 Asa@19: Asa@19: local function calculateQAThreshold(copper) Asa@19: if copper == 0 then Asa@19: copper = 1 Asa@19: end Asa@19: Asa@19: -- add my minimum profit margin Asa@20: -- GetAuctionThreshold returns a percent as a whole number. This will convert 25 to 1.25 Asa@20: copper = copper * (1+addon:GetAuctionThreshold()) Asa@19: Asa@19: -- Adding the cost of mailing every item once. Asa@19: copper = copper + 30 Asa@19: Asa@19: -- add AH Cut Asa@19: local keep = 1 - addon:GetAHCut() Asa@19: return copper/keep Asa@19: end Asa@19: Asa@18: function addon:UpdateQAGroup(groupName) Asa@18: if not addon.IsQAEnabled() then Asa@18: return Asa@18: end Asa@18: if groupName then Asa@18: local threshold = 0 Asa@18: Asa@18: for link in pairs(QAAPI:GetItemsInGroup(groupName)) do Asa@18: local _, itemCost= ItemAuditor:GetItemCost(link, 0) Asa@18: Asa@18: threshold = max(threshold, itemCost) Asa@18: end Asa@18: Asa@19: threshold = calculateQAThreshold(threshold) Asa@18: Asa@18: QAAPI:SetGroupThreshold(groupName, ceil(threshold)) Asa@18: end Asa@18: end Asa@18: Asa@18: --[[ Asa@18: This is based on KTQ Asa@18: ]] Asa@18: function addon:Queue() Asa@18: if LSW == nil then Asa@18: self:Print("This feature requires LilSparky's Workshop.") Asa@18: return Asa@18: end Asa@21: if Skillet == nil then Asa@21: self:Print("This feature requires Skillet.") Asa@21: return Asa@21: end Asa@21: if GetAuctionBuyout ~= nil then Asa@21: elseif AucAdvanced and AucAdvanced.Version then Asa@21: else Asa@21: self:Print("This feature requires Auctionator, Auctioneer, AuctionLite, or AuctionMaster.") Asa@21: return Asa@21: end Asa@21: Asa@21: Asa@21: if addon.IsQAEnabled() then Asa@24: self:Debug("Auction Threshold: %d%%", self:GetAuctionThreshold()*100 ) Asa@21: end Asa@20: self:Debug(format("Crafting Threshold: %s", self:FormatMoney(self:GetCraftingThreshold()))) Asa@21: local profitableItems = {} Asa@21: local profitableIndex = 1 Asa@21: local numChecked = 0 Asa@18: Asa@18: for i = 1, GetNumTradeSkills() do Asa@18: local itemLink = GetTradeSkillItemLink(i) Asa@18: local itemId = Skillet:GetItemIDFromLink(itemLink) Asa@18: Asa@18: --Figure out if its an enchant or not Asa@18: _, _, _, _, altVerb = GetTradeSkillInfo(i) Asa@18: if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then Asa@18: -- Ask LSW for the correct scroll Asa@18: itemId = LSW.scrollData[itemId]["scrollID"] Asa@18: end Asa@18: Asa@18: local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(i) Asa@18: local recipeLink = GetTradeSkillRecipeLink(i) Asa@19: local stackSize = 1 Asa@18: if recipeLink ~= nil then Asa@18: _, itemLink= GetItemInfo(itemId) Asa@21: Asa@21: Asa@21: -- if QA isn't enabled, this will just return nil Asa@21: local QAGroup = nil Asa@21: if addon.IsQAEnabled() then Asa@21: QAGroup = QAAPI:GetItemGroup(itemLink) Asa@21: if QAGroup ~= nil then Asa@21: stackSize = QAAPI:GetGroupPostCap(QAGroup) * QAAPI:GetGroupPerAuction(QAGroup) Asa@21: stackSize = stackSize / GetTradeSkillNumMade(i) Asa@21: Asa@21: -- bonus Asa@21: stackSize = ceil(stackSize *1.25) Asa@21: end Asa@18: end Asa@21: Asa@18: local count = Altoholic:GetItemCount(itemId) Asa@18: Asa@19: if count < stackSize and itemLink ~= nil then Asa@18: local found, _, skillString = string.find(recipeLink, "^|%x+|H(.+)|h%[.+%]") Asa@18: local _, skillId = strsplit(":", skillString ) Asa@18: Asa@19: local toQueue = stackSize - count Asa@19: local newCost = 0 Asa@18: for reagentId = 1, GetTradeSkillNumReagents(i) do Asa@18: _, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId); Asa@18: reagentLink = GetTradeSkillReagentItemLink(i, reagentId) Asa@19: newCost = newCost + addon:GetReagentCost(reagentLink, reagentCount) Asa@18: end Asa@18: Asa@19: local currentInvested, _, currentCount = addon:GetItemCost(itemLink) Asa@19: local newThreshold = (newCost + currentInvested) / (currentCount + toQueue) Asa@19: Asa@21: if addon.IsQAEnabled() then Asa@21: newThreshold = calculateQAThreshold(newThreshold) Asa@21: else Asa@21: -- if quick auctions isn't enabled, this will cause the decision to rely Asa@21: -- completly on the crafting threshold Asa@21: newThreshold = 0 Asa@21: end Asa@21: local currentPrice = addon:GetAuctionPrice(itemLink) or 0 Asa@21: numChecked = numChecked + 1 Asa@18: Asa@20: if newThreshold < currentPrice and (currentPrice - newCost) > self:GetCraftingThreshold() then Asa@21: Asa@21: profitableItems[profitableIndex] = { Asa@21: itemLink = itemLink, Asa@21: SkillID = skillId, Asa@21: Index = i, Asa@21: toQueue = toQueue, Asa@21: profit = (currentPrice - newCost) * toQueue Asa@21: } Asa@21: profitableIndex = profitableIndex + 1 Asa@23: else Asa@23: local skipMessage = format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost)) Asa@23: if ItemAuditor.db.profile.messages.queue_skip then Asa@23: self:Print(skipMessage) Asa@23: else Asa@23: self:Debug(format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost))) Asa@23: end Asa@18: end Asa@18: end Asa@21: end Asa@18: end Asa@21: local numAdded = 0 Asa@21: table.sort(profitableItems, function(a, b) return a.profit > b.profit end) Asa@21: for key, data in pairs(profitableItems) do Asa@21: self:Print(format("Adding %s x%s to skillet queue. Profit: %s", Asa@21: data.itemLink, Asa@21: data.toQueue, Asa@21: self:FormatMoney(data.profit) Asa@21: )) Asa@21: self:AddToQueue(data.SkillID, data.Index, data.toQueue) Asa@21: numAdded = numAdded +1 Asa@21: end Asa@21: self:Print(format("%d items checked", numChecked)) Asa@21: self:Print(format("%d queued", numAdded)) Asa@18: end Asa@18: Asa@18: function addon:GetReagentCost(link, total) Asa@18: local totalCost = 0 Asa@19: Asa@19: if Skillet:VendorSellsReagent(link) then Asa@19: local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link); Asa@19: totalCost = itemVendorPrice * total Asa@19: total = 0 Asa@19: end Asa@19: Asa@19: Asa@18: local investedTotal, investedPerItem, count = addon:GetItemCost(link) Asa@18: Asa@18: if count > 0 then Asa@18: if total <= count then Asa@18: totalCost = investedPerItem * total Asa@18: total = 0 Asa@18: else Asa@18: totalCost = investedTotal Asa@18: total = total - count Asa@18: end Asa@18: end Asa@18: Asa@18: -- If there is none on the auction house, this uses a large enough number Asa@18: -- to prevent us from trying to make the item. Asa@21: local ahPrice = (self:GetAuctionPrice(link) or 99990000) Asa@21: -- local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, _, _, _, _, itemVendorPrice = GetItemInfo (link); Asa@18: Asa@18: return totalCost + (ahPrice * total) Asa@18: end Asa@18: Asa@21: function addon:GetAuctionPrice(itemLink) Asa@21: if GetAuctionBuyout ~= nil then Asa@21: return GetAuctionBuyout(itemLink) Asa@21: elseif AucAdvanced and AucAdvanced.Version then Asa@21: local _, _, _, _, _, lowBuy= AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems(itemLink) Asa@21: return lowBuy Asa@21: end Asa@21: return nil Asa@21: end Asa@21: Asa@18: function addon:AddToQueue(skillId,skillIndex, toQueue) Asa@18: if Skillet == nil then Asa@18: self:Print("Skillet not loaded") Asa@21: return Asa@18: end Asa@18: if Skillet.QueueCommandIterate ~= nil then Asa@18: local queueCommand = Skillet:QueueCommandIterate(tonumber(skillId), toQueue) Asa@18: Skillet:AddToQueue(queueCommand) Asa@18: else Asa@18: Skillet.stitch:AddToQueue(skillIndex, toQueue) Asa@18: end Asa@18: end