Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion Dustman.lua
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,54 @@ local function pairsByQuality(bagCache)

end

local function pairsByQualityAndQuantity(bagCache)
local arraySorted = {}
-- we can't sort by 2 values at the same time, so we use a helper-array
local arrayQuality = {}
-- initialise one sub-array for every quality
for i = 1, 5 do
arrayQuality[i] = {}
end

-- Trash (0) items break the table.insert below and LUA tables can't be 0-indexed, so we put them into 9 as a run-around
arrayQuality[9] = {}

-- throw bag slots into respective quality array
for key, data in pairs(bagCache) do
if data.quality == 0 then
table.insert(arrayQuality[9], data)
else
table.insert(arrayQuality[data.quality], data)
end
end

local function sortByPosition(a, b)
-- ascending sort, sell smallest stacks first to free up bag space
return a.stackCount < b.stackCount
end

-- sort by quantity within each quality
for i = 1, 5 do
table.sort(arrayQuality[i], sortByPosition)
end

-- join arrays back together to be usable once returned
for i = 5, 1, -1 do
for key, data in pairs(arrayQuality[i]) do
-- d("quality: "..data.quality.." ; stackCount: "..data.stackCount.." ; rawName: "..data.rawName)
table.insert(arraySorted, data)
end
end

-- attach Trash (0) items we put into 9 above
for key, data in pairs(arrayQuality[9]) do
table.insert(arraySorted, data)
end

return arraySorted

end

local function SellJunkItems(isFence)

if GetInteractionType() == INTERACTION_VENDOR then
Expand All @@ -555,10 +603,11 @@ local function SellJunkItems(isFence)
if isFence then
hagglingBonus = GetNonCombatBonus(NON_COMBAT_BONUS_HAGGLING)
hasHagglingBonus = hagglingBonus > 0
bagCache = pairsByQuality(bagCache)
bagCache = pairsByQualityAndQuantity(bagCache)
end

for slotId, data in pairs(bagCache) do
-- d("quality: "..data.quality.." ; stackCount: "..data.stackCount.." ; rawName: "..data.rawName)
if transactions < 50 then
if data.isJunk then
if data.stolen == isFence then
Expand Down