Beispiel #1
0
        public static bool OpenYS_Command_Racing_CreateRace_Method(Client ThisClient, CommandReader Command)
        {
            #region Didn't Specify Path
            if (Command._CmdArguments.Count() < 1)
            {
                ThisClient.SendMessage("&eYou need to specify a path to race on!");
                return(false);
            }
            #endregion
            #region Didn't Specify Lap Count
            if (Command._CmdArguments.Count() < 2)
            {
                ThisClient.SendMessage("&eYou need to specify how many laps to race for!");
                return(false);
            }
            #endregion
            #region Try Convert Lap Count
            int  LapCount = 0;
            bool Failed   = !Int32.TryParse(Command._CmdArguments[1], out LapCount);
            #endregion
            #region Lap Count Not Integer
            if (Failed)
            {
                ThisClient.SendMessage("Lap Count given was not an integer! Lap Counts's must be in numeric format!");
                return(false);
            }
            #endregion
            #region Don't Have the Path
            if (!World.Objects.PathList
                .Where(y => y.Type == 15)
                .Select(x => x.Identify.ToUpperInvariant())
                .Contains(Command._CmdArguments[0]
                          .ToUpperInvariant()))
            {
                ThisClient.SendMessage("Path not found - use /ListPaths to see compatible racing paths!");
                return(false);
            }
            #endregion

            Games.Racing2.Race NewRace = new Games.Racing2.Race();
            NewRace.Path = World.Objects.PathList
                           .Where(y => y.Identify.ToUpperInvariant() == Command._CmdArguments[0].ToUpperInvariant()).ToArray()[0];
            NewRace.Owner             = ThisClient;
            NewRace.FastestSectors    = new float[NewRace.Path.Points.Count];
            NewRace.CumulativeSectors = new float[NewRace.Path.Points.Count];

            NewRace.RaceTypeSetRace();
            NewRace.TotalLapCount = LapCount;

            ThisClient.SendMessage("&eRace Created on Path: \"" + NewRace.Path.Identify + "\". To join in, type \"&c/JoinRace " + NewRace.ID + "&e\".");
            Clients.AllClients.Exclude(ThisClient).SendMessage("&e" + ThisClient.Username + " created a Race at " + NewRace.Path.Identify + ". To join in, type \"&c/JoinRace " + NewRace.ID + "&e\".");
            Games.Racing2.Races.Add(NewRace);
            return(true);
        }
Beispiel #2
0
        public static bool OpenYS_Command_Racing_CreateTT_Method(Client ThisClient, CommandReader Command)
        {
            #region Didn't Specify Path
            if (Command._CmdArguments.Count() < 1)
            {
                ThisClient.SendMessage("&eYou need to specify a path to race on!");
                return(false);
            }
            #endregion
            #region Don't Have the Path
            if (!World.Objects.PathList
                .Where(y => y.Type == 15)
                .Select(x => x.Identify.ToUpperInvariant())
                .Contains(Command._CmdArguments[0]
                          .ToUpperInvariant()))
            {
                ThisClient.SendMessage("Path not found - use /ListPaths to see compatible racing paths!");
                return(false);
            }
            #endregion
            #region Specified Duration
            TimeSpan RaceDuration = new TimeSpan(0, 0, 0);
            if (Command._CmdArguments.Count() > 1)
            {
                double Duration = 0;
                bool   Failed   = !Double.TryParse(Command._CmdArguments[1], out Duration);
                if (Failed)
                {
                    ThisClient.SendMessage("Duration in Minutes given was not an integer! Durations must be in numeric format!");
                    return(false);
                }
                RaceDuration = new TimeSpan(0, 0, 0, 0, (int)(Duration * 60 * 1000));
            }
            #endregion

            Games.Racing2.Race NewTT = new Games.Racing2.Race();
            NewTT.Path = World.Objects.PathList
                         .Where(y => y.Identify.ToUpperInvariant() == Command._CmdArguments[0].ToUpperInvariant()).ToArray()[0];
            NewTT.Owner             = ThisClient;
            NewTT.FastestSectors    = new float[NewTT.Path.Points.Count];
            NewTT.CumulativeSectors = new float[NewTT.Path.Points.Count];

            NewTT.RaceTypeSetTimeTrial();
            NewTT.RaceEnds = DateTime.Now + RaceDuration;

            ThisClient.SendMessage("&eTimeTrial Created on Path: \"" + NewTT.Path.Identify + "\". To join in, type \"&c/JoinRace " + NewTT.ID + "&e\".");
            Clients.AllClients.Exclude(ThisClient).SendMessage("&e" + ThisClient.Username + " created a TimeTrial at " + NewTT.Path.Identify + ". To join in, type \"&c/JoinRace " + NewTT.ID + "&e\".");
            Games.Racing2.Races.Add(NewTT);
            return(true);
        }
 public static bool OpenYS_Command_Racing_JoinRace_Method(Client ThisClient, CommandReader Command)
 {
     #region Didn't Specify Race ID
     if (Command._CmdArguments.Count() < 1)
     {
         ThisClient.SendMessage("&aYou need to specify a race id to join!");
         return(false);
     }
     #endregion
     #region Convert Race ID.
     bool Failed     = false;
     int  TargetRace = 0;
     Failed = !Int32.TryParse(Command._CmdArguments[0], out TargetRace);
     #endregion
     #region Race ID not an Integer
     if (Failed)
     {
         ThisClient.SendMessage("RaceID given was not an integer! RaceID's must be in numeric format!");
         return(false);
     }
     #endregion
     #region Race ID not found
     if (Games.Racing2.Races.Where(x => x.ID == TargetRace).Count() < 1)
     {
         ThisClient.SendMessage("No Race with that ID exists!");
         return(false);
     }
     #endregion
     #region Race Already Started!
     Games.Racing2.Race JoinedRace = Games.Racing2.Races.Where(x => x.ID == TargetRace).ToArray()[0];
     if (!JoinedRace.Status.IsNotStarted() & !JoinedRace.RaceTypeIsTimeTrial())
     {
         ThisClient.SendMessage("That race has already been started!");
         return(false);
     }
     #endregion
     Games.Racing2.RaceDescription._Racer ThisRacer = JoinedRace.AddRacer(ThisClient);
     ThisClient.SendMessage("Added you to the race! Have fun!");
     return(true);
 }
        public static bool OpenYS_Command_Racing_PreStartRace_Method(Client ThisClient, CommandReader Command)
        {
            #region Didn't Specify Race ID
            if (Command._CmdArguments.Count() < 1)
            {
                ThisClient.SendMessage("&eYou need to specify a Race ID to prestart!");
                return(false);
            }
            #endregion
            #region Convert Race ID.
            bool Failed     = false;
            int  TargetRace = 0;
            Failed = !Int32.TryParse(Command._CmdArguments[0], out TargetRace);
            #endregion
            #region Race ID not an Integer
            if (Failed)
            {
                ThisClient.SendMessage("RaceID given was not an integer! RaceID's must be in numeric format!");
                return(false);
            }
            #endregion
            #region Not The Owner of the race!
            Games.Racing2.Race StartedRace = Games.Racing2.Races.Where(x => x.ID == TargetRace).ToArray()[0];
            if (ThisClient != StartedRace.Owner)
            {
                ThisClient.SendMessage("&eOnly " + StartedRace.Owner + " can prestart the race!");
                return(false);
            }
            #endregion
            List <Client> ClientsInRace = StartedRace.Racers.Select(x => x.Client).ToList();

            Debug.TestPoint();
            //StartedRace.Status.SetPreStart();

            ClientsInRace.SendMessage("&eRace entry is now closed, take your positions on the starting grid!");
            Clients.AllClients.Except(ClientsInRace).ToList().SendMessage("&eRace " + StartedRace.ID + " is now closed and ready to start!");
            return(true);
        }
Beispiel #5
0
        public static bool OpenYS_Command_Racing_StartRace_Method(Client ThisClient, CommandReader Command)
        {
            if (Command._CmdArguments.Count() < 1)
            {
                ThisClient.SendMessage("&eYou need to specify a race id to start!");
                return(false);
            }
            bool Failed     = false;
            int  TargetRace = 0;

            Failed = !Int32.TryParse(Command._CmdArguments[0], out TargetRace);
            if (Failed)
            {
                ThisClient.SendMessage("&eRaceID given was not an integer! RaceID's must be in numeric format!");
            }
            bool NoRace = false;

            if (Games.Racing2.Races.Where(x => x.ID == TargetRace).Count() < 1)
            {
                NoRace = true;
            }
            Failed |= (NoRace);
            if (Failed)
            {
                ThisClient.SendMessage("&eNo Race found with that ID!");
                return(false);
            }
            if (!NoRace)
            {
                Games.Racing2.Race StartedRace = Games.Racing2.Races.Where(x => x.ID == TargetRace).ToArray()[0];
                if (ThisClient != StartedRace.Owner)
                {
                    ThisClient.SendMessage("&eOnly " + StartedRace.Owner + " can start the race!");
                    return(false);
                }
                Debug.TestPoint();
                //switch (StartedRace.Status.CurrentState.State)
                //{
                //    case Games.Racing2.RaceDescription._Status._RaceStateFlags.NotStarted:
                //        if (StartedRace.RaceTypeIsTimeTrial()) goto case Games.Racing2.RaceDescription._Status._RaceStateFlags.PreStart;
                //        ThisClient.SendMessage("&eThe race is not yet prestarted! Prestart the race first!");
                //        return false;
                //    case Games.Racing2.RaceDescription._Status._RaceStateFlags.PreStart:
                //        if (StartedRace.RaceTypeIsRace())
                //        {
                //            #region Countdown Start
                //            Threads.Add(() =>
                //            {
                //                List<Client> ClientsInRace = StartedRace.Racers.Select(x => x.Client).ToList();
                //                ClientsInRace.SendMessage("&eThe Race will start shortly! Ensure you are completely stopped or you will get a jump start penalty!");
                //                Clients.AllClients.Except(ClientsInRace).ToList().SendMessage("&eRace " + StartedRace.ID + " is about to begin!");
                //                Thread.Sleep(7000);
                //                StartedRace.EnableJumpStartDetection = true;
                //                ClientsInRace.SendMessage("&e3");
                //                Thread.Sleep(1000);
                //                ClientsInRace.SendMessage("&e2");
                //                Thread.Sleep(1000);
                //                ClientsInRace.SendMessage("&e1");
                //                Thread.Sleep(1000);
                //                foreach (Games.Racing2.RaceDescription._Racer ThisRacer in StartedRace.Racers)
                //                {
                //                    ThisRacer.TimeStamp_LapStarted = ThisRacer.Client.Vehicle.TimeStamp;
                //                    ThisRacer.TimeStamp_LastCheckpoint = ThisRacer.Client.Vehicle.TimeStamp;
                //                    ThisRacer.TimeStamp_RaceStarted = ThisRacer.Client.Vehicle.TimeStamp;
                //                    ThisRacer.CurrentLap = 1;
                //                }
                //                StartedRace.EnableJumpStartDetection = false;
                //                StartedRace.Status.SetStarted();
                //                StartedRace.RaceStarted = DateTime.Now;
                //                StartedRace.RaceEnds = StartedRace.RaceStarted;
                //                ClientsInRace.SendMessage("&eGO!");
                //                Clients.AllClients.Except(ClientsInRace).ToList().SendMessage("&eRace " + StartedRace.ID + " has begun!");
                //            }, "START RACE");
                //            #endregion
                //            return true;
                //        }
                //        if (StartedRace.RaceTypeIsTimeTrial())
                //        {
                //            List<Client> ClientsInRace = StartedRace.Racers.Select(x => x.Client).ToList();
                //            foreach (Games.Racing2.RaceDescription._Racer ThisRacer in StartedRace.Racers)
                //            {
                //                ThisRacer.TimeStamp_LapStarted = ThisRacer.Client.Vehicle.TimeStamp;
                //                ThisRacer.TimeStamp_LastCheckpoint = ThisRacer.Client.Vehicle.TimeStamp;
                //                ThisRacer.TimeStamp_RaceStarted = ThisRacer.Client.Vehicle.TimeStamp;
                //                ThisRacer.CurrentLap = 1;
                //            }
                //            StartedRace.Status.SetStarted();
                //            StartedRace.RaceStarted = DateTime.Now;
                //            StartedRace.RaceEnds = StartedRace.RaceStarted;
                //            ClientsInRace.SendMessage("&e## TIME TRIAL STARTED ##");
                //            Clients.AllClients.Except(ClientsInRace).ToList().SendMessage("&eRace " + StartedRace.ID + " has begun!");
                //        }
                //        return false;
                //    case Games.Racing2.RaceDescription._Status._RaceStateFlags.Started:
                //        ThisClient.SendMessage("&eThe race is already running!");
                //        return false;
                //    case Games.Racing2.RaceDescription._Status._RaceStateFlags.RedFlagged:
                //        ThisClient.SendMessage("&eThe race has been red flagged!");
                //        return false;
                //    case Games.Racing2.RaceDescription._Status._RaceStateFlags.Ended:
                //        ThisClient.SendMessage("&eThe race is over!");
                //        return false;
                //}
                ThisClient.SendMessage("Some Logic Error in the StartRace Command???");
                return(false);
            }
            else
            {
                ThisClient.SendMessage("Some Logic Error in the StartRace Command???");
                return(true);
            }
        }