40 lines
1.0 KiB
Plaintext
40 lines
1.0 KiB
Plaintext
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()
|
|
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
|