From a44183bd6bbaf3d29874136b2268e0b5a8b5d257 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 15 Aug 2024 00:05:13 +0200 Subject: [PATCH 1/2] Adjusted searching on cards to a smaller area --- src/core/GameKeyHandler.ttslua | 3 ++- src/core/Global.ttslua | 7 ++++--- src/util/SearchLib.ttslua | 11 ++++++----- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/core/GameKeyHandler.ttslua b/src/core/GameKeyHandler.ttslua index 43edb90b..7d79bd0d 100644 --- a/src/core/GameKeyHandler.ttslua +++ b/src/core/GameKeyHandler.ttslua @@ -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") diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index fffbf9d3..618b483b 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -2407,14 +2407,15 @@ 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 local maybeDeleteThese = {} if useInfo.token == "clue" then - for _, obj in ipairs(searchLib.onObject(card, "isClue")) do + for _, obj in ipairs(searchLib.onObject(card, "isClue", 0.8)) 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 @@ -2425,7 +2426,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()) diff --git a/src/util/SearchLib.ttslua b/src/util/SearchLib.ttslua index ad5da1b2..1700e51c 100644 --- a/src/util/SearchLib.ttslua +++ b/src/util/SearchLib.ttslua @@ -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 From 02ab80952e3803da9b04c7bb7ff4b203f2587406 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 15 Aug 2024 00:06:44 +0200 Subject: [PATCH 2/2] update for clues --- src/core/Global.ttslua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 618b483b..df4ad3ef 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -2408,9 +2408,10 @@ function TokenManager.replenishTokens(card, useInfo) 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", 0.8)) do + for _, obj in ipairs(searchLib.onObject(card, "isClue")) do foundTokens = foundTokens + math.abs(obj.getQuantity()) table.insert(maybeDeleteThese, obj) end