From bdaaedf26743171a75224b377635cf85c5cffca3 Mon Sep 17 00:00:00 2001 From: Xian55 <367101+Xian55@users.noreply.github.com> Date: Mon, 8 Jan 2024 11:55:49 +0100 Subject: [PATCH] Addon: [1.7.51] Refactor sell logic Core: AdhocNPCGoal: Be sure that pressing the Sell key action before the auto sell junk starts, in order to respect macro based item selling. --- Addons/DataToColor/DataToColor.lua | 67 ++++++++++++++++-------------- Addons/DataToColor/DataToColor.toc | 2 +- Core/Goals/AdhocNPCGoal.cs | 3 ++ 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/Addons/DataToColor/DataToColor.lua b/Addons/DataToColor/DataToColor.lua index f530a1d8..dc537fd5 100644 --- a/Addons/DataToColor/DataToColor.lua +++ b/Addons/DataToColor/DataToColor.lua @@ -1019,43 +1019,46 @@ function DataToColor:delete(items) end function DataToColor:sell(items) - if UnitExists(DataToColor.C.unitTarget) then - local item = GetMerchantItemLink(1) - if item ~= nil then - DataToColor:Print("Selling items...") - DataToColor:OnMerchantShow() - local TotalPrice = 0 - for b = 0, 4 do - for s = 1, GetContainerNumSlots(b) do - local CurrentItemLink = GetContainerItemLink(b, s) - if CurrentItemLink then - for i = 1, #items, 1 do - if strfind(CurrentItemLink, items[i]) then - local _, _, itemRarity, _, _, _, _, _, _, _, itemSellPrice = GetItemInfo(CurrentItemLink) - if (itemRarity < 2) then - local _, itemCount = GetContainerItemInfo(b, s) - TotalPrice = TotalPrice + (itemSellPrice * itemCount) - DataToColor:Print("Selling: ", itemCount, " ", CurrentItemLink, - " for ", GetCoinTextureString(itemSellPrice * itemCount)) - UseContainerItem(b, s) - else - DataToColor:Print("Item is not gray or common, not selling it: ", items[i]) - end - end + if not UnitExists(DataToColor.C.unitTarget) then + DataToColor:Print("Merchant is not targetted.") + return + end + + local item = GetMerchantItemLink(1) + if item == nil then + DataToColor:Print("Merchant is not open to sell to, please approach and open.") + return + end + + DataToColor:Print("Selling items...") + DataToColor:OnMerchantShow() + local TotalPrice = 0 + + for b = 0, 4 do + for s = 1, GetContainerNumSlots(b) do + local CurrentItemLink = GetContainerItemLink(b, s) + if CurrentItemLink then + for i = 1, #items, 1 do + if strfind(CurrentItemLink, items[i]) then + local _, _, itemRarity, _, _, _, _, _, _, _, itemSellPrice = GetItemInfo(CurrentItemLink) + if (itemRarity < 2) then + local _, itemCount = GetContainerItemInfo(b, s) + TotalPrice = TotalPrice + (itemSellPrice * itemCount) + DataToColor:Print("Selling: ", itemCount, " ", CurrentItemLink, + " for ", GetCoinTextureString(itemSellPrice * itemCount)) + UseContainerItem(b, s) + else + DataToColor:Print("Item is not gray or common, not selling it: ", items[i]) end end end end - - if TotalPrice ~= 0 then - DataToColor:Print("Total Price for all items: ", GetCoinTextureString(TotalPrice)) - else - DataToColor:Print("No grey items were sold.") - end - else - DataToColor:Print("Merchant is not open to sell to, please approach and open.") end + end + + if TotalPrice ~= 0 then + DataToColor:Print("Total Price for all items: ", GetCoinTextureString(TotalPrice)) else - DataToColor:Print("Merchant is not targetted.") + DataToColor:Print("No grey items were sold.") end end diff --git a/Addons/DataToColor/DataToColor.toc b/Addons/DataToColor/DataToColor.toc index 4de9497d..b6425968 100644 --- a/Addons/DataToColor/DataToColor.toc +++ b/Addons/DataToColor/DataToColor.toc @@ -3,7 +3,7 @@ ## Title: DataToColor ## Author: FreeHongKongMMO ## Notes: Displays data as colors -## Version: 1.7.50 +## Version: 1.7.51 ## RequiredDeps: ## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino ## SavedVariables: diff --git a/Core/Goals/AdhocNPCGoal.cs b/Core/Goals/AdhocNPCGoal.cs index 6d021dc2..be880266 100644 --- a/Core/Goals/AdhocNPCGoal.cs +++ b/Core/Goals/AdhocNPCGoal.cs @@ -333,6 +333,9 @@ private bool OpenMerchantWindow() Log($"Merchant window opened after {e}ms"); + // Sell custom items via macro + input.PressRandom(key); + e = wait.Until(TIMEOUT, gossipReader.MerchantWindowSelling); if (e >= 0) {