Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAB: new "isSameItem" function also considers if item is from CrownStore #59

Merged
merged 1 commit into from Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions PersonalAssistant/PersonalAssistant.lua
Expand Up @@ -165,6 +165,9 @@ function PA.cursorPickup(type, param1, bagId, slotIndex, param4, param5, param6,

local sellInformation = GetItemLinkSellInformation(itemLink)
d("sellInformation="..GetString("SI_ITEMSELLINFORMATION", sellInformation).."("..sellInformation..")")

local isItemFromCrownStore = IsItemFromCrownStore(bagId, slotIndex)
d("isItemFromCrownStore="..tostring(isItemFromCrownStore))
end
end

Expand Down
Expand Up @@ -152,6 +152,14 @@ local function moveSecureItemsFromTo(toBeMovedItemsTable, startIndex, toBeMovedA
end
end

local function _isSameItem(itemDataA, itemDataB)
if itemDataA.itemInstanceId == itemDataB.itemInstanceId then
local isItemAFromCrownStore = IsItemFromCrownStore(itemDataA.bagId, itemDataA.slotIndex)
local isItemBFromCrownStore = IsItemFromCrownStore(itemDataB.bagId, itemDataB.slotIndex)
return isItemAFromCrownStore == isItemBFromCrownStore
end
return false
end

-- Immediately moves items from source to target bag, if the same item exists in both locations (i.e. filling up existing
-- stacks). All items that either cannot be moved because there is no matching item in the target bag, or because the
Expand All @@ -169,8 +177,8 @@ local function stackInTargetBagAndPopulateNotMovedItemsTable(fromBagCache, toBag
PAHF.debugln("try to move %d x %s", stackToMove, itemLink)

for toBagCacheIndex, toBagItemData in pairs(toBagCache) do
if fromBagItemData.itemInstanceId == toBagItemData.itemInstanceId then
-- same itemInstanceId
if _isSameItem(fromBagItemData, toBagItemData) then
-- same itemInstanceId and same CrownStore source information
local _, targetMaxStack = GetSlotStackSize(toBagItemData.bagId, toBagItemData.slotIndex)
local targetStack = toBagItemData.stackCount -- cannot use [GetSlotStackSize] becuase it does not reflect changes after the bagCache is created
local targetFreeStacks = targetMaxStack - targetStack
Expand Down Expand Up @@ -211,7 +219,7 @@ local function stackInTargetBagAndPopulateNotMovedItemsTable(fromBagCache, toBag
-- loop through all items already added to list
for index, prevBagItemData in pairs(notMovedItemsTable) do
-- check if it is the same item and if there is some space left
if prevBagItemData.itemInstanceId == fromBagItemData.itemInstanceId and prevBagItemData.customStackToMove < sourceStackMaxSize then
if _isSameItem(prevBagItemData, fromBagItemData) and prevBagItemData.customStackToMove < sourceStackMaxSize then
local prevSourceFreeStack = sourceStackMaxSize - prevBagItemData.customStackToMove
if prevSourceFreeStack >= stackToMove and fromBagItemData.stackCount >= stackToMove then
-- stack everything
Expand Down