annotate Modules/QuickAuctions.lua @ 94:4ec8611d9466

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