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

40 lines
1.0 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)
local cardPos = self.getPosition()
2022-12-22 07:45:47 -05:00
local mat = playmatAPI.getMatbyPosition(cardPos)
if mat == nil then return end
-- get draw deck and discard pile
mat.call("getDrawDiscardDecks")
local drawDeck = mat.getVar("drawDeck")
local discardPos = mat.getTable("DISCARD_PILE_POSITION")
if discardPos == nil then
broadcastToAll("Couldn't retrieve discard position from playermat!", "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
discardPos.y = 0.5
for i = 1, 10 do
discardPos.y = discardPos.y + 0.05 * i
drawDeck.takeObject({
flip = true,
position = discardPos
})
end
end