Asa@63: local ItemAuditor = select(2, ...) Asa@63: local QuickAuctions= ItemAuditor:NewModule("QuickAuctions") Asa@64: local Crafting = ItemAuditor:GetModule("Crafting") Asa@68: local Utils = ItemAuditor:GetModule("Utils") Asa@89: local AuctionHouse = ItemAuditor:GetModule("AuctionHouse") Asa@18: Asa@86: local PT = LibStub("LibPeriodicTable-3.1") Asa@86: Asa@62: --[[ Asa@62: This is simply for compatibility while I change the QA API. Once Asa@62: my changes get merged into the main project, this can go away. Asa@62: ]] Asa@62: if QAAPI ~= nil and QAAPI.GetGroupThreshold ~= nil and QAAPI.GetGroupConfig == nil then Asa@62: function QAAPI:GetGroupConfig(groupName) Asa@62: return QAAPI:GetGroupThreshold(groupName), Asa@62: QAAPI:GetGroupPostCap(groupName), Asa@62: QAAPI:GetGroupPerAuction(groupName) Asa@62: end Asa@62: Asa@62: function QAAPI:SetGroupConfig(groupName, key, value) Asa@62: if key == 'threshold' then Asa@62: return QAAPI:SetGroupThreshold(groupName, value) Asa@62: end Asa@62: end Asa@62: end Asa@62: Asa@62: Asa@62: Asa@63: function ItemAuditor:IsQACompatible() Asa@62: return (QAAPI ~= nil and QAAPI.GetGroupConfig ~= nil) Asa@18: end Asa@18: Asa@63: function ItemAuditor:IsQAEnabled() Asa@63: return ItemAuditor:IsQACompatible() and ItemAuditor.db.char.use_quick_auctions Asa@18: end Asa@18: Asa@63: function ItemAuditor:IsQADisabled() Asa@18: return not self:IsQAEnabled() Asa@18: end Asa@18: Asa@63: function ItemAuditor:SetQAEnabled(info, value) Asa@18: ItemAuditor.db.char.use_quick_auctions = value Asa@18: end Asa@18: Asa@63: function ItemAuditor:RefreshQAGroups() Asa@63: if not ItemAuditor.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@63: function ItemAuditor:UpdateQAThreshold(link) Asa@63: if not ItemAuditor.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: 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@111: local min_by_percent = copper * (1+ItemAuditor:GetAuctionThreshold()) Asa@111: local min_by_value = copper + ItemAuditor.db.char.auction_threshold_value Asa@111: copper = max(min_by_percent, min_by_value) Asa@19: Asa@19: -- add AH Cut Asa@63: local keep = 1 - ItemAuditor:GetAHCut() Asa@19: return copper/keep Asa@19: end Asa@19: Asa@63: function ItemAuditor:UpdateQAGroup(groupName) Asa@63: if not ItemAuditor.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@62: QAAPI:SetGroupConfig(groupName, 'threshold', ceil(threshold)) Asa@18: end Asa@18: end Asa@18: Asa@59: local function isProfitable(data) Asa@63: if ItemAuditor.IsQAEnabled() then Asa@59: local QAGroup = QAAPI:GetItemGroup(data.link) Asa@59: if QAGroup ~= nil then Asa@63: local currentInvested, _, currentCount = ItemAuditor:GetItemCost(data.link) Asa@62: local threshold, postCap, perAuction = QAAPI:GetGroupConfig(QAGroup) Asa@62: local stackSize = postCap * perAuction Asa@59: Asa@59: -- bonus Asa@71: stackSize = ceil(stackSize * (1+ItemAuditor.db.char.qa_extra)) Asa@77: local target = stackSize Asa@77: stackSize = stackSize - currentCount Asa@59: Asa@59: local newThreshold = ((data.cost*stackSize) + currentInvested) / (currentCount + stackSize) Asa@59: newThreshold = calculateQAThreshold(newThreshold) Asa@59: Asa@59: if newThreshold < data.price then Asa@77: return target Asa@59: end Asa@59: Asa@59: return -1 Asa@59: end Asa@59: end Asa@59: return 0 Asa@59: end Asa@64: Crafting.RegisterCraftingDecider('IA QuickAuctions', isProfitable) Asa@59: Asa@68: Asa@63: function ItemAuditor:Queue() Asa@70: local dest, name = Crafting.GetQueueDestination() Asa@68: local function Export(data) Asa@70: ItemAuditor:Print(format("Adding %s x%s to %s queue. Profit: %s", Asa@68: data.link, Asa@68: data.queue, Asa@70: name, Asa@68: Utils.FormatMoney(data.profit) Asa@68: )) Asa@70: dest(data) Asa@18: end Asa@68: ItemAuditor:UpdateCraftingTable() Asa@68: Crafting.Export(Export) Asa@18: end Asa@18: Asa@63: function ItemAuditor:GetReagentCost(link, total) Asa@18: local totalCost = 0 Asa@19: Asa@86: if PT:ItemInSet(link,"Tradeskill.Mat.BySource.Vendor") then Asa@19: local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link); Asa@19: totalCost = itemVendorPrice * total Asa@19: total = 0 Asa@19: end Asa@19: Asa@19: Asa@63: local investedTotal, investedPerItem, count = ItemAuditor: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@63: function ItemAuditor:GetAuctionPrice(itemLink) Asa@89: return AuctionHouse:GetAuctionPrice(itemLink) Asa@21: end Asa@21: Asa@63: function ItemAuditor: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 Asa@67: Asa@67: ItemAuditor.Options.args.qa_options = { Asa@67: name = "QA Options", Asa@67: desc = "Control how ItemAuditor integrates with QuickAuctions", Asa@67: type = 'group', Asa@67: disabled = function() return not ItemAuditor:IsQACompatible() end, Asa@67: args = { Asa@67: toggle_qa = { Asa@67: type = "toggle", Asa@67: name = "Enable Quick Auctions", Asa@67: desc = "This will enable or disable Quick Auctions integration", Asa@67: get = "IsQAEnabled", Asa@67: set = "SetQAEnabled", Asa@67: order = 0, Asa@67: }, Asa@111: enable_percent = { Asa@111: type = "toggle", Asa@111: name = "Use percent to calculate threshold.", Asa@111: get = function() return ItemAuditor.db.char.auction_threshold > 0 end, Asa@111: set = function(info, value) Asa@111: value = value and 0.15 or 0 Asa@111: ItemAuditor.db.char.auction_threshold = value Asa@111: end, Asa@111: order = 1, Asa@111: }, Asa@67: auction_threshold = { Asa@67: type = "range", Asa@67: name = "Auction Threshold", Asa@111: desc = "Don't sell items for less than this amount of profit.", Asa@67: min = 0.0, Asa@67: max = 1.0, Asa@67: isPercent = true, Asa@111: hidden = function() return ItemAuditor.db.char.auction_threshold == 0 end, Asa@67: get = function() return ItemAuditor.db.char.auction_threshold end, Asa@67: set = function(info, value) Asa@67: ItemAuditor.db.char.auction_threshold = value Asa@71: -- ItemAuditor:RefreshQAGroups() Asa@71: end, Asa@71: disabled = 'IsQADisabled', Asa@111: order = 2, Asa@111: }, Asa@111: enable_absolute = { Asa@111: type = "toggle", Asa@111: name = "Use value to calculate threshold.", Asa@111: get = function() return ItemAuditor.db.char.auction_threshold_value > 0 end, Asa@111: set = function(info, value) Asa@111: value = value and 100000 or 0 Asa@111: ItemAuditor.db.char.auction_threshold_value = value Asa@111: end, Asa@111: order = 3, Asa@111: }, Asa@111: auction_threshold_absolute = { Asa@111: type = "input", Asa@111: name = "Auction Threshold", Asa@111: desc = "Don't sell items for less than this amount of profit.", Asa@111: hidden = function() return ItemAuditor.db.char.auction_threshold_value == 0 end, Asa@111: get = function() return Asa@111: Utils.FormatMoney(ItemAuditor.db.char.auction_threshold_value , '', true) Asa@111: end, Asa@111: validate = function(info, value) Asa@111: if not Utils.validateMoney(value) then Asa@111: return "Invalid money format" Asa@111: end Asa@111: return true Asa@111: end, Asa@111: set = function(info, value) Asa@111: ItemAuditor.db.char.auction_threshold_value = Utils.parseMoney(value) Asa@111: end, Asa@111: usage = "###g ##s ##c", Asa@111: disabled = 'IsQADisabled', Asa@111: order = 4, Asa@111: }, Asa@111: header = { Asa@111: type = 'header', Asa@111: name = '', Asa@111: order = 9, Asa@71: }, Asa@71: extra = { Asa@71: type = "range", Asa@71: name = "Create Extra", Asa@71: desc = "This is the amount of an item that should be created above what you sell in one post in QuickAuctions.".. Asa@71: "If you sell 4 stacks of 5 of an item and your extra is 25%, it will queue enough for you to have 25 of that item.", Asa@71: min = 0.0, Asa@71: max = 1.0, Asa@71: isPercent = true, Asa@71: get = function() return ItemAuditor.db.char.qa_extra end, Asa@71: set = function(info, value) Asa@71: ItemAuditor.db.char.qa_extra = value Asa@67: end, Asa@67: disabled = 'IsQADisabled', Asa@111: order = 10, Asa@67: }, Asa@67: refresh_qa = { Asa@67: type = "execute", Asa@67: name = "Refresh QA Thresholds", Asa@67: desc = "Resets all Quick Auctions thresholds", Asa@67: func = "RefreshQAGroups", Asa@67: disabled = 'IsQADisabled', Asa@111: order = 15, Asa@67: }, Asa@67: } Asa@67: } Asa@67: Asa@67: ItemAuditor.Options.args.queue = { Asa@67: type = "execute", Asa@67: name = "queue", Asa@67: desc = "Queue", Asa@67: func = "Queue", Asa@67: guiHidden = true, Asa@67: }