PLAYAREA = { position = { x=-25, y=4, z=0 }, rotation = { x=0, y=90, z=0 }, scale = { x=37, y=5, z=43 } } ASSEMBLY = { position = { x=68, y=2, z=36 }, rotation = { x=0, y=270, z=180 } } SET_ASIDE = { position = { x=-2.52, y=2, z=14.87 }, rotation = { x=0, y=270, z=180 } } EXPLORATION = { position = { x=-6.33, y=2, z=14.87 }, rotation = { x=0, y=270, z=180 } } START = { position = { x=-30.22, y=2, z=-0.03 }, rotation = { x=0, y=270, z=180 } } LOCATIONS = { "City of the Serpents", "Bridge over N'kai", "Abandoned Site", "Caverns of Yoth", "Hall of Heresy", "Bright Canyon", "Forked Path", "Crumbling Precipice", "Broken Passage", "Steps of Yoth" } STEPS = "Steps of Yoth" PERILS = "Perils of Yoth" function onLoad() self.createButton({ label="Set Up", click_function="setup", function_owner=self, position={0,0.1,0.4}, height=120, width=400, scale={x=1.75, y=1.75, z=1.75}, font_size=100 }) playarea = getObjectFromGUID("721ba2") TOKEN_IMAGES = Global.getTable("tokenplayerone") math.randomseed(os.time()) end function setup(_obj, _color, _alt_click) local objs = Physics.cast({ origin = PLAYAREA.position, direction = { x=0, y=1, z=0 }, type = 3, size = PLAYAREA.scale, orientation = PLAYAREA.rotation }) -- make index of all cards in play area and remove all clues and doom local allCards = {} for i,v in ipairs(objs) do local obj = v.hit_object local name = obj.getName() if name ~= nil then if obj.tag == "Card" then allCards[name] = { card = obj, guid = obj.getGUID() } elseif obj.tag == "Deck" then local cards = obj.getObjects() for j,card in ipairs(cards) do if card.guid ~= nil and card.name ~= nil then allCards[card.name] = { deck = obj, guid = card.guid } end end elseif obj.tag == "Tile" then local props = obj.getCustomObject() if (props.image == TOKEN_IMAGES.clue and props.image_bottom == TOKEN_IMAGES.doom) or (props.image == TOKEN_IMAGES.doom and props.image_bottom == TOKEN_IMAGES.clue) then Wait.time(|| Global.destroyObject(obj), 1) end end end end -- find location cards local locCards = {} local notFound = {} for i,loc in ipairs(LOCATIONS) do local card = allCards[loc] if card == nil then table.insert(notFound, loc) else table.insert(locCards, card) end end if #notFound > 0 then printToColor("The following locations were not found: " .. table.concat(notFound, ", "), _color) printToColor("Place them in the central play area and try again", _color) return end -- Perils of Yoth local peril = allCards[PERILS] if peril ~= nil then if peril.card ~= nil then placeCard(nil, peril.card, ASSEMBLY) else placeCard(peril.deck, peril.guid, ASSEMBLY) if peril.deck.is_face_down and #peril.deck.getObjects() > 0 then peril.deck.shuffle() end end end -- reset clue spawn status and make a deck of all location cards in the -- assembly area local spawnedGuids = playarea.getVar("SPAWNED_LOCATION_GUIDS") for i,loc in ipairs(locCards) do spawnedGuids[loc.guid] = nil if loc.card ~= nil then placeCard(nil, loc.card, ASSEMBLY) elseif loc.deck ~= nil and #loc.deck.getObjects() > 0 then placeCard(loc.deck, loc.guid, ASSEMBLY) else -- all but one card was taken from deck, so it doesn't exist anymore Wait.time(|| placeCard(nil, loc.guid, ASSEMBLY), 1) end end playarea.setVar("SPAWNED_LOCATION_GUIDS", spawnedGuids) Wait.time(setup_2, 2) end function setup_2() local objs = Physics.cast({ origin = ASSEMBLY.position, direction = { x=0, y=1, z=0 }, type = 3, size = { x=1, y=1, z=1 }, orientation = ASSEMBLY.rotation }) local deck = nil for i,v in ipairs(objs) do if v.hit_object.tag == "Deck" then deck = v.hit_object end end local locMap = {} for i,card in ipairs(deck.getObjects()) do locMap[card.name] = card.guid end -- place Steps of Yoth and Perils of Yoth (if necessary) placeCard(deck, locMap[STEPS], EXPLORATION) if locMap[PERILS] ~= nil then placeCard(deck, locMap[PERILS], EXPLORATION) end -- randomly select starting location deck.shuffle() placeCard(deck, nil, START, true) -- assemble exploration deck for i=1,4 do placeCard(deck, nil, EXPLORATION) end Wait.time(setup_3, 1) -- move remaining cards to set aside area deck.setPosition(SET_ASIDE.position) deck.setName("Set Aside Locations") end function setup_3() local objs = Physics.cast({ origin = EXPLORATION.position, direction = { x=0, y=1, z=0 }, type = 3, size = { x=1, y=1, z=1 }, orientation = EXPLORATION.rotation }) local deck = nil for i,v in ipairs(objs) do if v.hit_object.tag == "Deck" then deck = v.hit_object end end deck.shuffle() deck.setName("Exploration Deck") end function placeCard(deck, card, location, faceup) if deck ~= nil then deck.takeObject({ guid = card, position = location.position, rotation = location.rotation, smooth = false, flip = faceup }) return end if type(card) == "string" then card = getObjectFromGUID(card) end card.setRotation(location.rotation) card.setPosition(location.position) if faceup then card.flip() end end