Exemple #1
0
        private void DoneRacingCallback(DoneRacingMessage msg, float travelTime)
        {
            RacePlayer rp = players.FirstOrDefault(a => a.AssociatedMatchPlayer != null &&
                                                   a.AssociatedMatchPlayer.ClientGuid == msg.ClientGuid &&
                                                   a.AssociatedMatchPlayer.CtrlType == msg.CtrlType);

            DoneRacingInner(rp, msg.RaceTime, msg.Disqualified);
        }
Exemple #2
0
        private void DoneRacingInner(RacePlayer rp, double raceTime, bool disqualified)
        {
            int pos = players.IndexOf(rp) + 1;

            if (disqualified)
            {
                pos = RaceFinishReport.DISQUALIFIED_POS;
            }
            rp.FinishRace(new RaceFinishReport(pos, System.TimeSpan.FromSeconds(raceTime)));

            //Display scoreboard when all players have finished
            //TODO: Make proper scoreboard and have it trigger when only local players have finished
            if (!players.Any(a => a.IsPlayer && !a.RaceFinished))
            {
                StageReferences.Active.endOfMatchHandler.Activate(this);
            }
        }
Exemple #3
0
        private void CreateBallObjects()
        {
            int             nextBallPosition = 0;
            RaceBallSpawner ballSpawner      = StageReferences.Active.spawnPoint;

            //Enable lap records if there is only one local player.
            bool enableLapRecords = matchManager.Players.Count(a => a.ClientGuid == matchManager.LocalClientGuid) == 1;

            //Create all player balls
            for (int i = 0; i < matchManager.Players.Count; i++)
            {
                var matchPlayer = matchManager.Players[i];

                bool local = matchPlayer.ClientGuid == matchManager.LocalClientGuid;

                //Create ball
                string name = matchManager.Clients.FirstOrDefault(a => a.Guid == matchPlayer.ClientGuid).Name;
                matchPlayer.BallObject = ballSpawner.SpawnBall(
                    nextBallPosition,
                    BallType.Player,
                    local ? matchPlayer.CtrlType : ControlType.None,
                    matchPlayer.CharacterId,
                    name + " (" + GameInput.GetControlTypeName(matchPlayer.CtrlType) + ")"
                    );

                //Create race player
                var racePlayer = new RacePlayer(matchPlayer.BallObject, messenger, matchPlayer);
                players.Add(racePlayer);
                racePlayer.LapRecordsEnabled = enableLapRecords && local;
                racePlayer.FinishLinePassed += RacePlayer_FinishLinePassed;

                nextBallPosition++;
            }

            if (!matchManager.OnlineMode)
            {
                //Create all AI balls (In local play only)
                for (int i = 0; i < settings.AICount; i++)
                {
                    //Create ball
                    var aiBall = ballSpawner.SpawnBall(
                        nextBallPosition,
                        BallType.AI,
                        ControlType.None,
                        settings.GetAICharacter(i),
                        "AI #" + i
                        );
                    aiBall.CanMove = false;

                    //Create race player
                    var racePlayer = new RacePlayer(aiBall, messenger, null);
                    players.Add(racePlayer);
                    racePlayer.FinishLinePassed += RacePlayer_FinishLinePassed;

                    nextBallPosition++;
                }
            }

            int nextLocalPlayerIndex = 0;

            foreach (RacePlayer p in players.Where(a => a.CtrlType != ControlType.None))
            {
                //Create player UI
                var playerUI = Instantiate(playerUIPrefab);
                playerUI.TargetManager = this;
                playerUI.TargetPlayer  = p;

                //Connect UI to camera (when the camera has been instanced)
                int persistentIndex = nextLocalPlayerIndex;
                p.AssociatedMatchPlayer.BallObject.CameraCreated += (sender, e) =>
                {
                    playerUI.TargetCamera = e.CameraCreated.AttachedCamera;
                    var splitter = e.CameraCreated.AttachedCamera.GetComponent <CameraSplitter>();
                    if (splitter)
                    {
                        splitter.SplitscreenIndex = persistentIndex;
                    }
                };

                nextLocalPlayerIndex++;
            }
        }