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

59 lines
1.3 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:35:59 -05:00
local mat = playmatAPI.getMatbyColor(getMatColor(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
2022-12-22 07:35:59 -05:00
-- helper to find playermat color based on position
function getMatColor(cardPos)
local color
if cardPos.x < -42 then
if cardPos.z > 0 then
2022-12-22 07:35:59 -05:00
color = "White"
else
2022-12-22 07:35:59 -05:00
color = "Orange"
end
else
if cardPos.z > 0 then
2022-12-22 07:35:59 -05:00
color = "Green"
else
2022-12-22 07:35:59 -05:00
color = "Red"
end
end
2022-12-22 07:35:59 -05:00
return color
end