예제 #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
예제 #2
0
def generate_array_detail(worldboss, user):
    """生成阵容详情返回
    """
    teams = []
    for array_id in worldboss.get_arrays_id():
        array = data_loader.WorldBossArrayBasicInfo_dict[array_id]
        #buff和tech是针对整个阵容生效的
        buffs_id = array.buffIds
        techs_id = array.techIds

        heroes = []
        for i in range(len(array.heroIds)):
            basic_id = array.heroIds[i]
            star = array.heroStars[i]
            equipments_id = []
            equipments_id.append(array.heroEquipmentIds[i * 3])
            equipments_id.append(array.heroEquipmentIds[i * 3 + 1])
            equipments_id.append(array.heroEquipmentIds[i * 3 + 2])
            evolution_level = array.heroEvolutionLevels[i]
            soldier_basic_id = array.soldierBasicIds[i]
            soldier_level = array.soldierLevels[i]
            soldier = SoldierInfo.create(user.id, soldier_basic_id, soldier_level)

            hero = HeroInfo.create_special(user.id, user.level, basic_id, 
                    user.level, star, soldier, [], techs_id, equipments_id, 
                    buffs_id, False, evolution_level, False)
            heroes.append(hero)

        teams.append(heroes)

    return teams
예제 #3
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
예제 #4
0
파일: soldier.py 프로젝트: hw233/test-2
def unlock(user_id, basic_id):
    """
    解锁新兵种
    Args:
        user_id[int]: 用户 id
        basic_id[int]: 兵种 basic id
    Returns:
        SoldierInfo 兵种信息

    """
    soldier = SoldierInfo.create(user_id, basic_id)
    return soldier
예제 #5
0
파일: technology.py 프로젝트: hw233/test-2
def post_research_for_soldier_technology(
        data, user_id, technology, now, soldier = None, heroes = [], new = False):
    """
    兵种科技完成研究的影响
    1 解锁兵种
    2 或者升级兵种
    Args:
        user_id[int]: 用户 id
        technology[TechnologyInfo]: 兵种科技信息
        soldier[SoldierInfo in/out]: 兵种信息
        heroes[list(HeroInfo) in/out]: 配置了对应兵种的英雄信息,可能需要更新英雄的兵种信息
        new[bool]: 是否是解锁新兵种
    Returns:
        None: 失败
        SoldierInfo: 处理成功,返回兵种信息
    """
    #一定是已经完成研究的科技
    assert not technology.is_upgrade

    if not technology.is_soldier_technology():
        logger.warning("Not soldier technology")
        return None

    (soldier_basic_id, soldier_level) = technology_module.generate_soldier(technology)

    if new:
        #解锁新兵种
        assert soldier is None
        assert len(heroes) == 0

        soldier = SoldierInfo.create(user_id, soldier_basic_id, soldier_level)
        return soldier

    else:
        #原有兵种升级
        assert soldier is not None

        if not soldier.upgrade():
            return None

        if soldier.basic_id != soldier_basic_id or soldier.level != soldier_level:
            logger.warning("Soldier error[gen basic id=%d][gen level=%d]"
                    "[soldier basic id=%d][soldier level=%d]" %
                    (soldier_basic_id, soldier_level,
                        soldier.basic_id, soldier.level))
            return None

        #配置该兵种的武将,更新兵种信息(有可能升级)
        for hero in heroes:
            if not hero_business.soldier_update(data, hero, soldier, now):
                return None

        return soldier
예제 #6
0
    def _calc_update_soldier(self, data, req, timer):
        hero_id = HeroInfo.generate_id(data.id, req.hero.basic_id)
        hero = data.hero_list.get(hero_id)
        soldier_id = SoldierInfo.generate_id(data.id,
                                             req.hero.soldier_basic_id)
        soldier = data.soldier_list.get(soldier_id, True)

        if not hero_business.soldier_update(data, hero, soldier, timer.now):
            raise Exception("Soldier update failed")

        #验证
        compare.check_hero(data, req.hero, with_soldier=True)

        return DataBase().commit(data)
예제 #7
0
파일: technology.py 프로젝트: hw233/test-2
def post_research_for_battle_technology(data, technology, heroes = []):
    """
    战斗科技完成研究的影响
    更新英雄战力、部队战力、总战力
    Args:
        data[UserInfo]: 玩家数据
        technology[TechnologyInfo]: 新研究的战斗科技
        heroes[list(HeroInfo) in/out]: 需要更新战力的英雄

    Returns:
        False: 失败
        True: 处理成功,返回兵种信息
    """
    #一定是已经完成研究的科技
    assert not technology.is_upgrade

    if not technology.is_battle_technology():
        logger.warning("Not battle technology")
        return False

    new_technologys = [technology.basic_id]

    for hero in heroes:
        #影响英雄所带兵种战力的科技
        battle_technology_basic_id = technology_module.get_battle_technology_for_soldier(
                data.technology_list.get_all(True), hero.soldier_basic_id)
        
        soldier_id = SoldierInfo.generate_id(data.id, hero.soldier_basic_id)
        soldier = data.soldier_list.get(soldier_id)
        if not hero.update_soldier(soldier, battle_technology_basic_id):
            return False

        #如果英雄在队伍中,更新队伍信息
        for team in data.team_list.get_all():
            if team.is_hero_in_team(hero.id):
                if not team_business.refresh_team(data, team):
                    logger.warning("Try to refresh team failed")
                    return False

    #更新 top 阵容
    user = data.user.get(True)
    guard_list = data.guard_list.get_all()
    for guard in guard_list:
        if not guard.try_update_top_score(heroes, user.team_count):
            logger.warning("Try to update guard top score failed")
            return False

    return True
예제 #8
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
예제 #9
0
    def _calc_soldier(self, hero, score):
        """实时计算英雄的兵种信息
        """
        if score <= 0:
            return
        base = hero.battle_score
        logger.debug("try calc soldier[target delta=%f]" % score)

        #兵种 basic_id, level 合法取值范围
        soldier_range = {}

        for soldier_key in data_loader.SoldierBasicInfo_dict.keys():
            if (data_loader.SoldierBasicInfo_dict[soldier_key].type ==
                    data_loader.HeroBasicInfo_dict[hero.basic_id].soldierType
                    and
                    data_loader.SoldierBasicInfo_dict[soldier_key].heroLevel <=
                    hero.level):
                (soldier_basic_id,
                 soldier_level) = map(int, soldier_key.split('_'))
                if soldier_basic_id not in soldier_range:
                    soldier_range[soldier_basic_id] = []
                soldier_range[soldier_basic_id].append(soldier_level)

        #随机选择一个兵种
        soldier_basic_id = random.sample(soldier_range.keys(), 1)[0]
        soldier_range[soldier_basic_id].sort()  #从小到大排序
        for soldier_level in soldier_range[soldier_basic_id]:
            soldier = SoldierInfo.create(hero.user_id, soldier_basic_id,
                                         soldier_level)
            assert hero.update_soldier(soldier, technology_basic_ids=[])

            delta = hero.battle_score - base
            if delta >= score:
                logger.debug(
                    "update soldier[target delta=%d][finnal delta=%d]" %
                    (score, delta))
                return

        #理论上不该在此返回
        logger.warning("update soldier error[target delta=%d]" % score)
예제 #10
0
def _default_generate_array_detail(dungeon, battle_level, user, detail_type):
    """默认生成阵容方法"""
    if battle_level == 0:
        level = dungeon.level(user.level)
    else:
        battle_id = "%d_%d" % (dungeon.basic_id, battle_level)
        level = data_loader.ExpandDungeonBattleBasicInfo_dict[battle_id].enemyLevel

    array_id = "%d_%d" % (dungeon.basic_id, level)
    if detail_type == 'enemy':
        array = data_loader.ExpandDungeonEnemyBasicInfo_dict[array_id]
    else:
        array = data_loader.ExpandDungeonOwnBasicInfo_dict[array_id]

    buffs_id = array.buffIds
    techs_id = array.techIds
    heroes = []
    for i in range(len(array.heroIds)):
        basic_id = array.heroIds[i]
        hero_level = array.heroLevels[i]
        star = array.heroStarLevels[i]
        equipments_id = array.heroEquipmentIds[i*3 : i*3 + 3]
        evolution_level = array.heroEvolutionLevels[i]
        herostars_id = array.heroHeroStars[i*6 : i*6 + 6]
        soldier_basic_id = array.soldierBasicIds[i]
        soldier_level = array.soldierLevels[i]
        soldier = SoldierInfo.create(user.id, soldier_basic_id, soldier_level)

        if basic_id == 0:
            heroes.append(None)
        else:
            hero = HeroInfo.create_special(user.id, user.level, basic_id,
                    hero_level, star, soldier, [], techs_id, equipments_id,
                    buffs_id, False, evolution_level, False, herostars_id)
            heroes.append(hero)

    return heroes
예제 #11
0
파일: technology.py 프로젝트: hw233/test-2
def get_related_soldier_id(user_id, technology_basic_id):
    soldier_basic_id = data_loader.SoldierTechnologyBasicInfo_dict[
            technology_basic_id].soldierBasicInfoId
    return SoldierInfo.generate_id(user_id, soldier_basic_id)
예제 #12
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)