test update bags sort

This commit is contained in:
Crum
2018-07-04 01:06:49 -05:00
parent 8fd70922da
commit 3a2342f59f
+38 -19
View File
@@ -238,7 +238,7 @@ local function IterateForwards(bagList, i)
i = i + 1 i = i + 1
local step = 1 local step = 1
for _, bag in ipairs(bagList) do for _, bag in ipairs(bagList) do
local slots = B:GetNumSlots(bag, bagRole) local slots = B:GetNumSlots(bag)
if i > slots + step then if i > slots + step then
step = step + slots step = step + slots
else else
@@ -258,7 +258,7 @@ local function IterateBackwards(bagList, i)
local step = 1 local step = 1
for ii = getn(bagList), 1, -1 do for ii = getn(bagList), 1, -1 do
local bag = bagList[ii] local bag = bagList[ii]
local slots = B:GetNumSlots(bag, bagRole) local slots = B:GetNumSlots(bag)
if i > slots + step then if i > slots + step then
step = step + slots step = step + slots
else else
@@ -299,10 +299,11 @@ function B:SplitItem(bag, slot, amount)
return SplitContainerItem(bag, slot, amount) return SplitContainerItem(bag, slot, amount)
end end
function B:GetNumSlots(bag, role) function B:GetNumSlots(bag)
if bag then if bag then
return GetContainerNumSlots(bag); return GetContainerNumSlots(bag)
end end
return 0 return 0
end end
@@ -319,11 +320,11 @@ local function DefaultCanMove()
end end
function B:Encode_BagSlot(bag, slot) function B:Encode_BagSlot(bag, slot)
return (bag*100) + slot return (bag * 100) + slot
end end
function B:Decode_BagSlot(int) function B:Decode_BagSlot(int)
return floor(int/100), mod(int, 100) return floor(int / 100), mod(int, 100)
end end
function B:IsPartial(bag, slot) function B:IsPartial(bag, slot)
@@ -336,10 +337,10 @@ function B:EncodeMove(source, target)
end end
function B:DecodeMove(move) function B:DecodeMove(move)
local s = floor(move/10000) local s = floor(move / 10000)
local t = mod(move,10000) local t = mod(move, 10000)
s = (t>9000) and (s+1) or s s = (t > 9000) and (s + 1) or s
t = (t>9000) and (t-10000) or t t = (t > 9000) and (t - 10000) or t
return s, t return s, t
end end
@@ -361,10 +362,26 @@ function B:ScanBags()
end end
end end
local bagTypes = {
["Bag"] = 0,
["Quiver"] = 1,
["Ammo Pouch"] = 2,
["Soul Bag"] = 4,
["Leatherworking Bag"] = 8,
["Herb Bag"] = 16,
["Enchanting Bag"] = 32,
["Engineering Bag"] = 64,
["Mining Bag"] = 128
}
local function GetItemFamily(bag) local function GetItemFamily(bag)
local itemType = select(6, GetItemInfo(match(bag, "item:(%d+)"))) local bagID = match(bag, "item:(%d+)")
local itemType
if bagID then
itemType = select(6, GetItemInfo(bagID))
if itemType then if itemType then
return itemType return tonumber(bagTypes[itemType])
end
end end
return nil return nil
@@ -380,7 +397,7 @@ function B:IsSpecialtyBag(bagID)
if not bag then return false end if not bag then return false end
local family = GetItemFamily(bag) local family = GetItemFamily(bag)
if family == "Bag" or family == nil then return false else return false end if family == 0 or family == nil then return false end
return family return family
end end
@@ -388,13 +405,13 @@ end
function B:CanItemGoInBag(bag, slot, targetBag) function B:CanItemGoInBag(bag, slot, targetBag)
local item = bagIDs[B:Encode_BagSlot(bag, slot)] local item = bagIDs[B:Encode_BagSlot(bag, slot)]
local itemFamily = GetItemFamily(item) local itemFamily = GetItemFamily(item)
if itemFamily and (not itemFamily == "Bag") then if itemFamily then
local equipSlot = select(8, GetItemInfo(item)) local equipSlot = select(8, GetItemInfo(item))
if equipSlot == "INVTYPE_BAG" then if equipSlot == "INVTYPE_BAG" then
itemFamily = 1 itemFamily = 1
end end
end end
local bagFamily = select(2, GetContainerNumFreeSlots(targetBag)) local bagFamily = GetItemFamily(targetBag)
if itemFamily then if itemFamily then
return (bagFamily == 0) or band(itemFamily, bagFamily) > 0 return (bagFamily == 0) or band(itemFamily, bagFamily) > 0
else else
@@ -403,7 +420,7 @@ function B:CanItemGoInBag(bag, slot, targetBag)
end end
function B.Compress(...) function B.Compress(...)
for i = 1, getn(arg) do for i = 1, arg.n do
local bags = arg[i] local bags = arg[i]
B.Stack(bags, bags, B.IsPartial) B.Stack(bags, bags, B.IsPartial)
end end
@@ -425,6 +442,7 @@ function B.Stack(sourceBags, targetBags, canMove)
for _, bag, slot in B.IterateBags(sourceBags, true, "withdraw") do for _, bag, slot in B.IterateBags(sourceBags, true, "withdraw") do
local sourceSlot = B:Encode_BagSlot(bag, slot) local sourceSlot = B:Encode_BagSlot(bag, slot)
local itemID = bagIDs[sourceSlot] local itemID = bagIDs[sourceSlot]
if itemID and targetItems[itemID] and canMove(itemID, bag, slot) then if itemID and targetItems[itemID] and canMove(itemID, bag, slot) then
for i = getn(targetSlots), 1, -1 do for i = getn(targetSlots), 1, -1 do
local targetedSlot = targetSlots[i] local targetedSlot = targetSlots[i]
@@ -454,7 +472,7 @@ local blackListedSlots = {}
local blackList = {} local blackList = {}
local blackListQueries = {} local blackListQueries = {}
local function buildBlacklist(...) local function buildBlacklist(arg)
for entry in pairs(arg) do for entry in pairs(arg) do
local itemName = GetItemInfo(entry) local itemName = GetItemInfo(entry)
if itemName then if itemName then
@@ -463,7 +481,7 @@ local function buildBlacklist(...)
if find(entry, "%[") and find(entry, "%]") then if find(entry, "%[") and find(entry, "%]") then
entry = match(entry, "%[(.*)%]") entry = match(entry, "%[(.*)%]")
end end
blackListQueries[getn(blackListQueries)+1] = entry blackListQueries[getn(blackListQueries) + 1] = entry
end end
end end
end end
@@ -543,6 +561,7 @@ function B.FillBags(from, to)
tinsert(specialtyBags, bag) tinsert(specialtyBags, bag)
end end
end end
if getn(specialtyBags) > 0 then if getn(specialtyBags) > 0 then
B:Fill(from, specialtyBags) B:Fill(from, specialtyBags)
end end
@@ -585,7 +604,7 @@ function B.Fill(sourceBags, targetBags, reverse, canMove)
end end
function B.SortBags(...) function B.SortBags(...)
for i = 1, getn(arg) do for i = 1, arg.n do
local bags = arg[i] local bags = arg[i]
for i, slotNum in ipairs(bags) do for i, slotNum in ipairs(bags) do
local bagType = B:IsSpecialtyBag(slotNum) local bagType = B:IsSpecialtyBag(slotNum)