示例#1
0
    def _pack_query_melee_response(self, proxy, data, melee, melee_matcher, mails, req, timer):
        """构造返回
        args:
            mails : list(MailInfo)
        Returns:
            res[protobuf]: 向客户端的返回的响应
        """
        res = arena_pb2.QueryArenaInfoRes()
        res.status = 0

        pack.pack_melee_info(data.user.get(True), melee, res.arena_info, timer.now, melee_matcher.rank)
        if melee.is_arena_active(timer.now):
            #胜场奖励
            if melee.is_able_to_get_win_num_reward():
                pack.pack_arena_reward_info(melee, res.arena_info.win_num_reward)
            #对手信息
            rivals_id = melee.generate_arena_rivals_id()
            for rival_id in rivals_id:
                rival = data.rival_list.get(rival_id, True)
                pack.pack_melee_player(rival, res.arena_info.rivals.add())
            #对战记录
            record_list = data.melee_record_list.get_all(True)
            for record in record_list:
                pack.pack_arena_record(record, res.arena_info.records.add())

        for mail in mails:
            pack.pack_mail_info(mail, res.mails.add(), timer.now)

        defer = DataBase().commit(data)
        defer.addCallback(self._query_melee_succeed, req, res, timer)
        return defer
示例#2
0
    def _pack_update_melee_response(self, proxy, data, melee, melee_matcher, mails,
            last_battle_win, req, timer):
        """构造返回
        args:
        Returns:
            res[protobuf]: 向客户端的返回的响应
        """
        res = arena_pb2.QueryArenaInfoRes()
        res.status = 0

        pack.pack_melee_info(data.user.get(True), melee, res.arena_info, timer.now, melee_matcher.rank)
        #if last_battle_win:
        #    #对手信息
        #    rivals_id = melee.generate_arena_rivals_id()
        #    for rival_id in rivals_id:
        #        rival = data.rival_list.get(rival_id, True)
        #        if rival is not None:
        #            pack.pack_melee_player(rival, res.arena_info.rivals.add())

        for mail in mails:
            pack.pack_mail_info(mail, res.mails.add(), timer.now)

        defer = DataBase().commit(data)
        defer.addCallback(self._update_melee_succeed, req, res, timer)
        return defer
示例#3
0
 def _push_mail(self, user_id, mail, timer):
     """向客户端推送邮件,如果用户不在线,则推送失败
     """
     res = mail_pb2.QueryMailRes()
     res.status = 0
     pack.pack_mail_info(mail, res.mails.add(), timer.now)
     response = res.SerializeToString()
     return GlobalObject().root.callChild("portal", "push_mail", user_id,
                                          response)
示例#4
0
    def _query_mail_succeed(self, data, req, timer):
        res = mail_pb2.QueryMailRes()
        res.status = 0
        mails = data.mail_list.get_all(True)
        for mail in mails:
            pack.pack_mail_info(mail, res.mails.add(), timer.now)
        response = res.SerializeToString()

        log = log_formater.output(data, "Query mail succeed", req, res,
                                  timer.count_ms())
        logger.notice(log)
        return response
示例#5
0
    def _pack_finish_appoint_response(self, matcher, data, node_list, items,
                                      heroes, mails, req, timer):
        """构造返回
        args:
            items : list((num, basic_id)元组)
            heroes: list((basic_id, level, exp, battle_node_basic_id )元组)
        Returns:
            res[protobuf]: 向客户端的返回的响应
        """
        resource = data.resource.get(True)
        user = data.user.get(True)

        conscript_list = data.conscript_list.get_all(True)

        res = appoint_pb2.FinishAppointRes()
        res.status = 0
        res.ret = appoint_pb2.FinishAppointRes.OK

        pack.pack_resource_info(resource, res.resource)
        pack.pack_monarch_info(user, res.monarch)
        for conscript in conscript_list:
            pack.pack_conscript_info(conscript, res.conscripts.add(),
                                     timer.now)
        for node in node_list:
            pack.pack_node_info(data, node, res.nodes.add(), timer.now)

        for item in items:
            pack.pack_item_info(item, res.items.add())

        for hero in heroes:
            hero_message = res.heros.add()
            hero_message.basic_id = hero[0]
            hero_message.level = hero[1]
            hero_message.exp = hero[2]
            hero_message.battle_node_id = hero[3]

        for mail in mails:
            pack.pack_mail_info(mail, res.mails.add(), timer.now)

        if 'is_battle_cost_energy' in account_business.get_flags():
            energy = data.energy.get()
            energy.update_current_energy(timer.now)
            pack.pack_energy_info(energy, res.energy, timer.now)

        map_business.check_map_data(data)

        defer = DataBase().commit(data)
        defer.addCallback(self._finish_appoint_succeed, req, res, timer)
        return defer
示例#6
0
    def _pack_exploit_response(self, new_items, resource, mail, now):
        """打包开采响应
        """
        res = exploitation_pb2.ExploitRes()
        res.status = 0
        res.ret = exploitation_pb2.ExploitRes.OK

        pack.pack_resource_info(resource, res.resource)
        for (basic_id, num) in new_items:
            message_item = res.items.add()
            message_item.basic_id = basic_id
            message_item.num = num
        pack.pack_mail_info(mail, res.mail, now)

        return res
示例#7
0
    def _pack_event_response(self, matcher, data, items, mails, nodes, type,
                             req, timer):
        """打包返回 response
        """
        resource = data.resource.get(True)
        map = data.map.get(True)

        #更新邮件中的敌人信息
        for mail in mails:
            if mail.related_node_id in matcher.players:
                rival_id = mail.related_node_id
                rival = data.rival_list.get(rival_id)
                mail.attach_enemy_info(rival)
            else:
                node = data.node_list.get(mail.related_node_id)
                if node.is_key_node():
                    mail.attach_enemy_detail(
                        NameGenerator().gen(), 0,
                        NodeInfo.ENEMY_TYPE_PVE_RESOURCE)  #TODO 随机

        #打包响应
        res = map_pb2.TriggerEventRes()
        res.status = 0

        #res.map.next_war_gap = map.next_war_time - timer.now
        res.map.next_luck_gap = map.next_luck_time - timer.now
        for node in nodes:
            pack.pack_node_info(data, node, res.map.nodes.add(), timer.now)
        pack.pack_resource_info(resource, res.resource)
        for item in items:
            item_message = res.items.add()
            item_message.basic_id = item[1]
            item_message.num = item[0]
        for mail in mails:
            pack.pack_mail_info(mail, res.mails.add(), timer.now)
        energy = data.energy.get(True)
        pack.pack_energy_info(energy, res.energy_info, timer.now)

        map_business.check_map_data(data)

        defer = DataBase().commit(data)
        defer.addCallback(self._trigger_event_succeed, req, res, timer)
        return defer
示例#8
0
    def _pack_clear_lucky_event_response(self, matcher, data, change_nodes,
                                         items, mails, req, timer):
        """打包
        """
        resource = data.resource.get()
        map = data.map.get()

        #更新邮件中的敌人信息
        for mail in mails:
            if mail.related_node_id in matcher.players:
                rival_id = mail.related_node_id
                rival = data.rival_list.get(rival_id)
                mail.attach_enemy_info(rival)
            else:
                node = data.node_list.get(mail.related_node_id)
                if node.is_key_node():
                    mail.attach_enemy_detail(
                        NameGenerator().gen(), 0,
                        NodeInfo.ENEMY_TYPE_PVE_RESOURCE)  #TODO 随机

        #打包响应
        res = map_pb2.ClearLuckyEventRes()
        res.status = 0
        res.ret = map_pb2.ClearLuckyEventRes.OK

        for node in change_nodes:
            pack.pack_node_info(data, node, res.nodes.add(), timer.now)
        pack.pack_resource_info(resource, res.resource)
        for item in items:
            item_message = res.items.add()
            item_message.basic_id = item[1]
            item_message.num = item[0]
        for mail in mails:
            pack.pack_mail_info(mail, res.mails.add(), timer.now)

        map_business.check_map_data(data)

        defer = DataBase().commit(data)
        defer.addCallback(self._clear_lucky_event_succeed, req, res, timer)
        return defer
示例#9
0
    def _pack_user_info(self,
                        data,
                        basic_data,
                        req,
                        timer,
                        first_init,
                        arena_matcher=None,
                        melee_matcher=None):
        """打包所有用户数据
        Args:
            data[UserData]: 用户数据
            req[protobuf]: 请求
        Returns:
            res[protobuf]
        """
        res = init_pb2.InitRes()
        res.status = 0
        res.first_init = first_init
        info = res.info

        user = data.user.get(True)
        pay = data.pay.get(True)
        pack.pack_monarch_info(user, info.monarch)
        union = data.union.get(True)
        resource = data.resource.get(True)
        if union.is_belong_to_union():
            info.monarch.union_id = union.union_id
            info.union_battle_stage = UnionBattleStagePatcher().patch(
                union.union_id)

        pack.pack_resource_info(data.resource.get(True), info.resource)
        for item in data.item_list.get_all(True):
            pack.pack_item_info(item, info.items.add())
        for hero in data.hero_list.get_all(True):
            pack.pack_hero_info(hero, info.heroes.add(), timer.now)
        for team in data.team_list.get_all(True):
            pack.pack_team_info(team, info.teams.add())

        pack.pack_map_info(data, data.map.get(True), info.map, timer.now)

        for city in data.city_list.get_all(True):
            pack.pack_city_info(city, info.cities.add())
        for building in data.building_list.get_all(True):
            pack.pack_building_info(building, info.buildings.add(), timer.now)
        for technology in data.technology_list.get_all(True):
            pack.pack_technology_info(technology, info.techs.add(), timer.now)
        for conscript in data.conscript_list.get_all(True):
            pack.pack_conscript_info(conscript, info.conscripts.add(),
                                     timer.now)
        assert len(data.defense_list) == 1

        pack.pack_money_draw_info(data.draw.get(True), info.money_draw,
                                  timer.now)
        pack.pack_gold_draw_info(data.draw.get(True), info.gold_draw,
                                 timer.now)

        for mission in data.mission_list:
            pack.pack_mission_info(mission.get(True), info.missions.add())

        #邮件看产生时间顺序给出
        # data.mail.sort(cmp = None, key=lambda x:x.time, reverse = False)
        for mail in data.mail_list.get_all(True):
            pack.pack_mail_info(mail, info.mails.add(), timer.now)

        pack.pack_sign_info(data.sign.get(True), info.sign_in)

        #演武场
        arena = data.arena.get(True)
        arena_ranking = 0
        if arena_matcher is not None:
            arena_ranking = arena_matcher.rank
        pack.pack_arena_info(user, arena, info.arena, timer.now, arena_ranking)
        #if user.allow_pvp_arena and arena.is_arena_active(timer.now):
        #    #胜场奖励
        #    if arena.is_able_to_get_win_num_reward():
        #        pack.pack_arena_reward_info(arena, info.arena.win_num_reward)
        #    #对手信息
        #    if arena.rivals_user_id != '':
        #        rivals_id = arena.generate_arena_rivals_id()
        #        for rival_id in rivals_id:
        #            rival = data.rival_list.get(rival_id, True)
        #            pack.pack_arena_player(rival, info.arena.rivals.add())
        #        #系统选定的对战对手
        #        choose_rival_id = arena.get_choose_rival_id()
        #        choose_rival = data.rival_list.get(choose_rival_id, True)
        #        info.arena.choosed_user_id = choose_rival.rival_id

        #    #对战记录
        #    record_list = data.arena_record_list.get_all(True)
        #    for record in record_list:
        #        pack.pack_arena_record(record, info.arena.records.add())

        flags = account_business.get_flags()
        if 'is_open_melee' in flags:
            #乱斗场
            melee = data.melee.get(True)
            melee_ranking = 0
            if melee_matcher is not None:
                melee_ranking = melee_matcher.rank
            pack.pack_melee_info(user, melee, info.melee_arena, timer.now,
                                 melee_ranking)
            #if melee.is_able_to_unlock(user) and melee.is_arena_active(timer.now):
            #    #胜场奖励
            #    if melee.is_able_to_get_win_num_reward():
            #        pack.pack_arena_reward_info(melee, info.melee_arena.win_num_reward)
            #    #对手信息
            #    if melee.rivals_user_id != '':
            #        rivals_id = melee.generate_arena_rivals_id()
            #        for rival_id in rivals_id:
            #            rival = data.rival_list.get(rival_id, True)
            #            pack.pack_melee_player(rival, info.melee_arena.rivals.add())

            #    #对战记录
            #    record_list = data.melee_record_list.get_all(True)
            #    for record in record_list:
            #        pack.pack_arena_record(record, info.melee_arena.records.add())
            ##乱斗场阵容
            #(heroes_list, positions_list) = melee.get_heroes_position()
            #if len(heroes_list) > 0:
            #    info.melee_team.index = 0
            #for hero_basic_id in heroes_list:
            #    (info.melee_team.heroes.add()).basic_id = hero_basic_id
            #for position in positions_list:
            #    info.melee_team.hero_positions.append(position)

        #政令
        energy = data.energy.get(True)
        pack.pack_energy_info(energy, info.energy_info, timer.now)

        #祈福
        pray = data.pray.get(True)
        pack.pack_pray_info(pray, info.pray, timer.now)

        #红包
        chest = data.chest.get(True)
        pack.pack_chest_info(chest, info.chest, timer.now)

        #试炼场
        anneal = data.anneal.get(True)
        pack.pack_anneal_info(data, anneal, info.anneal, timer.now)

        #打包新手引导进度信息
        pack.pack_guide_info(data.user.get(True), info.guide)

        #将星盘
        herostar_list = data.herostar_list.get_all(True)
        for herostar in herostar_list:
            info.hero_star.append(herostar.star_id)

        #世界boss
        #pack.pack_worldboss_info(data.worldboss.get(True), user, info.world_boss, timer.now)

        #功能开关
        #flags = account_business.get_flags()
        pack.pack_flag_info(flags, info.flags)

        #扩展副本
        dungeons = data.expand_dungeon_list.get_all()
        for dungeon in dungeons:
            dungeon.daily_update(timer.now)
            pack.pack_expand_dungeon_info(dungeon,
                                          user,
                                          info.expand_dungeons.add(),
                                          0,
                                          timer.now,
                                          brief=True)

        #主界面的按钮提示
        pack.pack_button_tips(basic_data, data, info, timer.now)

        #lua
        #pack.pack_luas(info.luas)

        logger.notice(
            "Submit Role[user_id=%d][level=%d][name=%s][vip=%d][status=LOGIN][create_time=%d][last_login_time=%d][money=%d][food=%d][gold=%d][pay_count=%d][pay_amount=%.2f]"
            % (user.id, user.level, user.name, user.vip_level,
               user.create_time, user.last_login_time, resource.money,
               resource.food, resource.gold, pay.pay_count, pay.pay_amount))

        #log = log_formater.output_gold(data, 0, log_formater.INIT_RESOURCE_GOLD,
        #       "Gain gold from init resource", before_gold = data.resource.get(True).gold)
        #logger.notice(log)

        return self._init_succeed(data, req, res, timer)