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; }
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())); } }
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); } } }