From e5a716a7009e79e8332d1d5debad912e71c02ae5 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 23 Sep 2024 23:59:24 +0200 Subject: [PATCH] updated shuffling --- src/playermat/Playermat.ttslua | 26 +++++++++++++++++++++++++- src/util/DeckLib.ttslua | 14 ++++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index 61e75293..67abe0a2 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -550,18 +550,42 @@ function drawCards(numCards) end function shuffleDiscardIntoDeck(player, _, elementId) + -- update the message color if this was called via button + if player then + updateMessageColor(player.color) + end + + -- get object references local deckAreaObjects = getDeckAreaObjects() if not deckAreaObjects.discard then -- display a feedback message if called via button if elementId == "shuffleDiscardButton" then - broadcastToColor("Discard pile is empty.", player.color, "Orange") + broadcastToColor("Discard pile is empty.", messageColor, "Orange") end return end + -- Norman Withers handling + 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, not shuffling cards into your deck.", messageColor) + return + end + + -- create a list of objects to shuffle local objectsToShuffle = {} if deckAreaObjects.topCard then table.insert(objectsToShuffle, deckAreaObjects.topCard) + + -- this will be executed after the deck merging + shuffling + Wait.time(flipTopCardFromDeck, 1) end table.insert(objectsToShuffle, deckAreaObjects.discard) diff --git a/src/util/DeckLib.ttslua b/src/util/DeckLib.ttslua index c44d645b..c0d44af6 100644 --- a/src/util/DeckLib.ttslua +++ b/src/util/DeckLib.ttslua @@ -21,6 +21,16 @@ do -- search the new position for existing card/deck local searchResult = searchLib.atPosition(pos, "isCardOrDeck") + + -- remove objects from search result that are queued + for i = #searchResult, 1, -1 do + for _, obj in ipairs(objects) do + if searchResult[i] == obj then + table.remove(searchResult, i) + end + end + end + local targetObj -- get new position @@ -65,9 +75,9 @@ do targetObj = obj end - -- this is the final object, maybe shuffle + -- this is the final object, maybe shuffle (delay to look less uncanny) if i == 1 and targetObj.type == "Deck" and shuffle then - targetObj.shuffle() + Wait.frames(function() targetObj.shuffle() end, 3) end end, -- check state of the object (make sure it's not moving)