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 not addon.IsQAEnabled() then Asa@18: self:Debug("Refusing to run :Queue() QA is disabled") Asa@18: return Asa@18: end Asa@18: if LSW == nil then Asa@18: self:Print("This feature requires LilSparky's Workshop.") Asa@18: return Asa@18: end Asa@20: self:Debug(format("Auction Threshold: %d%%", self:GetAuctionThreshold()*100 )) Asa@20: self:Debug(format("Crafting Threshold: %s", self:FormatMoney(self:GetCraftingThreshold()))) 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@18: local QAGroup = QAAPI:GetItemGroup(itemLink) Asa@18: if QAGroup ~= nil then Asa@18: stackSize = QAAPI:GetGroupPostCap(QAGroup) * QAAPI:GetGroupPerAuction(QAGroup) Asa@18: stackSize = stackSize / GetTradeSkillNumMade(i) Asa@19: Asa@19: -- bonus Asa@19: stackSize = ceil(stackSize *1.25) Asa@18: end Asa@18: 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@19: Asa@19: newThreshold = calculateQAThreshold(newThreshold) Asa@18: local currentPrice = GetAuctionBuyout(itemLink) or 0 Asa@18: Asa@19: Asa@18: -- bonus? Asa@18: Asa@20: if newThreshold < currentPrice and (currentPrice - newCost) > self:GetCraftingThreshold() then Asa@19: self:Debug(format("Adding %s x%s to skillet queue. Profit: %s", Asa@19: itemLink, Asa@19: toQueue, Asa@19: addon:FormatMoney(currentPrice - newThreshold) Asa@19: )) Asa@18: self:AddToQueue(skillId,i, toQueue) Asa@20: elseif ItemAuditor.db.profile.messages.queue_skip then Asa@20: self:Debug(format("Skipping %s x%s. Profit: %s ", itemLink, toQueue, addon:FormatMoney(currentPrice - newCost))) Asa@18: end Asa@18: end Asa@18: end Asa@18: end Asa@18: Asa@18: 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@18: local ahPrice = (GetAuctionBuyout(link) or 99990000) Asa@18: Asa@18: return totalCost + (ahPrice * total) Asa@18: end Asa@18: Asa@18: function addon:AddToQueue(skillId,skillIndex, toQueue) Asa@18: if Skillet == nil then Asa@18: self:Print("Skillet not loaded") 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