annotate Modules/QuickAuctions.lua @ 18:c7b3585c73df

Added the missing QuickAuctions module. I've also added integration with Skillet and LilSparkysWorkshop. IA and queue any item set up in QuickAuctions where the reagent cost is less than the current price of the item. This is based on KevTool Queue.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Sat, 03 Jul 2010 14:53:27 -0700
parents
children 67f4151d535c
rev   line source
Asa@18 1 local addonName, addonTable = ...;
Asa@18 2 local addon = _G[addonName]
Asa@18 3
Asa@18 4 function addon:IsQACompatible()
Asa@18 5 return (QAAPI ~= nil and QAAPI.GetGroups ~= nil)
Asa@18 6 end
Asa@18 7
Asa@18 8 function addon:IsQAEnabled()
Asa@18 9 return addon:IsQACompatible() and ItemAuditor.db.char.use_quick_auctions
Asa@18 10 end
Asa@18 11
Asa@18 12 function addon:IsQADisabled()
Asa@18 13 return not self:IsQAEnabled()
Asa@18 14 end
Asa@18 15
Asa@18 16 function addon:SetQAEnabled(info, value)
Asa@18 17 ItemAuditor.db.char.use_quick_auctions = value
Asa@18 18 end
Asa@18 19
Asa@18 20 function addon:RefreshQAGroups()
Asa@18 21 if not addon.IsQAEnabled() then
Asa@18 22 return
Asa@18 23 end
Asa@18 24 for groupName in pairs(QAAPI:GetGroups()) do
Asa@18 25 self:UpdateQAGroup(groupName)
Asa@18 26 end
Asa@18 27 end
Asa@18 28
Asa@18 29 function addon:UpdateQAThreshold(link)
Asa@18 30 if not addon.IsQAEnabled() then
Asa@18 31 return
Asa@18 32 end
Asa@18 33 _, link= GetItemInfo(link)
Asa@18 34
Asa@18 35 self:UpdateQAGroup(QAAPI:GetItemGroup(link))
Asa@18 36 end
Asa@18 37
Asa@18 38 function addon:UpdateQAGroup(groupName)
Asa@18 39 if not addon.IsQAEnabled() then
Asa@18 40 return
Asa@18 41 end
Asa@18 42 if groupName then
Asa@18 43 local threshold = 0
Asa@18 44
Asa@18 45 for link in pairs(QAAPI:GetItemsInGroup(groupName)) do
Asa@18 46 local _, itemCost= ItemAuditor:GetItemCost(link, 0)
Asa@18 47
Asa@18 48 threshold = max(threshold, itemCost)
Asa@18 49 end
Asa@18 50
Asa@18 51 if threshold == 0 then
Asa@18 52 threshold = 1
Asa@18 53 end
Asa@18 54
Asa@18 55 -- add my minimum profit margin
Asa@18 56 threshold = threshold * 1.10
Asa@18 57
Asa@18 58 -- Adding the cost of mailing every item once.
Asa@18 59 threshold = threshold + 30
Asa@18 60
Asa@18 61 -- add AH Cut
Asa@18 62 local keep = 1 - addon:GetAHCut()
Asa@18 63 threshold = threshold/keep
Asa@18 64
Asa@18 65 QAAPI:SetGroupThreshold(groupName, ceil(threshold))
Asa@18 66 end
Asa@18 67 end
Asa@18 68
Asa@18 69 --[[
Asa@18 70 This is based on KTQ
Asa@18 71 ]]
Asa@18 72 function addon:Queue()
Asa@18 73 if not addon.IsQAEnabled() then
Asa@18 74 self:Debug("Refusing to run :Queue() QA is disabled")
Asa@18 75 return
Asa@18 76 end
Asa@18 77 if LSW == nil then
Asa@18 78 self:Print("This feature requires LilSparky's Workshop.")
Asa@18 79 return
Asa@18 80 end
Asa@18 81
Asa@18 82 for i = 1, GetNumTradeSkills() do
Asa@18 83 local itemLink = GetTradeSkillItemLink(i)
Asa@18 84 local itemId = Skillet:GetItemIDFromLink(itemLink)
Asa@18 85
Asa@18 86 --Figure out if its an enchant or not
Asa@18 87 _, _, _, _, altVerb = GetTradeSkillInfo(i)
Asa@18 88 if LSW.scrollData[itemId] ~= nil and altVerb == 'Enchant' then
Asa@18 89 -- Ask LSW for the correct scroll
Asa@18 90 itemId = LSW.scrollData[itemId]["scrollID"]
Asa@18 91 end
Asa@18 92
Asa@18 93 local skillName, skillType, numAvailable, isExpanded, altVerb = GetTradeSkillInfo(i)
Asa@18 94 local recipeLink = GetTradeSkillRecipeLink(i)
Asa@18 95 local stackSize = 0
Asa@18 96 if recipeLink ~= nil then
Asa@18 97 _, itemLink= GetItemInfo(itemId)
Asa@18 98 local QAGroup = QAAPI:GetItemGroup(itemLink)
Asa@18 99 if QAGroup ~= nil then
Asa@18 100 stackSize = QAAPI:GetGroupPostCap(QAGroup) * QAAPI:GetGroupPerAuction(QAGroup)
Asa@18 101 stackSize = stackSize / GetTradeSkillNumMade(i)
Asa@18 102 end
Asa@18 103
Asa@18 104 local count = Altoholic:GetItemCount(itemId)
Asa@18 105
Asa@18 106 if count < stackSize then
Asa@18 107 local found, _, skillString = string.find(recipeLink, "^|%x+|H(.+)|h%[.+%]")
Asa@18 108 local _, skillId = strsplit(":", skillString )
Asa@18 109
Asa@18 110
Asa@18 111 local totalCost = 0
Asa@18 112 for reagentId = 1, GetTradeSkillNumReagents(i) do
Asa@18 113 _, _, reagentCount = GetTradeSkillReagentInfo(i, reagentId);
Asa@18 114 reagentLink = GetTradeSkillReagentItemLink(i, reagentId)
Asa@18 115
Asa@18 116 totalCost = totalCost + addon:GetReagentCost(reagentLink, reagentCount)
Asa@18 117 end
Asa@18 118
Asa@18 119 local currentPrice = GetAuctionBuyout(itemLink) or 0
Asa@18 120
Asa@18 121 local toQueue = stackSize - count
Asa@18 122 -- bonus?
Asa@18 123
Asa@18 124 if totalCost < currentPrice then
Asa@18 125 self:Debug(format("Adding %s x%s to skillet queue.", itemLink, toQueue))
Asa@18 126 self:AddToQueue(skillId,i, toQueue)
Asa@18 127 else
Asa@18 128 self:Debug(format("Skipping %s. Would cost %s to craft and sell for %s", itemLink, addon:FormatMoney(totalCost), addon:FormatMoney(currentPrice)))
Asa@18 129 end
Asa@18 130 end
Asa@18 131 end
Asa@18 132 end
Asa@18 133
Asa@18 134
Asa@18 135 end
Asa@18 136
Asa@18 137 function addon:GetReagentCost(link, total)
Asa@18 138 local totalCost = 0
Asa@18 139 local investedTotal, investedPerItem, count = addon:GetItemCost(link)
Asa@18 140
Asa@18 141 if count > 0 then
Asa@18 142 if total <= count then
Asa@18 143 totalCost = investedPerItem * total
Asa@18 144 total = 0
Asa@18 145 else
Asa@18 146 totalCost = investedTotal
Asa@18 147 total = total - count
Asa@18 148 end
Asa@18 149 end
Asa@18 150
Asa@18 151 -- If there is none on the auction house, this uses a large enough number
Asa@18 152 -- to prevent us from trying to make the item.
Asa@18 153 local ahPrice = (GetAuctionBuyout(link) or 99990000)
Asa@18 154
Asa@18 155 return totalCost + (ahPrice * total)
Asa@18 156 end
Asa@18 157
Asa@18 158 function addon:AddToQueue(skillId,skillIndex, toQueue)
Asa@18 159 if Skillet == nil then
Asa@18 160 self:Print("Skillet not loaded")
Asa@18 161 end
Asa@18 162 if Skillet.QueueCommandIterate ~= nil then
Asa@18 163 local queueCommand = Skillet:QueueCommandIterate(tonumber(skillId), toQueue)
Asa@18 164 Skillet:AddToQueue(queueCommand)
Asa@18 165 else
Asa@18 166 Skillet.stitch:AddToQueue(skillIndex, toQueue)
Asa@18 167 end
Asa@18 168 end