Exemplo n.º 1
0
def buildingBuild(request, response):
    '''
    创建建筑
    '''
    centerX = getattr(request.logic_request, "centerX", 0)
    centerY = getattr(request.logic_request, "centerY", 0)
    building_id = getattr(request.logic_request, "buildingId", -1)

    player = request.player

    building = get_building(building_id)
    if not building:
        raise ErrorException(
            player, u"buildingBuild:building(%s) is not existed" % building_id)

    building_upgrade = get_building_upgrade_by_building_and_level(building, 0)
    #能否升级等级检查
    if not building_upgrade:
        raise ErrorException(
            player,
            u"buildingBuild:building(%s) can not be created" % building_id)

    if building.is_castle:
        if building_upgrade.userLevel > player.level:
            AlertHandler(
                player, response, AlertID.ALERT_PLAYER_LEVEL_NOT_ENOUGH,
                u"buildingBuild:building(%s) upgrade  needlevel(%s) playerlevel(%s)"
                % (building_id, building_upgrade.userLevel, player.level))
            return response

    elif building_upgrade.castleLevel > player.castleLevel:
        AlertHandler(
            player, response, AlertID.ALERT_BUILDING_CASTLE_LEVEL_NOT_ENOUGH,
            u"buildingBuild:building(%s) upgrade  needlevel(%s) playercastlelevel(%s)"
            % (building_id, building_upgrade.castleLevel, player.castleLevel))
        return response

    #建造数量检查
    building_count = get_building_count_by_level(building, player.castleLevel)
    if building_count <= 0:
        AlertHandler(
            player, response, AlertID.ALERT_PLAYER_LEVEL_NOT_ENOUGH,
            u"buildingBuild:building(%s) create allow number is %s" %
            (building_id, building_count))
        return response
    #建造数量上限检查
    playerbuilding_count = player.get_buildings_count(building.pk)
    if playerbuilding_count >= building_count:
        AlertHandler(
            player, response, AlertID.ALERT_BUILDING_BUILD_OVER_MAX_NUMBER,
            u"buildingBuild:building(%s) create allow number is %s , already building number is %s"
            % (building_id, building_count, playerbuilding_count))
        return response

    #能否升级消耗检查
    for cost in building_upgrade.costs:
        if not reward_cost_check(player, cost):
            if building.is_statue:
                AlertHandler(
                    player, response,
                    AlertID.ALERT_BUILDING_MATERIAL_NOT_ENOUGH,
                    u"buildingBuild:building(%s) create cost(%s) is error" %
                    (building_id, cost.pk))
                return response
            AlertHandler(
                player, response, AlertID.ALERT_BUILDING_MATERIAL_NOT_ENOUGH,
                u"buildingBuild:building(%s) create cost(%s) is error" %
                (building_id, cost.pk))
            return response

    #建造神像数量检查
    if building.is_statue:
        #神像总数的检查
        vip = get_vip(player.vip_level)
        if player.get_statue_count(building_id) >= vip.statueCount:
            AlertHandler(
                player, response, AlertID.ALERT_BUILDING_BUILD_OVER_MAX_NUMBER,
                u"buildingBuild:building(%s) create allow number is %s , already building number is %s"
                % (building_id, Static.STATUE_MAX_COUNT,
                   player.get_statue_count()))
            return response

    info = u"建造:%s" % building.name
    for cost in building_upgrade.costs:
        reward_cost(player, cost, info)

    playerbuilding = acquire_building(player,
                                      building,
                                      centerX=centerX,
                                      centerY=centerY,
                                      status=0,
                                      info=info)
    #神像刚建造时
    building_upgrade = get_building_upgrade_by_building_and_level(
        playerbuilding.building, playerbuilding.level)

    # 建造铁匠铺
    if building.is_blacksmith:
        if player.tutorial_id == Static.TUTORIAL_ID_BLACK_SMITH_5:
            player.tutorial_complete()
            player.next_tutorial_open()
    #  建造金矿
    if building.is_goldmine:
        if player.tutorial_id == Static.TUTORIAL_ID_GOLDEN_7:
            player.tutorial_complete()
            player.next_tutorial_open()
    # 建造伐木场
    if building.is_loggingfield:
        if player.tutorial_id == Static.TUTORIAL_ID_LOGFIELD_8:
            player.tutorial_complete()

    if building.is_tarven:
        if player.tutorial_id == Static.TUTORIAL_ID_TAVERN_9:
            player.tutorial_complete()
            player.next_tutorial_open()

    if building.is_arena:
        if player.tutorial_id == Static.TUTORIAL_ID_ARENA_BUILD_17:
            player.tutorial_complete()
        player.setArenaOpen()  #玩家可以被其他人搜索到
        player.PVP.reset_daily_data()
        player.arenashop.refresh_auto()
        response.common_response.player.set("honorShop",
                                            player.arenashop.to_dict())
        response.common_response.player.set("arena", player.PVP.to_dict())

    if building.is_elementtower:
        player.elementTower.init()
        response.common_response.player.set("elementTower",
                                            player.elementTower.to_dict())

    # 战争图腾建造 开启1700新手引导
    if building.is_hordelab:
        player.start_tutorial_by_id(Static.TUTORIAL_ID_INSTANCE_16)

    # 上古遗迹建造 开启1800新手引导
    if building.is_taitan:
        player.start_tutorial_by_id(Static.TUTORIAL_ID_INSTANCE_17)

    # 全视之眼建造 开启1900新手引导
    if building.is_radar:
        player.start_tutorial_by_id(Static.TUTORIAL_ID_INSTANCE_18)
        player.setSiegeOpen()  #玩家可以被其他人搜到
        #城墙
        acquire_building(player,
                         1002002,
                         level=1,
                         centerX=0,
                         centerY=0,
                         status=0,
                         info=info)
        #城墙配置点
        point = player.castleLevel < 10 and range(1, 4) or range(0, 5)
        defenseSiegeSoldierIds = player.castleLevel < 10 and [-1, 0, 0, 0, -1
                                                              ] or [
                                                                  0, 0, 0, 0, 0
                                                              ]
        for i in point:
            acquire_building(player,
                             1002003,
                             level=1,
                             centerX=i,
                             centerY=0,
                             status=0,
                             info=info)
        #防御塔配置点
        for i in range(2):
            acquire_building(player,
                             1002004,
                             level=1,
                             centerX=i,
                             centerY=0,
                             status=0,
                             info=info)
        player.update_siege_defenseSoldierIds(defenseSiegeSoldierIds)
        response.common_response.player.set("defenseSiegeSoldierIds",
                                            defenseSiegeSoldierIds)
        response.common_response.player.set("siegeBattle",
                                            player.SiegeBattle.to_dict())

    return response
Exemplo n.º 2
0
def buildingLevelUp(request, response):
    '''
    建筑升级
    '''
    player = request.player
    playerbuilding_id = getattr(request.logic_request, "playerBuildingId", 0)

    playerbuilding = player.buildings.get(playerbuilding_id)
    if not playerbuilding:
        raise ErrorException(
            player,
            u"buildingLevelUp:no playerbuilding(%s)" % (playerbuilding_id))

    building_id = playerbuilding.building.pk
    if not playerbuilding.is_normal:
        if playerbuilding.is_upgrading:
            alert_id = AlertID.ALERT_BUILDING_IS_UPGRADING
        elif playerbuilding.is_producing:
            alert_id = AlertID.ALERT_BUILDING_IS_PRODUCING

        player.update_building(playerbuilding)
        AlertHandler(
            player, response, alert_id,
            u"buildingLevelUp:building(%s) upgrade playerbuilding(%s) status(%s) is not normal"
            % (building_id, playerbuilding_id, playerbuilding.status))
        return response

    building_upgrade = get_building_upgrade_by_building_and_level(
        playerbuilding.building, playerbuilding.level)
    #能否升级等级检查
    if not building_upgrade:
        raise ErrorException(
            player,
            u"buildingLevelUp:building(%s) upgrade playerbuilding(%s) level(%s) not upgrade info"
            % (building_id, playerbuilding_id, playerbuilding.level))

    if playerbuilding.building.is_castle:
        if building_upgrade.userLevel > player.level:
            AlertHandler(
                player, response, AlertID.ALERT_PLAYER_LEVEL_NOT_ENOUGH,
                u"buildingLevelUp:building(%s) upgrade playerbuilding(%s) needlevel(%s) playerlevel(%s)"
                % (building_id, playerbuilding_id, building_upgrade.userLevel,
                   player.level))
            return response

    elif building_upgrade.castleLevel > player.castleLevel:
        AlertHandler(
            player, response, AlertID.ALERT_BUILDING_CASTLE_LEVEL_NOT_ENOUGH,
            u"buildingLevelUp:building(%s) upgrade playerbuilding(%s) needlevel(%s) playercastlelevel(%s)"
            % (building_id, playerbuilding_id, building_upgrade.castleLevel,
               player.castleLevel))
        return response

    #消耗检查
    for cost in building_upgrade.costs:
        if not reward_cost_check(player, cost):
            AlertHandler(
                player, response, AlertID.ALERT_BUILDING_MATERIAL_NOT_ENOUGH,
                u"buildingLevelUp:building(%s) upgrade cost(%s) is error" %
                (building_id, cost.pk))
            return response

    info = u"升级:%s->%s" % (playerbuilding.building.name, playerbuilding.level)
    for cost in building_upgrade.costs:
        reward_cost(player, cost, info)

    before_level = playerbuilding.level
    playerbuilding.upgrade(building_upgrade)
    if playerbuilding.building.is_statue and playerbuilding.level == 1:
        playerbuilding.random_attrbutes()

    after_level = playerbuilding.level
    ActionLogWriter.building_upgrade(player, playerbuilding.pk,
                                     playerbuilding.building_id, before_level,
                                     after_level, info)

    player.update_building(playerbuilding, True)
    return response
Exemplo n.º 3
0
def heroStarUpgrade(request, response):
    """
    英雄升星
    """
    # 获取升星英雄id
    playerhero_id = getattr(request.logic_request, "playerHeroId", 0)
    # 选择升星模式,是否优先使用英雄灵魂碎片,再使用万能碎片
    useSoulFirst = getattr(request.logic_request, "useSoulFirst", True)
    player = request.player

    playerhero = player.heroes.get(playerhero_id)

    if not playerhero:
        raise ErrorException(
            player, u"heroStarUpgrade:no playerhero(%s)" % (playerhero_id))

    # 通过英雄星级获取数据表中对应的数据
    herostarupgrade = get_herostarupgrade(playerhero.star)
    if not herostarupgrade:
        raise ErrorException(
            player,
            u"heroStarUpgrade:no herostarupgrade(%s)" % (playerhero.star))

    # 获取相应英雄的碎片
    soul_id = playerhero.warrior.hero.soulId
    playersoul = player.souls.get(soul_id)
    # 这个是英雄的碎片
    soul_number = playersoul.count if playersoul else 0
    soul_number = soul_number if soul_number <= herostarupgrade.soulCount else herostarupgrade.soulCount

    # 这个是万能的碎片
    player_soulitem = player.items.get(Static.ITEM_HERO_UPGRADE_ID)
    player_soulitem_number = player_soulitem.count if player_soulitem else 0
    soulitem_number = player_soulitem_number if player_soulitem_number < herostarupgrade.sepecialItemMaxCount else herostarupgrade.sepecialItemMaxCount

    # 但是使用有特殊的规则,万能碎片的使用数量有上限的限制,到达上限以后仍然不够的话需要使用英雄碎片补充。
    if soul_number + soulitem_number < herostarupgrade.soulCount:
        AlertHandler(
            player, response, AlertID.ALERT_SOUL_NOT_ENOUGH,
            u"heroStarUpgrade: playerheroId(%s) soulNumber(%s) soulitemNumber(%s) star(%s)"
            % (playerhero_id, soul_number, player_soulitem_number,
               playerhero.star))
        return response

    # 升星需要三种物品,英雄碎片,万能碎片,消耗表里面的物品。
    for cost in herostarupgrade.costs:
        if not reward_cost_check(player, cost):
            AlertHandler(
                player, response,
                AlertID.ALERT_HERO_STAR_UPGRADE_MATERIAL_NOT_ENOUGH,
                u"heroStarUpgrade: playerheroId(%s) cost(%s) is not enough star(%s)"
                % (playerhero_id, cost.id, playerhero.star))
            return response

    info = u"英雄(%s)升星(%s)" % (playerhero_id, playerhero.star)
    # 优先使用英雄灵魂碎片
    if useSoulFirst:
        playersoul.sub(soul_number, info)
        extra_soulitem_number = herostarupgrade.soulCount - soul_number
        if extra_soulitem_number > 0:
            player_soulitem.sub(extra_soulitem_number, info)
    else:
        if soulitem_number != 0:
            player_soulitem.sub(soulitem_number, info)
        extra_soul_number = herostarupgrade.soulCount - soulitem_number
        playersoul.sub(extra_soul_number, info)

    for cost in herostarupgrade.costs:
        reward_cost(player, cost)

    playerhero.start_upgrade()

    if playerhero.star == 3:
        player.seven_days_task_going(
            Static.SEVEN_TASK_CATEGORY_HERO_STAR_UP_GREEN3,
            number=1,
            is_incr=True,
            is_series=True)

    elif playerhero.star == 5:
        player.seven_days_task_going(
            Static.SEVEN_TASK_CATEGORY_HERO_STAR_UP_GREEN5,
            number=1,
            is_incr=True,
            is_series=True)

    elif playerhero.star == 6:
        player.task_going(Static.TASK_CATEGORY_HERO_STAR2_UPGRADE,
                          number=1,
                          is_incr=True,
                          is_series=True)

    elif playerhero.star == 7:
        player.seven_days_task_going(
            Static.SEVEN_TASK_CATEGORY_HERO_STAR_UP_BLUE2,
            number=1,
            is_incr=True,
            is_series=True)

    elif playerhero.star == 10:
        player.seven_days_task_going(
            Static.SEVEN_TASK_CATEGORY_HERO_STAR_UP_BLUE5,
            number=1,
            is_incr=True,
            is_series=True)

    elif playerhero.star == 11:
        player.task_going(Static.TASK_CATEGORY_HERO_STAR3_UPGRADE,
                          number=1,
                          is_incr=True,
                          is_series=True)
        player.seven_days_task_going(
            Static.SEVEN_TASK_CATEGORY_HERO_STAR_UP_PURPLE,
            number=1,
            is_incr=True,
            is_series=True)

    elif playerhero.star == 16:
        player.task_going(Static.TASK_CATEGORY_HERO_STAR5_UPGRADE,
                          number=1,
                          is_incr=True,
                          is_series=True)

    playerheroteam = player.heroteams.get(playerhero.warrior.hero.heroTeamId)
    playerheroteam.update_score()
    player.update_heroteam(playerheroteam, True)

    player.update_hero(playerhero, True)
    return response
Exemplo n.º 4
0
def heroSkillLevelUp(request, response):
    """
    技能升级
    """
    player = request.player
    playerhero_id = getattr(request.logic_request, "playerHeroId", 0)
    skill_pos = getattr(request.logic_request, "pos", -1)
    playerhero = player.heroes.get(playerhero_id)

    if not playerhero:
        raise ErrorException(
            player, u"heroSkillLevelUp:no playerhero(%s)" % (playerhero_id))

    if not playerhero.skill_can_levelup(skill_pos):
        player.update_hero(playerhero)
        AlertHandler(
            player, response, AlertID.ALERT_HERO_SKILL_LEVELUP_ERROR,
            u"heroSkillLevelUp:hero(%s) playerhero(%s) pos(%s) can not levelup "
            % (playerhero.warrior_id, playerhero_id, skill_pos))
        return response

    if skill_pos <= 0 or skill_pos > 4:
        AlertHandler(
            player, response, AlertID.ALERT_HERO_SKILL_LEVELUP_ERROR,
            u"heroSkillLevelUp:hero(%s) playerhero(%s) pos(%s) " %
            (playerhero.warrior_id, playerhero_id, skill_pos))

    skill_id, skill_level = playerhero.get_skill_info(skill_pos)
    skilllevel = get_skilllevel(skill_id, skill_level)
    next_skilllevel = get_skilllevel(skill_id, skill_level + 1)

    if not skilllevel:
        raise ErrorException(
            player,
            u"heroSkillLevelUp:hero(%s) playerhero(%s) skilllevel(%s)" %
            (playerhero.warrior_id, playerhero_id, skill_level))
    if not next_skilllevel:
        raise ErrorException(
            player,
            u"heroSkillLevelUp:hero(%s) playerhero(%s) nextskilllevel(%s)" %
            (playerhero.warrior_id, playerhero_id, skill_level + 1))

    if playerhero.level < skilllevel.heroLevel:
        player.update_hero(playerhero)
        AlertHandler(
            player, response,
            AlertID.ALERT_HERO_SKILL_LEVELUP_LEVEL_NOT_ENOUGH,
            u"heroSkillLevelUp:hero(%s) playerhero(%s) level(%s) skilllevel(%s)"
            % (playerhero.warrior_id, playerhero_id, playerhero.level,
               skilllevel.heroLevel))
        return response

    _gold = skilllevel.costGold

    if player.gold < _gold:
        AlertHandler(
            player, response, AlertID.ALERT_GOLD_NOT_ENOUGH,
            u"heroSkillLevelUp:hero(%s) playerhero(%s) needGold(%s) playerGold(%s)"
            % (playerhero.warrior_id, playerhero_id, _gold, player.gold))
        return response

    for cost in skilllevel.costs:
        if not reward_cost_check(player, cost):
            AlertHandler(
                player, response,
                AlertID.ALERT_HERO_SKILL_LEVELUP_MATERIAL_NOT_ENOUGH,
                u"heroSkillLevelUp:hero(%s) playerhero(%s) cost(%s) is error" %
                (playerhero.warrior_id, playerhero_id, cost.pk))
            return response

    for cost in skilllevel.costs:
        reward_cost(player, cost)

    _info = u"技能升级:%s" % (playerhero.pk)
    player.sub_gold(_gold, _info)
    skill_id, before_level = playerhero.get_skill_info(skill_pos)
    playerhero.skill_levelup(skill_pos)
    _, after_level = playerhero.get_skill_info(skill_pos)
    ActionLogWriter.hero_skilllevelup(player, playerhero.pk,
                                      playerhero.warrior_id, skill_pos,
                                      skill_id, before_level, after_level,
                                      playerhero.warrior.cardId, _info)
    player.update_hero(playerhero, True)

    player.dailytask_going(Static.DAILYTASK_CATEGORY_HERO_LEVELUP,
                           number=1,
                           is_incr=True,
                           is_series=True)
    player.seven_days_task_going(Static.SEVEN_TASK_CATEGORY_HERO_SKILL_LEVELUP,
                                 is_incr=True,
                                 with_top=False,
                                 is_series=True)
    if player.tutorial_id == Static.TUTORIAL_ID_SKILL_LEVELUP_13:
        player.tutorial_complete()

    return response
Exemplo n.º 5
0
def heroUpgrade(request, response):
    """
    进阶
    """
    player = request.player
    playerhero_id = getattr(request.logic_request, "playerHeroId", 0)

    playerhero = player.heroes.get(playerhero_id)
    hero = playerhero.warrior.hero

    if playerhero.level < hero.evolveLevel:
        player.update_hero(playerhero)
        AlertHandler(
            player, response, AlertID.ALERT_HERO_UPGRADE_LEVEL_NOT_ENOUGH,
            u"evolveHero:hero(%s) playerhero(%s) level(%s) evolveLevel(%s)" %
            (playerhero.warrior_id, playerhero_id, playerhero.level,
             hero.evolveLevel))
        return response

    _warrior = get_warrior(hero.evolveHero_id)
    for cost in hero.evolveCosts:
        if not reward_cost_check(player, cost):
            AlertHandler(
                player, response,
                AlertID.ALERT_HERO_UPGRADE_MATERIAL_NOT_ENOUGH,
                u"evolveHero:hero(%s) playerhero(%s) cost(%s) is error" %
                (playerhero.warrior_id, playerhero_id, cost.pk))
            return response

    _info = u"进阶:%s,%s" % (playerhero.pk, playerhero.upgrade)

    for cost in hero.evolveCosts:
        reward_cost(player, cost)

    if _warrior.hero.is_purple:
        player.task_going(Static.TASK_CATEGORY_HERO_EVOLVE_UPGRADE_PURPLE,
                          number=1,
                          is_incr=True,
                          is_series=True)
    elif _warrior.hero.is_blue:
        player.task_going(Static.TASK_CATEGORY_HERO_EVOLVE_UPGRADE_BLUE,
                          number=1,
                          is_incr=True,
                          is_series=True)
        player.seven_days_task_going(
            Static.SEVEN_TASK_CATEGORY_HERO_UPGRADE_BLUE,
            number=1,
            is_incr=True,
            is_series=True)
    elif _warrior.hero.is_green_plus_2:
        player.seven_days_task_going(
            Static.SEVEN_TASK_CATEGORY_HERO_UPGRADE_GREEN2,
            number=1,
            is_incr=True,
            is_series=True)
    elif _warrior.hero.is_green_plus_1:
        player.seven_days_task_going(
            Static.SEVEN_TASK_CATEGORY_HERO_UPGRADE_GREEN1,
            number=1,
            is_incr=True,
            is_series=True)
    if _warrior.hero.is_green:
        player.task_going(Static.TASK_CATEGORY_HERO_EVOLVE_UPGRADE_GREEN,
                          number=1,
                          is_incr=True,
                          is_series=True)

    ActionLogWriter.hero_evolve(player, playerhero.pk, playerhero.warrior_id,
                                _warrior.pk, playerhero.upgrade,
                                _warrior.hero.upgrade,
                                playerhero.warrior.cardId, _info)

    playerhero.warrior_id = _warrior.pk
    playerhero.upgrade = _warrior.hero.upgrade

    #检查是否开启新技能
    skillhero = get_heroskill(_warrior.cardId)
    for i in range(0, len(skillhero.skillinfo) / 3):
        skillGild, _, upgrade = skillhero.skillinfo[i * 3:(i + 1) * 3]
        if upgrade == playerhero.upgrade:
            setattr(playerhero, "skill%sLevel" % (i + 1), 1)

    playerheroteam = player.heroteams.get(playerhero.warrior.hero.heroTeamId)
    playerheroteam.update_score()
    player.update_heroteam(playerheroteam, True)
    player.update_hero(playerhero, True)

    if player.tutorial_id == Static.TUTORIAL_ID_HERO_UPGRADE_15:
        player.tutorial_complete()

    return response
Exemplo n.º 6
0
def heroGacha(request, response):

    player = request.player
    is_ten = getattr(request.logic_request, "isTen", False)
    tavernId = getattr(request.logic_request, "tavernId", 0)
    rewards = []

    # 这个是先判断是什么抽奖,是金币还是钻石类型。
    tavern = get_tavern(tavernId)

    if not tavern:
        raise ErrorException(player, u"heroGacha:no tavern(%s)" % tavernId)

    else:
        #第一次十连抽使用ID = 3的抽奖配置
        if tavern.is_diamond and player.isFirstTenGacha and is_ten:
            gashapon_id = 3
        else:
            gashapon_id = tavern.gashapon_id

        gashapon = get_gashapon(gashapon_id)
        is_new, playergashapon = player.gashapons.get_or_create(gashapon.pk)

        playerGashaponItem = None

        # 如果是金币
        if tavern.is_gold:
            # 不是十连抽
            if not is_ten:
                #
                if not player.gashapon_is_gold_free and not reward_cost_check(
                        player, tavern.tavern_cost):
                    AlertHandler(
                        player, response, AlertID.ALERT_GOLD_NOT_ENOUGH,
                        u"heroGacha:tavern(%s) needGold(%s) playerGold(%s)" %
                        (tavern.pk, tavern.tavern_cost.count, player.gold))
                    return response
            else:
                if not reward_cost_check(player, tavern.tavern_tencost):
                    AlertHandler(
                        player, response, AlertID.ALERT_GOLD_NOT_ENOUGH,
                        u"heroGacha:tavern(%s) needGold(%s) playerGold(%s)" %
                        (tavern.pk, tavern.tavern_tencost.count, player.gold))
                    return response
        else:
            if not is_ten:
                playerGashaponItem = player.items.get(
                    Static.ITEM_DIAMOND_GASHAPON_ID)
                if not playerGashaponItem or not playerGashaponItem.can_sub(1):
                    if not player.gashapon_is_yuanbo_free and not reward_cost_check(
                            player, tavern.tavern_cost):
                        AlertHandler(
                            player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH,
                            u"heroGacha:tavern(%s) needYuanbo(%s) playerYuanbo(%s)"
                            % (tavern.pk, tavern.tavern_cost.count,
                               player.yuanbo))
                        return response
            else:
                if not reward_cost_check(player, tavern.tavern_tencost):
                    AlertHandler(
                        player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH,
                        u"heroGacha:tavern(%s) needYuanbo(%s) playerYuanbo(%s)"
                        % (tavern.pk, tavern.tavern_tencost.count,
                           player.yuanbo))
                    return response

        if tavern.is_gold:
            if not is_ten and player.gashapon_is_gold_free:
                player.use_gashapon_gold_free()
            else:
                if is_ten:
                    reward_cost(player,
                                tavern.tavern_tencost,
                                info=u"抽奖:%s:%s" % (gashapon.name, is_ten))
                else:
                    reward_cost(player,
                                tavern.tavern_cost,
                                info=u"抽奖:%s:%s" % (gashapon.name, is_ten))

        else:
            if not is_ten and player.gashapon_is_yuanbo_free:
                player.use_gashapon_yuanbo_free()
            else:
                if is_ten:
                    reward_cost(player,
                                tavern.tavern_tencost,
                                info=u"抽奖:%s:%s" % (gashapon.name, is_ten))
                else:
                    if not playerGashaponItem or not playerGashaponItem.can_sub(
                            1):
                        reward_cost(player,
                                    tavern.tavern_cost,
                                    info=u"抽奖:%s:%s" % (gashapon.name, is_ten))
                    else:
                        playerGashaponItem.sub(1, info=u"英雄单抽卡")

        # 新手引导的话就只有新手引导,否则就走其他的抽奖
        if player.tutorial_id == Static.TUTORIAL_ID_GASHAPON_2 and player.tutorial[
                'status'] != 2:
            playerhero = acquire_hero(player, 112000400, u"新手引导", star=6)
            playerhero.gashapon_number = 1
            units = [playerhero]
            player.tutorial_complete()
            player.next_tutorial_open()
        else:
            if is_ten:
                gashapon_count = 10
                if not tavern.is_gold:
                    player.seven_days_task_going(
                        Static.SEVEN_TASK_CATEGORY_GASHAPON,
                        number=1,
                        is_incr=True,
                        with_top=False,
                        is_series=True)
                    player.tenDiamondCount += 1

                    player.set_update("tenDiamondCount")
            else:
                gashapon_count = 1
            units = playergashapon.acquire(player,
                                           gashapon,
                                           count=gashapon_count)

        #第一次十连抽使用ID = 3的抽奖配置
        if tavern.is_diamond and player.isFirstTenGacha and is_ten:
            player.useFirstTenGacha()

        player.gashapons.update(playergashapon)
        player.dailytask_going(Static.DAILYTASK_CATEGORY_GASHAPON,
                               number=len(units),
                               is_incr=True,
                               is_series=True)  #召唤大师

    if is_ten and tavern.tenReward:
        reward_send(player, tavern.tenReward, info=u"%s:10连抽" % tavern.pk)

    elif not is_ten and tavern.reward:
        reward_send(player, tavern.reward, info=u"%s:单抽" % tavern.pk)

    for unit in units:
        reward = {"count": unit.gashapon_number, "type": unit.obj_id}
        if hasattr(unit, "from_hero"):
            reward["fromHero"] = unit.from_hero
        else:
            reward["fromHero"] = False

        rewards.append(reward)

    response.common_response.player.set("tavern", player.tavern)
    response.logic_response.set("rewards", rewards)

    return response