Example #1
0
    def _calc_individual_step_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.AcceptUnionBattleIndividualsRes()
        res.status = 0
        res.ret = union_res.ret

        if res.ret == union_pb2.UNION_OK:
            #领取战功阶段奖励
            (honor,
             items) = union_battle_business.accept_individual_step_award(
                 data, req.target_step, timer.now)

            pack.pack_resource_info(data.resource.get(True), res.resource)
            for (item_basic_id, item_num) in items:
                item_msg = res.items.add()
                item_msg.basic_id = item_basic_id
                item_msg.num = item_num
            res.honor = honor

        defer = DataBase().commit(data)
        defer.addCallback(self._accept_individual_step_succeed, req, res,
                          timer)
        return defer
Example #2
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 #3
0
    def _calc_gain_post(self, union_response, data, req, timer):
        union_res = internal_union_pb2.InternalQueryUnionBattleRes()
        union_res.ParseFromString(union_response)

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

        defer = DataBase().commit(data)
        return defer
Example #4
0
    def _patch_rival_battle_info(self, union_response, message, data, now):
        """填充敌对联盟的战争信息
        """
        rival_union_res = internal_union_pb2.InternalQueryUnionBattleRes()
        rival_union_res.ParseFromString(union_response)
        if rival_union_res.status != 0 or rival_union_res.ret != union_pb2.UNION_OK:
            raise Exception("Query rival union battle res error")

        #敌对联盟防守地图信息
        message.rival_map.CopyFrom(rival_union_res.battle.own_map)

        #补充战斗记录
        for record in rival_union_res.battle.records:
            message.records.add().CopyFrom(record)

        return self._patch_ranking_info(message, data, now)
Example #5
0
    def _calc_query_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.QueryUnionBattleRes()
        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_query_post, data, req, res, timer)
            return defer

        return self._calc_query_post(None, data, req, res, timer)