From b10f8b81528dad0846dd6184892a2c02d484ea32 Mon Sep 17 00:00:00 2001 From: Genju Date: Fri, 22 Nov 2024 13:51:03 +0100 Subject: [PATCH] 1 click buy macro --- CraftSim.toc | 2 +- Data/News.lua | 6 ++ Modules/CraftQueue/CraftQueue.lua | 92 +++++++++++++------------------ 3 files changed, 45 insertions(+), 55 deletions(-) diff --git a/CraftSim.toc b/CraftSim.toc index 07daf6f5..4f47c5ef 100644 --- a/CraftSim.toc +++ b/CraftSim.toc @@ -4,7 +4,7 @@ ## Title: CraftSim ## Notes: Calculates the average profit based on your profession stats and other tools for the war within gold making ## Author: genju -## Version: 19.6.3.1 +## Version: 19.7.0 ## X-Curse-Project-ID: 705015 ## X-Wago-ID: 0mNwaPKo ## X-WoWI-ID: 26519 diff --git a/Data/News.lua b/Data/News.lua index c802d87c..840fc927 100644 --- a/Data/News.lua +++ b/Data/News.lua @@ -17,6 +17,12 @@ function CraftSim.NEWS:GET_NEWS(itemMap) local news = { f.bb(" Hello and thank you for using CraftSim!\n"), f.bb(" ( You are awesome! )"), + newP("19.7.0"), + f.P .. "New Feature: " .. f.g("Quick Buy"), + f.p .. "- Works only with " .. f.bb("Auctionator Shopping List"), + f.p .. "- Command: " .. f.l("/craftsim quickbuy"), + f.p .. "- To be used in 1-Click Macro to buy all items", + f.p .. " in the CraftSim CraftQueue Shopping List", newP("19.6.3"), f.s .. "Fixed " .. f.bb("CraftLog") .. " PvP Item Bug", f.s .. "Fixed " .. f.bb("CraftQueue") .. " PvP Item Queueing", diff --git a/Modules/CraftQueue/CraftQueue.lua b/Modules/CraftQueue/CraftQueue.lua index 933f4416..5d869d80 100644 --- a/Modules/CraftQueue/CraftQueue.lua +++ b/Modules/CraftQueue/CraftQueue.lua @@ -26,6 +26,7 @@ local QB_STATUS = { ---@class CraftSim.CRAFTQ : Frame CraftSim.CRAFTQ = GUTIL:CreateRegistreeForEvents({ "TRADE_SKILL_ITEM_CRAFTED_RESULT", "COMMODITY_PURCHASE_SUCCEEDED", + "COMMODITY_PURCHASE_FAILED", "AUCTION_HOUSE_THROTTLED_SYSTEM_READY", "NEW_RECIPE_LEARNED", "CRAFTINGORDERS_CLAIMED_ORDER_UPDATED", "CRAFTINGORDERS_CLAIMED_ORDER_REMOVED" }) @@ -53,7 +54,10 @@ CraftSim.CRAFTQ.quickBuyCache = { ---@type string Auctionator SearchString currentSearchString = nil, purchasePending = false, -- listen for commoditybought event / item bought event - purchaseConfirmed = false, + ---@type ItemID? + pendingItemID = nil, + ---@type number? + pendingItemCount = nil, } local printQB = CraftSim.DEBUG:RegisterDebugID("Modules.CraftQueue.AuctionatorQuickBuy") @@ -76,20 +80,21 @@ function CraftSim.CRAFTQ:OnConfirmCommoditiesPurchase(itemID, boughtQuantity) item = Item:CreateFromItemID(itemID), quantity = boughtQuantity } - - - -- -- continue with - -- local qbCache = self.quickBuyCache - -- if qbCache.status - -- qbCache.status = QB_STATUS.CONFIRM_READY - self.quickBuyCache.purchaseConfirmed = true - --self:AuctionatorQuickBuy() -- wil trigger confirm await end function CraftSim.CRAFTQ:COMMODITY_PURCHASE_SUCCEEDED() -- reset purchase pending in qbCache printQB("- " .. f.l("COMMODITY_PURCHASE_SUCCEEDED")) - CraftSim.CRAFTQ.quickBuyCache.purchasePending = false + if self.quickBuyCache.purchasePending then + self.purchasedItem.item:ContinueOnItemLoad(function() + CraftSim.DEBUG:SystemPrint(f.l("CraftSim ") .. + f.g("Quick Buy: ") .. + "Purchased " .. self.quickBuyCache.pendingItemCount .. "x " .. self.purchasedItem.item:GetItemLink()) + end) + end + self.quickBuyCache.purchasePending = false + self.quickBuyCache.pendingItemCount = nil + self.quickBuyCache.pendingItemID = nil if not select(2, C_AddOns.IsAddOnLoaded(CraftSim.CONST.SUPPORTED_PRICE_API_ADDONS[2])) then return -- do not need if Auctionator not loaded @@ -1048,10 +1053,6 @@ function CraftSim.CRAFTQ:AuctionatorQuickBuy() local listsContainer = AuctionatorShoppingFrame.ListsContainer local resultsList = AuctionatorShoppingFrame.ResultsListing - local buyButton = AuctionatorBuyCommodityFrame.DetailsContainer.BuyButton - - local commodityFrame = AuctionatorBuyCommodityFrame - local confirmationDialog = commodityFrame.FinalConfirmationDialog ---@param value CraftSim.CRAFTQ.QB_STATUS ---@return boolean @@ -1117,21 +1118,13 @@ function CraftSim.CRAFTQ:AuctionatorQuickBuy() end -- get item that was not bought yet - local firstShoppingListSearchString = GUTIL:Find(list.data.items, function(searchString) + local buyShoppingListSearchString = GUTIL:Find(list.data.items, function(searchString) return not qbCache.boughtSearchStrings[searchString] end) print("- STATUS: " .. tostring(qbCache.status)) - --print("- firstShoppingListSearchString: " .. tostring(firstShoppingListSearchString)) - - - -- if qbCache.purchasePending then - -- print(f.r("- Purchase Pending")) - -- return - -- end - - if not firstShoppingListSearchString then + if not buyShoppingListSearchString then print("- All bought") self:ResetQuickBuyCache() return @@ -1162,53 +1155,45 @@ function CraftSim.CRAFTQ:AuctionatorQuickBuy() end end - if firstShoppingListSearchString and status(QB_STATUS.RESULT_LIST_READY) then - local resultRow = qbCache.resultRows[firstShoppingListSearchString] + if buyShoppingListSearchString and status(QB_STATUS.RESULT_LIST_READY) then + local resultRow = qbCache.resultRows[buyShoppingListSearchString] if not resultRow then - print("Result Row not found in result list: " .. tostring(firstShoppingListSearchString)) + print("Result Row not found in result list: " .. tostring(buyShoppingListSearchString)) return end - resultRow:OnClick() - qbCache.currentSearchString = firstShoppingListSearchString - set(QB_STATUS.BUY_READY) - return - end - - if status(QB_STATUS.BUY_READY) then - if buyButton:IsVisible() and buyButton:IsEnabled() then - buyButton:Click() - set(QB_STATUS.CONFIRM_START) - return - else - return - end - end + qbCache.pendingItemID = resultRow.rowData.itemKey.itemID + qbCache.pendingItemCount = resultRow.rowData.purchaseQuantity - if status(QB_STATUS.CONFIRM_START) and confirmationDialog:IsVisible() and not confirmationDialog.purchasePending then - print("- " .. f.g("Confirm Purchase")) + qbCache.currentSearchString = buyShoppingListSearchString qbCache.purchasePending = true - qbCache.purchaseConfirmed = false - - confirmationDialog:ConfirmPurchase() -- will trigger event - set(QB_STATUS.CONFIRM_AWAIT) - end - - if status(QB_STATUS.CONFIRM_AWAIT) and qbCache.purchaseConfirmed then - qbCache.boughtSearchStrings[qbCache.currentSearchString] = true set(QB_STATUS.PURCHASE_AWAIT) + + -- Triggers AUCTION_HOUSE_THROTTLED_SYSTEM_READY and needs confirmation there + C_AuctionHouse.StartCommoditiesPurchase(qbCache.pendingItemID, qbCache.pendingItemCount) return end if status(QB_STATUS.PURCHASE_AWAIT) and not qbCache.purchasePending then + qbCache.boughtSearchStrings[qbCache.currentSearchString] = true set(QB_STATUS.RESULT_LIST_READY) - self:AuctionatorQuickBuy() -- to instantly click next item + self:AuctionatorQuickBuy() end end function CraftSim.CRAFTQ:AUCTION_HOUSE_THROTTLED_SYSTEM_READY() + local qbCache = self.quickBuyCache + if qbCache.pendingItemCount and qbCache.pendingItemID then + C_AuctionHouse.ConfirmCommoditiesPurchase(qbCache.pendingItemID, qbCache.pendingItemCount) + -- triggers COMMODITY_PURCHASE_SUCCEEDED + -- TODO: Consider COMMODITY_PURCHASE_FAILED + end +end +function CraftSim.CRAFTQ:COMMODITY_PURCHASE_FAILED() + -- reset quick buy + self:ResetQuickBuyCache() end function CraftSim.CRAFTQ:ResetQuickBuyCache() @@ -1216,7 +1201,6 @@ function CraftSim.CRAFTQ:ResetQuickBuyCache() qbCache.status = QB_STATUS.INIT qbCache.currentSearchString = nil qbCache.purchasePending = false - qbCache.purchaseConfirmed = false wipe(qbCache.boughtSearchStrings) wipe(qbCache.resultRows) end