Beispiel #1
0
def unload_herostar(data, hero, star_id, timer):
    """英雄卸下将星"""
    assert star_id in hero.get_herostars_set()
    battle_technology_basic_id = technology_module.get_battle_technology_for_soldier(
            data.technology_list.get_all(True), hero.soldier_basic_id)
    hero.unload_herostar(star_id, battle_technology_basic_id)
    assert hero_business.post_upgrade(data, hero, timer.now, battle_technology_basic_id)
Beispiel #2
0
def strength_herostar(data, star_id, items_id, items_num, cost_money, timer):
    """给将星升级"""
    # 1.消耗物品
    # 2.消耗金币
    # 3.升级将星
    # 4.更新英雄的将星
    # 5.判断是否需要发送广播
    output_items=[]
    for i, id in enumerate(items_id):
        item = item_business.get_item_by_id(data, id)
        if item is None:# or item.num < items_num[i]:
            raise Exception("No enough items")
        consume = item.consume(min(item.num, items_num[i]))
        output_items.append("[item=")
        output_items.append(utils.join_to_string(list(consume[1])))
        output_items.append("]")
    log = log_formater.output_item(data, "herostar", log_formater.STRENGTH_HEROSTAR, ''.join(output_items))
    logger.notice(log)
    #logger.notice("strength herostar %s"%''.join(output_items))

    resource = data.resource.get()
    resource.update_current_resource(timer.now)
    if not resource.cost_money(cost_money):
        raise Exception("No enough money")

    new_star_id = _do_strength_herostar(data, star_id)

    hero_list = data.hero_list.get_all()
    for hero in hero_list:
        if star_id in hero.get_herostars_set():
            battle_technology_basic_id = technology_module.get_battle_technology_for_soldier(
                data.technology_list.get_all(True), hero.soldier_basic_id)
            hero.update_herostar(star_id, new_star_id, battle_technology_basic_id)
            assert hero_business.post_upgrade(data, hero, timer.now, battle_technology_basic_id)
Beispiel #3
0
def _update_hero_buffs(data, hero, relationships_id):
    """更新有羁绊英雄的buff
    """
    #影响英雄所带兵种战力的科技
    battle_technology_basic_id = technology_module.get_battle_technology_for_soldier(
        data.technology_list.get_all(True), hero.soldier_basic_id)

    #英雄是否有羁绊
    buffs_id = _calc_hero_buffs_in_relationship(hero.basic_id,
                                                relationships_id)
    if len(buffs_id) != 0:
        #英雄有羁绊,需要重新计算战力
        hero.update_buffs(buffs_id, battle_technology_basic_id)
Beispiel #4
0
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
Beispiel #5
0
    def _calc_update(self, data, req):
        """更新军队信息
        """
        #先清除有变化部队的所有英雄的buff
        heroes_id = []
        for team_info in req.teams:
            team_id = TeamInfo.generate_id(data.id, team_info.index)
            team = data.team_list.get(team_id)
            if team is not None:
                heroes_id.extend(team.get_heroes())
        for hero_id in heroes_id:
            if hero_id != 0:
                hero = data.hero_list.get(hero_id)
                if hero.buffs_id != '':
                    #清除英雄所有羁绊,需要重新计算战力
                    #影响英雄所带兵种战力的科技
                    battle_technology_basic_id = technology_module.get_battle_technology_for_soldier(
                        data.technology_list.get_all(True),
                        hero.soldier_basic_id)
                    hero.clear_buffs(battle_technology_basic_id)
                    logger.debug(
                        "clear buffs and calc battlescore[hero_id=%d]" %
                        hero_id)

        for team_info in req.teams:
            heroes_basic_id = []
            for hero_info in team_info.heroes:
                heroes_basic_id.append(hero_info.basic_id)

            #更换英雄
            if not team_business.update_team(data, team_info.index,
                                             heroes_basic_id):
                raise Exception("Update team failed")

        if not team_business.validation(data):
            raise Exception("Teams invalid")

        return DataBase().commit(data)
Beispiel #6
0
def use_starsoul_item(data, item, num, soldier):
    """消耗将魂石,生成对应英雄
    Args:
        data[UserData]: 用户信息
        item[ItemInfo out] 出售的物品
        num[int] 消耗的数量
        soldier[SoldierInfo] 生成的英雄所配置的兵种
    Returns:
        成功返回 HeroInfo
        失败返回 None
    """
    info = item.use_starsoul_item(num)
    if info is None:
        return None

    (hero_basic_id, starsoul_num) = info

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

    return HeroInfo.create_by_starsoul(item.user_id, hero_basic_id,
                                       starsoul_num, soldier,
                                       battle_technology_basic_id)
Beispiel #7
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)