コード例 #1
0
def totally_reset(server_id, send_notify=False):
    MongoChampionship.db(server_id).update_many(
        {}, {'$set': {
            'applied': False,
            'bet': {},
            'has_bet': False,
        }})

    MongoChampionshipGroup.db(server_id).drop()
    MongoChampionshipLevel.db(server_id).drop()

    if send_notify:
        basic_notify = make_common_basic_notify_msg(server_id)
        basic_data = MessageFactory.pack(basic_notify)

        group_notify = make_empty_group_notify_msg()
        group_data = MessageFactory.pack(group_notify)

        level_notify = ChampionshipLevel(server_id).make_protomsg()
        level_data = MessageFactory.pack(level_notify)

        char_ids = OperationLog.get_recent_action_char_ids(server_id)
        for cid in char_ids:
            mp = MessagePipe(cid)
            mp.put(data=basic_data)
            mp.put(data=group_data)
            mp.put(data=level_data)
コード例 #2
0
 def finish(self):
     doc = MongoChampionshipGroup.document()
     doc['_id'] = self.group_id
     doc['member_ids'] = self._member_ids
     doc['info'] = self._info
     doc['scores'] = {i: 0 for i in self._member_ids}
     doc['logs'] = {i: [] for i in self._member_ids}
     doc['match_times'] = 1
     MongoChampionshipGroup.db(self.server_id).insert_one(doc)
コード例 #3
0
    def start_match(self):
        match_times = self.doc['match_times']
        if match_times == 7:
            return match_times

        hour, minute = GROUP_MATCH_TIME[match_times - 1]
        match_at = make_time_of_today(hour, minute).timestamp

        scores = self.get_scores_sorted()
        pairs = make_pairs_from_flat_list(scores)

        for (id_one, _), (id_two, _) in pairs:
            info_one = self.doc['info'][id_one]
            info_two = self.doc['info'][id_two]

            m = Match(self.server_id, id_one, info_one, id_two, info_two)
            one_way_wins, record_ids = m.start()

            two_way_wins = [1 - _w for _w in one_way_wins]

            one_way_wins_count = len([_w for _w in one_way_wins if _w == 1])
            two_way_wins_count = len([_w for _w in two_way_wins if _w == 1])

            one_got_score = ConfigChampionWinScore.get(
                one_way_wins_count).score
            two_got_score = ConfigChampionWinScore.get(
                two_way_wins_count).score

            self.doc['scores'][id_one] += one_got_score
            self.doc['scores'][id_two] += two_got_score

            one_name = self.doc['info'][id_one]['name']
            two_name = self.doc['info'][id_two]['name']
            one_log = self.make_match_log(match_at, two_name, one_got_score,
                                          one_way_wins, record_ids)
            two_log = self.make_match_log(match_at, one_name, two_got_score,
                                          two_way_wins, record_ids)

            self.doc['logs'][id_one].append(one_log)
            self.doc['logs'][id_two].append(two_log)

            self.send_score_reward_mail(id_one, self.doc['scores'][id_one])
            self.send_score_reward_mail(id_two, self.doc['scores'][id_two])

        self.doc['match_times'] += 1
        MongoChampionshipGroup.db(self.server_id).update_one(
            {'_id': self.group_id}, {
                '$set': {
                    'scores': self.doc['scores'],
                    'logs': self.doc['logs'],
                    'match_times': self.doc['match_times'],
                }
            })

        return self.doc['match_times']
コード例 #4
0
    def find_by_char_id(self, char_id):
        self.doc = MongoChampionshipGroup.db(self.server_id).find_one(
            {'member_ids': str(char_id)})

        if self.doc:
            self.group_id = self.doc['_id']
            self._char_id = char_id
コード例 #5
0
 def make_match_log(match_at, target_name, got_score, way_wins, record_ids):
     doc = MongoChampionshipGroup.document_match_log()
     doc['timestamp'] = match_at
     doc['target_name'] = target_name
     doc['got_score'] = got_score
     doc['way_wins'] = way_wins
     doc['record_ids'] = record_ids
     return doc
コード例 #6
0
    def find_all_groups(cls, server_id):
        """

        :rtype: list[ChampionshipGroup]
        """
        groups = []
        """:type: list[ChampionshipGroup]"""

        group_docs = MongoChampionshipGroup.db(server_id).find({})
        for doc in group_docs:
            g = ChampionshipGroup(server_id)
            g.group_id = doc['_id']
            g.doc = doc

            groups.append(g)

        return groups
コード例 #7
0
    def find_by_group_id(self, group_id):
        self.doc = MongoChampionshipGroup.db(self.server_id).find_one(
            {'_id': group_id})

        if self.doc:
            self.group_id = group_id
コード例 #8
0
    def after_final_match(self):
        # 已经打完了,但还要得出第三四名,并记录前四名
        level_4_member_ids = self.doc['levels']['4']['member_ids'][:]
        level_2_member_ids = self.doc['levels']['2']['member_ids'][:]
        for i in level_2_member_ids:
            level_4_member_ids.remove(i)

        id_one = level_4_member_ids[0]
        id_two = level_4_member_ids[1]

        info_one = self.doc['info'][id_one]
        info_two = self.doc['info'][id_two]

        m = Match(self.server_id, id_one, info_one, id_two, info_two)
        one_way_wins, one_record_ids = m.start()
        # two_way_wins = [1 - _w for _w in one_way_wins]
        one_way_wins_count = len([_w for _w in one_way_wins if _w == 1])

        if one_way_wins_count >= 2:
            third = id_one
            fourth = id_two
        else:
            third = id_two
            fourth = id_one

        first = self.doc['levels']['1']['member_ids'][0]
        level_2_member_ids.remove(first)
        second = level_2_member_ids[0]

        first_info = self.doc['info'][first]
        second_info = self.doc['info'][second]
        third_info = self.doc['info'][third]
        fourth_info = self.doc['info'][fourth]

        MongoChampionHistory.db(self.server_id).drop()
        history_doc = MongoChampionHistory.document()
        history_doc['member_ids'] = [first, second, third, fourth]
        history_doc['info'] = {
            first: first_info,
            second: second_info,
            third: third_info,
            fourth: fourth_info,
        }

        MongoChampionHistory.db(self.server_id).insert_one(history_doc)

        # 清空小组赛
        MongoChampionshipGroup.db(self.server_id).drop()
        group_notify = make_empty_group_notify_msg()
        group_data = MessageFactory.pack(group_notify)

        # 清空玩家的报名标识
        MongoChampionship.db(self.server_id).update_many(
            {}, {'$set': {
                'applied': False
            }})

        char_ids = OperationLog.get_recent_action_char_ids(self.server_id)
        basic_notify = make_common_basic_notify_msg(self.server_id)
        for _cid in char_ids:
            MessagePipe(_cid).put(data=group_data)
            Championship(self.server_id,
                         _cid).send_basic_notify(basic_notify=basic_notify)

        # 设置winning
        winning_notify = LeaderboardChampionshipNotify()
        winning_notify.session = ""
        for __id, __info in [(first, first_info), (second, second_info),
                             (third, third_info)]:
            __match = Match(self.server_id, None, None, None, None)
            __clubs, __skill_sequence = __match.make_3_way_clubs(__id, __info)

            winning_notify_club = winning_notify.clubs.add()
            winning_notify_club.club.MergeFrom(__clubs[0].make_protomsg())
            for __way_id in [1, 2, 3]:
                winning_notify_club_formation = winning_notify_club.formation.add(
                )
                winning_notify_club_formation.MergeFrom(
                    make_plunder_formation_msg(__clubs[__way_id - 1],
                                               __way_id))

        WinningChampionship(self.server_id, None).set_to_common(winning_notify)