public void PrepareMe(Dictionary <int, Result[]> inGameResults, Result[] afterGameResults, string reason, int distance, Mission mission, PlayerState player)
    {
        Distance         = distance;
        GameOverReason   = reason;
        Mission          = mission;
        InGameResults    = inGameResults;
        AfterGameResults = afterGameResults;

        if (Passed = Mission.Passed(InGameResults, AfterGameResults))
        {
            player.MissionDone(Mission);
        }
        CarSmasherSocial.UpdateLeaderboard(GoogleLeaderboard.LEADERB_BEST_DISTANCES_ADV, afterGameResults);
        HighScores.AddScore(Distance, HighScoreType.Adventure);

        foreach (AchievQuery aq in Mission.AfterGameReqs)
        {
            TaskToBeDone       = aq.ScoreType;
            TaskToBeDoneAmount = aq.Value;
        }

        foreach (Result r in afterGameResults)
        {
            if (r.ScoreType == SCORE_TYPE.COINS)
            {
                CoinsCollected = r.Value;
            }
            if (r.ScoreType == TaskToBeDone)
            {
                TaskDoneAmount = r.Value;
            }
        }
    }
    public void GameOver(string reason)
    {
        IsGameOver = true;
        //results to unlock and increment achievements (we don't want to increment achievements several times for one ride)
        Result[] afterGameAchievements = new Result[] {
            new Result(SCORE_TYPE.DISTANCE, Distance),
            new Result(SCORE_TYPE.FUEL_PICKED, Car.GetComponent <Car> ().FuelPickedUpThisGame),
            new Result(SCORE_TYPE.FUEL_PICKED_WHEN_LOW, Car.GetComponent <Car> ().FuelPickedUpWhenLow),
            new Result(SCORE_TYPE.FUEL_PICKED_IN_ROW, Car.GetComponent <Car> ().FuelPickedUpInARowBest),
            new Result(SCORE_TYPE.TURNS, Car.GetComponent <Car> ().TurnsMade),
            new Result(SCORE_TYPE.COINS, Car.GetComponent <Car>().PickedUpCoins),
            new Result(SCORE_TYPE.SHIELDS_USED, Car.GetComponent <Car>().ShieldsUsed)
        };

        Player.RewardHim(Mission, InGameAchievements, afterGameAchievements);
        Player.Save();
        Destroy(Car.GetComponent <Fuel> ());
        if (Car.GetComponent <ShieldCompo>() != null)
        {
            Destroy(Car.GetComponent <ShieldCompo> ());
        }

        foreach (KeyValuePair <int, Result[]> result in InGameAchievements)
        {
            CarSmasherSocial.UnlockAchievements(result.Value);
        }
        CarSmasherSocial.UpdateAchievements(afterGameAchievements);


        AfterMinigame(InGameAchievements, afterGameAchievements, reason, Distance, Mission, Player);
    }
    override protected void OnGUIInner()
    {
        GuiHelper.DrawAtTop("Settings");

        float textY   = 0.3f;
        float buttonY = 0.04f;
        float diff    = 0.1f;

        GuiHelper.DrawText("Sounds", GuiHelper.SmallFontLeft, 0.1, textY, 0.8, 0.1);
        GuiHelper.ButtonWithText(0.8, textY + buttonY, 0.2, 0.15, (Sounds.IsMuted()?" Turn on":"Turn off"), SpriteManager.GetRoundButton(), GuiHelper.MicroFont, delegate(){
            Sounds.Mute(!Sounds.IsMuted());
        });

        textY += diff;
        GuiHelper.DrawText("Fb fan page", GuiHelper.SmallFontLeft, 0.1, textY, 0.8, 0.1);
        GuiHelper.ButtonWithText(0.8, textY + buttonY, 0.13, 0.13, "", SpriteManager.GetFbIcon(), GuiHelper.SmallFont, delegate(){
        });

        textY += diff;
        string isNow  = CarSmasherSocial.Authenticated ? "on" : "off";
        string willBe = CarSmasherSocial.Authenticated ? "disconnect" : "connect";

        GuiHelper.DrawText("Google games are " + isNow, GuiHelper.MicroFontLeft, 0.1, textY, 0.8, 0.1);
        Texture googlePlay = CarSmasherSocial.Authenticated ? SpriteManager.GetGooglePlay() : SpriteManager.GetInactiveGooglePlay();

        GuiHelper.ButtonWithText(0.8, textY + buttonY - 0.015, 0.25, 0.2, willBe, googlePlay, GuiHelper.MicroFont, delegate(){
            CarSmasherSocial.InitializeOrLogOut(true, null, null, this);
        });

        textY += diff;
        bool vibrationsOn = Parameter.IsOn(ParameterType.VIBRATION);

        GuiHelper.DrawText("Vibrations", GuiHelper.SmallFontLeft, 0.1, textY, 0.8, 0.1);
        GuiHelper.ButtonWithText(0.8, textY + buttonY, 0.2, 0.15, "Turn " + (vibrationsOn ? "off" : "on"), SpriteManager.GetRoundButton(), GuiHelper.MicroFont, delegate() {
            ParameterType.VIBRATION.Switch(!vibrationsOn);
        });

        textY += diff;
        bool fasterStart = Parameter.IsOn(ParameterType.FASTER_START);

        GuiHelper.DrawText("Faster start", GuiHelper.SmallFontLeft, 0.1, textY, 0.8, 0.1);
        GuiHelper.ButtonWithText(0.8, textY + buttonY, 0.2, 0.15, "Turn " + (fasterStart ? "off" : "on"), SpriteManager.GetRoundButton(), GuiHelper.MicroFont, delegate() {
            ParameterType.FASTER_START.Switch(!fasterStart);
        });
        GuiHelper.ButtonWithText(0.66, textY + buttonY, 0.2, 0.1, "i", SpriteManager.GetRoundButton(), GuiHelper.MicroFont, delegate() {
            ScreenText st = gameObject.AddComponent <ScreenText>();
            Destroy(this);
            st.Prepare(delegate(){
                st.gameObject.AddComponent <ScreenOptions>();
                Destroy(st);
            }, "Faster start", "If your high score is good, your car will be faster in first 300 distance to save you time."
                       + "\n\nUse this when you want to show this game to a new person, he will have slower start");
        });
    }
    public void PrepareMe(Dictionary <int, Result[]> inGameResults, Result[] afterGameResults, string reason, int distance, Mission mission, PlayerState player)
    {
        Distance       = distance;
        GameOverReason = reason;
        Mission        = mission;
        Player         = player;
        HighScores.AddScore(distance, HighScoreType.Classic);
        int place = HighScores.GetPlaceFor(distance, HighScoreType.Classic);

        if (place == 1)
        {
            PlaySingleSound.SpawnSound(Sounds.Fanfare, Camera.main.gameObject.transform.position, 0.2f);
            if (distance > 50)
            {
                ShowNewHighScoreScreen = true;
            }
        }

        foreach (Result result in afterGameResults)
        {
            switch (result.ScoreType)
            {
            case SCORE_TYPE.FUEL_PICKED:
                FuelPickedUp = result.Value;
                break;

            case SCORE_TYPE.FUEL_PICKED_IN_ROW:
                FuelPickedUpInARow = result.Value;
                break;

            case SCORE_TYPE.FUEL_PICKED_WHEN_LOW:
                FuelPickedUpWhenLow = result.Value;
                break;

            case SCORE_TYPE.TURNS:
                Turns = result.Value;
                break;

            case SCORE_TYPE.COINS:
                CoinsPickedUp = result.Value;
                break;
            }
        }
        CarSmasherSocial.UpdateLeaderboard(CarSmasherSocial.ClassicLeaderboard.Id, afterGameResults);
        //if someone had internet issues before, at least we can update high score with his best distance and come unlockable achievements
        //we don't want this. this is sending best score for every day player is playing
        //List<int> topScores = HighScores.GetTopScores (1);
        //int bestDistance = topScores.Count > 0 ? topScores [0] : 0;
        //InGameAchievements.Add(bestDistance, new Result[]{new Result (SCORE_TYPE.DISTANCE, bestDistance)});
    }
    public static void InitializeSocial(bool forceUI, AfterAuthenticateD afterSuccess = null, AfterAuthenticateD afterFailure = null, MonoBehaviour mb = null)
    {
        AuthenticationAnswer aa = GetPreviousAnswer();

        if (!Authenticated && aa == AuthenticationAnswer.NeverAsked && mb != null)
        {
            ScreenAsk sa = mb.gameObject.AddComponent <ScreenAsk>();
            Destroy(mb);
            sa.PrepareMe(delegate() {
                CarSmasherSocial.SaveAnswerForAuthentication(CarSmasherSocial.AuthenticationAnswer.Accepted);
                sa.gameObject.AddComponent <ScreenSplash>();
                Destroy(sa);
            }, delegate() {
                CarSmasherSocial.SaveAnswerForAuthentication(CarSmasherSocial.AuthenticationAnswer.Denied);
                sa.gameObject.AddComponent <ScreenSplash>();
                Destroy(sa);
            });
        }
        else if (!Authenticated && (aa == AuthenticationAnswer.Accepted || forceUI))
        {
            Social.localUser.Authenticate((bool success) => {
                Authenticated = success;
                SaveAnswerForAuthentication(success ? AuthenticationAnswer.Accepted : AuthenticationAnswer.Denied);
                if (Authenticated)
                {
                    if (afterSuccess != null)
                    {
                        afterSuccess();
                    }
                }
                else
                {
                    if (afterFailure != null)
                    {
                        afterFailure();
                    }
                }
            });
        }
        else
        {
            if (afterFailure != null)
            {
                afterFailure();
            }
        }
    }
    // Use this for initialization
    override protected void StartInner()
    {
        GuiDepth = Game.Me.ClosestGui;

        if (!CarSmasherSocial.Authenticated && CarSmasherSocial.GetPreviousAnswer() == CarSmasherSocial.AuthenticationAnswer.NeverAsked || CarSmasherSocial.GetPreviousAnswer() == CarSmasherSocial.AuthenticationAnswer.Accepted)
        {
            CarSmasherSocial.InitializeSocial(false, null, null, this);
        }
        Game.Me.Player.Load();

        Prepare(delegate() {
            ScreenQuit sq = gameObject.AddComponent <ScreenQuit>();
            sq.Prepare(delegate(){
                sq.gameObject.AddComponent <ScreenSplash>();
                Destroy(sq);
            });
            Destroy(this);
        }, false);
    }
    override protected void OnGUIInner()
    {
        GuiHelper.YesButton(delegate() {
            ScreenStartingMission ssm = gameObject.AddComponent <ScreenStartingMission>();
            Destroy(this);
        }, "Race");


        GuiHelper.DrawAtTop("Mission " + (Passed ? "Completed" : "Failed") + " (" + Mission.Description + ")");
        string text = "";

        int sumOfCoins = CoinsCollected + (Passed?Mission.Reward.Coins:0);

        text += "Coins: +" + sumOfCoins + " (reward: " + (Passed?Mission.Reward.Coins:0) + ", collected: " + CoinsCollected + ") \n\n\n\n";


        text += "Distance: " + Distance;
        int best = HighScores.GetTopScore(HighScoreType.Adventure);

        if (Distance == best)
        {
            text += " New Record!!!";
        }
        else
        {
            text += ", best: " + best + "";
        }
        text += "\n";


        GuiHelper.DrawBeneathLine(text);

        Texture leaderBoard = SpriteManager.GetLeaderboard();

        GuiHelper.ButtonWithText(0.85, 0.487, 0.2, 0.15, "Scores", SpriteManager.GetRoundButton(), GuiHelper.MicroFont, delegate(){
            CarSmasherSocial.ShowLeaderBoard(GoogleLeaderboard.LEADERB_BEST_DISTANCES_ADV);
        });
    }
Exemplo n.º 8
0
    override protected void OnGUIInner()
    {
        PlayerState state        = Game.Me.Player;
        int         upgAvailable = 0;

        foreach (KeyValuePair <CarStatisticType, CarStatistic> kvp in state.CarConfig.CarStatistics)
        {
            if (kvp.Value.IsUnlockedFor(state) && kvp.Value.CanUpgrade(state.Coins))
            {
                upgAvailable++;
            }
        }

        GuiHelper.DrawAtTop(Mission.Description);
        string text = "Reward: " + Mission.Reward.Description +
                      "\n\n " + upgAvailable + " upgrades are available" +
                      "\n\n\n\n Your best distance: " + HighScores.GetTopScore(HighScoreType.Adventure);

        GuiHelper.DrawBeneathLine(text);

        if (upgAvailable > 0)
        {
            GuiHelper.ButtonWithText(0.85, 0.4, 0.13, 0.13, "", SpriteManager.GetUpArrow(), GuiHelper.SmallFont, BackButton);
        }

        Texture leaderBoard = SpriteManager.GetLeaderboard();

        GuiHelper.ButtonWithText(0.85, 0.585, 0.2, 0.15, "Scores", SpriteManager.GetRoundButton(), GuiHelper.MicroFont, delegate(){
            CarSmasherSocial.ShowLeaderBoard(GoogleLeaderboard.LEADERB_BEST_DISTANCES_ADV);
        });

        GuiHelper.YesButton(delegate(){
            Minigame mi = gameObject.AddComponent <Minigame>();
            Destroy(this);
            mi.PrepareRace(Game.Me.Player, ScreenAfterMinigameAdv.PrepareScreen, Mission, Game.Me.Player.CarConfig);
        }, "Start");
    }
    override protected void OnGUIInner()
    {
        if (ShowNewHighScoreScreen)
        {
            GuiHelper.DrawBackground(delegate() {
                ShowNewHighScoreScreen = false;
            });

            GuiHelper.DrawAtTop("New High Score!");
            GuiHelper.DrawBeneathLine("You just beat your high score with distance " + Distance + ". \n\n Like to tell your friends about it?");

            if (GUI.Button(new Rect(GuiHelper.PercentW(0.2), GuiHelper.PercentH(0.70), GuiHelper.PercentW(0.6), GuiHelper.PercentH(0.11)), SpriteManager.GetFbShareButton(), GuiHelper.CustomButton))
            {
                ShowNewHighScoreScreen = false;
            }
        }
        else if (ShowRideInfoScreen)
        {
            GuiHelper.DrawBackground(delegate() {
                ShowRideInfoScreen = false;
            });

            GuiHelper.DrawAtTop(GameOverReason);
            GuiHelper.DrawBeneathLine(
                "Collect oil drops to replenish fuel tank. Avoid obstacles.\n" +
                "\nDistance made: " + Distance +
                "\nTurns made: " + Turns +
                "\nFuel picked up: " + FuelPickedUp + " " +
                "(in a row: " + FuelPickedUpInARow + ") " +
                "(when low: " + FuelPickedUpWhenLow + ") ");
        }
        else
        {
            GuiHelper.DrawBackground(delegate() {
                gameObject.AddComponent <ScreenSplash>();
                Destroy(this);
            });
            GuiHelper.DrawAtTop(GameOverReason);


            if (GUI.Button(new Rect(GuiHelper.PercentW(0.8), GuiHelper.PercentH(0.13), GuiHelper.PercentW(0.15), GuiHelper.PercentH(0.1)), "help", GuiHelper.SmallFont))
            {
                ShowRideInfoScreen = true;
            }
            DrawTopScores(0.3f);

            Texture achievements = SpriteManager.GetAchievements();
            if (GUI.Button(new Rect(GuiHelper.PercentW(0.07), GuiHelper.PercentH(0.65), GuiHelper.PercentW(0.15), GuiHelper.PercentH(0.14)), achievements, GuiHelper.CustomButton))
            {
                CarSmasherSocial.ShowAchievements();
            }

            Texture leaderBoard = SpriteManager.GetLeaderboard();
            if (GUI.Button(new Rect(GuiHelper.PercentW(0.28), GuiHelper.PercentH(0.61), GuiHelper.PercentW(0.15), GuiHelper.PercentH(0.14)), leaderBoard, GuiHelper.CustomButton))
            {
                CarSmasherSocial.ShowLeaderBoard(GoogleLeaderboard.LEADERB_BEST_DISTANCES);
            }

            GuiHelper.YesButton(delegate(){
                Minigame m = gameObject.AddComponent <Minigame>();
                m.PrepareRace(Game.Me.Player, ScreenAfterMinigameClassic.PrepareScreen, Mission.Classic, Game.Me.ClassicCarConfig);
                Destroy(this);
            }, "Start");

            GuiHelper.ButtonWithText(0.9, 0.92, 0.4, 0.2, "", SpriteManager.GetBackButton(), GuiHelper.CustomButton, delegate() {
                BackToSplash();
            });
        }
    }