local playmatAPI = require("playermat/PlaymatApi") -- forward declaration of variables that are used across functions local matColor local setAsidePosition local setAsideRotation local drawDeckPosition local quickParameters = {} quickParameters.function_owner = self quickParameters.font_size = 165 quickParameters.width = 275 quickParameters.height = 275 quickParameters.color = "White" -- common parameters local buttonParameters = {} buttonParameters.function_owner = self buttonParameters.font_size = 125 buttonParameters.width = 650 buttonParameters.height = 225 buttonParameters.color = "White" local inputParameters = {} inputParameters.function_owner = self inputParameters.input_function = "updateSearchNumber" inputParameters.tooltip = "custom search amount" inputParameters.label = "#" inputParameters.font_size = 175 inputParameters.width = 400 inputParameters.height = inputParameters.font_size + 23 inputParameters.position = { 0, 0.11, 0 } inputParameters.alignment = 3 inputParameters.validation = 2 function onLoad() normalView() end -- regular view with search box function normalView() self.clearButtons() self.clearInputs() self.createInput(inputParameters) -- create custom search button buttonParameters.click_function = "searchCustom" buttonParameters.tooltip = "Search the entered number of cards" buttonParameters.position = { 0, 0.11, 0.65 } buttonParameters.label = "Search" self.createButton(buttonParameters) -- create buttons to search 3, 6 or 9 cards quickParameters.click_function = "search3" quickParameters.label = "3" quickParameters.position = { -0.65, 0.11, -0.65 } self.createButton(quickParameters) quickParameters.click_function = "search6" quickParameters.label = "6" quickParameters.position = { 0, 0.11, -0.65 } self.createButton(quickParameters) quickParameters.click_function = "search9" quickParameters.label = "9" quickParameters.position = { 0.65, 0.11, -0.65 } self.createButton(quickParameters) end -- click functions function search3(_, playerColor) startSearch(playerColor, 3) end function search6(_, playerColor) startSearch(playerColor, 6) end function search9(_, playerColor) startSearch(playerColor, 9) end -- view during a search with "done" buttons function searchView() self.clearButtons() self.clearInputs() -- create the "End Search" button buttonParameters.click_function = "endSearch" buttonParameters.tooltip = "Left-click: Return cards and shuffle\nRight-click: Return cards without shuffling" buttonParameters.position = { 0, 0.11, 0 } buttonParameters.label = "End Search" self.createButton(buttonParameters) end -- input_function to get number of cards to search function updateSearchNumber(_, _, input) inputParameters.value = tonumber(input) end -- starts the search with the number from the input field function searchCustom(_, messageColor) local number = inputParameters.value if number ~= nil then startSearch(messageColor, number) else printToColor("Enter the number of cards to search in the textbox.", messageColor, "Orange") end end -- start the search (change UI, set handCards aside, draw cards) function startSearch(messageColor, number) matColor = playmatAPI.getMatColorByPosition(self.getPosition()) -- get draw deck local drawDeck = playmatAPI.getDrawDeck(matColor) if drawDeck == nil then printToColor(matColor .. " draw deck could not be found!", messageColor, "Red") return end drawDeckPosition = drawDeck.getPosition() printToColor("Place target(s) of search on set aside hand.", messageColor, "Green") -- get playmat orientation local offset = -15 if matColor == "Orange" or matColor == "Red" then offset = 15 end -- get position and rotation for set aside cards local handData = Player[matColor].getHandTransform() local handCards = Player[matColor].getHandObjects() setAsidePosition = handData.position + offset * handData.right setAsideRotation = { handData.rotation.x, handData.rotation.y + 180, 180 } for i = #handCards, 1, -1 do handCards[i].setPosition(setAsidePosition - Vector(0, i * 0.3, 0)) handCards[i].setRotation(setAsideRotation) end -- handling for Norman Withers for _, v in ipairs(searchArea(drawDeckPosition)) do local object = v.hit_object if object.tag == "Card" and not object.is_face_down then object.flip() Wait.time(function() drawDeck = playmatAPI.getDrawDeck(matColor) end, 1) break end end Wait.time(function() drawDeck.deal(number, matColor) end, 1) searchView() end -- place handCards back into deck and optionally shuffle function endSearch(_, _, isRightClick) local handCards = Player[matColor].getHandObjects() for i = #handCards, 1, -1 do handCards[i].setPosition(drawDeckPosition + Vector(0, 6 - i * 0.3, 0)) handCards[i].setRotation(setAsideRotation) end if not isRightClick then Wait.time(function() local deck = playmatAPI.getDrawDeck(matColor) if deck ~= nil then deck.shuffle() end end, 2) end -- draw set aside cards (from the ground!) for _, v in ipairs(searchArea(setAsidePosition - Vector(0, 5, 0))) do local obj = v.hit_object if obj.tag == "Deck" then Wait.time(function() obj.deal(#obj.getObjects(), matColor) end, 1) break elseif obj.tag == "Card" then obj.setPosition(Player[matColor].getHandTransform().position) obj.flip() break end end normalView() end -- utility function function searchArea(position) return Physics.cast({ origin = position, direction = { 0, 1, 0 }, type = 3, size = { 2, 2, 2 }, max_distance = 0 }) end