annotate Modules/QuickAuctions.lua @ 112:619ee0a1ff3b

[mq]: QAManagerIntegration
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 01 Sep 2010 23:21:44 -0700
parents 1cb0027da35c
children d94195157a6b
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@112 30 local qam = GetAddOnInfo('QAManager')
Asa@112 31 if qam then
Asa@112 32 ItemAuditor.Options.args.qa_options.disabled = true
Asa@112 33 if ItemAuditor.db.char.use_quick_auctions then
Asa@112 34 ItemAuditor.db.char.use_quick_auctions = false
Asa@112 35 StaticPopupDialogs["ItemAuditor_QAOptionsReplaced"] = {
Asa@112 36 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@112 37 button1 = "OK",
Asa@112 38 timeout = 0,
Asa@112 39 whileDead = true,
Asa@112 40 hideOnEscape = true,
Asa@112 41 OnAccept = function()
Asa@112 42 -- StaticPopupDialogs["ItemAuditor_QAOptionsReplaced"] = nil
Asa@112 43 end,
Asa@112 44 }
Asa@112 45 StaticPopup_Show('ItemAuditor_QAOptionsReplaced')
Asa@112 46 end
Asa@112 47 return false
Asa@112 48 end
Asa@62 49 return (QAAPI ~= nil and QAAPI.GetGroupConfig ~= nil)
Asa@18 50 end
Asa@18 51
Asa@63 52 function ItemAuditor:IsQAEnabled()
Asa@63 53 return ItemAuditor:IsQACompatible() and ItemAuditor.db.char.use_quick_auctions
Asa@18 54 end
Asa@18 55
Asa@63 56 function ItemAuditor:IsQADisabled()
Asa@18 57 return not self:IsQAEnabled()
Asa@18 58 end
Asa@18 59
Asa@63 60 function ItemAuditor:SetQAEnabled(info, value)
Asa@18 61 ItemAuditor.db.char.use_quick_auctions = value
Asa@18 62 end
Asa@18 63
Asa@63 64 function ItemAuditor:RefreshQAGroups()
Asa@63 65 if not ItemAuditor.IsQAEnabled() then
Asa@18 66 return
Asa@18 67 end
Asa@18 68 for groupName in pairs(QAAPI:GetGroups()) do
Asa@18 69 self:UpdateQAGroup(groupName)
Asa@18 70 end
Asa@18 71 end
Asa@18 72
Asa@63 73 function ItemAuditor:UpdateQAThreshold(link)
Asa@63 74 if not ItemAuditor.IsQAEnabled() then
Asa@18 75 return
Asa@18 76 end
Asa@18 77 _, link= GetItemInfo(link)
Asa@18 78
Asa@18 79 self:UpdateQAGroup(QAAPI:GetItemGroup(link))
Asa@18 80 end
Asa@18 81
Asa@19 82 local function calculateQAThreshold(copper)
Asa@19 83 if copper == 0 then
Asa@19 84 copper = 1
Asa@19 85 end
Asa@19 86
Asa@19 87 -- add my minimum profit margin
Asa@20 88 -- GetAuctionThreshold returns a percent as a whole number. This will convert 25 to 1.25
Asa@111 89 local min_by_percent = copper * (1+ItemAuditor:GetAuctionThreshold())
Asa@111 90 local min_by_value = copper + ItemAuditor.db.char.auction_threshold_value
Asa@111 91 copper = max(min_by_percent, min_by_value)
Asa@19 92
Asa@19 93 -- add AH Cut
Asa@63 94 local keep = 1 - ItemAuditor:GetAHCut()
Asa@19 95 return copper/keep
Asa@19 96 end
Asa@19 97
Asa@63 98 function ItemAuditor:UpdateQAGroup(groupName)
Asa@63 99 if not ItemAuditor.IsQAEnabled() then
Asa@18 100 return
Asa@18 101 end
Asa@18 102 if groupName then
Asa@18 103 local threshold = 0
Asa@18 104
Asa@18 105 for link in pairs(QAAPI:GetItemsInGroup(groupName)) do
Asa@18 106 local _, itemCost= ItemAuditor:GetItemCost(link, 0)
Asa@18 107
Asa@18 108 threshold = max(threshold, itemCost)
Asa@18 109 end
Asa@18 110
Asa@19 111 threshold = calculateQAThreshold(threshold)
Asa@18 112
Asa@62 113 QAAPI:SetGroupConfig(groupName, 'threshold', ceil(threshold))
Asa@18 114 end
Asa@18 115 end
Asa@18 116
Asa@59 117 local function isProfitable(data)
Asa@63 118 if ItemAuditor.IsQAEnabled() then
Asa@59 119 local QAGroup = QAAPI:GetItemGroup(data.link)
Asa@59 120 if QAGroup ~= nil then
Asa@63 121 local currentInvested, _, currentCount = ItemAuditor:GetItemCost(data.link)
Asa@62 122 local threshold, postCap, perAuction = QAAPI:GetGroupConfig(QAGroup)
Asa@62 123 local stackSize = postCap * perAuction
Asa@59 124
Asa@59 125 -- bonus
Asa@71 126 stackSize = ceil(stackSize * (1+ItemAuditor.db.char.qa_extra))
Asa@77 127 local target = stackSize
Asa@77 128 stackSize = stackSize - currentCount
Asa@59 129
Asa@59 130 local newThreshold = ((data.cost*stackSize) + currentInvested) / (currentCount + stackSize)
Asa@59 131 newThreshold = calculateQAThreshold(newThreshold)
Asa@59 132
Asa@59 133 if newThreshold < data.price then
Asa@77 134 return target
Asa@59 135 end
Asa@59 136
Asa@59 137 return -1
Asa@59 138 end
Asa@59 139 end
Asa@59 140 return 0
Asa@59 141 end
Asa@112 142
Asa@112 143 local QADeciderOptions = {
Asa@112 144 extra = {
Asa@112 145 type = "range",
Asa@112 146 name = "Create Extra",
Asa@112 147 desc = "This is the amount of an item that should be created above what you sell in one post in QuickAuctions."..
Asa@112 148 "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 149 min = 0.0,
Asa@112 150 max = 1.0,
Asa@112 151 step = 0.01,
Asa@112 152 isPercent = true,
Asa@112 153 get = function() return ItemAuditor.db.char.qa_extra end,
Asa@112 154 set = function(info, value)
Asa@112 155 ItemAuditor.db.char.qa_extra = value
Asa@112 156 end,
Asa@112 157 handler = ItemAuditor,
Asa@112 158 disabled = 'IsQACompatible',
Asa@112 159 order = 10,
Asa@112 160 },
Asa@112 161 }
Asa@112 162 Crafting.RegisterCraftingDecider('IA QuickAuctions', isProfitable, QADeciderOptions)
Asa@59 163
Asa@68 164
Asa@63 165 function ItemAuditor:Queue()
Asa@70 166 local dest, name = Crafting.GetQueueDestination()
Asa@68 167 local function Export(data)
Asa@70 168 ItemAuditor:Print(format("Adding %s x%s to %s queue. Profit: %s",
Asa@68 169 data.link,
Asa@68 170 data.queue,
Asa@70 171 name,
Asa@68 172 Utils.FormatMoney(data.profit)
Asa@68 173 ))
Asa@70 174 dest(data)
Asa@18 175 end
Asa@68 176 ItemAuditor:UpdateCraftingTable()
Asa@68 177 Crafting.Export(Export)
Asa@18 178 end
Asa@18 179
Asa@63 180 function ItemAuditor:GetReagentCost(link, total)
Asa@18 181 local totalCost = 0
Asa@19 182
Asa@86 183 if PT:ItemInSet(link,"Tradeskill.Mat.BySource.Vendor") then
Asa@19 184 local _, _, _, _, _, _, _, _, _, _, itemVendorPrice = GetItemInfo (link);
Asa@19 185 totalCost = itemVendorPrice * total
Asa@19 186 total = 0
Asa@19 187 end
Asa@19 188
Asa@19 189
Asa@63 190 local investedTotal, investedPerItem, count = ItemAuditor:GetItemCost(link)
Asa@18 191
Asa@18 192 if count > 0 then
Asa@18 193 if total <= count then
Asa@18 194 totalCost = investedPerItem * total
Asa@18 195 total = 0
Asa@18 196 else
Asa@18 197 totalCost = investedTotal
Asa@18 198 total = total - count
Asa@18 199 end
Asa@18 200 end
Asa@18 201
Asa@18 202 -- If there is none on the auction house, this uses a large enough number
Asa@18 203 -- to prevent us from trying to make the item.
Asa@21 204 local ahPrice = (self:GetAuctionPrice(link) or 99990000)
Asa@21 205 -- local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, _, _, _, _, itemVendorPrice = GetItemInfo (link);
Asa@18 206
Asa@18 207 return totalCost + (ahPrice * total)
Asa@18 208 end
Asa@18 209
Asa@63 210 function ItemAuditor:GetAuctionPrice(itemLink)
Asa@89 211 return AuctionHouse:GetAuctionPrice(itemLink)
Asa@21 212 end
Asa@21 213
Asa@63 214 function ItemAuditor:AddToQueue(skillId,skillIndex, toQueue)
Asa@18 215 if Skillet == nil then
Asa@18 216 self:Print("Skillet not loaded")
Asa@21 217 return
Asa@18 218 end
Asa@18 219 if Skillet.QueueCommandIterate ~= nil then
Asa@18 220 local queueCommand = Skillet:QueueCommandIterate(tonumber(skillId), toQueue)
Asa@18 221 Skillet:AddToQueue(queueCommand)
Asa@18 222 else
Asa@18 223 Skillet.stitch:AddToQueue(skillIndex, toQueue)
Asa@18 224 end
Asa@18 225 end
Asa@67 226
Asa@67 227 ItemAuditor.Options.args.qa_options = {
Asa@67 228 name = "QA Options",
Asa@67 229 desc = "Control how ItemAuditor integrates with QuickAuctions",
Asa@67 230 type = 'group',
Asa@67 231 disabled = function() return not ItemAuditor:IsQACompatible() end,
Asa@67 232 args = {
Asa@67 233 toggle_qa = {
Asa@67 234 type = "toggle",
Asa@67 235 name = "Enable Quick Auctions",
Asa@67 236 desc = "This will enable or disable Quick Auctions integration",
Asa@67 237 get = "IsQAEnabled",
Asa@67 238 set = "SetQAEnabled",
Asa@67 239 order = 0,
Asa@67 240 },
Asa@111 241 enable_percent = {
Asa@111 242 type = "toggle",
Asa@111 243 name = "Use percent to calculate threshold.",
Asa@111 244 get = function() return ItemAuditor.db.char.auction_threshold > 0 end,
Asa@111 245 set = function(info, value)
Asa@111 246 value = value and 0.15 or 0
Asa@111 247 ItemAuditor.db.char.auction_threshold = value
Asa@111 248 end,
Asa@111 249 order = 1,
Asa@111 250 },
Asa@67 251 auction_threshold = {
Asa@67 252 type = "range",
Asa@67 253 name = "Auction Threshold",
Asa@111 254 desc = "Don't sell items for less than this amount of profit.",
Asa@67 255 min = 0.0,
Asa@67 256 max = 1.0,
Asa@67 257 isPercent = true,
Asa@111 258 hidden = function() return ItemAuditor.db.char.auction_threshold == 0 end,
Asa@67 259 get = function() return ItemAuditor.db.char.auction_threshold end,
Asa@67 260 set = function(info, value)
Asa@67 261 ItemAuditor.db.char.auction_threshold = value
Asa@71 262 -- ItemAuditor:RefreshQAGroups()
Asa@71 263 end,
Asa@71 264 disabled = 'IsQADisabled',
Asa@111 265 order = 2,
Asa@111 266 },
Asa@111 267 enable_absolute = {
Asa@111 268 type = "toggle",
Asa@111 269 name = "Use value to calculate threshold.",
Asa@111 270 get = function() return ItemAuditor.db.char.auction_threshold_value > 0 end,
Asa@111 271 set = function(info, value)
Asa@111 272 value = value and 100000 or 0
Asa@111 273 ItemAuditor.db.char.auction_threshold_value = value
Asa@111 274 end,
Asa@111 275 order = 3,
Asa@111 276 },
Asa@111 277 auction_threshold_absolute = {
Asa@111 278 type = "input",
Asa@111 279 name = "Auction Threshold",
Asa@111 280 desc = "Don't sell items for less than this amount of profit.",
Asa@111 281 hidden = function() return ItemAuditor.db.char.auction_threshold_value == 0 end,
Asa@111 282 get = function() return
Asa@111 283 Utils.FormatMoney(ItemAuditor.db.char.auction_threshold_value , '', true)
Asa@111 284 end,
Asa@111 285 validate = function(info, value)
Asa@111 286 if not Utils.validateMoney(value) then
Asa@111 287 return "Invalid money format"
Asa@111 288 end
Asa@111 289 return true
Asa@111 290 end,
Asa@111 291 set = function(info, value)
Asa@111 292 ItemAuditor.db.char.auction_threshold_value = Utils.parseMoney(value)
Asa@111 293 end,
Asa@111 294 usage = "###g ##s ##c",
Asa@111 295 disabled = 'IsQADisabled',
Asa@111 296 order = 4,
Asa@111 297 },
Asa@67 298 refresh_qa = {
Asa@67 299 type = "execute",
Asa@67 300 name = "Refresh QA Thresholds",
Asa@67 301 desc = "Resets all Quick Auctions thresholds",
Asa@67 302 func = "RefreshQAGroups",
Asa@67 303 disabled = 'IsQADisabled',
Asa@111 304 order = 15,
Asa@67 305 },
Asa@67 306 }
Asa@67 307 }
Asa@67 308
Asa@67 309 ItemAuditor.Options.args.queue = {
Asa@67 310 type = "execute",
Asa@67 311 name = "queue",
Asa@67 312 desc = "Queue",
Asa@67 313 func = "Queue",
Asa@67 314 guiHidden = true,
Asa@67 315 }