updated random discard feedback

This commit is contained in:
Chr1Z93 2024-07-08 13:52:28 +02:00
parent f8d8cb0d28
commit a0895762a8

View File

@ -393,7 +393,7 @@ function doUpkeep(_, clickedByColor, isRightClick)
for _, card in ipairs(handCards) do for _, card in ipairs(handCards) do
local md = JSON.decode(card.getGMNotes()) 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) table.insert(cardsToDiscard, card)
end end
end end
@ -553,21 +553,46 @@ function doDiscardOne()
broadcastToColor("Cannot discard from empty hand!", messageColor, "Red") broadcastToColor("Cannot discard from empty hand!", messageColor, "Red")
else else
local choices = {} local choices = {}
for i = 1, #hand do local hiddenCards = {}
local md = JSON.decode(hand[i].getGMNotes()) local missingMetadataCards = {}
if md ~= nil and (not md.weakness and not md.hidden and md.type ~= "Enemy") then for i, handObj in ipairs(hand) do
table.insert(choices, i) if handObj.type == "Card" then
elseif md == nil then -- get a name for the card or use the index if unnamed
broadcastToColor(hand[i].getName() .. " is missing metadata and won't be discarded.", messageColor, "Orange") 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
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 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 return
end 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) local num = math.random(1, #choices)
deckLib.placeOrMergeIntoDeck(hand[choices[num]], returnGlobalDiscardPosition(), self.getRotation()) deckLib.placeOrMergeIntoDeck(hand[choices[num]], returnGlobalDiscardPosition(), self.getRotation())
broadcastToAll(getColoredName(playerColor) .. " randomly discarded card " broadcastToAll(getColoredName(playerColor) .. " randomly discarded card "
@ -575,6 +600,19 @@ function doDiscardOne()
end end
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 -- checks if DES is present
function checkForDES() function checkForDES()
hasDES = false hasDES = false