Skip to content

Commit

Permalink
Updates for 3.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
b-morgan committed Jan 18, 2023
1 parent 6917841 commit 48f1179
Showing 1 changed file with 66 additions and 52 deletions.
118 changes: 66 additions & 52 deletions UI/ShoppingList.lua
Original file line number Diff line number Diff line change
Expand Up @@ -554,33 +554,6 @@ function Skillet:PrintAuctionData()
end
end

--
-- checks to see if this is a normal bag (not ammo, herb, enchanting, etc)
-- I borrowed this code from ClosetGnome.
--
local function isNormalBag(bagId)
--DA.DEBUG(0, "isNormalBag("..tostring(bagId)..")")
--
-- backpack and bank are always normal
--
if bagId == 0 or bagId == -1 then return true end
local id = GetInventoryItemID("player", ContainerIDToInventoryID(bagId))
if not id then return false end
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount,
itemEquipLoc, itemIcon, itemSellPrice, itemClassID, itemSubClassID, bindType, expacID, itemSetID,
isCraftingReagent = GetItemInfo(id)
--
-- is this one normal?
--
if itemClassID and itemSubClassID and itemClassID == LE_ITEM_CLASS_CONTAINER and itemSubClassID == 0 then return true end
--
-- not a normal bag
--
--DA.DEBUG(1, "isNormalBag: bagId= "..tostring(bagId)..", itemClassID= "..tostring(itemClassID)..", itemSubClassID= "..tostring(itemSubClassID))
--DA.DEBUG(1, "isNormalBag: itemType= "..tostring(itemType)..", itemSubType= "..tostring(itemSubType))
return false
end

--
-- Returns a bag that the item can be placed in.
--
Expand All @@ -589,19 +562,37 @@ local function findBagForItem(itemID, count)
if not itemID then return nil end
local _, _, _, _, _, _, _, itemStackCount = GetItemInfo(itemID)
for container = 0, 4, 1 do
if isNormalBag(container) then
local bag_size = C_Container.GetContainerNumSlots(container) -- 0 if there is no bag
--DA.DEBUG(1, "findBagForItem: container= "..tostring(container)..", bag_size= "..tostring(bag_size))
for slot = 1, bag_size, 1 do
local bagitem = GetContainerItemID(container, slot)
if bagitem then
if itemID == bagitem then
local bagSize, freeSlots, bagType
if isClassic then
bagSize = GetContainerNumSlots(container)
freeSlots, bagType = GetContainerNumFreeSlots(container)
else
bagSize = C_Container.GetContainerNumSlots(container)
freeSlots, bagType = C_Container.GetContainerNumFreeSlots(container)
end
--DA.DEBUG(1, "findBagForItem: container= "..tostring(container)..", bagSize= "..tostring(bagSize)..", freeSlots= "..tostring(freeSlots)..", bagType= "..tostring(bagType))
if bagType == 0 then
for slot = 1, bagSize, 1 do
local bagItem, info, num_in_bag, locked
if isClassic then
bagItem = GetContainerItemID(container, slot)
info, num_in_bag, locked = GetContainerItemInfo(container, slot)
else
bagItem = C_Container.GetContainerItemLink(container, slot)
end
if bagItem then
if not isClassic then
info = C_Container.GetContainerItemInfo(container, slot)
--DA.DEBUG(1, "findBagForItem: container= "..tostring(container)..", slot= "..tostring(slot)..", info= "..DA.DUMP1(info))
bagItem = info.itemID
num_in_bag = info.stackCount
locked = info.isLocked
end
if itemID == bagItem then
--
-- found some of the same, it is a full stack or locked?
--
local _, num_in_bag, locked = GetContainerItemInfo(container, slot)
local space_available = itemStackCount - num_in_bag
if space_available >= count and not locked then
if (itemStackCount - num_in_bag ) >= count and not locked then
--DA.DEBUG(1, "findBagForItem: container= "..tostring(container)..", slot= "..tostring(slot)..", true")
return container, slot, true
end
Expand All @@ -613,27 +604,40 @@ local function findBagForItem(itemID, count)
--DA.DEBUG(1, "findBagForItem: container= "..tostring(container)..", slot= "..tostring(slot)..", false")
return container, slot, false
end
end
else
--DA.DEBUG(0, "findBagForItem: container= "..tostring(container).." is not a normal bag")
end
end
end -- for slot
end -- bagType
end -- for container
return nil, nil, nil
end

local function getItemFromBank(itemID, bag, slot, count)
--DA.DEBUG(0,"getItemFromBank(", itemID, bag, slot, count,")")
ClearCursor()
local _, available = GetContainerItemInfo(bag, slot)
local info, available
if isClassic then
info, available = GetContainerItemInfo(bag, slot)
else
info = C_Container.GetContainerItemInfo(bag, slot)
--DA.DEBUG(2,"info="..DA.DUMP1(info))
available = info.stackCount
end
local num_moved = 0
if available then
if available == 1 or count >= available then
--DA.DEBUG(1,"PickupContainerItem(",bag,", ", slot,")")
PickupContainerItem(bag, slot)
if isClassic then
PickupContainerItem(bag, slot)
else
C_Container.PickupContainerItem(bag, slot)
end
num_moved = available
else
--DA.DEBUG(1,"SplitContainerItem(",bag, slot, count,")")
SplitContainerItem(bag, slot, count)
if isClassic then
SplitContainerItem(bag, slot, count)
else
C_Container.SplitContainerItem(bag, slot, count)
end
num_moved = count
end
local tobag, toslot = findBagForItem(itemID, num_moved)
Expand All @@ -648,37 +652,47 @@ local function getItemFromBank(itemID, bag, slot, count)
PutItemInBackpack()
else
--DA.DEBUG(1,"PutItemInBag(",ContainerIDToInventoryID(tobag),")")
PutItemInBag(ContainerIDToInventoryID(tobag))
if isClassic then
PutItemInBag(ContainerIDToInventoryID(tobag))
else
PutItemInBag(C_Container.ContainerIDToInventoryID(tobag))
end
end
else
--DA.DEBUG(1,"getItemFromBank: none available")
end
ClearCursor()
return num_moved
end

local function getItemFromGuildBank(itemID, bag, slot, count)
DA.DEBUG(0,"getItemFromGuildBank(",itemID, bag, slot, count,")")
--DA.DEBUG(0,"getItemFromGuildBank(",itemID, bag, slot, count,")")
ClearCursor()
local _, available = GetGuildBankItemInfo(bag, slot)
local num_moved = 0
if available then
if available == 1 or count >= available then
DA.DEBUG(1,"PickupGuildBankItem(",bag, slot,")")
--DA.DEBUG(1,"PickupGuildBankItem(",bag, slot,")")
PickupGuildBankItem(bag, slot)
num_moved = available
else
DA.DEBUG(1,"SplitGuildBankItem(",bag, slot, count,")")
--DA.DEBUG(1,"SplitGuildBankItem(",bag, slot, count,")")
SplitGuildBankItem(bag, slot, count)
num_moved = count
end
local tobag, toslot = findBagForItem(itemID, num_moved)
DA.DEBUG(1,"tobag=", tobag, " toslot=", toslot, " findBagForItem(", itemID, num_moved,")")
--DA.DEBUG(1,"tobag=", tobag, " toslot=", toslot, " findBagForItem(", itemID, num_moved,")")
if not tobag then
Skillet:Print(L["Could not find bag space for"]..": "..GetGuildBankItemLink(bag, slot))
ClearCursor()
return 0
else
DA.DEBUG(1,"PickupContainerItem(",tobag, toslot,")")
PickupContainerItem(tobag, toslot) -- actually puts the item in the bag
--DA.DEBUG(1,"getItemFromGuildBank: PickupContainerItem("..tostring(tobag)..", "..tostring(toslot)..")")
if isClassic then
PickupContainerItem(tobag, toslot) -- actually puts the item in the bag
else
C_Container.PickupContainerItem(tobag, toslot)
end
end
end
ClearCursor()
Expand Down

0 comments on commit 48f1179

Please sign in to comment.