Exemplo n.º 1
0
 public RaceRecord(CharacterTier tier, float time, DateTime date, int stage, int character, float[] checkpointTimes, float gameVersion, bool isTesting)
 {
     this.tier            = tier;
     this.time            = time;
     this.date            = date;
     this.stage           = stage;
     this.character       = character;
     this.checkpointTimes = checkpointTimes;
     this.gameVersion     = gameVersion;
     this.wasTesting      = isTesting;
 }
Exemplo n.º 2
0
        private void PassNextCheckpoint(float lapTime)
        {
            checkpointTimes[currentCheckpointIndex] = lapTime;

            //Call NextCheckpointPassed BEFORE doing anything else. This ensures things like lap records work correctly.
            if (NextCheckpointPassed != null)
            {
                NextCheckpointPassed(this, new NextCheckpointPassArgs(currentCheckpointIndex, TimeSpan.FromSeconds(lapTime)));
            }

            currentCheckpointIndex = (currentCheckpointIndex + 1) % sr.checkpoints.Length;
            currentCheckpointPos   = nextCheckpoint.transform.position;

            if (currentCheckpointIndex == 0)
            {
                lap++;

                if (FinishLinePassed != null)
                {
                    FinishLinePassed(this, EventArgs.Empty);
                }

                if (LapRecordsEnabled)
                {
                    CharacterTier tier      = ActiveData.Characters[Character].tier;
                    string        sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
                    int           stage     = ActiveData.Stages.Where(a => a.sceneName == sceneName).First().id;

                    ActiveData.RaceRecords.Add(new RaceRecord(
                                                   tier,
                                                   lapTime,
                                                   DateTime.Now,
                                                   stage,
                                                   Character,
                                                   checkpointTimes,
                                                   GameVersion.AS_FLOAT,
                                                   GameVersion.IS_TESTING
                                                   ));

                    Debug.Log("Saved lap record (" + TimeSpan.FromSeconds(lapTime) + ")");
                }

                //Reset lap time
                this.lapTime    = 0 + (this.lapTime - lapTime);
                checkpointTimes = new float[StageReferences.Active.checkpoints.Length];
            }

            SetNextCheckpoint();

            //Set next target node if this is an AI ball
            TrySetAITarget();
        }
Exemplo n.º 3
0
        private void TargetPlayer_NextCheckpointPassed(object sender, NextCheckpointPassArgs e)
        {
            UISound.Play(checkpointSound);
            checkpointTimeField.text = Utils.GetTimeString(e.CurrentLapTime);
            checkpointTimeField.GetComponent <ToggleCanvasGroup>().ShowTemporarily(2f);

            if (TargetPlayer.LapRecordsEnabled)
            {
                CharacterTier tier      = ActiveData.Characters[targetPlayer.Character].tier;
                string        sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
                int           stage     = ActiveData.Stages.Where(a => a.sceneName == sceneName).First().id;

                float time = (float)e.CurrentLapTime.TotalSeconds;

                RaceRecord bestRecord = ActiveData.RaceRecords
                                        .Where(a => a.Tier == tier && a.Stage == stage && a.GameVersion == GameVersion.AS_FLOAT && a.WasTesting == GameVersion.IS_TESTING)
                                        .OrderBy(a => a.Time)
                                        .FirstOrDefault();

                if (bestRecord != null)
                {
                    float diff = time - bestRecord.CheckpointTimes[e.IndexOfPreviousCheckpoint];

                    bool     faster   = diff < 0;
                    TimeSpan diffSpan = TimeSpan.FromSeconds(Mathf.Abs(diff));

                    checkpointTimeDiffField.text  = (faster ? "-" : "+") + Utils.GetTimeString(diffSpan);
                    checkpointTimeDiffField.color = faster ? Color.blue : Color.red;
                    checkpointTimeDiffField.GetComponent <ToggleCanvasGroup>().ShowTemporarily(2f);

                    if (e.IndexOfPreviousCheckpoint == StageReferences.Active.checkpoints.Length - 1 && faster)
                    {
                        checkpointTimeDiffField.text = "New lap record!";
                    }
                }
                else
                {
                    if (e.IndexOfPreviousCheckpoint == StageReferences.Active.checkpoints.Length - 1)
                    {
                        checkpointTimeDiffField.text  = "Lap record set!";
                        checkpointTimeDiffField.color = Color.blue;
                        checkpointTimeDiffField.GetComponent <ToggleCanvasGroup>().ShowTemporarily(2f);
                    }
                }
            }
        }