2022-12-22 07:35:59 -05:00
|
|
|
local playmatAPI = require("playermat/PlaymatApi")
|
|
|
|
|
2022-12-21 21:29:16 -05:00
|
|
|
function onLoad()
|
|
|
|
self.addContextMenuItem("Discard 10 cards", shortSupply)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- called by context menu entry
|
|
|
|
function shortSupply(color)
|
2022-12-30 14:25:50 -05:00
|
|
|
local matColor = playmatAPI.getMatColorbyPosition(self.getPosition())
|
2022-12-21 21:29:16 -05:00
|
|
|
|
2022-12-30 14:25:50 -05:00
|
|
|
-- get draw deck and discard position
|
|
|
|
local drawDeck = playmatAPI.getDrawDeck(matColor)
|
|
|
|
local discardPos = playmatAPI.getDiscardPosition(matColor)
|
|
|
|
|
|
|
|
-- error handling
|
2022-12-21 21:29:16 -05:00
|
|
|
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
|
2022-12-30 14:25:50 -05:00
|
|
|
drawDeck.takeObject({ flip = true, position = discardPos })
|
2022-12-21 21:29:16 -05:00
|
|
|
end
|
|
|
|
end
|