Example #1
0
    def _calc_deploy_result(self, union_response, data, req, timer):
        union_res = internal_union_pb2.InternalQueryUnionBattleRes()
        union_res.ParseFromString(union_response)

        if union_res.status != 0:
            raise Exception("Query union battle res error")

        if union_res.ret == union_pb2.UNION_OK:
            #锁定所有派出的队伍
            teams = []
            for team_info in req.teams:
                team_id = TeamInfo.generate_id(data.id, team_info.index)
                team = data.team_list.get(team_id)
                teams.append(team)
            union_battle_business.deploy_for_union_battle(
                data, req.node_index, teams)

        res = union_battle_pb2.DeployUnionBattleRes()
        res.status = 0
        res.ret = union_res.ret
        if union_res.HasField("battle"):
            defer = UnionBattlePatcher().patch(res.battle, union_res.battle,
                                               data, timer.now)
            defer.addCallback(self._calc_deploy_post, data, req, res, timer)
            return defer

        return self._calc_deploy_post(None, data, req, res, timer)
Example #2
0
 def _cancel_deploy_failed(self, err, req, timer):
     logger.fatal("Cancel deploy union battle failed[reason=%s]" % err)
     res = union_battle_pb2.DeployUnionBattleRes()
     res.status = -1
     response = res.SerializeToString()
     logger.notice("Cancel deploy union battle failed"
                   "[user_id=%d][req=%s][res=%s][consume=%d]" %
                   (timer.id, req, res, timer.count_ms()))
     return response
Example #3
0
    def _calc_deploy(self, data, req, timer):
        union = data.union.get(True)
        if not union.is_belong_to_target_union(req.union_id):
            #玩家不属于联盟
            res = union_battle_pb2.DeployUnionBattleRes()
            res.status = 0
            res.ret = union_pb2.UNION_NOT_MATCHED

            defer = DataBase().commit(data)
            defer.addCallback(self._deploy_succeed, req, res, timer)
            return defer

        #检查队伍是否合法
        teams = []
        for team_info in req.teams:
            team_id = TeamInfo.generate_id(data.id, team_info.index)
            team = data.team_list.get(team_id, True)
            teams.append(team)
        if not union_battle_business.is_able_to_deploy(data, req.node_index,
                                                       teams):
            raise Exception("Team deploy invalid")

        #部署防御
        union_req = internal_union_pb2.InternalDeployUnionBattleReq()
        user = data.user.get(True)
        union_req.user_id = data.id
        union_req.defender_user_id = data.id
        union_req.defender_user_name = user.get_readable_name()
        union_req.defender_user_icon = user.icon_id
        union_req.defender_user_level = user.level
        union_req.node_index = req.node_index
        for team in teams:
            team_msg = union_req.teams.add()
            team_msg.index = team.index
            for hero_id in team.get_heroes():
                if hero_id != 0:
                    hero = data.hero_list.get(hero_id, True)
                    pack.pack_hero_info(hero, team_msg.heroes.add(), timer.now)
        for tech in data.technology_list.get_all(True):
            if tech.is_battle_technology() and not tech.is_upgrade:
                union_req.battle_tech_ids.append(tech.basic_id)

        defer = GlobalObject().remote['gunion'].callRemote(
            "deploy_battle", req.union_id, union_req.SerializeToString())
        defer.addCallback(self._calc_deploy_result, data, req, timer)
        return defer
Example #4
0
    def _calc_cancel_deploy_result(self, union_response, data, req, timer):
        union_res = internal_union_pb2.InternalQueryUnionBattleRes()
        union_res.ParseFromString(union_response)

        if union_res.status != 0:
            raise Exception("Query union battle res error")

        res = union_battle_pb2.DeployUnionBattleRes()
        res.status = 0
        res.ret = union_res.ret
        if union_res.HasField("battle"):
            defer = UnionBattlePatcher().patch(res.battle, union_res.battle,
                                               data, timer.now)
            defer.addCallback(self._calc_cancel_deploy_post, data, req, res,
                              timer)
            return defer

        return self._calc_cancel_deploy_post(None, data, req, res, timer)
Example #5
0
    def _calc_cancel_deploy(self, data, req, timer):
        union = data.union.get(True)
        if not union.is_belong_to_target_union(req.union_id):
            #玩家不属于联盟
            res = union_battle_pb2.DeployUnionBattleRes()
            res.status = 0
            res.ret = union_pb2.UNION_NOT_MATCHED

            defer = DataBase().commit(data)
            defer.addCallback(self._cancel_deploy_succeed, req, res, timer)
            return defer

        #部署防御
        union_req = internal_union_pb2.InternalDeployUnionBattleReq()
        user = data.user.get(True)
        union_req.user_id = data.id
        union_req.node_index = req.node_index
        union_req.defender_user_id = req.user_id
        defer = GlobalObject().remote['gunion'].callRemote(
            "cancel_deploy_battle", req.union_id,
            union_req.SerializeToString())
        defer.addCallback(self._calc_cancel_deploy_result, data, req, timer)
        return defer