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 characterBound check should prevent invalid item transfers #181

Merged
merged 1 commit into from
Jul 24, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PersonalAssistant/Menu/ItemContextMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local function _isBankingRuleNotAllowed(itemLink, bagId, slotIndex)
if itemType == ITEMTYPE_RECIPE then return true end
if itemType == ITEMTYPE_MASTER_WRIT then return true end
if itemType == ITEMTYPE_AVA_REPAIR then return true end
if PAHF.isItemLinkCharacterBound(itemLink) then return true end
-- TODO: add logic to also check other itemTypes that are already covered! --> Crafting Materials?
return false
end
Expand Down
4 changes: 4 additions & 0 deletions PersonalAssistant/PersonalAssistant.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,14 @@ function PA.cursorPickup(type, param1, bagId, slotIndex, param4, param5, param6,

local boundState = select(21, ZO_LinkHandler_ParseLink(itemLink))
local isBound = IsItemLinkBound(itemLink)
local bindType = GetItemBindType(bagId, slotIndex)
local isBOPAndTradeable = IsItemBoPAndTradeable(bagId, slotIndex)
local isCharacterBound = isBound and bindType == BIND_TYPE_ON_PICKUP_BACKPACK
d("boundState="..tostring(boundState))
d("isBound="..tostring(isBound))
d("bindType="..tostring(bindType))
d("isBOPAndTradeable="..tostring(isBOPAndTradeable))
d("isCharacterBound="..tostring(isCharacterBound))

local isStolen = IsItemStolen(bagId, slotIndex)
if isStolen then
Expand Down
23 changes: 23 additions & 0 deletions PersonalAssistant/Utilities/HelperFunctions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ local PAC = PA.Constants
-- == COMPARATORS == --
-- -----------------------------------------------------------------------------------------------------------------

local function _isItemCharacterBound(bagId, slotIndex)
local isBound = IsItemBound(bagId, slotIndex)
if isBound then
local bindType = GetItemBindType(bagId, slotIndex)
return bindType == BIND_TYPE_ON_PICKUP_BACKPACK
end
return false
end

local function getCombinedItemTypeSpecializedComparator(combinedLists)
local function _isItemOfItemTypeAndKnowledge(bagId, slotIndex, expectedItemType, expectedIsKnown)
local itemType = GetItemType(bagId, slotIndex)
Expand Down Expand Up @@ -48,6 +57,7 @@ local function getCombinedItemTypeSpecializedComparator(combinedLists)

return function(itemData)
if IsItemStolen(itemData.bagId, itemData.slotIndex) then return false end
if _isItemCharacterBound(itemData.bagId, itemData.slotIndex) then return false end
local itemLink = GetItemLink(itemData.bagId, itemData.slotIndex)
for _, itemType in pairs(combinedLists.learnableKnownItemTypes) do
if _isItemOfItemTypeAndKnowledge(itemData.bagId, itemData.slotIndex, itemType, true) then return true end
Expand Down Expand Up @@ -75,6 +85,7 @@ end
local function getItemTypeComparator(itemTypeList)
return function(itemData)
if IsItemStolen(itemData.bagId, itemData.slotIndex) then return false end
if _isItemCharacterBound(itemData.bagId, itemData.slotIndex) then return false end
for _, itemType in pairs(itemTypeList) do
if itemType == itemData.itemType then return true end
end
Expand All @@ -85,6 +96,7 @@ end
local function getItemIdComparator(itemIdList)
return function(itemData)
if IsItemStolen(itemData.bagId, itemData.slotIndex) then return false end
if _isItemCharacterBound(itemData.bagId, itemData.slotIndex) then return false end
for itemId, _ in pairs(itemIdList) do
if itemId == GetItemId(itemData.bagId, itemData.slotIndex) then return true end
end
Expand All @@ -94,6 +106,7 @@ end

local function getStolenJunkComparator()
return function(itemData)
if _isItemCharacterBound(itemData.bagId, itemData.slotIndex) then return false end
local isStolen = IsItemStolen(itemData.bagId, itemData.slotIndex)
local isJunk = IsItemJunk(itemData.bagId, itemData.slotIndex)
return isStolen and isJunk
Expand Down Expand Up @@ -300,6 +313,15 @@ end
-- == ITEM LINKS == --
-- -----------------------------------------------------------------------------------------------------------------

local function isItemLinkCharacterBound(itemLink)
local isBound = IsItemLinkBound(itemLink)
if isBound then
local bindType = GetItemLinkBindType(itemLink)
return bindType == BIND_TYPE_ON_PICKUP_BACKPACK
end
return false
end

local function isItemLinkIntricateTraitType(itemLink)
local itemTraitInformation = GetItemTraitInformationFromItemLink(itemLink)
return itemTraitInformation == ITEM_TRAIT_INFORMATION_INTRICATE
Expand Down Expand Up @@ -341,6 +363,7 @@ PA.HelperFunctions = {
debuglnAuthor = debuglnAuthor,
getDefaultProfileName = getDefaultProfileName,
isAddonRunning = isAddonRunning,
isItemLinkCharacterBound = isItemLinkCharacterBound,
isItemLinkIntricateTraitType = isItemLinkIntricateTraitType,
getIconExtendedItemLink = getIconExtendedItemLink
}