Skip to content

Commit

Permalink
Addon: [1.7.51] Refactor sell logic
Browse files Browse the repository at this point in the history
Core: AdhocNPCGoal: Be sure that pressing the Sell key action before the auto sell junk starts, in order to respect macro based item selling.
  • Loading branch information
Xian55 committed Jan 8, 2024
1 parent 64da5ed commit bdaaedf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 33 deletions.
67 changes: 35 additions & 32 deletions Addons/DataToColor/DataToColor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Addons/DataToColor/DataToColor.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions Core/Goals/AdhocNPCGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit bdaaedf

Please sign in to comment.