Merge pull request #813 from argonui/searching-on-cards

Adjusted searching on cards to a smaller area
This commit is contained in:
dscarpac 2024-08-14 19:11:29 -05:00 committed by GitHub
commit 1d99f0af12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 8 deletions

View File

@ -268,7 +268,8 @@ function removeOneUse(playerColor, hoveredObject)
if hoveredObject.type == "Tile" then if hoveredObject.type == "Tile" then
targetObject = hoveredObject targetObject = hoveredObject
elseif hoveredObject.type == "Card" then elseif hoveredObject.type == "Card" then
local searchResult = searchLib.onObject(hoveredObject, "isTileOrToken") -- we're only searching 80% of the cards area to avoid matching tokens on other cards
local searchResult = searchLib.onObject(hoveredObject, "isTileOrToken", 0.8)
if #searchResult == 0 then if #searchResult == 0 then
broadcastToColor("No tokens found!", playerColor, "Yellow") broadcastToColor("No tokens found!", playerColor, "Yellow")

View File

@ -2407,6 +2407,8 @@ function TokenManager.replenishTokens(card, useInfo)
local clickableResourceCounter = nil local clickableResourceCounter = nil
local foundTokens = 0 local foundTokens = 0
-- we're only searching 80% of the cards area to avoid matching tokens on other cards
-- (except for clues, since these are on locations and they should never be this close)
local maybeDeleteThese = {} local maybeDeleteThese = {}
if useInfo.token == "clue" then if useInfo.token == "clue" then
for _, obj in ipairs(searchLib.onObject(card, "isClue")) do for _, obj in ipairs(searchLib.onObject(card, "isClue")) do
@ -2414,7 +2416,7 @@ function TokenManager.replenishTokens(card, useInfo)
table.insert(maybeDeleteThese, obj) table.insert(maybeDeleteThese, obj)
end end
elseif useInfo.token == "doom" then elseif useInfo.token == "doom" then
for _, obj in ipairs(searchLib.onObject(card, "isDoom")) do for _, obj in ipairs(searchLib.onObject(card, "isDoom", 0.8)) do
foundTokens = foundTokens + math.abs(obj.getQuantity()) foundTokens = foundTokens + math.abs(obj.getQuantity())
table.insert(maybeDeleteThese, obj) table.insert(maybeDeleteThese, obj)
end end
@ -2425,7 +2427,7 @@ function TokenManager.replenishTokens(card, useInfo)
searchType = useInfo.token searchType = useInfo.token
end end
for _, obj in ipairs(searchLib.onObject(card, "isTileOrToken")) do for _, obj in ipairs(searchLib.onObject(card, "isTileOrToken", 0.8)) do
local memo = obj.getMemo() local memo = obj.getMemo()
if searchType == memo then if searchType == memo then
foundTokens = foundTokens + math.abs(obj.getQuantity()) foundTokens = foundTokens + math.abs(obj.getQuantity())

View File

@ -42,25 +42,26 @@ do
end end
-- searches the specified area -- searches the specified area
SearchLib.inArea = function(pos, rot, size, filter) function SearchLib.inArea(pos, rot, size, filter)
return returnSearchResult(pos, rot, size, filter) return returnSearchResult(pos, rot, size, filter)
end end
-- searches the area on an object -- searches the area on an object
SearchLib.onObject = function(obj, filter) function SearchLib.onObject(obj, filter, scale)
scale = scale or 1
local pos = obj.getPosition() local pos = obj.getPosition()
local size = obj.getBounds().size:setAt("y", 1) local size = obj.getBounds().size:scale(scale):setAt("y", 1)
return returnSearchResult(pos, _, size, filter) return returnSearchResult(pos, _, size, filter)
end end
-- searches the specified position (a single point) -- searches the specified position (a single point)
SearchLib.atPosition = function(pos, filter) function SearchLib.atPosition(pos, filter)
local size = { 0.1, 2, 0.1 } local size = { 0.1, 2, 0.1 }
return returnSearchResult(pos, _, size, filter) return returnSearchResult(pos, _, size, filter)
end end
-- searches below the specified position (downwards until y = 0) -- searches below the specified position (downwards until y = 0)
SearchLib.belowPosition = function(pos, filter) function SearchLib.belowPosition(pos, filter)
local size = { 0.1, 2, 0.1 } local size = { 0.1, 2, 0.1 }
local direction = { 0, -1, 0 } local direction = { 0, -1, 0 }
local maxDistance = pos.y local maxDistance = pos.y