2022-12-22 13:35:59 +01:00
|
|
|
local playmatAPI = require("playermat/PlaymatApi")
|
|
|
|
|
2022-12-22 03:29:16 +01:00
|
|
|
function onLoad()
|
|
|
|
self.addContextMenuItem("Discard 10 cards", shortSupply)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- called by context menu entry
|
|
|
|
function shortSupply(color)
|
2022-12-31 02:57:50 +01:00
|
|
|
local matColor = playmatAPI.getMatColorByPosition(self.getPosition())
|
2022-12-22 03:29:16 +01:00
|
|
|
|
2022-12-30 20:25:50 +01:00
|
|
|
-- get draw deck and discard position
|
|
|
|
local drawDeck = playmatAPI.getDrawDeck(matColor)
|
|
|
|
local discardPos = playmatAPI.getDiscardPosition(matColor)
|
|
|
|
|
|
|
|
-- error handling
|
2022-12-22 03:29:16 +01:00
|
|
|
if discardPos == nil then
|
2022-12-31 00:14:02 +01:00
|
|
|
broadcastToColor("Couldn't retrieve discard position from playermat!", color, "Red")
|
2022-12-22 03:29:16 +01:00
|
|
|
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 20:43:55 +01:00
|
|
|
broadcastToColor("Discarding top 10 cards for player color '" .. matColor .. "'.", color, "White")
|
2022-12-22 03:29:16 +01:00
|
|
|
for i = 1, 10 do
|
2023-01-22 04:19:02 +01:00
|
|
|
drawDeck.takeObject({ flip = true, position = { discardPos.x, 2 + 0.075 * i, discardPos.z } })
|
2022-12-22 03:29:16 +01:00
|
|
|
end
|
|
|
|
end
|