Exemplo n.º 1
0
        public static async Task <bool> AttemptRaceFinishAsync(RaceItem Race)
        {
            DatabaseHandler database = new DatabaseHandler(Globals.MySqlConnectionString);

            EntrantsSummary entrantsSummary = database.GetEntrantsSummary(Race.RaceId);

            var raceServer  = client.GetGuild(Globals.GuildId);
            var raceRole    = raceServer.GetRole(Race.RoleId);
            var raceChannel = raceServer.GetTextChannel(Race.TextChannelId);

            //we sometimes may need to know if the race is actually finishing
            bool raceIsFinishing = false;

            //Racers are stored as "Ready" until they finish, forfeit, or are disqualified
            if (entrantsSummary.Ready == 0)
            {
                await raceChannel.SendMessageAsync("Everyone is finished! GGs all around! This channel will be deleted in 10 minutes.");

                database.UpdateRace(Race.RaceId, Status: "Recently Completed");
                var newTimer = new CountdownTimer();
                newTimer.Interval  = 600000;
                newTimer.race      = Race;
                newTimer.AutoReset = false;
                newTimer.Elapsed  += DeleteFinishedRaceAsync;
                newTimer.Enabled   = true;
                newTimer.Start();
                _completedRaceTimerList.Add(newTimer);
                raceIsFinishing = true;
                _ = UpdateRacesChannelAsync();
            }

            _ = UpdateChannelTopicAsync(Race.RaceId);
            database.Dispose();
            return(raceIsFinishing);
        }
Exemplo n.º 2
0
        public static async Task BeginForceStartAsync(RaceItem Race)
        {
            var raceServer  = client.GetGuild(Globals.GuildId);
            var raceRole    = raceServer.GetRole(Race.RoleId);
            var raceChannel = raceServer.GetTextChannel(Race.TextChannelId);

            //Set the race status to "Countdown" so no new entrants can join
            DatabaseHandler database = new DatabaseHandler(Globals.MySqlConnectionString);

            database.UpdateRace(Race.RaceId, Status: "Countdown");
            database.Dispose();

            //We're going to set a timer to give the remaining entrants time to ready up
            await raceChannel.SendMessageAsync(raceRole.Mention + ", a moderator is force starting this race. Entrants who are not ready within 30 seconds will be kicked from the race.");

            var newTimer = new CountdownTimer();

            newTimer.Interval  = 30000;
            newTimer.race      = Race;
            newTimer.AutoReset = false;
            newTimer.Elapsed  += ForceStartRaceAsync;
            newTimer.Enabled   = true;
            newTimer.Start();
            _forceStartTimerList.Add(newTimer);

            _ = UpdateChannelTopicAsync(Race.RaceId);
            _ = UpdateRacesChannelAsync();
        }
Exemplo n.º 3
0
        public static async Task <bool> AttemptRaceStartAsync(RaceItem Race)
        {
            DatabaseHandler database = new DatabaseHandler(Globals.MySqlConnectionString);

            EntrantsSummary entrantsSummary = database.GetEntrantsSummary(Race.RaceId);

            var raceServer  = client.GetGuild(Globals.GuildId);
            var raceRole    = raceServer.GetRole(Race.RoleId);
            var raceChannel = raceServer.GetTextChannel(Race.TextChannelId);

            //sometimes we need to know if we're actually starting the race.
            bool raceIsStarting = false;

            //See if the number of ready entrants + disqualified entrants equals the total number of entrants
            //It is possible (but rare) for an entrant to be marked disqualified before a race starts
            //Excessive DQs may result in a penalty at some point, so it's important to record them
            if (entrantsSummary.Ready + entrantsSummary.Disqalified == entrantsSummary.TotalEntrants)
            {
                //we don't want a situation where there is only one racer who is ready, but the race starts
                //because of DQed entrants.
                if (entrantsSummary.Ready > 1)
                {
                    //All of the entrants are ready, and we have enough entrants, so we can start the race
                    await raceChannel.SendMessageAsync(raceRole.Mention + " Everyone is ready! Race will start in 10 seconds.");

                    database.UpdateRace(Race.RaceId, Status: "Countdown");
                    var newTimer = new CountdownTimer();
                    newTimer.Interval  = 7000;
                    newTimer.race      = Race;
                    newTimer.AutoReset = false;
                    newTimer.Elapsed  += CountdownRaceAsync;
                    newTimer.Enabled   = true;
                    newTimer.Start();

                    //check for and remove any force start timers that may be waiting to fire
                    RemoveTimer(_forceStartTimerList, Race.RaceId);
                    _ = UpdateRacesChannelAsync();
                    raceIsStarting = true;
                }
            }

            _ = UpdateChannelTopicAsync(Race.RaceId);
            database.Dispose();
            return(raceIsStarting);
        }