annotate Modules/QuickAuctions.lua @ 119:d94195157a6b

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