Ejemplo n.º 1
0
    def _calc_receive_notice(self, data, req, timer):
        """接收到战斗结果通知
        1 变更演武场积分
        2 新增演武场对战记录
        """
        melee = data.melee.get()
        (win_score, lose_score) = melee_business.calc_battle_score(melee, req.rival_score)
        score_delta = 0
        if req.status == MeleeRecordInfo.STATUS_DEFEND_LOSE:
            score_delta = lose_score
        else:
            score_delta = win_score

        melee.add_score(score_delta)
        record = melee_business.add_melee_record(data,
                req.rival_user_id, base64.b64encode(req.rival_name), req.rival_level,
                req.rival_icon_id, req.status, score_delta)

        mails = []
        melee_matcher = MeleeMatcher()
        if melee.need_query_rank():
            defer = melee_matcher.query_ranking(data, melee)
            defer.addCallback(self._update_title_level,
                    data, melee, melee_matcher, mails, timer)
            defer.addCallback(self._check)
        else:
            defer = Deferred()
            defer.addCallback(self._update_title_level,
                    data, melee, melee_matcher, mails, timer)
            defer.addCallback(self._check)
            defer.callback(True)

        defer = DataBase().commit(data)
        defer.addCallback(self._receive_notice_succeed, req, melee, melee_matcher, record, timer)
        return defer
Ejemplo n.º 2
0
    def _calc_query_melee_ranking(self, data, req, timer):
        user = data.user.get()
        if not user.allow_pvp_arena:
            raise Exception("melee is not unlock[user_level=%d]" % user.level)

        melee = data.melee.get()
        melee_matcher = MeleeMatcher()
        RANKING_COUNT = 20
        users = []
        defer = melee_matcher.query_melee_users_by_ranking(data, melee, RANKING_COUNT, users)
        defer.addCallback(self._pack_query_melee_ranking_response,
                data, melee, melee_matcher, users, req, timer)
        return defer
Ejemplo n.º 3
0
    def _calc_update_melee(self, data, req, timer):
        user = data.user.get()
        melee = data.melee.get()
        if not melee.is_able_to_unlock(user):
            raise Exception("melee is not unlock[user_level=%d]" % user.level)

        arena = data.arena.get(True)
        melee.node_id = arena.node_id
        
        mails = []
        last_battle_win = melee.last_battle_win
        old_title_level = melee.title_level
        melee_matcher = MeleeMatcher()
        #if last_battle_win:
        #    #更新段位
        #    defer = Deferred()
        #    defer.addCallback(self._update_title_level,
        #            data, melee, melee_matcher, mails, timer)
        #    defer.addCallback(self._check)
        #    defer.callback(True)
        #else:
        #    if melee.need_query_rank():
        #        defer = melee_matcher.query_ranking(data, melee)
        #        defer.addCallback(self._update_title_level,
        #                data, melee, melee_matcher, mails, timer)
        #        defer.addCallback(self._check)
        #    else:
        #        defer = Deferred()
        #        defer.addCallback(self._update_title_level,
        #                data, melee, melee_matcher, mails, timer)
        #        defer.addCallback(self._check)
        #        defer.callback(True)
        if melee.need_query_rank():
            defer = melee_matcher.query_ranking(data, melee)
            defer.addCallback(self._update_title_level,
                    data, melee, melee_matcher, mails, timer)
            defer.addCallback(self._check)
        else:
            defer = Deferred()
            defer.addCallback(self._update_title_level,
                    data, melee, melee_matcher, mails, timer)
            defer.addCallback(self._check)
            defer.callback(True)

        #if melee_business.is_need_broadcast_title(old_title_level, melee):
        #    #演武场获得高段位发广播
        #    self._add_melee_broadcast_title(user, melee)
            
        defer.addCallback(self._pack_update_melee_response,
                data, melee, melee_matcher, mails, last_battle_win, req, timer)
        return defer
Ejemplo n.º 4
0
    def _calc_query_melee(self, data, req, timer):
        user = data.user.get()
        melee = data.melee.get()

        if not melee.is_able_to_unlock(user):
            raise Exception("Melee is not unlock[user_level=%d]" % user.level)

        arena = data.arena.get(True)
        melee.node_id = arena.node_id
        
        new_mails = []
        melee_matcher = MeleeMatcher()
        if timer.now < melee.next_time:
            logger.warning("Melee can not query now")

        #若乱斗场轮次过时,需要清算
        if melee.is_arena_round_overdue(timer.now):
            melee_business.calc_melee_round_result(data, melee, new_mails, timer.now)
            logger.debug("calc melee round result")

        #更新乱斗场场next_time
        melee.update_next_time(timer.now)

        if melee.is_arena_active(timer.now):
            if melee.rivals_user_id == '':
                #匹配对手
                defer = melee_matcher.match(data, melee)
            else:
                defer = melee_matcher.query_ranking(data, melee)
            #更新段位
            defer.addCallback(self._update_title_level,
                    data, melee, melee_matcher, new_mails, timer)
            defer.addCallback(self._pack_query_melee_response,
                data, melee, melee_matcher, new_mails, req, timer)
            return defer

        else:
            if melee.need_query_rank():
                defer = melee_matcher.query_ranking(data, melee)
                defer.addCallback(self._pack_query_melee_response,
                    data, melee, melee_matcher, new_mails, req, timer)
            else:
                defer = Deferred()
                defer.addCallback(self._pack_query_melee_response,
                    data, melee, melee_matcher, new_mails, req, timer)
                defer.callback(True)
            return defer
Ejemplo n.º 5
0
    def _calc_refresh_melee(self, data, req, timer):
        #涉及到跨天的数据统计,所以此处要更新所有跨天数据
        if not account_business.update_across_day_info(data, timer.now):
            raise Exception("Update across day info failed")
        
        user = data.user.get()
        melee = data.melee.get()
        if not melee.is_able_to_unlock(user):
            raise Exception("Melee is not unlock[user_level=%d]" % user.level)

        arena = data.arena.get(True)
        melee.node_id = arena.node_id
        
        if not melee_business.refresh_melee(data, melee, timer.now):
            raise Exception("Refresh melee failed")

        #匹配对手
        melee_matcher = MeleeMatcher()
        defer = melee_matcher.match(data, melee)
        defer.addCallback(self._pack_refresh_melee_response,
                data, melee, melee_matcher, req, timer)
        return defer
Ejemplo n.º 6
0
    def _calc_get_melee_win_num_reward(self, data, req, timer):
        user = data.user.get()
        melee = data.melee.get()
        if not melee.is_able_to_unlock(user):
            raise Exception("melee is not unlock[user_level=%d]" % user.level)

        if not melee_business.get_melee_win_num_reward(data, melee, timer.now):
            raise Exception("melee get win num reward failed")

        #验证客户端正确性
        for item_info in req.items:
            compare.check_item(data, item_info)

        melee_matcher = MeleeMatcher()
        if melee.need_query_rank():
            defer = melee_matcher.query_ranking(data, melee)
        else:
            defer = Deferred()
            defer.callback(True)

        defer.addCallback(self._pack_get_melee_win_num_reward_response,
                data, melee, melee_matcher, req, timer)
        return defer
Ejemplo n.º 7
0
    def _load_user(self, basic_data, data, req, timer):
        """载入玩家数据,并计算离线数据
        """
        defer = Deferred()

        arena_matcher = ArenaMatcher()
        melee_matcher = MeleeMatcher()
        defer.addCallback(self._query_arena_ranking, data, req, timer,
                          arena_matcher)
        defer.addCallback(self._query_melee_ranking, data, req, timer,
                          melee_matcher)
        defer.addCallback(self._update_all_info, basic_data, data, req, timer)
        defer.addCallback(self._pack_user_info, basic_data, req, timer, False,
                          arena_matcher, melee_matcher)
        defer.callback(True)
        return defer