Exemple #1
0
    def _calc_receive_update_arena_offline(self, data, req, timer):
        """更新演武场数据
        """
        user = data.user.get()
        if not user.allow_pvp_arena:
            return True

        arena = data.arena.get()
        new_mails = []
        #若演武场轮次过时,需要清算
        if arena.is_arena_round_overdue(timer.now):
            arena_business.calc_arena_round_result(data, arena, new_mails,
                                                   timer.now)

        #离线更新演武场数据
        if not arena_business.update_arena_offline(data, user, arena):
            raise Exception("Update arena offline failed")

        #TODO 先更新积分,再更改段位,排队信息就不对了   to fix

        arena_matcher = ArenaMatcher()
        if arena.need_query_rank():
            defer = arena_matcher.query_ranking(data, arena)
            defer.addCallback(self._update_title_level, data, arena,
                              arena_matcher, new_mails, timer)
            defer.addCallback(self._check)
        else:
            defer = Deferred()
            defer.addCallback(self._update_title_level, data, arena,
                              arena_matcher, new_mails, timer)
            defer.addCallback(self._check)
            defer.callback(True)

        defer = DataBase().commit(data)
        return defer
Exemple #2
0
    def _calc_query_arena(self, data, req, timer):
        user = data.user.get()
        if not user.allow_pvp_arena:
            raise Exception("Arena is not unlock[user_level=%d]" % user.level)

        new_mails = []
        arena_matcher = ArenaMatcher()
        arena = data.arena.get()
        if timer.now < arena.next_time:
            #raise Exception("Arena can not query now")
            logger.warning("Arena can not query now")

        #若演武场轮次过时,需要清算
        if arena.is_arena_round_overdue(timer.now):
            arena_business.calc_arena_round_result(data, arena, new_mails,
                                                   timer.now)
            logger.debug("calc arena round result")

        #更新演武场next_time
        arena.update_next_time(timer.now)

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

        else:
            if arena.need_query_rank():
                defer = arena_matcher.query_ranking(data, arena)
                defer.addCallback(self._pack_query_arena_response, data, arena,
                                  arena_matcher, new_mails, req, timer)
            else:
                defer = Deferred()
                defer.addCallback(self._pack_query_arena_response, data, arena,
                                  arena_matcher, new_mails, req, timer)
                defer.callback(True)
            return defer
Exemple #3
0
    def _calc_update_arena(self, data, req, timer):
        user = data.user.get()
        if not user.allow_pvp_arena:
            raise Exception("Arena is not unlock[user_level=%d]" % user.level)

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

        if arena_business.is_need_broadcast_title(old_title_level, arena):
            #演武场获得高段位发广播
            try:
                self._add_arena_broadcast_title(user, arena)
            except:
                logger.warning("Send arena broadcast failed")

        defer.addCallback(self._pack_update_arena_response, data, arena,
                          arena_matcher, mails, last_battle_win, req, timer)
        return defer
Exemple #4
0
    def _calc_get_arena_win_num_reward(self, data, req, timer):
        user = data.user.get()
        if not user.allow_pvp_arena:
            raise Exception("Arena is not unlock[user_level=%d]" % user.level)

        arena = data.arena.get()
        if not arena_business.get_arena_win_num_reward(data, arena, timer.now):
            raise Exception("Arena get win num reward failed")

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

        arena_matcher = ArenaMatcher()
        if arena.need_query_rank():
            defer = arena_matcher.query_ranking(data, arena)
        else:
            defer = Deferred()
            defer.callback(True)

        defer.addCallback(self._pack_get_arena_win_num_reward_response, data,
                          arena, arena_matcher, req, timer)
        return defer
Exemple #5
0
    def _calc_receive_notice(self, data, req, timer):
        """接收到战斗结果通知
        1 变更演武场积分
        2 新增演武场对战记录
        """
        arena = data.arena.get()
        (win_score, lose_score) = arena_business.calc_battle_score(
            arena, req.rival_score)
        score_delta = 0
        if req.status == ArenaRecordInfo.STATUS_DEFEND_LOSE:
            score_delta = lose_score
        else:
            score_delta = win_score

        arena.add_score(score_delta)
        record = arena_business.add_arena_record(
            data, req.rival_user_id, base64.b64encode(req.rival_name),
            req.rival_level, req.rival_icon_id, req.status, score_delta)

        mails = []
        arena_matcher = ArenaMatcher()
        if arena.need_query_rank():
            defer = arena_matcher.query_ranking(data, arena)
            defer.addCallback(self._update_title_level, data, arena,
                              arena_matcher, mails, timer)
            defer.addCallback(self._check)
        else:
            defer = Deferred()
            defer.addCallback(self._update_title_level, data, arena,
                              arena_matcher, mails, timer)
            defer.addCallback(self._check)
            defer.callback(True)

        defer = DataBase().commit(data)
        defer.addCallback(self._receive_notice_succeed, req, arena,
                          arena_matcher, record, timer)
        return defer