Ejemplo n.º 1
0
 def current_time_str(self):
     if self._status == RaceStatus['paused']:
         return racetime.to_str( int(100*(self._pause_time - self._start_time)) )
     elif self._status == RaceStatus['racing']:
         return racetime.to_str( int(100*(time.monotonic() - self._start_time)) )
     else:
         return ''
Ejemplo n.º 2
0
 def current_time_str(self):
     if self._status == RaceStatus["paused"]:
         return racetime.to_str(int(100 * (self._pause_time - self._start_time)))
     elif self._status == RaceStatus["racing"]:
         return racetime.to_str(int(100 * (time.clock() - self._start_time)))
     else:
         return ""
Ejemplo n.º 3
0
 def current_time_str(self):
     if self._status == RaceStatus['paused']:
         return racetime.to_str(
             int(100 * (self._pause_time - self._start_time)))
     elif self._status == RaceStatus['racing']:
         return racetime.to_str(int(100 *
                                    (time.clock() - self._start_time)))
     else:
         return ''
Ejemplo n.º 4
0
    def record_race(self, cancelled=False):
        if self.race and self.race.start_time:
            self.recorded_race = True
            racer_1_time = -1
            racer_2_time = -1
            racer_1_finished = False
            racer_2_finished = False
            for racer in self.race.racer_list:
                if int(racer.id) == int(self.match.racer_1.discord_id):
                    if racer.is_finished:
                        racer_1_time = racer.time
                        racer_1_finished = True
                elif int(racer.id) == int(self.match.racer_2.discord_id):
                    if racer.is_finished:
                        racer_2_time = racer.time
                        racer_2_finished = True

            winner = 0
            if racer_1_finished and not racer_2_finished:
                winner = 1
            elif not racer_1_finished and racer_2_finished:
                winner = 2
            elif racer_1_finished and racer_2_finished:
                if racer_1_time < racer_2_time:
                    winner = 1
                elif racer_2_time < racer_1_time:
                    winner = 2

            if abs(racer_1_time - racer_2_time) <= (config.RACE_NOTIFY_IF_TIMES_WITHIN_SEC*100):
                race_number = self._cm.condordb.number_of_finished_races(self.match) + 1
                yield from self.client.send_message(self.necrobot.notifications_channel,
                    'Race number {0} has finished within {1} seconds in channel {2}. ({3} -- {4}, {5} -- {6})'.format(
                        race_number, config.RACE_NOTIFY_IF_TIMES_WITHIN_SEC, self.channel.mention,
                        self.match.racer_1.escaped_twitch_name, racetime.to_str(racer_1_time),
                        self.match.racer_2.escaped_twitch_name, racetime.to_str(racer_2_time)))

            self._cm.condordb.record_race(self.match, racer_1_time, racer_2_time, winner, self.race.race_info.seed, self.race.start_time.timestamp(), cancelled)

            if not cancelled:
                racer_1_member = self.necrobot.find_member_with_id(self.match.racer_1.discord_id)
                racer_2_member = self.necrobot.find_member_with_id(self.match.racer_2.discord_id)
                racer_1_mention = racer_1_member.mention if racer_1_member else ''
                racer_2_mention = racer_2_member.mention if racer_2_member else ''
                write_str = '{0}, {1}: The race is over, and has been recorded.'.format(racer_1_mention, racer_2_mention)
            else:
                write_str = 'Race cancelled.'
                
            yield from self.write(write_str)
            yield from self.write('If you wish to contest the previous race\'s result, use the `.contest` command. This marks the race as contested; CoNDOR Staff will be alerted, and will '
                                  'look into your race.')

            if self.played_all_races:
                #Send match ending event if all races have been played
                self.events.matchend(self.match.racer_1.twitch_name, self.match.racer_2.twitch_name)
                yield from self.record_match()
            else:
                yield from self.begin_new_race()
Ejemplo n.º 5
0
    def record_race(self, cancelled=False):
        if self.race and self.race.start_time:
            self.recorded_race = True
            racer_1_time = -1
            racer_2_time = -1
            racer_1_finished = False
            racer_2_finished = False
            for racer in self.race.racer_list:
                if int(racer.id) == int(self.match.racer_1.discord_id):
                    if racer.is_finished:
                        racer_1_time = racer.time
                        racer_1_finished = True
                elif int(racer.id) == int(self.match.racer_2.discord_id):
                    if racer.is_finished:
                        racer_2_time = racer.time
                        racer_2_finished = True

            winner = 0
            if racer_1_finished and not racer_2_finished:
                winner = 1
            elif not racer_1_finished and racer_2_finished:
                winner = 2
            elif racer_1_finished and racer_2_finished:
                if racer_1_time < racer_2_time:
                    winner = 1
                elif racer_2_time < racer_1_time:
                    winner = 2

            if abs(racer_1_time - racer_2_time) <= (config.RACE_NOTIFY_IF_TIMES_WITHIN_SEC*100):
                race_number = self._cm.condordb.number_of_finished_races(self.match) + 1
                yield from self.client.send_message(self.necrobot.notifications_channel,
                    'Race number {0} has finished within {1} seconds in channel {2}. ({3} -- {4}, {5} -- {6})'.format(
                        race_number, config.RACE_NOTIFY_IF_TIMES_WITHIN_SEC, self.channel.mention,
                        self.match.racer_1.escaped_twitch_name, racetime.to_str(racer_1_time),
                        self.match.racer_2.escaped_twitch_name, racetime.to_str(racer_2_time)))

            self._cm.condordb.record_race(self.match, racer_1_time, racer_2_time, winner, self.race.race_info.seed, self.race.start_time.timestamp(), cancelled)

            if not cancelled:
                racer_1_member = self.necrobot.find_member_with_id(self.match.racer_1.discord_id)
                racer_2_member = self.necrobot.find_member_with_id(self.match.racer_2.discord_id)
                racer_1_mention = racer_1_member.mention if racer_1_member else ''
                racer_2_mention = racer_2_member.mention if racer_2_member else ''
                write_str = '{0}, {1}: The race is over, and has been recorded.'.format(racer_1_mention, racer_2_mention)
            else:
                write_str = 'Race cancelled.'
                
            yield from self.write(write_str)
            yield from self.write('If you wish to contest the previous race\'s result, use the `.contest` command. This marks the race as contested; CoNDOR Staff will be alerted, and will '
                                  'look into your race.')

            if self.played_all_races:
                yield from self.record_match()
            else:
                yield from self.begin_new_race()
Ejemplo n.º 6
0
    def status_str(self):
        status = ''
        if self._state == RacerStatus['finished']:
            status += racetime.to_str(self.time)
            if not self.igt == -1:
                status += ' (igt {})'.format(racetime.to_str(self.igt))
        else:
            status += RacerStatusInv[str(self._state)]
            if self._state == RacerStatus['forfeit']:
                status += ' (rta {}'.format(racetime.to_str(self.time))
                if self.level > 0 and self.level < 18:
                    status += ', ' + level.to_str(self.level)
                if not self.igt == -1:
                    status += ', igt {}'.format(racetime.to_str(self.igt))
                status += ')'

        if not self.comment == '':
            status += ': ' + self.comment

        return status
Ejemplo n.º 7
0
    def _status_str(self, short):
        status = ''
        if self._state == RacerStatus['finished']:
            status += racetime.to_str(self.time)
            if not self.igt == -1 and not short:
                status += ' (igt {})'.format(racetime.to_str(self.igt))
        else:
            status += RacerStatusInv[str(self._state)]
            if self._state == RacerStatus['forfeit'] and not short:
                status += ' (rta {}'.format(racetime.to_str(self.time))
                if self.level > 0 and self.level < 18:
                    status += ', ' + level.to_str(self.level)
                if not self.igt == -1:
                    status += ', igt {}'.format(racetime.to_str(self.igt))
                status += ')'

        if not self.comment == '' and not short:
            status += ': ' + self.comment

        return status
Ejemplo n.º 8
0
    def leaderboard_text(self, daily_number, display_seed=False):
        text = "``` \n"
        text += self.leaderboard_header(daily_number) + '\n'

        params = (daily_number, self._type.id)

        if display_seed:
            for row in self._db_conn.execute("SELECT seed FROM daily_data WHERE daily_id=? AND type=?", params):
                text += "Seed: {}\n".format(row[0])
                break

        no_entries = True
        rank = int(0)
        
        prior_result = ''   #detect and handle ties
        rank_to_display = int(1)

        for row in self._db_conn.execute("""SELECT user_data.name,daily_races.level,daily_races.time
                                         FROM daily_races INNER JOIN user_data ON daily_races.discord_id=user_data.discord_id
                                         WHERE daily_races.daily_id=? AND daily_races.type=?
                                         ORDER BY daily_races.level DESC, daily_races.time ASC""", params):
            name = row[0]
            lv = row[1]
            time = row[2]
            result_string = ''
            if lv == 18:
                result_string = racetime.to_str(time)
            elif lv == -1:
                continue
            else:
                result_string = level.to_str(lv)
                if result_string == '':
                    result_string = "death"
                else:
                    result_string = "death ({0})".format(result_string)

            rank += 1
            no_entries = False

            # update the rank only if we've gotten a different result than the last entrant
            if not result_string == prior_result: #kinda hacky to use a string comparison here, but works for the moment
                rank_to_display = rank

            prior_result = result_string
            
            text += '{0: >3}. {1: <24} {2}\n'.format(rank_to_display, name, result_string)

        if no_entries:
            text += 'No entries yet.\n'

        text += '```'
        return text
Ejemplo n.º 9
0
    def leaderboard_text(self, daily_number, display_seed=False):
        text = "``` \n"
        text += self.leaderboard_header(daily_number) + '\n'

        params = (daily_number, self._type.id)

        if display_seed:
            for row in self.necrodb.get_daily_seed(params):
                text += "Seed: {}\n".format(row[0])
                break

        no_entries = True
        rank = int(0)

        prior_result = ''   #detect and handle ties
        rank_to_display = int(1)

        for row in self.necrodb.get_daily_times(params):
            name = row[0]
            lv = row[1]
            time = row[2]
            result_string = ''
            if lv == 18:
                result_string = racetime.to_str(time)
            elif lv == -1:
                continue
            else:
                result_string = level.to_str(lv)
                if result_string == '':
                    result_string = "death"
                else:
                    result_string = "death ({0})".format(result_string)

            rank += 1
            no_entries = False

            # update the rank only if we've gotten a different result than the last entrant
            if not result_string == prior_result: #kinda hacky to use a string comparison here, but works for the moment
                rank_to_display = rank

            prior_result = result_string

            text += '{0: >3}. {1: <24} {2}\n'.format(rank_to_display, name, result_string)

        if no_entries:
            text += 'No entries yet.\n'

        text += '```'
        return text
Ejemplo n.º 10
0
    def parse_submission(self, daily_number, user, args):
        lv = -1
        time = -1
        ret_str = ''
        if len(args) > 0:
            if args[0] == 'death':
                if len(args) == 2:
                    lv = level.from_str(args[1])
                    if not lv == -1:
                        ret_str = 'died on {}'.format(args[1])
                else:
                    lv = 0
                    ret_str = 'died'
            else:
                time = racetime.from_str(args[0])
                if not time == -1:
                    lv = 18
                    ret_str = 'finished in {}'.format(racetime.to_str(time))

        if not lv == -1: # parse succeeded
            asyncio.ensure_future(self.submit_to_daily(daily_number, user, lv, time))
            return ret_str
        else:
            return ''
Ejemplo n.º 11
0
 def time_str(self):
     return racetime.to_str(self.time)
Ejemplo n.º 12
0
 def time_str(self):
     return racetime.to_str(self.time)