Ejemplo n.º 1
0
    private IEnumerator PlayOpponentReplay()
    {
        if (this.raceMeters.Length <= 1 || CakeRaceMode.OpponentReplay == null)
        {
            yield break;
        }
        this.cakeRaceMode.OpponentScore = 0;
        this.raceMeters[1].SetScoreLabel(string.Format("{0:n0}", this.cakeRaceMode.OpponentScore));
        bool[] collected = new bool[CakeRaceMode.OpponentReplay.GetCollectedCakeCount()];
        for (int i = 0; i < collected.Length; i++)
        {
            collected[i] = false;
        }
        int collectedCount = 0;

        while (collectedCount < CakeRaceMode.OpponentReplay.GetCollectedCakeCount())
        {
            yield return(null);

            for (int j = 0; j < collected.Length; j++)
            {
                int num             = this.cakeRaceMode.RaceTimeLeftInHundrethOfSeconds();
                int cakeCollectTime = CakeRaceMode.OpponentReplay.GetCakeCollectTime(j);
                if (!collected[j] && cakeCollectTime >= 0 && cakeCollectTime >= num)
                {
                    collected[j] = true;
                    collectedCount++;
                    this.cakeRaceMode.OpponentScore += CakeRaceReplay.CalculateCakeScore(false, cakeCollectTime, CakeRaceMode.OpponentReplay.PlayerLevel, CakeRaceMode.OpponentReplay.HasKingsFavoritePart);
                    this.raceMeters[1].EatCake();
                    this.raceMeters[1].SetScoreLabel(string.Format("{0:n0}", this.cakeRaceMode.OpponentScore));
                }
            }
        }
        yield break;
    }
Ejemplo n.º 2
0
 private void UpdatePlayerInfo(Dictionary <string, UserDataRecord> replayData)
 {
     if (replayData == null)
     {
         this.ChangeView(LeaderboardDialog.LeaderboardView.List, string.Empty);
         return;
     }
     for (int i = 0; i < this.playerInfo.CakeRaceReplayCount; i++)
     {
         string text = string.Format("replay_track_{0}", i);
         if (replayData.ContainsKey(text))
         {
             CakeRaceReplay cakeRaceReplay = new CakeRaceReplay(replayData[text].Value);
             UnityEngine.Debug.LogWarning(string.Concat(new string[]
             {
                 "[UpdatePlayerInfo] replay [",
                 text,
                 "][",
                 replayData[text].Value,
                 "]"
             }));
             this.playerInfo.UpdateReplayEntry(i, (!CakeRaceMenu.IsWeeklyTrack(i, cakeRaceReplay.UniqueIdentifier, true)) ? null : cakeRaceReplay);
         }
         else
         {
             this.playerInfo.UpdateReplayEntry(i, null);
         }
     }
     this.ChangeView(LeaderboardDialog.LeaderboardView.PlayerInfo, string.Empty);
 }
Ejemplo n.º 3
0
    private bool IsPersonalBest(int trackIndex, int score)
    {
        string key = string.Format("cake_race_track_{0}_pb_replay", trackIndex);
        int    num = 0;

        if (GameProgress.HasKey(key, GameProgress.Location.Local, null))
        {
            CakeRaceReplay replay = new CakeRaceReplay(GameProgress.GetString(key, string.Empty, GameProgress.Location.Local, null));
            num = CakeRaceReplay.TotalScore(replay);
        }
        return(num < score);
    }
Ejemplo n.º 4
0
 public void UpdateReplayEntry(int index, CakeRaceReplay replay)
 {
     if (this.replayEntries != null && this.replayEntries.ContainsKey(index) && this.replayEntries[index] != null)
     {
         if (replay == null || !replay.IsValid)
         {
             this.replayEntries[index].SetInfo(index, 0, 0, false);
         }
         else
         {
             this.replayEntries[index].SetInfo(index, replay);
         }
     }
 }
Ejemplo n.º 5
0
    public void SetInfo(int track, CakeRaceReplay replay)
    {
        if (replay == null || !replay.IsValid)
        {
            this.SetInfo(track, 0, 0, false);
            return;
        }
        int score = CakeRaceReplay.TotalScore(replay);
        int num   = replay.GetCollectedCakeCount();

        if (replay.GetCakeCollectTime(-1) >= 0)
        {
            num--;
        }
        this.SetInfo(track, score, num, replay.HasKingsFavoritePart);
    }
Ejemplo n.º 6
0
 private void OnReplayFetched(string replayJson)
 {
     if (!CakeRaceMenu.IsCakeRaceMenuOpen)
     {
         return;
     }
     if (CakeRaceMenu.UseDefaultReplay || string.IsNullOrEmpty(replayJson))
     {
         this.LoadDefaultReplay();
     }
     else
     {
         UnityEngine.Debug.LogWarning("[OnReplayFetched]\n" + replayJson);
         Singleton <GuiManager> .Instance.enabled = true;
         CakeRaceReplay cakeRaceReplay = new CakeRaceReplay(replayJson);
         if (cakeRaceReplay.IsValid)
         {
             if (CakeRaceMenu.IsWeeklyTrack(this.currentWeeklyTrackIndex, cakeRaceReplay.UniqueIdentifier, false))
             {
                 CakeRaceInfo?cakeRaceInfo;
                 if (WPFMonoBehaviour.gameData.m_cakeRaceData.GetInfo(cakeRaceReplay.UniqueIdentifier, out cakeRaceInfo))
                 {
                     CakeRaceMode.OpponentReplay = cakeRaceReplay;
                     this.SetInfoLabel("Opponent found");
                     this.LoadCakeRaceLevel(cakeRaceInfo.Value);
                 }
                 else
                 {
                     this.SetInfoLabel("Opponent replay has unknown level");
                     this.LoadDefaultReplay();
                 }
             }
             else
             {
                 this.SetInfoLabel("Opponent replay not from this week");
                 this.LoadDefaultReplay();
             }
         }
         else
         {
             this.SetInfoLabel("Opponent replay is invalid");
             this.LoadDefaultReplay();
         }
     }
 }
Ejemplo n.º 7
0
 private void SetScore(CakeRaceReplay replay)
 {
     if (replay == null)
     {
         for (int i = 0; i < this.cakes.Length; i++)
         {
             this.cakes[i].SetActive(false);
         }
         this.score.text = "-";
         this.kingsFavorite.SetActive(false);
     }
     else
     {
         for (int j = 0; j < this.cakes.Length; j++)
         {
             this.cakes[j].SetActive(replay.CakesCollected > j);
         }
         this.score.text = string.Format("{0:N0}", CakeRaceReplay.TotalScore(replay));
         this.kingsFavorite.SetActive(replay.HasKingsFavoritePart);
     }
 }
Ejemplo n.º 8
0
    private void ReportCupScore(int cupIndex)
    {
        int num = 0;

        for (int i = 0; i < 7; i++)
        {
            string text = string.Format("cake_race_track_{0}_pb_replay", i);
            if (GameProgress.HasKey(text, GameProgress.Location.Local, null))
            {
                CakeRaceReplay cakeRaceReplay = new CakeRaceReplay(GameProgress.GetString(text, string.Empty, GameProgress.Location.Local, null));
                if (cakeRaceReplay.IsValid)
                {
                    int num2 = CakeRaceReplay.TotalScore(cakeRaceReplay);
                    num += num2;
                    UnityEngine.Debug.LogWarning("[CakeRaceMode] Track (" + text + ") score " + num2.ToString());
                }
            }
        }
        PlayFabLeaderboard.Leaderboard board = (PlayFabLeaderboard.Leaderboard)cupIndex;
        UnityEngine.Debug.LogWarning("[CakeRaceMode] ReportCupScore [" + board.ToString() + "] " + num.ToString());
        Singleton <PlayFabManager> .Instance.Leaderboard.AddScore(board, num, new Action <UpdatePlayerStatisticsResult>(this.OnCupScoreReported), new Action <PlayFabError>(this.OnCupScoreError));
    }
Ejemplo n.º 9
0
 private void OnCakeCollected(Cake cake)
 {
     if (this.CakeCollected != null)
     {
         this.CakeCollected(0);
     }
     if (cake.CollectedByOtherPlayer)
     {
         return;
     }
     this.CollectedCakes++;
     if (this.CollectedCakes >= this.cakes.Count)
     {
         this.EndRace(cake.CakeIndex, true);
     }
     else
     {
         int collectTime = this.RaceTimeLeftInHundrethOfSeconds();
         CakeRaceMode.CurrentReplay.SetCollectedCake(cake.CakeIndex, collectTime);
         this.AddScore(CakeRaceReplay.CalculateCakeScore(false, collectTime, Singleton <PlayerProgress> .Instance.Level, this.HasKingsFavoritePart()));
     }
 }
Ejemplo n.º 10
0
    private void EndRace(int cakeIndex, bool waitToExplode = true)
    {
        EventManager.Disconnect(new EventManager.OnEvent <TimeBombExplodeEvent>(this.OnTimeBombExplode));
        if (this.IsRaceOn && this.levelManager.gameState != LevelManager.GameState.CakeRaceCompleted)
        {
            int collectTime = this.RaceTimeLeftInHundrethOfSeconds();
            CakeRaceMode.CurrentReplay.SetCollectedCake(cakeIndex, collectTime);
            this.AddScore(CakeRaceReplay.CalculateCakeScore(cakeIndex < 0, collectTime, Singleton <PlayerProgress> .Instance.Level, this.HasKingsFavoritePart()));
            this.IsRaceOn      = false;
            this.OpponentScore = 0;
            if (CakeRaceMode.OpponentReplay != null)
            {
                this.OpponentScore = CakeRaceReplay.TotalScore(CakeRaceMode.OpponentReplay);
            }
            PlayerProgressBar.Instance.DelayUpdate();
            this.gainedXP = Singleton <PlayerProgress> .Instance.AddExperience((!this.LocalPlayerIsWinner)?PlayerProgress.ExperienceType.LoseCakeRace : PlayerProgress.ExperienceType.WinCakeRace);

            int num = GameProgress.GetInt("cake_race_total_wins", 0, GameProgress.Location.Local, null);
            if (!CakeRaceMode.IsPreviewMode && this.LocalPlayerIsWinner)
            {
                this.RewardCrate(num);
                Singleton <PlayFabManager> .Instance.Leaderboard.AddScore(PlayFabLeaderboard.Leaderboard.CakeRaceWins, 1);

                CakeRaceMenu.WinCount++;
            }
            else
            {
                CakeRaceMode.CurrentRewardCrate = LootCrateType.None;
            }
            int trackIndex = CakeRaceMenu.GetTrackIndex(CakeRaceMode.cakeRaceInfo.Value.UniqueIdentifier, false);
            if (this.IsPersonalBest(trackIndex, this.CurrentScore) && trackIndex >= 0 && trackIndex < 7)
            {
                string key  = string.Format("replay_track_{0}", trackIndex);
                string text = CakeRaceMode.CurrentReplay.TrimmedString();
                Singleton <PlayFabManager> .Instance.UpdateUserData(new Dictionary <string, string>
                {
                    {
                        key,
                        text
                    }
                }, UserDataPermission.Public);

                this.SavePersonalBest(trackIndex, text);
                this.ReportCupScore(GameProgress.GetInt("cake_race_current_cup", (int)PlayFabLeaderboard.LowestCup(), GameProgress.Location.Local, null));
            }
            CoroutineRunner.Instance.StartCoroutine(this.EndingSequence(waitToExplode));
            int    num2            = GameProgress.GetInt("cake_race_total_losses", 0, GameProgress.Location.Local, null);
            string currentSeasonID = CakeRaceMode.GetCurrentSeasonID();
            string key2            = string.Format("Season_{0}_wins", currentSeasonID);
            string key3            = string.Format("Season_{0}_losses", currentSeasonID);
            int    num3            = GameProgress.GetInt(key2, 0, GameProgress.Location.Local, null);
            int    num4            = GameProgress.GetInt(key3, 0, GameProgress.Location.Local, null);
            if (this.LocalPlayerIsWinner)
            {
                GameProgress.SetInt("cake_race_total_wins", ++num, GameProgress.Location.Local);
                GameProgress.SetInt(key2, ++num3, GameProgress.Location.Local);
            }
            else
            {
                GameProgress.SetInt("cake_race_total_losses", ++num2, GameProgress.Location.Local);
                GameProgress.SetInt(key3, ++num4, GameProgress.Location.Local);
            }
        }
    }