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@119: if ItemAuditor:IsQACompatible() then Asa@119: local qam = GetAddOnInfo('QAManager') Asa@119: if qam then Asa@119: ItemAuditor.Options.args.qa_options.disabled = true Asa@119: if ItemAuditor.db.char.use_quick_auctions then Asa@119: ItemAuditor.db.char.use_quick_auctions = false Asa@119: StaticPopupDialogs["ItemAuditor_QAOptionsReplaced"] = { Asa@119: text = "The ability to have ItemAuditor adjust your QA thresholds is being moved to QAManager. If you have to use the options within ItemAuditor you can disable QAManager to restore them for now, but this option will change in the future.", Asa@119: button1 = "OK", Asa@119: timeout = 0, Asa@119: whileDead = true, Asa@119: hideOnEscape = true, Asa@119: OnAccept = function() Asa@119: -- StaticPopupDialogs["ItemAuditor_QAOptionsReplaced"] = nil Asa@119: end, Asa@119: } Asa@119: StaticPopup_Show('ItemAuditor_QAOptionsReplaced') Asa@119: end Asa@119: return false Asa@119: end Asa@119: return ItemAuditor.db.char.use_quick_auctions Asa@119: end Asa@119: return false 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@129: if ItemAuditor:IsQACompatible() 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@112: Asa@112: local QADeciderOptions = { Asa@112: extra = { Asa@112: type = "range", Asa@112: name = "Create Extra", Asa@112: desc = "This is the amount of an item that should be created above what you sell in one post in QuickAuctions.".. Asa@112: "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@112: min = 0.0, Asa@112: max = 1.0, Asa@112: step = 0.01, Asa@112: isPercent = true, Asa@112: get = function() return ItemAuditor.db.char.qa_extra end, Asa@112: set = function(info, value) Asa@112: ItemAuditor.db.char.qa_extra = value Asa@112: end, Asa@129: disabled = function() return not ItemAuditor:IsQACompatible() end, Asa@112: order = 10, Asa@112: }, Asa@112: } Asa@112: Crafting.RegisterCraftingDecider('IA QuickAuctions', isProfitable, QADeciderOptions) 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@153: Asa@153: if not link then Asa@153: return 99990000 Asa@153: end Asa@153: 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@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: }