local s=script.Parent local P=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local m=game:GetService("\082\117\110\083\101\114\118\105\099\101")local T=game:GetService("\067\111\108\108\101\099\116\105\111\110\083\101\114\118\105\099\101")local w=require(P:WaitForChild("\069\118\101\110\116\083\101\113\117\101\110\099\101\114"))local r=require(P:WaitForChild("\067\108\105\101\110\116\067\111\117\110\116\100\111\119\110\077\111\100\117\108\101"))local v=require(P:WaitForChild("\070\117\108\108\115\099\114\101\101\110\077\111\100\117\108\101"))local G=require(P:WaitForChild("\077\101\114\099\104\066\111\111\116\104"))local X=require(P:WaitForChild("\070\114\105\101\110\100\115\076\111\099\097\116\111\114"))local L=require(P:WaitForChild("\066\111\117\110\099\101\080\108\097\116\102\111\114\109\115"))local t=(game:GetService("\080\108\097\121\101\114\115")).LocalPlayer local u=w.createSchema()local k=nil local x=nil local C=nil local H=nil local f=nil function setFriendsLocatorEnabled(s)X.configure({showAllPlayers=m:IsStudio(),thresholdDistance=s and 100 or math.huge})end function enableBouncyPads()for s,P in pairs(T:GetTagged("\066\111\117\110\099\121"))do L.new(P,{debounce=.2,bounceVector=Vector3.new(0,1,0);bounceForce=150})end L:enable()end function getTimeLengthRemaining()return(s:GetAttribute("\084\105\109\101\076\101\110\103\116\104")-H.Value)-5 end function updateTimerDate()if H and C then C.UniversalEventDate=DateTime.fromUnixTimestamp((DateTime.now()).UnixTimestamp+getTimeLengthRemaining())end end u.OnSetup=function(s)H=s k=w.getCurrentSceneEnvironment()x=w.getCurrentServerEnvironmentFromClient()if not G.isMerchBoothEnabled()then G.setEnabled(true)end f=((x:WaitForChild("\083\116\097\103\101")):WaitForChild("\068\105\115\112\108\097\121")):WaitForChild("\067\111\117\110\116\100\111\119\110\066\111\097\114\100\080\097\114\116")v.CreateButtonToFocusScreen(f)setFriendsLocatorEnabled(true)enableBouncyPads()local P=(t:WaitForChild("\080\108\097\121\101\114\071\117\105")):WaitForChild("\067\111\117\110\116\100\111\119\110\084\105\109\101\114\071\085\073")local m=(P:WaitForChild("\084\111\112\070\114\097\109\101\085\073")):WaitForChild("\084\105\109\101\114\066\117\098\098\108\101\085\073")local T=(f:WaitForChild("\083\117\114\102\097\099\101\071\117\105")):WaitForChild("\084\105\109\101\114\083\099\114\101\101\110\085\073")C=r:AddTimer({Enabled=false,UniversalEventDate=DateTime.fromUnixTimestamp((DateTime.now()).UnixTimestamp+getTimeLengthRemaining());BubbleTimerUI=m,BoardTimerUI=T,DisableBubbleWhenBoardVisible=true})end u.OnRun=function()if C then updateTimerDate()C.Enabled=true end local P=u:schedule({StartTimes={s:GetAttribute("\084\105\109\101\076\101\110\103\116\104")-10},OnStart=function()v.RemoveButton()if f and f.Parent then v.FocusScreen(f)end end})end u.OnEndScene=function()if C then C.Enabled=false r:RemoveTimer(C)C=nil end v.RemoveButton()v.FocusScreen()if G.isMerchBoothEnabled()then G.setEnabled(false)end setFriendsLocatorEnabled(false)end return u
-- Pre Show Venue

local scene = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local CollectionService = game:GetService("CollectionService")

local EventSequencer = require(ReplicatedStorage:WaitForChild("EventSequencer"))
local CountdownTimersModule = require(ReplicatedStorage:WaitForChild("ClientCountdownModule"))
local FullScreenModule = require(ReplicatedStorage:WaitForChild("FullscreenModule"))
local MerchBooth = require(ReplicatedStorage:WaitForChild("MerchBooth"))
local FriendsLocator = require(ReplicatedStorage:WaitForChild("FriendsLocator"))
local BouncePlatforms = require(ReplicatedStorage:WaitForChild("BouncePlatforms"))

local localPlayer = game:GetService("Players").LocalPlayer

local Schema = EventSequencer.createSchema()

local Environment = nil
local ServerEnvironment = nil
local timer = nil
local timePositionObject = nil
local screenPart = nil

function setFriendsLocatorEnabled(enabled)
	FriendsLocator.configure({
		showAllPlayers = RunService:IsStudio(), -- Shows all players when testing, but only friends when live.
		thresholdDistance = enabled and 100 or math.huge, -- Locators will not show up if
	})
end

function enableBouncyPads()
	for _, part in pairs(CollectionService:GetTagged("Bouncy")) do
		BouncePlatforms.new(part, {
			debounce = 0.2,
			bounceVector = Vector3.new(0, 1, 0),
			bounceForce = 150,
		})
	end
	BouncePlatforms:enable()
end

function getTimeLengthRemaining()
	-- We wait 5 seconds because of eventSequencer's roughly 5 second grace period to load a scene before orchestrating
	return scene:GetAttribute("TimeLength") - timePositionObject.Value - 5
end

function updateTimerDate()
	if timePositionObject and timer then
		timer.UniversalEventDate = DateTime.fromUnixTimestamp(DateTime.now().UnixTimestamp + getTimeLengthRemaining())
	end
end

Schema.OnSetup = function(timePositionObjectParam)
	timePositionObject = timePositionObjectParam
	Environment = EventSequencer.getCurrentSceneEnvironment()
	ServerEnvironment = EventSequencer.getCurrentServerEnvironmentFromClient()

	if not MerchBooth.isMerchBoothEnabled() then
		MerchBooth.setEnabled(true)
	end

	screenPart = ServerEnvironment:WaitForChild("Stage"):WaitForChild("Display"):WaitForChild("CountdownBoardPart")
	FullScreenModule.CreateButtonToFocusScreen(screenPart)

	setFriendsLocatorEnabled(true)

	enableBouncyPads()

	local countdownTimerGUI = localPlayer:WaitForChild("PlayerGui"):WaitForChild("CountdownTimerGUI")
	local bubbleTimerUI = countdownTimerGUI:WaitForChild("TopFrameUI"):WaitForChild("TimerBubbleUI")
	local boardTimerUI = screenPart:WaitForChild("SurfaceGui"):WaitForChild("TimerScreenUI")

	timer = CountdownTimersModule:AddTimer({
		Enabled = false,
		UniversalEventDate = DateTime.fromUnixTimestamp(DateTime.now().UnixTimestamp + getTimeLengthRemaining()),
		BubbleTimerUI = bubbleTimerUI,
		BoardTimerUI = boardTimerUI,
		DisableBubbleWhenBoardVisible = true,
	})
end

Schema.OnRun = function()
	if timer then
		updateTimerDate()
		timer.Enabled = true
	end

	local zoomInOnCountdown = Schema:schedule({ -- Force focus the screen for final countdown
		StartTimes = { scene:GetAttribute("TimeLength") - 10 },
		OnStart = function()
			FullScreenModule.RemoveButton()
			if screenPart and screenPart.Parent then
				FullScreenModule.FocusScreen(screenPart)
			end
		end,
	})
end

Schema.OnEndScene = function()
	-- Disable all of these scene specific things

	if timer then
		timer.Enabled = false
		CountdownTimersModule:RemoveTimer(timer)
		timer = nil
	end

	FullScreenModule.RemoveButton()
	FullScreenModule.FocusScreen() -- Return camera to character

	if MerchBooth.isMerchBoothEnabled() then
		MerchBooth.setEnabled(false)
	end

	setFriendsLocatorEnabled(false)
end

return Schema
