Altz-UI icon indicating copy to clipboard operation
Altz-UI copied to clipboard

Autobuy feature is broken

Open gamer-angel05 opened this issue 5 years ago • 2 comments

https://github.com/Paojy/Altz-UI/blob/c9b4fb20fbbfd1ef968ad76a8041f650346c21c2/Interface/AddOns/AltzUI/mods/tweaks/tweaks.lua#L114

Hello again. There is an issue with autobuy when there's more than one item in the autobuy list and not all of them are available at the vendor.

The line I linked stops autobuy from moving through the list, but the following change resolves it:

		for ItemID, Need in pairs(aCoreCDB["ItemOptions"]["autobuylist"]) do
			local ItemCount = GetItemCount(tonumber(ItemID))
			if ItemCount < tonumber(Need) then			
				local ItemName = GetItemInfo(tonumber(ItemID))
				local numMerchantItems = GetMerchantNumItems()
				for index = 1, numMerchantItems do
					local name, texture, price, quantity, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(index)
					if ItemName == name then-- 有卖的嘛?
						local needbuy = tonumber(Need) - ItemCount
						if numAvailable >1 and needbuy > numAvailable then -- 数量够不够
							print(L["货物不足"]..G.classcolor.." "..ItemName.."|r")
						elseif needbuy/quantity*price > GetMoney() then -- 钱够不够
							print(L["钱不够"]..G.classcolor.." "..ItemName.."|r")
						elseif needbuy > 0 then
							BuyMerchantItem(index, needbuy)
							print(format(L["购买"], needbuy, G.classcolor..ItemName.."|r"))
						end
					end
				end
			end
		end
`

gamer-angel05 avatar Dec 04 '20 09:12 gamer-angel05

It might even be better to also reverse the logic. Instead of checking quantity needed first, check if it's even part of the vendor's items and then check the quantity needed..

Something like this instead, moving the condition here if ItemName == name and ItemCount < tonumber(Need) then-- 有卖的嘛?

gamer-angel05 avatar Dec 05 '20 11:12 gamer-angel05

Sometimes I encounter itemName value being nil. I'm guessing because the item wasn't cached by the server yet. That causes a false positive that needs to be avoided... if ItemName and ItemName == name and ItemCount < tonumber(Need) then-- 有卖的嘛?

gamer-angel05 avatar Dec 21 '20 16:12 gamer-angel05