annotate Modules/QuickAuctions.lua @ 68:2d65db19d3ce

Fixed a bug with the crafting threshold options. Updated /ia queue so that it is a shortcut to using /ia crafting and then clicking export.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 28 Jul 2010 11:37:43 -0700
parents b6c30a5156f9
children 3930518cb8d9
rev   line source
Asa@63 1 local ItemAuditor = select(2, ...)
Asa@63 2 local QuickAuctions= ItemAuditor:NewModule("QuickAuctions")
Asa@64 3 local Crafting = ItemAuditor:GetModule("Crafting")
Asa@68 4 local Utils = ItemAuditor:GetModule("Utils")
Asa@18 5
Asa@62 6 --[[
Asa@62 7 This is simply for compatibility while I change the QA API. Once
Asa@62 8 my changes get merged into the main project, this can go away.
Asa@62 9 ]]
Asa@62 10 if QAAPI ~= nil and QAAPI.GetGroupThreshold ~= nil and QAAPI.GetGroupConfig == nil then
Asa@62 11 function QAAPI:GetGroupConfig(groupName)
Asa@62 12 return QAAPI:GetGroupThreshold(groupName),
Asa@62 13 QAAPI:GetGroupPostCap(groupName),
Asa@62 14 QAAPI:GetGroupPerAuction(groupName)
Asa@62 15 end
Asa@62 16
Asa@62 17 function QAAPI:SetGroupConfig(groupName, key, value)
Asa@62 18 if key == 'threshold' then
Asa@62 19 return QAAPI:SetGroupThreshold(groupName, value)
Asa@62 20 end
Asa@62 21 end
Asa@62 22 end
Asa@62 23
Asa@62 24
Asa@62 25
Asa@63 26 function ItemAuditor:IsQACompatible()
Asa@62 27 return (QAAPI ~= nil and QAAPI.GetGroupConfig ~= nil)
Asa@18 28 end
Asa@18 29
Asa@63 30 function ItemAuditor:IsQAEnabled()
Asa@63 31 return ItemAuditor:IsQACompatible() and ItemAuditor.db.char.use_quick_auctions
Asa@18 32 end
Asa@18 33
Asa@63 34 function ItemAuditor:IsQADisabled()
Asa@18 35 return not self:IsQAEnabled()
Asa@18 36 end
Asa@18 37
Asa@63 38 function ItemAuditor:SetQAEnabled(info, value)
Asa@18 39 ItemAuditor.db.char.use_quick_auctions = value
Asa@18 40 end
Asa@18 41
Asa@63 42 function ItemAuditor:RefreshQAGroups()
Asa@63 43 if not ItemAuditor.IsQAEnabled() then
Asa@18 44 return
Asa@18 45 end
Asa@18 46 for groupName in pairs(QAAPI:GetGroups()) do
Asa@18 47 self:UpdateQAGroup(groupName)
Asa@18 48 end
Asa@18 49 end
Asa@18 50
Asa@63 51 function ItemAuditor:UpdateQAThreshold(link)
Asa@63 52 if not ItemAuditor.IsQAEnabled() then
Asa@18 53 return
Asa@18 54 end
Asa@18 55 _, link= GetItemInfo(link)
Asa@18 56
Asa@18 57 self:UpdateQAGroup(QAAPI:GetItemGroup(link))
Asa@18 58 end
Asa@18 59
Asa@19 60 local function calculateQAThreshold(copper)
Asa@19 61 if copper == 0 then
Asa@19 62 copper = 1
Asa@19 63 end
Asa@19 64
Asa@19 65 -- add my minimum profit margin
Asa@20 66 -- GetAuctionThreshold returns a percent as a whole number. This will convert 25 to 1.25
Asa@63 67 copper = copper * (1+ItemAuditor:GetAuctionThreshold())
Asa@19 68
Asa@19 69 -- add AH Cut
Asa@63 70 local keep = 1 - ItemAuditor:GetAHCut()
Asa@19 71 return copper/keep
Asa@19 72 end
Asa@19 73
Asa@63 74 function ItemAuditor:UpdateQAGroup(groupName)
Asa@63 75 if not ItemAuditor.IsQAEnabled() then
Asa@18 76 return
Asa@18 77 end
Asa@18 78 if groupName then
Asa@18 79 local threshold = 0
Asa@18 80
Asa@18 81 for link in pairs(QAAPI:GetItemsInGroup(groupName)) do
Asa@18 82 local _, itemCost= ItemAuditor:GetItemCost(link, 0)
Asa@18 83
Asa@18 84 threshold = max(threshold, itemCost)
Asa@18 85 end
Asa@18 86
Asa@19 87 threshold = calculateQAThreshold(threshold)
Asa@18 88
Asa@62 89 QAAPI:SetGroupConfig(groupName, 'threshold', ceil(threshold))
Asa@18 90 end
Asa@18 91 end
Asa@18 92
Asa@59 93 local function isProfitable(data)
Asa@63 94 if ItemAuditor.IsQAEnabled() then
Asa@59 95 local QAGroup = QAAPI:GetItemGroup(data.link)
Asa@59 96 if QAGroup ~= nil then
Asa@63 97 local currentInvested, _, currentCount = ItemAuditor:GetItemCost(data.link)
Asa@62 98 local threshold, postCap, perAuction = QAAPI:GetGroupConfig(QAGroup)
Asa@62 99 local stackSize = postCap * perAuction
Asa@59 100
Asa@59 101 stackSize = stackSize / GetTradeSkillNumMade(data.tradeSkillIndex)
Asa@59 102
Asa@59 103 -- bonus
Asa@59 104 stackSize = ceil(stackSize *1.25)
Asa@59 105
Asa@59 106 local newThreshold = ((data.cost*stackSize) + currentInvested) / (currentCount + stackSize)
Asa@59 107 newThreshold = calculateQAThreshold(newThreshold)
Asa@59 108
Asa@59 109 if newThreshold < data.price then
Asa@59 110 return stackSize
Asa@59 111 end
Asa@59 112
Asa@59 113 return -1
Asa@59 114 end
Asa@59 115 end
Asa@59 116 return 0
Asa@59 117 end
Asa@64 118 Crafting.RegisterCraftingDecider('IA QuickAuctions', isProfitable)
Asa@59 119
Asa@68 120
Asa@63 121 function ItemAuditor:Queue()
Asa@68 122 local function Export(data)
Asa@68 123 ItemAuditor:Print(format("Adding %s x%s to skillet queue. Profit: %s",
Asa@68 124 data.link,
Asa@68 125 data.queue,
Asa@68 126 Utils.FormatMoney(data.profit)
Asa@68 127 ))
Asa@68 128 Crafting.ExportToSkillet(data)
Asa@18 129 end
Asa@68 130 ItemAuditor:UpdateCraftingTable()
Asa@68 131 Crafting.Export(Export)
Asa@18 132 end
Asa@18 133
Asa@63 134 function ItemAuditor:GetReagentCost(link, total)
Asa@18 135 local totalCost = 0
Asa@19 136
Asa@19 137 if Skillet:VendorSellsReagent(link) then
Asa@19 138 local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link);
Asa@19 139 totalCost = itemVendorPrice * total
Asa@19 140 total = 0
Asa@19 141 end
Asa@19 142
Asa@19 143
Asa@63 144 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link)
Asa@18 145
Asa@18 146 if count > 0 then
Asa@18 147 if total <= count then
Asa@18 148 totalCost = investedPerItem * total
Asa@18 149 total = 0
Asa@18 150 else
Asa@18 151 totalCost = investedTotal
Asa@18 152 total = total - count
Asa@18 153 end
Asa@18 154 end
Asa@18 155
Asa@18 156 -- If there is none on the auction house, this uses a large enough number
Asa@18 157 -- to prevent us from trying to make the item.
Asa@21 158 local ahPrice = (self:GetAuctionPrice(link) or 99990000)
Asa@21 159 -- local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, _, _, _, _, itemVendorPrice = GetItemInfo (link);
Asa@18 160
Asa@18 161 return totalCost + (ahPrice * total)
Asa@18 162 end
Asa@18 163
Asa@63 164 function ItemAuditor:GetAuctionPrice(itemLink)
Asa@21 165 if GetAuctionBuyout ~= nil then
Asa@21 166 return GetAuctionBuyout(itemLink)
Asa@21 167 elseif AucAdvanced and AucAdvanced.Version then
Asa@21 168 local _, _, _, _, _, lowBuy= AucAdvanced.Modules.Util.SimpleAuction.Private.GetItems(itemLink)
Asa@21 169 return lowBuy
Asa@21 170 end
Asa@21 171 return nil
Asa@21 172 end
Asa@21 173
Asa@63 174 function ItemAuditor:AddToQueue(skillId,skillIndex, toQueue)
Asa@18 175 if Skillet == nil then
Asa@18 176 self:Print("Skillet not loaded")
Asa@21 177 return
Asa@18 178 end
Asa@18 179 if Skillet.QueueCommandIterate ~= nil then
Asa@18 180 local queueCommand = Skillet:QueueCommandIterate(tonumber(skillId), toQueue)
Asa@18 181 Skillet:AddToQueue(queueCommand)
Asa@18 182 else
Asa@18 183 Skillet.stitch:AddToQueue(skillIndex, toQueue)
Asa@18 184 end
Asa@18 185 end
Asa@67 186
Asa@67 187 ItemAuditor.Options.args.qa_options = {
Asa@67 188 name = "QA Options",
Asa@67 189 desc = "Control how ItemAuditor integrates with QuickAuctions",
Asa@67 190 type = 'group',
Asa@67 191 disabled = function() return not ItemAuditor:IsQACompatible() end,
Asa@67 192 args = {
Asa@67 193 toggle_qa = {
Asa@67 194 type = "toggle",
Asa@67 195 name = "Enable Quick Auctions",
Asa@67 196 desc = "This will enable or disable Quick Auctions integration",
Asa@67 197 get = "IsQAEnabled",
Asa@67 198 set = "SetQAEnabled",
Asa@67 199 order = 0,
Asa@67 200 },
Asa@67 201 auction_threshold = {
Asa@67 202 type = "range",
Asa@67 203 name = "Auction Threshold",
Asa@67 204 desc = "Don't create items that will make less than this amount of profit",
Asa@67 205 min = 0.0,
Asa@67 206 max = 1.0,
Asa@67 207 isPercent = true,
Asa@67 208 get = function() return ItemAuditor.db.char.auction_threshold end,
Asa@67 209 set = function(info, value)
Asa@67 210 ItemAuditor.db.char.auction_threshold = value
Asa@67 211 ItemAuditor:RefreshQAGroups()
Asa@67 212 end,
Asa@67 213 disabled = 'IsQADisabled',
Asa@67 214 order = 1,
Asa@67 215 },
Asa@67 216 refresh_qa = {
Asa@67 217 type = "execute",
Asa@67 218 name = "Refresh QA Thresholds",
Asa@67 219 desc = "Resets all Quick Auctions thresholds",
Asa@67 220 func = "RefreshQAGroups",
Asa@67 221 disabled = 'IsQADisabled',
Asa@67 222 order = 9,
Asa@67 223 },
Asa@67 224 }
Asa@67 225 }
Asa@67 226
Asa@67 227 ItemAuditor.Options.args.queue = {
Asa@67 228 type = "execute",
Asa@67 229 name = "queue",
Asa@67 230 desc = "Queue",
Asa@67 231 func = "Queue",
Asa@67 232 guiHidden = true,
Asa@67 233 }