SCED/objects/AllPlayerCards.15bb07/ShortSupply.e5f541.ttslua

37 lines
1.1 KiB
Plaintext
Raw Normal View History

2022-12-22 07:35:59 -05:00
local playmatAPI = require("playermat/PlaymatApi")
function onLoad()
self.addContextMenuItem("Discard 10 cards", shortSupply)
end
-- called by context menu entry
function shortSupply(color)
2022-12-30 20:57:50 -05:00
local matColor = playmatAPI.getMatColorByPosition(self.getPosition())
-- get draw deck and discard position
local drawDeck = playmatAPI.getDrawDeck(matColor)
local discardPos = playmatAPI.getDiscardPosition(matColor)
-- error handling
if discardPos == nil then
2022-12-30 18:14:02 -05:00
broadcastToColor("Couldn't retrieve discard position from playermat!", color, "Red")
return
end
if drawDeck == nil then
broadcastToColor("Deck not found!", color, "Yellow")
return
elseif drawDeck.tag ~= "Deck" then
broadcastToColor("Deck only contains a single card!", color, "Yellow")
return
end
-- discard cards
2022-12-30 14:43:55 -05:00
broadcastToColor("Discarding top 10 cards for player color '" .. matColor .. "'.", color, "White")
discardPos.y = 0.5
for i = 1, 10 do
discardPos.y = discardPos.y + 0.05 * i
drawDeck.takeObject({ flip = true, position = discardPos })
end
end