From a0895762a8250189c6171f7bea2136826d845f97 Mon Sep 17 00:00:00 2001 From: Chr1Z93 Date: Mon, 8 Jul 2024 13:52:28 +0200 Subject: [PATCH] updated random discard feedback --- src/playermat/Playermat.ttslua | 56 ++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/src/playermat/Playermat.ttslua b/src/playermat/Playermat.ttslua index 4e97e3ec..e2baeb45 100644 --- a/src/playermat/Playermat.ttslua +++ b/src/playermat/Playermat.ttslua @@ -393,7 +393,7 @@ function doUpkeep(_, clickedByColor, isRightClick) for _, card in ipairs(handCards) do local md = JSON.decode(card.getGMNotes()) - if md ~= nil and (not md.weakness and not md.hidden and md.type ~= "Enemy") then + if card.type == "Card" and md ~= nil and (not md.weakness and not md.hidden and md.id ~= "52020") then table.insert(cardsToDiscard, card) end end @@ -553,21 +553,46 @@ function doDiscardOne() broadcastToColor("Cannot discard from empty hand!", messageColor, "Red") else local choices = {} - for i = 1, #hand do - local md = JSON.decode(hand[i].getGMNotes()) - if md ~= nil and (not md.weakness and not md.hidden and md.type ~= "Enemy") then - table.insert(choices, i) - elseif md == nil then - broadcastToColor(hand[i].getName() .. " is missing metadata and won't be discarded.", messageColor, "Orange") + local hiddenCards = {} + local missingMetadataCards = {} + for i, handObj in ipairs(hand) do + if handObj.type == "Card" then + -- get a name for the card or use the index if unnamed + local name = handObj.getName() + if name == "" then + name = "Card " .. i + end + + -- check card for metadata + local md = JSON.decode(handObj.getGMNotes()) + if md == nil then + table.insert(missingMetadataCards, name) + elseif md.hidden or md.id == "52020" then + table.insert(hiddenCards, name) + else + table.insert(choices, i) + end end end + -- print message with hidden cards + if #hiddenCards > 0 then + local cardList = concatenateListOfStrings(hiddenCards) + printToColor("Excluded (hidden): " .. cardList, messageColor) + end + + -- print message with missing metadata cards + if #missingMetadataCards > 0 then + local cardList = concatenateListOfStrings(missingMetadataCards) + printToColor("Excluded (missing data): " .. cardList, messageColor) + end + if #choices == 0 then - broadcastToColor("Hidden cards can't be randomly discarded.", messageColor, "Orange") + broadcastToColor("Didn't find any eligible cards for random discarding.", messageColor, "Orange") return end - -- get a random non-hidden card (from the "choices" table) + -- get a random eligible card (from the "choices" table) local num = math.random(1, #choices) deckLib.placeOrMergeIntoDeck(hand[choices[num]], returnGlobalDiscardPosition(), self.getRotation()) broadcastToAll(getColoredName(playerColor) .. " randomly discarded card " @@ -575,6 +600,19 @@ function doDiscardOne() end end +function concatenateListOfStrings(list) + local cardList + for _, cardName in ipairs(list) do + if not cardList then + cardList = "" + else + cardList = cardList .. ", " + end + cardList = cardList .. cardName + end + return cardList +end + -- checks if DES is present function checkForDES() hasDES = false