-- -- Autor: Catalin Marcu -- Date: 20-09-2009 -- -- Main loading script -- goToSuddenDeath = false shootingPhase = false lastInGameStateIdx = -1 INGAME_MSG_ID_GO = 1 INGAME_MSG_ID_GOAL = 2 INGAME_MSG_ID_FAILED = 3 INGAME_MSG_ID_OUT = 4 activeInGameMsgIdx = INGAME_MSG_ID_GO -- replay related local canStartReplay = true -- used to control if the replay should start after the current game state or not local replayTextBlinking = false -- used by the blinkReplayText() function local numReplayTimes = 3 -- the number of times the replay will be played with different cameras local numReplayIteration = 0 -- the number of times the replay has iterated local userInterruptedReplay = false -- this is set to true when the intrerupts the replay isGoal = 0 currentNewPoints = 0 execute("menu/functions_gui.lua") --=============================================================================== function initCurrentMatch(_teamAId, _teamBId, _shotsNumber, _matchName) currentMatch = { teamAId = _teamAId, teamBId = _teamBId, nbOfShots = _shotsNumber, scoreA = 0, scoreB = 0, shotsA = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, -- maximum 10 shots; -1 = didn't shoot, 0 = didn't score, 1 = goal shotsB = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, -- maximum 10 shots suddenDeath = false, suddenDeathA = -1, -- if the game is in sudden death, tells if in the last turn this team shot and scored suddenDeathB = -1, -- if the game is in sudden death, tells if in the last turn this team shot and scored currentTurn = 1, -- a turn consists of 2 shots, one from each team; a turn ends when both teams shoot currentTeam = 1, -- the current team to shoot, can be 1 or 2 matchName = _matchName, } end --=============================================================================== function playIntro() playingIntro = true introGuiHidden = false -- create the meshes for the kicker and goalkeeper intro animations CreateActor("ActorGeom", {name = "PlayerIntro", model = "jugador_intro_1.mesh"}) DeactivateActor("PlayerIntro") CreateActor("ActorGeom", {name = "GoalkeeperIntro", model = "portero_intro_1.mesh"}) DeactivateActor("GoalkeeperIntro") changeClothes("PlayerIntro", "GoalkeeperIntro") CreateActor("ActorGeom", {name = "VersusGuiIntro", model = "gui_intro.mesh", camera = "guiCamera", layer = LF_PANELS, touchable = false}) SetActorAnimPenalty("VersusGuiIntro", { anim = "gui_intro_in.anm", loop = false }) setCurrentTeam(currentMatch.teamAId) SetTexture("VersusGuiIntro", "flagA", currentTeam.flag) setCurrentTeam(currentMatch.teamBId) SetTexture("VersusGuiIntro", "flagB", currentTeam.flag) ChangeCamera("stadiumIntroCamera" .. (GetRandomNumber() % 5 + 1)) GotoGameState(K_INTRO_GAME_STATE) EnqueueTimeExecuteScript("startKickerIntroAnimation()", 4.0) EnqueueTimeExecuteScript("hideVSIntroGuiPanels()", 3.0) if (LITE_VERSION == true) then AlignAdsTopCenter() RequestNewAd() SetAdsChangeTimeInterval(5.0) ShowAdsBanner(true) end end --=============================================================================== function hideVSIntroGuiPanels() if (introGuiHidden == false) then introGuiHidden = true SetActorAnimPenalty("VersusGuiIntro", { anim = "gui_intro_out.anm", loop = false }) end end --=============================================================================== function hideVSOutroGuiPanels() if (outroGuiHidden == false) then outroGuiHidden = true SetActorAnimPenalty("VersusGuiOutro", { anim = "gui_outro_out.anm", loop = false }) end end --=============================================================================== function endMatchPhase(currentGameStateIdx) local strDebug = "endMatchPhase() called from game state:" .. currentGameStateIdx .."\n" -- print(strDebug) lastInGameStateIdx = currentGameStateIdx if (canStartReplay) then goToReplayState() else decideNextGameState(currentGameStateIdx) end end --=============================================================================== function hasUserWon() local userWon = false if ((currentMatch.teamAId == userTeamId and currentMatch.scoreA > currentMatch.scoreB) or (gameModeSelected == GAME_MODE_WORLDCUP and currentMatch.teamBId == userTeamId and currentMatch.scoreB > currentMatch.scoreA)) then userWon = true end return userWon end --=============================================================================== function updateStats() local userWon = hasUserWon() local inTournament = false if (gameModeSelected == GAME_MODE_WORLDCUP) then inTournament = true end local inOnline = false if (gameModeSelected == GAME_MODE_ONLINE) then inOnline = true end UpdateUserStatsOnMatchOver(userWon, inTournament, inOnline, userTeamId) end --=============================================================================== function stopIntroAnimation() -- print("Script: stopIntroAnimation() called...") if (playingIntro == true) then playingIntro = false ClearAllTimeExecuteScripts() ClearAllExecuteScripts() if (introGuiHidden == false) then introGuiHidden = true SetActorAnimPenalty("VersusGuiIntro", { anim = "gui_intro_out.anm", loop = false }) end EnqueueExecuteScript("VersusGuiIntro", "afterIntroActions()") elseif (playingOutro == true) then stopOutroAnimation() elseif (playingWorldCupCutscene == true) then stopWorldCupWinCutscene() end end --=============================================================================== function afterIntroActions() -- print("Script: afterIntroActions() called...") if (LITE_VERSION == true) then SetAdsChangeTimeInterval(0.0) ShowAdsBanner(false) end DestroyActor("VersusGuiIntro") DestroyActor("PlayerIntro") DestroyActor("GoalkeeperIntro") activateGameActors() showGui() if (currentMatch.teamAId == userTeamId) then goToShootingState() else goToDefendingState() end end --=============================================================================== function startKickerIntroAnimation() -- switch to the kicker camera ActivateActor("PlayerIntro") SetActorAnimPenalty("PlayerIntro", { anim = "jugador_intro_".. (GetRandomNumber() % 3 + 1) .. ".anm", loop = false }) ChangeCamera("stadiumKickerIntroCamera" .. (GetRandomNumber() % 3 + 1)) EnqueueExecuteScript("PlayerIntro", "startGoalkeeperIntroAnimation()") end --=============================================================================== function startGoalkeeperIntroAnimation() ActivateActor("GoalkeeperIntro") SetActorAnimPenalty("GoalkeeperIntro", { anim = "portero_intro_" .. (GetRandomNumber() % 3 + 1) .. ".anm", loop = false }) ChangeCamera("stadiumGoalkeeperIntroCamera" .. (GetRandomNumber() % 3 + 1)) EnqueueExecuteScript("GoalkeeperIntro", "stopIntroAnimation()") end --=============================================================================== function startTeamOutroAnimation() -- randomly pick the outro animation for the goalkeeper or the player local playerTypeIdx = GetRandomNumber() % 2 + 1 -- index 1 corresponds to the sad animations, index 2 corresponds to the joy animations local sadJoyIdx = 1 if ( hasUserWon() ) then sadJoyIdx = 2 else sadJoyIdx = 1 end local animNames = { {"jugador_tristeza_final.anm", "jugador_alegria_final.anm"}, {"portero_tristeza_final.anm", "portero_alegria_final.anm"}, } local camNames = { {"stadiumKickerSadOutroCamera", "stadiumKickerHappyOutroCamera"}, {"stadiumGoalkeeperSadOutroCamera", "stadiumGoalkeeperHappyOutroCamera"}, } if (playerTypeIdx == 1) then ActivateActor("PlayerIntro") SetActorAnimPenalty("PlayerIntro", { anim = animNames[playerTypeIdx][sadJoyIdx], loop = false }) EnqueueExecuteScript("PlayerIntro", "startOutroVSAnimation()") else ActivateActor("GoalkeeperIntro") SetActorAnimPenalty("GoalkeeperIntro", { anim = animNames[playerTypeIdx][sadJoyIdx], loop = false }) EnqueueExecuteScript("GoalkeeperIntro", "startOutroVSAnimation()") end ChangeCamera(camNames[playerTypeIdx][sadJoyIdx]) end --=============================================================================== function playOutro() playingOutro = true outroGuiHidden = false DestroyActor("GameBall") -- create the meshes for the kicker and goalkeeper intro animations CreateActor("ActorGeom", {name = "PlayerIntro", model = "jugador_intro_1.mesh"}) DeactivateActor("PlayerIntro") CreateActor("ActorGeom", {name = "GoalkeeperIntro", model = "portero_intro_1.mesh"}) DeactivateActor("GoalkeeperIntro") SetTexture("PlayerIntro", "piel", playersSkins[teamsTextures[userTeamId + 1].playerSkins[(currentMatch.currentTurn - 1) % 10 + 1]]) SetTexture("PlayerIntro", "ropa", teamsTextures[userTeamId + 1].player) SetTexture("GoalkeeperIntro", "piel", goalkeepersSkins[teamsTextures[userTeamId + 1].goalkeeperSkin]) SetTexture("GoalkeeperIntro", "ropa", teamsTextures[userTeamId + 1].goalkeeper) CreateActor("ActorGeom", {name = "VersusGuiOutro", model = "gui_outro.mesh", camera = "guiCamera", layer = LF_PANELS, touchable = false}) SetActorAnimPenalty("VersusGuiOutro", { anim = "gui_outro_in.anm", loop = false }) setCurrentTeam(currentMatch.teamAId) SetTexture("VersusGuiOutro", "flagA", currentTeam.flag) setCurrentTeam(currentMatch.teamBId) SetTexture("VersusGuiOutro", "flagB", currentTeam.flag) DeactivateActor("VersusGuiOutro") -- ChangeCamera("stadiumIntroCamera" .. (GetRandomNumber() % 5 + 1)) StartMenuMusic(MenuSounds.Music.outro) GotoGameState(K_INTRO_GAME_STATE) startTeamOutroAnimation() -- EnqueueTimeExecuteScript("startTeamOutroAnimation()", 4.0) -- EnqueueTimeExecuteScript("hideVSOutroGuiPanels()", 3.0) if (LITE_VERSION == true) then AlignAdsTopCenter() RequestNewAd() SetAdsChangeTimeInterval(5.0) ShowAdsBanner(true) end end --=============================================================================== function startOutroVSAnimation() DeactivateActor("PlayerIntro") DeactivateActor("GoalkeeperIntro") ChangeCamera("stadiumIntroCamera" .. (GetRandomNumber() % 5 + 1)) ActivateActor("VersusGuiOutro") EnqueueTimeExecuteScript("stopOutroAnimation()", 6.0) -- EnqueueTimeExecuteScript("hideVSOutroGuiPanels()", 3.0) end --=============================================================================== function stopOutroAnimation() -- print("Script: stopOutroAnimation() called...") if (playingOutro == true) then playingOutro = false ClearAllTimeExecuteScripts() ClearAllExecuteScripts() if (outroGuiHidden == false) then outroGuiHidden = true SetActorAnimPenalty("VersusGuiOutro", { anim = "gui_outro_out.anm", loop = false }) end if ( IsActiveActor("VersusGuiOutro") ) then EnqueueExecuteScript("VersusGuiOutro", "afterOutroActions()") else afterOutroActions() end end end --=============================================================================== function afterOutroActions() -- print("Script: afterOutroActions() called...") if (LITE_VERSION == true) then SetAdsChangeTimeInterval(0.0) ShowAdsBanner(false) end if (isWorldCupFinal() == true and hasUserWon() == true) then playWorldCupWinCutscene() else onExitMatchActions() end end --=============================================================================== function isWorldCupFinal() local cupFinal = gameModeSelected == GAME_MODE_WORLDCUP and roundGame == true if (cupFinal) then for index = 1, 4 do if (IsRoundFinished(index - 1) == false) then cupFinal = false break end end end return cupFinal end --=============================================================================== function playWorldCupWinCutscene() playingWorldCupCutscene = true -- create the meshes for the kicker and goalkeeper intro animations CreateActor("ActorGeom", {name = "PlayerWorldCup", model = "jugador_wincup.mesh"}) SetActorAnimPenalty("PlayerWorldCup", { anim = "jugador_wincup.anm", loop = false }) SetTexture("PlayerWorldCup", "piel", playersSkins[teamsTextures[userTeamId + 1].playerSkins[(currentMatch.currentTurn - 1) % 10 + 1]]) SetTexture("PlayerWorldCup", "ropa", teamsTextures[userTeamId + 1].player) ChangeCamera("winCupCamera" .. (GetRandomNumber() % 2 + 1)) GotoGameState(K_INTRO_GAME_STATE) EnqueueExecuteScript("PlayerWorldCup", "stopWorldCupWinCutscene()") end --=============================================================================== function stopWorldCupWinCutscene() -- print("Script: stopWorldCupWinCutscene() called...") if (playingWorldCupCutscene == true) then playingWorldCupCutscene = false onExitMatchActions() end end --=============================================================================== function onExitMatchActions() FreeInGameSounds() ClearAllTimeExecuteScripts() ClearAllExecuteScripts() PauseTimeScripts(false) UnregisterTouchableActor("PauseButton") UnregisterTouchableActor("InGameMenu") -- ShootingGameState::doEnd() and DefendGameState::doEnd() use the actors, -- so we can't destroy them here. Moved this to main menu init. --DestroyAllActors() StopMenuMusic(MenuSounds.Music.outro) if (gameModeSelected == GAME_MODE_WORLDCUP and matchOver == false) then SaveMatch(gameModeSelected) backFromExit = true -- go to main menu and not the tournament screens else backFromExit = false end backFromGame = true GotoGameState(K_MENU_STATE) end --=============================================================================== function getGuiVersusText(index) if (index == 0) then return { scale = 0.08, font = "font4.fnt", overlap = -3, color = {255, 255, 255, 255}, vertical = E_VALIGN_CENTER, text = currentMatch.matchName } elseif (index == 1) then return { scale = 0.08, font = "font4.fnt", overlap = -3, color = {255, 255, 255, 255}, align = E_ALIGN_RIGHT, vertical = E_VALIGN_CENTER, text = getTeamFullName(currentMatch.teamAId) } elseif (index == 2) then return { scale = 0.08, font = "font4.fnt", overlap = -3, color = {255, 255, 255, 255}, align = E_ALIGN_LEFT, vertical = E_VALIGN_CENTER, text = getTeamFullName(currentMatch.teamBId) } elseif (index == 3) then return { scale = 0.13, font = "font4.fnt", overlap = -3, color = {255, 255, 255, 255}, align = E_ALIGN_CENTER, vertical = E_VALIGN_CENTER, text = currentMatch.scoreA .. " - " .. currentMatch.scoreB } elseif (index == 4) then return { name = "GuiPointsText", scale = 0.07, font = "font4.fnt", overlap = -3, color = {200, 200, 200, 255}, vertical = E_VALIGN_CENTER, text = "" .. GetAwardedUserPoints() .. " " ..txtPlayerPointsSmall } end end --=============================================================================== function getGuiText(index) if (index == 1) then return { name = "TeamANameText", scale = 0.19, font = "font5.fnt", overlap = -3, color = {255, 255, 255, 255}, vertical = E_VALIGN_CENTER, text = getTeamFullName(currentMatch.teamAId), layer = LF_PANELS } elseif (index == 2) then return { name = "TeamBNameText", scale = 0.19, font = "font5.fnt", overlap = -3, color = {255, 255, 255, 255}, vertical = E_VALIGN_CENTER, text = getTeamFullName(currentMatch.teamBId), layer = LF_PANELS } elseif (index == 3) then return { name = "EventPointsText", scale = 0.19, font = "font5.fnt", overlap = -3, color = {255, 255, 255, 255}, vertical = E_VALIGN_CENTER, text = "" .. GetAwardedUserPoints() .. " " .. txtPlayerPointsSmall, layer = LF_PANELS } elseif (index == 4) then return { name = "NewPointsText", scale = 0.19, font = "font5.fnt", overlap = -3, color = {255, 255, 255, 255}, vertical = E_VALIGN_CENTER, text = "", layer = LF_PANELS } end end --=============================================================================== function updatePlayerPoints(newPoints, eventPoints, multiplier) if (ExistsActor("NewPointsText") == true) then if (newPoints ~= 0) then -- SetText("NewPointsText", "") -- else currentNewPoints = currentNewPoints + newPoints SetText("NewPointsText", "" .. newPoints .. " x " .. multiplier) end end if (ExistsActor("EventPointsText") == true) then SetText("EventPointsText", "" .. eventPoints .. " " .. txtPlayerPointsSmall) end end --=============================================================================== function getMatchOpponentId() if (currentMatch.teamAId == userTeamId) then return currentMatch.teamBId else return currentMatch.teamAId end end --=============================================================================== function getInGameMessage(index) if (activeInGameMsgIdx == INGAME_MSG_ID_GO) then -- print("creating text GO!") return { scale = 0.36, font = "font4.fnt", overlap = -3, color = {0, 190, 0, 255}, vertical = E_VALIGN_CENTER, text = txtGo } elseif (activeInGameMsgIdx == INGAME_MSG_ID_GOAL) then -- print("creating text GOAL!") if (shootingPhase == true) then return { scale = 0.36, font = "font4.fnt", overlap = -3, color = {0, 190, 0, 255}, vertical = E_VALIGN_CENTER, text = txtGoal } else return { scale = 0.36, font = "font4.fnt", overlap = -3, color = {255, 0, 0, 255}, vertical = E_VALIGN_CENTER, text = txtGoal } end elseif (activeInGameMsgIdx == INGAME_MSG_ID_FAILED) then -- print("creating text FAILED!") if (shootingPhase == true) then return { scale = 0.34, font = "font4.fnt", overlap = -3, color = {255, 0, 0, 255}, vertical = E_VALIGN_CENTER, text = txtMissed } else return { scale = 0.34, font = "font4.fnt", overlap = -3, color = {0, 190, 0, 255}, vertical = E_VALIGN_CENTER, text = txtSaved } end else --OUT -- print("creating text OUT!") if (shootingPhase == true) then return { scale = 0.34, font = "font4.fnt", overlap = -3, color = {255, 0, 0, 255}, vertical = E_VALIGN_CENTER, text = txtOut } else return { scale = 0.34, font = "font4.fnt", overlap = -3, color = {0, 190, 0, 255}, vertical = E_VALIGN_CENTER, text = txtOut } end end end --=============================================================================== function loadGameActors() -- UnloadMenuSounds() LoadInGameSounds() ClearAllTimeExecuteScripts() DestroyAllActors() CreateActor("ActorGeom", {name = "GoalGate", model = "goal_idle.mesh", touchable = true}) CreateStadiumActor("Stadium", "stadium1.lua") CreateGoalkeeperActor("Goalkeeper", "portero_espera.mesh", "", "Stadium") --TODO: player_shadow.pvr CreatePlayerActor("Player", "jugador_espera.mesh", "", "Stadium") --TODO -- EnableActorEdgeRender("Player") -- EnableActorEdgeRender("Goalkeeper") CreateBallActor("GameBall", "ball.mesh", "", "Stadium") -- TODO: ball_shadow.pvr was used for shadow (it didn't work correctly) CreateActor("ActorGeom", {name = "PlayerGui", model = "gui_heightbar_2.mesh", camera = "guiCamera", layer = LF_PANELS, touchable = true}) CreateActor("ActorGeom", {name = "InGameHint", model = "gui_hint.mesh", camera = "guiCamera", layer = LF_PANELS, touchable = true}) DeactivateActor("PlayerGui") CreateActor("ActorGeom", {name = "DefendCursor", model = "gui_defend_2.mesh", layer = LF_PANELS, touchable = false}) SetActorAnimPenalty("DefendCursor", { anim = "gui_defend_2.anm", loop = true }) CreateActor("ActorGeom", {name = "ScoreAGui", model = "gui_scorebar_idle.mesh", camera = "guiCamera", layer = LF_PANELS, touchable = false}) CreateActor("ActorGeom", {name = "ScoreBGui", model = "gui_scorebar_idle.mesh", camera = "guiCamera", layer = LF_PANELS, touchable = false}) CreateActor("ActorGeom", {name = "PauseButton", model = "gui_pause.mesh", camera = "guiCamera", layer = LF_PANELS, touchable = true}) CreateActor("ActorGeom", {name = "TeamsNamesGui", model = "gui_teambar_idle.mesh", camera = "guiCamera", layer = LF_PANELS, touchable = false}) -- CreateActor("ActorGeom", {name = "TeamsFlagsGui", model = "gui_flags_idle.mesh", camera = "guiCamera", layer = LF_PANELS, touchable = false}) RegisterTouchableActor("PauseButton") setCurrentTeam(currentMatch.teamAId) SetTexture("TeamsNamesGui", "flagA", currentTeam.flag) SetTexture("Stadium", "flagA", "stadium_" .. currentTeam.flag) -- SetTexture("TeamsFlagsGui", "flagA", currentTeam.flag) setCurrentTeam(currentMatch.teamBId) SetTexture("TeamsNamesGui", "flagB", currentTeam.flag) SetTexture("Stadium", "flagB", "stadium_" .. currentTeam.flag) -- SetTexture("TeamsFlagsGui", "flagB", currentTeam.flag) end --=============================================================================== function activateGameActors() ActivateActor("Goalkeeper") ActivateActor("Player") ActivateActor("GameBall") ActivateActor("ScoreAGui") ActivateActor("ScoreBGui") ActivateActor("PauseButton") ActivateActor("TeamsNamesGui") -- ActivateActor("TeamsFlagsGui") ActivateActor("TeamANameText") ActivateActor("TeamBNameText") -- TODO: these lines are for testing only --[[ DeactivateActor("PlayerGui") DeactivateActor("TeamsNamesGui") DeactivateActor("ScoreAGui") DeactivateActor("ScoreBGui") DeactivateActor("TeamsFlagsGui") --]] end --=============================================================================== function deactivateGameActors() DeactivateActor("Goalkeeper") DeactivateActor("Player") DeactivateActor("GameBall") DeactivateActor("PlayerGui") DeactivateActor("DefendCursor") DeactivateActor("PauseButton") DeactivateActor("TeamsNamesGui") -- DeactivateActor("TeamsFlagsGui") DeactivateActor("ScoreAGui") DeactivateActor("ScoreBGui") DeactivateActor("TeamANameText") DeactivateActor("TeamBNameText") end --=============================================================================== function changeClothes(shooterActor, goalkeeperActor) local shooterTeam local goalkeeperTeam if (currentMatch.currentTeam == 1) then shooterTeam = currentMatch.teamAId goalkeeperTeam = currentMatch.teamBId else shooterTeam = currentMatch.teamBId goalkeeperTeam = currentMatch.teamAId end if (shooterActor ~= "") then SetTexture(shooterActor, "piel", playersSkins[teamsTextures[shooterTeam + 1].playerSkins[(currentMatch.currentTurn - 1) % 10 + 1]]) SetTexture(shooterActor, "ropa", teamsTextures[shooterTeam + 1].player) end if (goalkeeperActor ~= "") then SetTexture(goalkeeperActor, "piel", goalkeepersSkins[teamsTextures[goalkeeperTeam + 1].goalkeeperSkin]) SetTexture(goalkeeperActor, "ropa", teamsTextures[goalkeeperTeam + 1].goalkeeper) end end --=============================================================================== function goToReplayState() DeactivateActor("PlayerGui") if ANDROID_VERSION == true then local width, height = GetViewportSize() local xRatio = width/480 local yRatio = height/320 local minRatio = math.min(xRatio, yRatio) CreateActor("Actor2DText", { name = "CornerReplayText", scale = 1.5*minRatio, font = "font5.fnt", overlap = -1, color = {255, 255, 255, 255}, vertical = E_VALIGN_CENTER, x = -210*xRatio, y = -130*yRatio, text = "R" }) elseif (IPAD_VERSION == true) then CreateActor("Actor2DText", { name = "CornerReplayText", scale = 2.5, font = "font5.fnt", overlap = -1, color = {255, 255, 255, 255}, vertical = E_VALIGN_CENTER, x = -450, y = -350, text = "R" }) else CreateActor("Actor2DText", { name = "CornerReplayText", scale = 1.5, font = "font5.fnt", overlap = -1, color = {255, 255, 255, 255}, vertical = E_VALIGN_CENTER, x = -210, y = -150, text = "R" }) end -- activate the "R" blinking text replayTextBlinking = true EnqueueTimeExecuteScript("blinkReplayText()", 0.25) -- print("Script: go to replay state") GotoGameState(K_REPLAY_GAME_STATE) userInterruptedReplay = false -- start counting the replay iterations numReplayIteration = 0 numReplayIteration = numReplayIteration + 1 -- select a random replay camera from the group of cameras for the current replay iteration local replayCameraIdx = GetRandomNumber() % table.getn(Stadium.replayCameras[numReplayIteration]) + 1 -- print("Script: replay camera selected:" .. Stadium.replayCameras[numReplayIteration][replayCameraIdx]) ChangeCamera(Stadium.replayCameras[numReplayIteration][replayCameraIdx]) if (LITE_VERSION == true) then AlignAdsBottomCenter() RequestNewAd() SetAdsChangeTimeInterval(5.0) ShowAdsBanner(true) end -- print("Script: starting replay iteration number: " .. numReplayIteration) end --=============================================================================== function blinkReplayText() if (replayTextBlinking) then EnqueueTimeExecuteScript("blinkReplayText()", 0.25) if ( IsActiveActor("CornerReplayText") ) then DeactivateActor("CornerReplayText") else ActivateActor("CornerReplayText") end else DestroyActor("CornerReplayText") end end --=============================================================================== --NOTE: this function is called from code when the ball hits the goal gate function callbackReplayBallHitGoalGate() -- print("Script: called callbackReplayBallHitGoalGate()") -- check if we are in the replay iteration that uses triggered camera animation (ex: when the ball hits the goal gate it triggers a camera shake animation) if (numReplayIteration == 3) then SetCurrentCameraAnimStatus(true) end end --=============================================================================== -- This function is called from the TReplayGameState class when the replay is interrupted by the user function callbackUserInterruptedReplay() -- print("Script: replay has been interrupted by the user!") userInterruptedReplay = true callbackReplayFinished() end --=============================================================================== -- This function is called from the TReplayGameState class when the replay finishes an iteration without being interrupted by the user function callbackReplayFinished() -- print("Script: callbackReplayFinished() called...") if ( (userInterruptedReplay == false) and (numReplayIteration < 3) ) then numReplayIteration = numReplayIteration + 1 if (isGoal == 0) then -- skip the ball follow camera if it wasn't goal numReplayIteration = numReplayIteration + 1 end RestartPhaseReplay() -- remove the slow motion effect for the last replay iteration if (numReplayIteration == 3) then SetGameTimeScale(1.0) end -- select random replay camera from the group of cameras for the current replay iteration local replayCameraIdx = GetRandomNumber() % table.getn(Stadium.replayCameras[numReplayIteration]) + 1 -- print("Script: replay camera selected:" .. Stadium.replayCameras[numReplayIteration][replayCameraIdx]) ChangeCamera(Stadium.replayCameras[numReplayIteration][replayCameraIdx]) -- check if we've selected a camera with a custom behaviour if ( Stadium.replayCameras[numReplayIteration][replayCameraIdx] == "stadiumBallReplayCamera" ) then SetBallFollowCameraStatus(true) else SetBallFollowCameraStatus(false) end -- print("Script: starting replay iteration number: " .. numReplayIteration) else -- print("Script: stopping replay and continuing game flow...") if (LITE_VERSION == true) then SetAdsChangeTimeInterval(0.0) ShowAdsBanner(false) end SetBallFollowCameraStatus(false) SetText("NewPointsText", "") currentNewPoints = 0 StopPhaseReplay() -- stop blinking the "R" text (the text should auto destroy itself) replayTextBlinking = false decideNextGameState(lastInGameStateIdx) end end --=============================================================================== function decideNextGameState(currentGameStateIdx) if (matchOver == true) then exitMatch() return end if (goToSuddenDeath == true) then goToSuddenDeath = false animateGuiToSuddenDeath() end if (currentGameStateIdx == K_SHOOT_GAME_STATE) then goToDefendingState() elseif (currentGameStateIdx == K_DEFEND_GAME_STATE) then goToShootingState() end end --=============================================================================== function goToShootingState() -- ChangeCamera("stadiumTestCamera") local cameraIdx = GetRandomNumber() % 3 + 1; ChangeCamera("stadiumShootCamera" .. cameraIdx) EnqueueTimeExecuteScript("ActivateActor(\"PlayerGui\")", 2.0) -- SetActorAnimPenalty("PlayerGui", { anim = "gui_heightbar_2.anm", loop = true }) changeClothes("Player", "Goalkeeper") -- print("go to shooting state") shootingPhase = true GotoGameState(K_SHOOT_GAME_STATE) -- GotoGameState(K_REPLAY_GAME_STATE) showInGameAnimatedMsg(INGAME_MSG_ID_GO, 1.0) EnqueueTimeExecuteScript("Sound.PlaySound(InGameSounds.Fx.whistle, false, 200)", 2.0) end --=============================================================================== function goToDefendingState() local cameraIdx = GetRandomNumber() % 3 + 1; -- cameraIdx = 4 ChangeCamera("stadiumDefendCamera" .. cameraIdx) DeactivateActor("PlayerGui") changeClothes("Player", "Goalkeeper") -- print("go to defending state") shootingPhase = false GotoGameState(K_DEFEND_GAME_STATE) showInGameAnimatedMsg(INGAME_MSG_ID_GO, 1.0) EnqueueTimeExecuteScript("Sound.PlaySound(InGameSounds.Fx.whistle, false, 200)", 2.0) -- EnqueueTimeExecuteScript("ActivateActor(\"DefendCursor\")", 2.0) EnqueueTimeExecuteScript("SelectDefaultGoalGateZone()", 2.0) end --=============================================================================== function beginNewMatch() currentScreen=nil StartNewMatch(gameModeSelected == GAME_MODE_WORLDCUP) playingMatch = true matchOver = false loadGameActors() deactivateGameActors() playIntro() Sound.PlaySound(InGameSounds.Ambiance.crowd, true, 80.0) end --=============================================================================== function continueMatch() currentScreen=nil playingMatch = true matchOver = false loadGameActors() if ((currentMatch.currentTeam == 1 and currentMatch.teamAId == userTeamId) or (currentMatch.currentTeam == 2 and currentMatch.teamBId == userTeamId)) then goToShootingState() else goToDefendingState() end showGui() local shotsPositions = currentMatch.nbOfShots if (currentMatch.suddenDeath == true) then shotsPositions = 1 end EnqueueTimeExecuteScript("restoreGuiGoals()", 0.05 * shotsPositions + 0.15) Sound.PlaySound(InGameSounds.Ambiance.crowd, true, 80.0) end --=============================================================================== function isMatchOver(shotsRemainingA, shotsRemainingB) if (currentMatch.suddenDeath == true) then return false end if (gameModeSelected == GAME_MODE_WORLDCUP and roundGame == false) then return false end if (currentMatch.scoreA + shotsRemainingA >= currentMatch.scoreB and currentMatch.scoreB + shotsRemainingB >= currentMatch.scoreA) then return false else return true end end --=============================================================================== function exitMatch() currentScreen=nil deactivateGameActors() for index = 1, currentMatch.currentTurn * 2 do if (ExistsActor("GuiGoal" .. index)) then DestroyActor("GuiGoal" .. index) end end playOutro() end --=============================================================================== function stopShootStateCutscene() -- print("stopShootStateCutscene() script function called...") FinishShootStateCutscenes() end --=============================================================================== function startShootStateCutscene() -- print("startShootStateCutscene() script function called...") FinishShootStateCutscenes() end --=============================================================================== function stopDefendStateCutscene() -- print("stopDefendStateCutscene() script function called...") FinishDefendStateCutscenes() end --=============================================================================== function startDefendStateCutscene() -- print("startDefendStateCutscene() script function called...") FinishDefendStateCutscenes() end --=============================================================================== function calculateHeightBarSpeed() if (currentMatch.currentTeam == 1) then setCurrentTeam(currentMatch.teamAId) else setCurrentTeam(currentMatch.teamBId) end local value = ((100 - currentTeam.precision + 30) / 40.0) * settings.heightIndicatorBaseSpeed * settings.heightIndicatorSpeedFactor return value end --=============================================================================== function calculateFinalBallSpeed(initialSpeed) if (currentMatch.currentTeam == 1) then setCurrentTeam(currentMatch.teamAId) else setCurrentTeam(currentMatch.teamBId) end local value = settings.shootGestureMinSpeed + (initialSpeed - settings.shootGestureMinSpeed) * (currentTeam.power / 100) if (value < settings.shootGestureMinSpeed) then value = settings.shootGestureMinSpeed end return value end --=============================================================================== function calculateShootAreaHeightScale() if (currentMatch.currentTeam == 1) then setCurrentTeam(currentMatch.teamAId) else setCurrentTeam(currentMatch.teamBId) end local value = ((currentTeam.precision - 50.0) / 10.0) * settings.influenceAreaCrossbarFactor return value end --=============================================================================== function calculateShootAreaWidthScale() if (currentMatch.currentTeam == 1) then setCurrentTeam(currentMatch.teamAId) else setCurrentTeam(currentMatch.teamBId) end local value = ((currentTeam.precision - 50.0) / 10.0) * settings.influenceAreaPostsFactor return value end --=============================================================================== function calculateSecondStagingAreaScale() if (currentMatch.currentTeam == 1) then setCurrentTeam(currentMatch.teamBId) else setCurrentTeam(currentMatch.teamAId) end local dive = currentTeam.dive if (dive <= 50) then return 0.0 else local value = (dive / 50.0) * settings.secondStagingAreaGrowthFactor return value end end --=============================================================================== function checkDefendingStandardArea() if (currentMatch.currentTeam == 1) then setCurrentTeam(currentMatch.teamBId) else setCurrentTeam(currentMatch.teamAId) end local dive = currentTeam.dive if (dive < 50) then local diveChance = settings.stagingAreaZeroDiveChance + (1.0 - settings.stagingAreaZeroDiveChance) * (dive / 50.0) return checkDefending(diveChance) else return clearanceVersusPower() end end --=============================================================================== function checkDefendingSecondArea() return checkDefending(settings.secondStagingAreaDiveChance) end --=============================================================================== function checkDefending(diveChance) local randomValue = GetRandomFloatNumber() if (randomValue <= diveChance) then return clearanceVersusPower() else return false end end --=============================================================================== function clearanceVersusPower() local clearance, power local defendChance = settings.goalkeeperBaseChance if (currentMatch.currentTeam == 1) then setCurrentTeam(currentMatch.teamBId) clearance = currentTeam.clearance setCurrentTeam(currentMatch.teamAId) power = currentTeam.power else setCurrentTeam(currentMatch.teamAId) clearance = currentTeam.clearance setCurrentTeam(currentMatch.teamBId) power = currentTeam.power end if (clearance >= power) then defendChance = settings.goalkeeperBaseChance + (1.0 - settings.goalkeeperBaseChance) * ((clearance - power) / 100.0) else defendChance = settings.goalkeeperBaseChance * ((100 - power + clearance) / 100.0) end local randomValue = GetRandomFloatNumber() --[[ print("Power: " .. power) print("Clearance: " .. clearance) print("Defend chance: " .. defendChance) print("randomValue :" .. randomValue) --]] if (randomValue <= defendChance) then return true -- should defend else return false end end --=============================================================================== -- param msgId - INGAME_MSG_ID_GO, INGAME_MSG_ID_GOAL, INGAME_MSG_ID_FAILED or INGAME_MSG_ID_OUT -- param animType - "in" or "out" -- param execScript - a string that represents a script to execute after the specified animation type finishes, -- or "destroy" to destroy the actor after the animation or just "" to do nothing function setInGameAnimatedMsg(msgId, animType, execScript) activeInGameMsgIdx = msgId if ( ExistsActor("InGameAnimatedMsg") == false ) then CreateActor("ActorGeom", {name = "InGameAnimatedMsg", model = "gui_mesages.mesh", camera = "guiCamera", layer = LF_PANELS, touchable = false}) end SetActorAnimPenalty("InGameAnimatedMsg", { anim = "gui_mesages_" .. animType .. ".anm", loop = false }) if (execScript == "destroy") then EnqueueExecuteScript("InGameAnimatedMsg", "destroyInGameAnimatedMsg()") elseif (execScript ~= "") then EnqueueExecuteScript("InGameAnimatedMsg", execScript) end end --=============================================================================== function destroyInGameAnimatedMsg() DestroyActor("InGameAnimatedMsg") NotifyInGameModalMsgStatus(false) end --=============================================================================== function hideCurrentInGameAnimatedMsg() setInGameAnimatedMsg(0, "out", "destroy") end --=============================================================================== function showInGameAnimatedMsg(msgId, timeToShow) NotifyInGameModalMsgStatus(true) local execScript = "EnqueueTimeExecuteScript(\"hideCurrentInGameAnimatedMsg()\", " .. timeToShow .. ")" setInGameAnimatedMsg(msgId, "in", execScript) end