Beispiel #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
Beispiel #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
Beispiel #3
0
    def _mock_hero(self, basic_id, star, level):
        USER_ID = 0
        USER_LEVEL = int(
            float(data_loader.OtherBasicInfo_dict["MaxMonarchLevel"].value))
        hero_id = HeroInfo.generate_id(USER_ID, basic_id)
        soldier_basic_id = HeroInfo.get_default_soldier_basic_id(basic_id)
        soldier = SoldierInfo.create(USER_ID, soldier_basic_id)

        hero = HeroInfo.create_special(USER_ID,
                                       USER_LEVEL,
                                       basic_id,
                                       level,
                                       star,
                                       soldier, [],
                                       technology_basic_ids=[])
        return hero
Beispiel #4
0
    def _calc_add_hero(self, data, req, timer):
        hero_basic_id = req.hero.basic_id

        soldier_basic_id = HeroInfo.get_default_soldier_basic_id(hero_basic_id)
        soldier_id = SoldierInfo.generate_id(data.id, soldier_basic_id)
        soldier = data.soldier_list.get(soldier_id, True)

        skill_ids = []
        skill_ids.append(req.hero.first_skill_id)
        skill_ids.append(req.hero.second_skill_id)
        skill_ids.append(req.hero.third_skill_id)
        skill_ids.append(req.hero.fourth_skill_id)

        user = data.user.get(True)
        #影响英雄所带兵种战力的科技
        battle_technology_basic_id = technology_module.get_battle_technology_for_soldier(
            data.technology_list.get_all(True), soldier_basic_id)

        equipments_id = []
        if (req.hero.HasField("equipment_weapon_id")
                and req.hero.HasField("equipment_armor_id")
                and req.hero.HasField("equipment_treasure_id")):
            equipments_id.append(req.hero.equipment_weapon_id)
            equipments_id.append(req.hero.equipment_armor_id)
            equipments_id.append(req.hero.equipment_treasure_id)

        stone_weapon = []
        if len(req.hero.stone_weapon) == 4:
            stone_weapon.append(req.hero.stone_weapon[0])
            stone_weapon.append(req.hero.stone_weapon[1])
            stone_weapon.append(req.hero.stone_weapon[2])
            stone_weapon.append(req.hero.stone_weapon[3])
        stone_armor = []
        if len(req.hero.stone_armor) == 4:
            stone_armor.append(req.hero.stone_armor[0])
            stone_armor.append(req.hero.stone_armor[1])
            stone_armor.append(req.hero.stone_armor[2])
            stone_armor.append(req.hero.stone_armor[3])
        stone_treasure = []
        if len(req.hero.stone_treasure) == 4:
            stone_treasure.append(req.hero.stone_treasure[0])
            stone_treasure.append(req.hero.stone_treasure[1])
            stone_treasure.append(req.hero.stone_treasure[2])
            stone_treasure.append(req.hero.stone_treasure[3])

        evolution_level = 1
        if req.hero.HasField("evolution_level"):
            evolution_level = req.hero.evolution_level

        hero = HeroInfo.create_special(user.id,
                                       user.level,
                                       hero_basic_id,
                                       req.hero.level,
                                       req.hero.star_level,
                                       soldier,
                                       skill_ids,
                                       battle_technology_basic_id,
                                       equipments_id, [],
                                       True,
                                       evolution_level,
                                       stones_weapon_id=stone_weapon,
                                       stones_armor_id=stone_armor,
                                       stones_treasure_id=stone_treasure)
        if hero is None:
            raise Exception("Create hero failed")

        data.hero_list.add(hero)
        hero_business.post_gain_hero(data, hero)

        return DataBase().commit(data)