Exemple #1
0
def eliteInstanceStart(request, response):
    '''
    精英结算
    '''
    player = request.player
    eliteInstancelevel_id = getattr(request.logic_request, "instanceId", 0)
    heroLayoutData = getattr(request.logic_request, "heroLayoutData", [])
    deadCount = 0
    isWin = getattr(request.logic_request, "isWin", False)
    summary = getattr(request.logic_request, "summary", {})

    elite_instancelevel = get_eliteinstancelevel(eliteInstancelevel_id)
    playereliteinstancelevel = player.eliteinstancelevels.get(eliteInstancelevel_id)

    #副本没有开启
    if not playereliteinstancelevel:
        AlertHandler(player, response, AlertID.ALERT_INSTANCE_NOT_OPEN, u"eliteInstanceStart:instance(%s) is not open" % eliteInstancelevel_id)
        return response


    if playereliteinstancelevel.succeedCount >= elite_instancelevel.eliteMaxPlayCount:
        AlertHandler(player, response, AlertID.ALERT_INSTANCE_FIGHT_COUNT_EXCEED_MAX, u"eliteInstanceStart:instance(%s) fight number(%s) exceed maxCount(%s)" % (eliteInstancelevel_id, playereliteinstancelevel.succeedCount, elite_instancelevel.eliteMaxPlayCount))
        return response

    #[玩家卡id, 卡id, 站位行, 列]
    player.update_hero_layout(heroLayoutData)

    if summary:
        leftWarriorDead = summary["leftWarriorDead"] #英雄小兵全部存在
        for i in range(0, len(leftWarriorDead), 2):
            if int(str(leftWarriorDead[i])[0:2]) == 11:
                deadCount += leftWarriorDead[i+1]

    # 默認三星,死一個兩星,其餘一星
    star = get_star(deadCount)

    data = playereliteinstancelevel.fight(star, isWin)
    if isWin:
        player.sub_power(elite_instancelevel.elitePowerCost)

    rewards = data["rewards"]
    heroLevelUp = data["heroLevelUp"]


    if isWin:
        # 策划修改,完成精英副本的时候,计算每日任务,既算完成一次普通副本,也算完成一次精英副本
        player.dailytask_going(Static.DAILYTASK_CATEGORY_ELIT_INSTANCE, number=1, is_incr=True, is_series=True)
        # 完成一个副本以后,进行任务值的添加
        player.task_going(Static.TASK_CATEGORY_ELIT_INSTANCE, number=1, c1=eliteInstancelevel_id, is_incr=False, is_series=False)
        player.dailytask_going(Static.DAILYTASK_CATEGORY_INSTANCE, number=1, is_incr=True, is_series=True)
    player.update_eliteinstancelevel(playereliteinstancelevel, True)

    response.logic_response.set("rewards", rewards)
    response.logic_response.set("heroLevelUp",heroLevelUp)
    response.logic_response.set("summary",summary)
    response.common_response.player.set("soldiers", player.armies.to_dict())
    response.common_response.player.set("populationCost", player.populationCost)
    response.logic_response.set("star", star)

    return response
Exemple #2
0
    def success(self, star):
        """
        挑战成功
        """

        unlock_new_instance = False
        if star > self.star:
            self.star = star

        if self.level_id == self.player.lastEliteInstance["lastEliteLevelId"]:
            self.player.lastEliteInstance["lastEliteFinished"] = True
            self.player.set_update("lastEliteInstance")
            #有后续关卡
            if self.eliteInstancelevel.eliteNextInstanceId:
                next_eliteinstancelevel = get_eliteinstancelevel(
                    self.eliteInstancelevel.eliteNextInstanceId)
                #开启同一章节关卡
                if self.eliteInstancelevel.instance_id == next_eliteinstancelevel.instance_id:
                    unlock_new_instance = PlayerEliteInstanceLevel.unlock(
                        self.player, next_eliteinstancelevel.id)
                #开启下一章节关卡
                else:
                    #普通章节当前关卡已通关
                    if self.player.lastInstance["lastFinished"]:
                        unlock_new_instance = PlayerEliteInstanceLevel.unlock(
                            self.player, next_eliteinstancelevel.id)

                    else:
                        instancelevel = get_instancelevel(
                            self.player.lastInstance["lastLevelId"])
                        if instancelevel.instance_id > next_eliteinstancelevel.instance_id:
                            unlock_new_instance = PlayerEliteInstanceLevel.unlock(
                                self.player, next_eliteinstancelevel.id)

        return unlock_new_instance
Exemple #3
0
def instanceReset(request, response):
    '''
    刷新副本次数
    '''
    #type = 1 普通 2 精英
    player = request.player
    level_id = getattr(request.logic_request, "instanceId", 0)
    category = getattr(request.logic_request, "category", 0)


    if category == 1:
        isElite = False
        instancelevel = get_instancelevel(level_id)
    elif category == 2:
        isElite = True
        instancelevel = get_eliteinstancelevel(level_id)
    else:
        raise ErrorException(player, u"instance reset category error (%s)" % level_id)

    if isElite:
        playerinstancelevel = player.eliteinstancelevels.get(instancelevel.pk)
    else:
        playerinstancelevel = player.instancelevels.get(instancelevel.pk)

    if not playerinstancelevel:
        AlertHandler(player, response, AlertID.ALERT_INSTANCE_NOT_OPEN, u"instanceReset:instance(%s) is not open" % level_id)
        return response


    vip = get_vip(player.vip_level)
    if playerinstancelevel.refreshCount >= vip.resetElitInstanceCount:
        AlertHandler(player, response, AlertID.ALERT_INSTANCE_REFRESH_COUNT_EXCEED_MAX, u"instanceReset:instance(%s) refresh count(%s) exceed max(%s)" % (level_id, playerinstancelevel.refreshCount , vip.resetElitInstanceCount))
        return response

    cost_diamond = Static.REFRESH_INSTANCE_COST * (playerinstancelevel.refreshCount + 1)

    if player.yuanbo < cost_diamond:
        AlertHandler(player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"instanceReset:instance(%s) refresh costDiamond(%s) playerDiamond(%s)" % (level_id, cost_diamond,  player.yuanbo ))
        return response

    player.sub_yuanbo(cost_diamond, info=u"重置副本次数")
    playerinstancelevel.refresh_count()

    if isElite:
        player.update_eliteinstancelevel(playerinstancelevel, True)
    else:
        player.update_instancelevel(playerinstancelevel, True)

    return response
Exemple #4
0
def _debug_open_player_eliteinstance_at_instance_id(player,
                                                    stop_instancelevel_id):
    """
    DEBUG 解锁玩家副本
    """
    instancelevel_id = Static.FIRST_ELITE_INSTANCE_LEVEL_ID

    playerinstancelevels = player.eliteinstancelevels.all()
    for level_id, playerinstancelevel in playerinstancelevels.items():
        player.eliteinstancelevels.delete(playerinstancelevel.pk)

    while True:
        instancelevel = get_eliteinstancelevel(instancelevel_id)
        playerinstancelevel = PlayerEliteInstanceLevel.unlock(
            player, instancelevel.id)
        playerinstancelevel.success(3)
        player.eliteinstancelevels.update(playerinstancelevel)
        instancelevel_id = instancelevel.eliteNextInstanceId
        if instancelevel_id > stop_instancelevel_id:
            break
Exemple #5
0
def eliteInstanceSetUp(request, response):
    '''
    请求精英敌军信息
    '''

    player = request.player
    eliteInstanceId= getattr(request.logic_request, "instanceId", 0)

    eliteInstancelevel = get_eliteinstancelevel(eliteInstanceId)
    playereliteinstancelevel =  player.eliteinstancelevels.get(eliteInstanceId)

    if not playereliteinstancelevel:
        AlertHandler(player, response, AlertID.ALERT_INSTANCE_NOT_OPEN, u"eliteInstanceSetUp:instance(%s) is not open" % eliteInstanceId)
        return response

    if playereliteinstancelevel.succeedCount >= eliteInstancelevel.eliteMaxPlayCount:
        AlertHandler(player, response, AlertID.ALERT_INSTANCE_FIGHT_COUNT_EXCEED_MAX, u"eliteInstanceSetUp:instance(%s) fight count(%s) exceed max count(%s)" % (eliteInstanceId, playereliteinstancelevel.succeedCount, eliteInstancelevel.eliteMaxPlayCount))
        return response


    if player.power < eliteInstancelevel.elitePowerCost:
        AlertHandler(player, response, AlertID.ALERT_POWER_NOT_ENOUGH, u"eliteInstanceSetUp:power error (%s)" % player.power)
        return response
    # 敌人的信息表里面已经配置好了,不出意外可以直接拿来使用
    enemies = eliteInstancelevel.eliteEnemies
    if not enemies:
        raise ErrorException(player, u"eliteInstanceSetUp:levelid(%s) has not enemy" % eliteInstancelevel.id)

    # 做的是奖励的提前展示,具体这部分代码,以下会详细说明
    rewards = playereliteinstancelevel.make_elite_rewards_before_fight()

    player.update_eliteinstancelevel(playereliteinstancelevel, True)
    # 这里面添加了一个奖励的返回信息
    response.logic_response.set("rewards", rewards)
    response.logic_response.set("enemies", [enemy.to_dict() for enemy in enemies])
    return response
Exemple #6
0
def instanceSweep(request, response):
    '''
    扫荡
    '''
    level_id = getattr(request.logic_request, "instanceId", 0)
    count = getattr(request.logic_request, "count", 0)
    category = getattr(request.logic_request, "category", 0)


    player = request.player
    if category == 2:
        isElite = True
        instancelevel = get_eliteinstancelevel(level_id)
        playerinstancelevel = player.eliteinstancelevels.get(level_id)
    else:
        isElite = False
        instancelevel = get_instancelevel(level_id)
        playerinstancelevel = player.instancelevels.get(level_id)

    #副本没有开启
    if not playerinstancelevel:
        AlertHandler(player, response, AlertID.ALERT_INSTANCE_NOT_OPEN, u"instanceSweep:instance(%s) is not open" % level_id)
        return response

    if not playerinstancelevel.can_sweep():
        AlertHandler(player, response, AlertID.ALERT_INSTANCE_CAN_NOT_SWEEP, u"instanceSweep:instance(%s) can not sweep" % level_id)
        return response

    # todo 10级以前不可以扫荡

    if player.level < Static.SWEEP_OPEN_LEVEL:
        return response

    #扫荡卷判断
    #Static.ITEM_TYPE_SWEEP  扫荡卷id
    item_sweep = player.items.get(Static.ITEM_SWEEP_ID)
    if item_sweep and item_sweep.count > 0:
        use_diamond = False
    else:
        use_diamond = True

    if player.vip_level < Static.SWEEP_VIP_LEVEL and use_diamond:
        AlertHandler(player, response, AlertID.ALERT_INSTANCE_SWEEP_VIP_ERROR, u"instanceSweep:vip(%s)  error" % player.vip_level)
        return response

    #次数判断
    if isElite:
        maxCount = instancelevel.eliteMaxPlayCount
        powerCost = instancelevel.elitePowerCost
    else:
        maxCount = instancelevel.maxPlayCount
        powerCost = instancelevel.powerCost

    if count > maxCount - playerinstancelevel.succeedCount:
        count = maxCount - playerinstancelevel.succeedCount

    if count == 0:
        AlertHandler(player, response, AlertID.ALERT_INSTANCE_FIGHT_COUNT_EXCEED_MAX, u"instanceSweep:instance(%s) fight number(%s) exceed maxCount(%s)" % (level_id, count, maxCount))
        return response

    #体力判断
    if count > player.power/powerCost:
        count = player.power/powerCost

    if count == 0:
        AlertHandler(player, response, AlertID.ALERT_POWER_NOT_ENOUGH, u"instanceSweep:instance(%s) power is not enough" % level_id)
        return response

    if not use_diamond and not item_sweep.can_sub(count):
        AlertHandler(player, response, AlertID.ALERT_INSTANCE_ITEM_SWEEP_NOT_ENOUGH, u"instanceSweep:item sweep number (%s) not enough" % (item_sweep.count))
        return response

    if use_diamond:
        if player.yuanbo < Static.SWEEP_INSTANCE_COST*count:
            AlertHandler(player, response, AlertID.ALERT_DIAMOND_NOT_ENOUGH, u"instanceSweep:playerDiamond(%s) costDiamond(%s)" % (player.yuanbo, Static.SWEEP_INSTANCE_COST*count))
            return response
        player.sub_yuanbo(Static.SWEEP_INSTANCE_COST*count, info=u"扫荡")
    else:
        item_sweep.sub(count , info=u"扫荡:%s:%s" % (level_id, isElite))


    rewards_list = playerinstancelevel.sweep(count)
    for rewards in rewards_list:
        for rewardDict in rewards:
            rewardTemp = CommonReward(rewardDict["type"], rewardDict["count"], 0)
            reward_send(player, rewardTemp, info=u"副本扫荡结算:%s" % level_id)


    if not isElite:
        player.sub_power(instancelevel.powerCost * count)
        player.task_going(Static.TASK_CATEGORY_INSTANCE, number=count, c1=instancelevel.id, is_incr=False, is_series=False)

    else:
        player.sub_power(instancelevel.elitePowerCost * count)
        player.task_going(Static.TASK_CATEGORY_ELIT_INSTANCE, number=count, c1=instancelevel.pk, is_incr=False, is_series=False)
        player.dailytask_going(Static.DAILYTASK_CATEGORY_ELIT_INSTANCE, number=count, is_incr=True, is_series=True)

    player.dailytask_going(Static.DAILYTASK_CATEGORY_INSTANCE, number=count, is_incr=True, is_series=True)


    if isElite:
        player.update_eliteinstancelevel(playerinstancelevel, True)
    else:
        player.update_instancelevel(playerinstancelevel, True)
    response.logic_response.set("rewards", rewards_list)
    return response
Exemple #7
0
 def eliteInstancelevel(self):
     # 这个level_id是父类的里面的的pk主键
     return get_eliteinstancelevel(self.level_id)
Exemple #8
0
    def success(self, star):
        """
        挑战成功
        """
        unlock_new_instance = False
        # 星级赋值这里有什么用??
        if star > self.star:
            self.star = star

        # 这个是最后的副本id
        # lastInstance = DictField(default = {"lastFinished":False, "lastLevelId":Static.FIRST_INSTANCE_LEVEL_ID})
        # 会初始化一个id但是默认的是false,在这里给他赋值的true记录玩家当前的关卡进度
        if self.level_id == self.player.lastInstance["lastLevelId"]:
            self.player.lastInstance["lastFinished"] = True
            # 更新相关信息 更新属性的字段值 这么使用
            self.player.set_update("lastInstance")
            # 如果有下一个关卡
            if self.instancelevel.nextInstanceId:
                # 取得下一个关卡通过 nextInstanceId
                next_instancelevel = get_instancelevel(
                    self.instancelevel.nextInstanceId)

                # 如果没有下一关证明,已经是副本的最后一关了.那么就返回当前的关卡。
                if not next_instancelevel:
                    return self.instancelevel
                # 如果玩家的等级满足条件就去解锁下一个
                if self.player.level >= next_instancelevel.minUserLevel:
                    # 这个是传入的下一个关卡id,目的是为了打通一关为新的信息赋值
                    unlock_new_instance = PlayerInstanceLevel.unlock(
                        self.player, next_instancelevel.pk)
                #普通副本第一章节通关开启第一章节精英副本
                # 判断当前关的章节id和下一关的章节id不同。证明这是某一章的最后一关。
                if self.instancelevel.instance_id != next_instancelevel.instance_id:

                    # 如果是第2章普通关卡全部完成,那么开启精英的关卡
                    if self.instancelevel.instance_id == 2:

                        # 解锁相应的精英关卡,这里的id需要重新设置。
                        PlayerEliteInstanceLevel.unlock(
                            self.player, Static.FIRST_ELITE_INSTANCE_LEVEL_ID)
                        self.player.start_tutorial_by_id(
                            Static.TUTORIAL_ID_ELITE_INSTANCE)
                    else:
                        # 如果已经不是第一章完成了。是第二章或者第三章。
                        # 最后一个精英关已经完成
                        if self.player.lastEliteInstance["lastEliteFinished"]:
                            # 拿到当前解锁的最后一关
                            eliteinstancelevel = get_eliteinstancelevel(
                                self.player.
                                lastEliteInstance["lastEliteLevelId"])
                            # 如果有下一关就取下一个。
                            if eliteinstancelevel.eliteNextInstanceId:
                                next_eliteinstancelevel = get_eliteinstancelevel(
                                    eliteinstancelevel.eliteNextInstanceId)
                                # 当前的精英关章节id 和 下一关的精英章节id不同,说明当前是某一章的最后一个精英关。这里就需要普通关卡和精英的章节对应起来。
                                if eliteinstancelevel.instance_id != next_eliteinstancelevel.instance_id and next_instancelevel.instance_id >= next_eliteinstancelevel.instance_id:
                                    # 对应解锁下一关精英
                                    PlayerEliteInstanceLevel.unlock(
                                        self.player,
                                        next_eliteinstancelevel.id)
        # 返回的是下一关的对象信息
        return unlock_new_instance