Exemplo n.º 1
0
    def _pack_signin_response(self, data, hero_list, item_list, now):
        """封装签到响应
        """
        #为了封装 response 构造 HeroInfo 和 ItemInfo
        win_hero = []
        for (basic_id, num) in hero_list:
            soldier_basic_id = HeroInfo.get_default_soldier_basic_id(basic_id)
            soldier_id = SoldierInfo.generate_id(data.id, soldier_basic_id)
            soldier = data.soldier_list.get(soldier_id, True)
            hero = HeroInfo.create(data.id, basic_id, soldier, [])
            for i in range(0, num):
                win_hero.append(hero)

        win_item = []
        for (basic_id, num) in item_list:
            item = ItemInfo.create(data.id, basic_id, num)
            win_item.append(item)

        res = user_pb2.SignInRes()
        res.status = 0
        if len(win_hero) > 0:
            assert len(win_hero) == 1
            pack.pack_hero_info(win_hero[0], res.hero, now)
        if len(win_item) > 0:
            assert len(win_item) == 1
            pack.pack_item_info(win_item[0], res.item)

        return res
Exemplo n.º 2
0
    def _pack_draw_response(self, data, hero_list, item_list,
            resource, search_num, next_time, now):
        """封装响应
        返回客户端的是抽奖获得的英雄和物品(并未将已经拥有的英雄分解成将魂石)
        客户端会自行进行分解
        """
        win_hero = []
        for (basic_id, num) in hero_list:
            soldier_basic_id = HeroInfo.get_default_soldier_basic_id(basic_id)
            soldier_id = SoldierInfo.generate_id(data.id, soldier_basic_id)
            soldier = data.soldier_list.get(soldier_id, True)

            hero = HeroInfo.create(data.id, basic_id, soldier, technology_basic_ids = [])
            for i in range(0, num):
                win_hero.append(hero)

        win_item = []
        for (basic_id, num) in item_list:
            item = ItemInfo.create(data.id, basic_id, num)
            win_item.append(item)

        res = wineShop_pb2.WineShopDrawRes()
        res.status = 0

        for item in win_item:
            pack.pack_item_info(item, res.items.add())
        for hero in win_hero:
            pack.pack_hero_info(hero, res.heroes.add(), now)
        pack.pack_resource_info(resource, res.resource)
        res.draw.search_num = search_num
        res.draw.next_left_time = max(0, next_time - now)
        return res