Skip to content

Commit b10f8b8

Browse files
committed
1 click buy macro
1 parent 7d2c883 commit b10f8b8

File tree

3 files changed

+45
-55
lines changed

3 files changed

+45
-55
lines changed

CraftSim.toc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## Title: CraftSim
55
## Notes: Calculates the average profit based on your profession stats and other tools for the war within gold making
66
## Author: genju
7-
## Version: 19.6.3.1
7+
## Version: 19.7.0
88
## X-Curse-Project-ID: 705015
99
## X-Wago-ID: 0mNwaPKo
1010
## X-WoWI-ID: 26519

Data/News.lua

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ function CraftSim.NEWS:GET_NEWS(itemMap)
1717
local news = {
1818
f.bb(" Hello and thank you for using CraftSim!\n"),
1919
f.bb(" ( You are awesome! )"),
20+
newP("19.7.0"),
21+
f.P .. "New Feature: " .. f.g("Quick Buy"),
22+
f.p .. "- Works only with " .. f.bb("Auctionator Shopping List"),
23+
f.p .. "- Command: " .. f.l("/craftsim quickbuy"),
24+
f.p .. "- To be used in 1-Click Macro to buy all items",
25+
f.p .. " in the CraftSim CraftQueue Shopping List",
2026
newP("19.6.3"),
2127
f.s .. "Fixed " .. f.bb("CraftLog") .. " PvP Item Bug",
2228
f.s .. "Fixed " .. f.bb("CraftQueue") .. " PvP Item Queueing",

Modules/CraftQueue/CraftQueue.lua

+38-54
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ local QB_STATUS = {
2626

2727
---@class CraftSim.CRAFTQ : Frame
2828
CraftSim.CRAFTQ = GUTIL:CreateRegistreeForEvents({ "TRADE_SKILL_ITEM_CRAFTED_RESULT", "COMMODITY_PURCHASE_SUCCEEDED",
29+
"COMMODITY_PURCHASE_FAILED",
2930
"AUCTION_HOUSE_THROTTLED_SYSTEM_READY",
3031
"NEW_RECIPE_LEARNED", "CRAFTINGORDERS_CLAIMED_ORDER_UPDATED", "CRAFTINGORDERS_CLAIMED_ORDER_REMOVED" })
3132

@@ -53,7 +54,10 @@ CraftSim.CRAFTQ.quickBuyCache = {
5354
---@type string Auctionator SearchString
5455
currentSearchString = nil,
5556
purchasePending = false, -- listen for commoditybought event / item bought event
56-
purchaseConfirmed = false,
57+
---@type ItemID?
58+
pendingItemID = nil,
59+
---@type number?
60+
pendingItemCount = nil,
5761
}
5862

5963
local printQB = CraftSim.DEBUG:RegisterDebugID("Modules.CraftQueue.AuctionatorQuickBuy")
@@ -76,20 +80,21 @@ function CraftSim.CRAFTQ:OnConfirmCommoditiesPurchase(itemID, boughtQuantity)
7680
item = Item:CreateFromItemID(itemID),
7781
quantity = boughtQuantity
7882
}
79-
80-
81-
-- -- continue with
82-
-- local qbCache = self.quickBuyCache
83-
-- if qbCache.status
84-
-- qbCache.status = QB_STATUS.CONFIRM_READY
85-
self.quickBuyCache.purchaseConfirmed = true
86-
--self:AuctionatorQuickBuy() -- wil trigger confirm await
8783
end
8884

8985
function CraftSim.CRAFTQ:COMMODITY_PURCHASE_SUCCEEDED()
9086
-- reset purchase pending in qbCache
9187
printQB("- " .. f.l("COMMODITY_PURCHASE_SUCCEEDED"))
92-
CraftSim.CRAFTQ.quickBuyCache.purchasePending = false
88+
if self.quickBuyCache.purchasePending then
89+
self.purchasedItem.item:ContinueOnItemLoad(function()
90+
CraftSim.DEBUG:SystemPrint(f.l("CraftSim ") ..
91+
f.g("Quick Buy: ") ..
92+
"Purchased " .. self.quickBuyCache.pendingItemCount .. "x " .. self.purchasedItem.item:GetItemLink())
93+
end)
94+
end
95+
self.quickBuyCache.purchasePending = false
96+
self.quickBuyCache.pendingItemCount = nil
97+
self.quickBuyCache.pendingItemID = nil
9398

9499
if not select(2, C_AddOns.IsAddOnLoaded(CraftSim.CONST.SUPPORTED_PRICE_API_ADDONS[2])) then
95100
return -- do not need if Auctionator not loaded
@@ -1048,10 +1053,6 @@ function CraftSim.CRAFTQ:AuctionatorQuickBuy()
10481053

10491054
local listsContainer = AuctionatorShoppingFrame.ListsContainer
10501055
local resultsList = AuctionatorShoppingFrame.ResultsListing
1051-
local buyButton = AuctionatorBuyCommodityFrame.DetailsContainer.BuyButton
1052-
1053-
local commodityFrame = AuctionatorBuyCommodityFrame
1054-
local confirmationDialog = commodityFrame.FinalConfirmationDialog
10551056

10561057
---@param value CraftSim.CRAFTQ.QB_STATUS
10571058
---@return boolean
@@ -1117,21 +1118,13 @@ function CraftSim.CRAFTQ:AuctionatorQuickBuy()
11171118
end
11181119

11191120
-- get item that was not bought yet
1120-
local firstShoppingListSearchString = GUTIL:Find(list.data.items, function(searchString)
1121+
local buyShoppingListSearchString = GUTIL:Find(list.data.items, function(searchString)
11211122
return not qbCache.boughtSearchStrings[searchString]
11221123
end)
11231124

11241125
print("- STATUS: " .. tostring(qbCache.status))
1125-
--print("- firstShoppingListSearchString: " .. tostring(firstShoppingListSearchString))
1126-
1127-
1128-
-- if qbCache.purchasePending then
1129-
-- print(f.r("- Purchase Pending"))
1130-
-- return
1131-
-- end
11321126

1133-
1134-
if not firstShoppingListSearchString then
1127+
if not buyShoppingListSearchString then
11351128
print("- All bought")
11361129
self:ResetQuickBuyCache()
11371130
return
@@ -1162,61 +1155,52 @@ function CraftSim.CRAFTQ:AuctionatorQuickBuy()
11621155
end
11631156
end
11641157

1165-
if firstShoppingListSearchString and status(QB_STATUS.RESULT_LIST_READY) then
1166-
local resultRow = qbCache.resultRows[firstShoppingListSearchString]
1158+
if buyShoppingListSearchString and status(QB_STATUS.RESULT_LIST_READY) then
1159+
local resultRow = qbCache.resultRows[buyShoppingListSearchString]
11671160

11681161
if not resultRow then
1169-
print("Result Row not found in result list: " .. tostring(firstShoppingListSearchString))
1162+
print("Result Row not found in result list: " .. tostring(buyShoppingListSearchString))
11701163
return
11711164
end
11721165

1173-
resultRow:OnClick()
1174-
qbCache.currentSearchString = firstShoppingListSearchString
1175-
set(QB_STATUS.BUY_READY)
1176-
return
1177-
end
1178-
1179-
if status(QB_STATUS.BUY_READY) then
1180-
if buyButton:IsVisible() and buyButton:IsEnabled() then
1181-
buyButton:Click()
1182-
set(QB_STATUS.CONFIRM_START)
1183-
return
1184-
else
1185-
return
1186-
end
1187-
end
1166+
qbCache.pendingItemID = resultRow.rowData.itemKey.itemID
1167+
qbCache.pendingItemCount = resultRow.rowData.purchaseQuantity
11881168

1189-
if status(QB_STATUS.CONFIRM_START) and confirmationDialog:IsVisible() and not confirmationDialog.purchasePending then
1190-
print("- " .. f.g("Confirm Purchase"))
1169+
qbCache.currentSearchString = buyShoppingListSearchString
11911170
qbCache.purchasePending = true
1192-
qbCache.purchaseConfirmed = false
1193-
1194-
confirmationDialog:ConfirmPurchase() -- will trigger event
1195-
set(QB_STATUS.CONFIRM_AWAIT)
1196-
end
1197-
1198-
if status(QB_STATUS.CONFIRM_AWAIT) and qbCache.purchaseConfirmed then
1199-
qbCache.boughtSearchStrings[qbCache.currentSearchString] = true
12001171
set(QB_STATUS.PURCHASE_AWAIT)
1172+
1173+
-- Triggers AUCTION_HOUSE_THROTTLED_SYSTEM_READY and needs confirmation there
1174+
C_AuctionHouse.StartCommoditiesPurchase(qbCache.pendingItemID, qbCache.pendingItemCount)
12011175
return
12021176
end
12031177

12041178
if status(QB_STATUS.PURCHASE_AWAIT) and not qbCache.purchasePending then
1179+
qbCache.boughtSearchStrings[qbCache.currentSearchString] = true
12051180
set(QB_STATUS.RESULT_LIST_READY)
1206-
self:AuctionatorQuickBuy() -- to instantly click next item
1181+
self:AuctionatorQuickBuy()
12071182
end
12081183
end
12091184

12101185
function CraftSim.CRAFTQ:AUCTION_HOUSE_THROTTLED_SYSTEM_READY()
1186+
local qbCache = self.quickBuyCache
1187+
if qbCache.pendingItemCount and qbCache.pendingItemID then
1188+
C_AuctionHouse.ConfirmCommoditiesPurchase(qbCache.pendingItemID, qbCache.pendingItemCount)
1189+
-- triggers COMMODITY_PURCHASE_SUCCEEDED
1190+
-- TODO: Consider COMMODITY_PURCHASE_FAILED
1191+
end
1192+
end
12111193

1194+
function CraftSim.CRAFTQ:COMMODITY_PURCHASE_FAILED()
1195+
-- reset quick buy
1196+
self:ResetQuickBuyCache()
12121197
end
12131198

12141199
function CraftSim.CRAFTQ:ResetQuickBuyCache()
12151200
local qbCache = self.quickBuyCache
12161201
qbCache.status = QB_STATUS.INIT
12171202
qbCache.currentSearchString = nil
12181203
qbCache.purchasePending = false
1219-
qbCache.purchaseConfirmed = false
12201204
wipe(qbCache.boughtSearchStrings)
12211205
wipe(qbCache.resultRows)
12221206
end

0 commit comments

Comments
 (0)