Skip to content
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
3 changes: 2 additions & 1 deletion src/core/GameKeyHandler.ttslua
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ function removeOneUse(playerColor, hoveredObject)
if hoveredObject.type == "Tile" then
targetObject = hoveredObject
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
broadcastToColor("No tokens found!", playerColor, "Yellow")
Expand Down
6 changes: 4 additions & 2 deletions src/core/Global.ttslua
Original file line number Diff line number Diff line change
Expand Up @@ -2407,14 +2407,16 @@ function TokenManager.replenishTokens(card, useInfo)
local clickableResourceCounter = nil
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 = {}
if useInfo.token == "clue" then
for _, obj in ipairs(searchLib.onObject(card, "isClue")) do
foundTokens = foundTokens + math.abs(obj.getQuantity())
table.insert(maybeDeleteThese, obj)
end
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())
table.insert(maybeDeleteThese, obj)
end
Expand All @@ -2425,7 +2427,7 @@ function TokenManager.replenishTokens(card, useInfo)
searchType = useInfo.token
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()
if searchType == memo then
foundTokens = foundTokens + math.abs(obj.getQuantity())
Expand Down
11 changes: 6 additions & 5 deletions src/util/SearchLib.ttslua
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,26 @@ do
end

-- searches the specified area
SearchLib.inArea = function(pos, rot, size, filter)
function SearchLib.inArea(pos, rot, size, filter)
return returnSearchResult(pos, rot, size, filter)
end

-- 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 size = obj.getBounds().size:setAt("y", 1)
local size = obj.getBounds().size:scale(scale):setAt("y", 1)
return returnSearchResult(pos, _, size, filter)
end

-- searches the specified position (a single point)
SearchLib.atPosition = function(pos, filter)
function SearchLib.atPosition(pos, filter)
local size = { 0.1, 2, 0.1 }
return returnSearchResult(pos, _, size, filter)
end

-- 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 direction = { 0, -1, 0 }
local maxDistance = pos.y
Expand Down