From ec64ca6f768202bdb909f214708304a5a27a181f Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 31 Jul 2024 23:58:06 +0200 Subject: [PATCH 1/4] Updated topcard handling --- src/accessories/SearchAssistant.ttslua | 14 ++++++++------ src/core/Global.ttslua | 2 +- src/playermat/Playermat.ttslua | 6 ++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/accessories/SearchAssistant.ttslua b/src/accessories/SearchAssistant.ttslua index 316dffbe..d3dd4e08 100644 --- a/src/accessories/SearchAssistant.ttslua +++ b/src/accessories/SearchAssistant.ttslua @@ -113,7 +113,7 @@ function startSearch(messageColor, number) -- get draw deck local deckAreaObjects = playermatApi.getDeckAreaObjects(matColor) - if deckAreaObjects.draw == nil then + if deckAreaObjects.draw == nil and deckAreaObjects.topCard == nil then printToColor(matColor .. " draw deck could not be found!", messageColor, "Red") return end @@ -158,16 +158,18 @@ function startSearch(messageColor, number) -- handling for Norman Withers if deckAreaObjects.topCard then - deckAreaObjects.topCard.setRotation(setAsideRotation) + deckAreaObjects.topCard.deal(1, handColor) + number = number - 1 topCardDetected = true end searchView() - Wait.time(function() - deckAreaObjects = playermatApi.getDeckAreaObjects(matColor) - deckAreaObjects.draw.deal(number, handColor) - end, 1) + if number > 0 then + Wait.time(function() + deckAreaObjects.draw.deal(number, handColor) + end, 0.1) + end end -- place handCards back into deck and optionally shuffle diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index f856dbad..7ec35688 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -258,7 +258,7 @@ function onObjectNumberTyped(hoveredObject, playerColor, number) end -- check whether the hovered object is part of a players draw objects - for _, color in ipairs(playermatApi.getUsedMatColors()) do + for color, _ in ipairs(guidReferenceApi.getObjectsByType("Playermat")) do local deckAreaObjects = playermatApi.getDeckAreaObjects(color) if deckAreaObjects.topCard == hoveredObject or deckAreaObjects.draw == hoveredObject then playermatApi.drawCardsWithReshuffle(color, number) diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index 9fc8ac46..e3ad7862 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -473,8 +473,7 @@ function drawCardsWithReshuffle(numCards) if deckSize >= numCards then drawCards(numCards) - -- flip top card again for Norman - if topCardDetected and string.match(activeInvestigatorId, "%d%d%d%d%d") == "08004" then + if topCardDetected then flipTopCardFromDeck() end else @@ -483,8 +482,7 @@ function drawCardsWithReshuffle(numCards) shuffleDiscardIntoDeck() Wait.time(function() drawCards(numCards - deckSize) - -- flip top card again for Norman - if topCardDetected and string.match(activeInvestigatorId, "%d%d%d%d%d") == "08004" then + if topCardDetected then flipTopCardFromDeck() end end, 1) From e67c4e0cb38e816d7d1b3ff5596ee77c1f0e2580 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Wed, 31 Jul 2024 23:59:52 +0200 Subject: [PATCH 2/4] updated function --- src/core/Global.ttslua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/Global.ttslua b/src/core/Global.ttslua index 7ec35688..d273d4f0 100644 --- a/src/core/Global.ttslua +++ b/src/core/Global.ttslua @@ -258,7 +258,7 @@ function onObjectNumberTyped(hoveredObject, playerColor, number) end -- check whether the hovered object is part of a players draw objects - for color, _ in ipairs(guidReferenceApi.getObjectsByType("Playermat")) do + for color, _ in pairs(guidReferenceApi.getObjectsByType("Playermat")) do local deckAreaObjects = playermatApi.getDeckAreaObjects(color) if deckAreaObjects.topCard == hoveredObject or deckAreaObjects.draw == hoveredObject then playermatApi.drawCardsWithReshuffle(color, number) From 4594629d5e369f6267c5c85ef05b948cd913726a Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 1 Aug 2024 16:43:05 +0200 Subject: [PATCH 3/4] removed delay --- src/accessories/SearchAssistant.ttslua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/accessories/SearchAssistant.ttslua b/src/accessories/SearchAssistant.ttslua index d3dd4e08..4830ba4b 100644 --- a/src/accessories/SearchAssistant.ttslua +++ b/src/accessories/SearchAssistant.ttslua @@ -166,9 +166,7 @@ function startSearch(messageColor, number) searchView() if number > 0 then - Wait.time(function() - deckAreaObjects.draw.deal(number, handColor) - end, 0.1) + deckAreaObjects.draw.deal(number, handColor) end end From c88fb4764763230887ad93bb59e7a85ad32527ea Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Thu, 1 Aug 2024 19:41:29 +0200 Subject: [PATCH 4/4] harbinger handling --- src/accessories/SearchAssistant.ttslua | 19 +++++++++++++++++++ src/playermat/Playermat.ttslua | 15 +++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/accessories/SearchAssistant.ttslua b/src/accessories/SearchAssistant.ttslua index 4830ba4b..67bbdbf5 100644 --- a/src/accessories/SearchAssistant.ttslua +++ b/src/accessories/SearchAssistant.ttslua @@ -118,6 +118,20 @@ function startSearch(messageColor, number) return end + -- check for harbinger + local harbinger + if deckAreaObjects.topCard then + harbinger = isHarbinger(deckAreaObjects.topCard.getGMNotes()) + elseif deckAreaObjects.draw and not deckAreaObjects.draw.is_face_down then + local cards = deckAreaObjects.draw.getObjects() + harbinger = isHarbinger(cards[#cards].gm_notes) + end + + if harbinger then + printToColor("The Harbinger is on top of your deck, searching isn't allowed", messageColor) + return + end + -- get bounds to know the height of the deck local bounds = deckAreaObjects.draw.getBounds() drawDeckPosition = bounds.center + Vector(0, bounds.size.y / 2 + 0.2, 0) @@ -170,6 +184,11 @@ function startSearch(messageColor, number) end end +function isHarbinger(notes) + local md = JSON.decode(notes or "") or {} + return md.id == "08006" +end + -- place handCards back into deck and optionally shuffle function endSearch(_, _, isRightClick) local handCards = Player[handColor].getHandObjects() diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index e3ad7862..e65568b1 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -438,14 +438,12 @@ function drawCardsWithReshuffle(numCards) local deckAreaObjects = getDeckAreaObjects() -- Norman Withers handling - local harbinger = false - if deckAreaObjects.topCard and deckAreaObjects.topCard.getName() == "The Harbinger" then - harbinger = true + local harbinger + if deckAreaObjects.topCard then + harbinger = isHarbinger(deckAreaObjects.topCard.getGMNotes()) elseif deckAreaObjects.draw and not deckAreaObjects.draw.is_face_down then local cards = deckAreaObjects.draw.getObjects() - if cards[#cards].name == "The Harbinger" then - harbinger = true - end + harbinger = isHarbinger(cards[#cards].gm_notes) end if harbinger then @@ -491,6 +489,11 @@ function drawCardsWithReshuffle(numCards) end end +function isHarbinger(notes) + local md = JSON.decode(notes or "") or {} + return md.id == "08006" +end + -- get the draw deck and discard pile objects and returns the references ---@return table: string-indexed table with references to the found objects function getDeckAreaObjects()