Exemple #1
0
def for_player_hero_test(player):
    test_json = "%s/../doc/test.json/_create.heroes.json" % settings.ROOT_PATH

    fh = open(test_json, "r")
    datas = simplejson.loads(fh.read())
    fh.close()

    for data in datas:
        del data["userId"]
        warrior_id = int(data["gid"]) * 100
        del data["gid"]
        acquire_hero(player, warrior_id, data)
Exemple #2
0
    def acquire(self, player, gashapon, count=1):
        """
        玩家抽奖
        [(unit, is_new),(unit, is_new)]
        """
        choices_list = []
        data_list = []
        super_hero = False
        include_hero = False

        for i in range(1, count + 1):
            rarity = Gashapon.get_random_rarity(gashapon)
            target = Gashapon.get_random_target(gashapon, rarity)
            target.rarit = rarity
            data_list.append(target)

        print data_list
        if count == 10:
            self.topreward_count += 1
            if self.topreward_count == 10:
                for data in data_list:
                    print data
                    if data.rarit.rarity == gashapon.topreward_rarity and data.rarit.quality == gashapon.topreward_quality:
                        super_hero = True
                        break
                if not super_hero:
                    rarity = Gashapon.get_random_rarity(
                        gashapon,
                        rarity=gashapon.topreward_rarity,
                        quality=gashapon.topreward_quality)
                    target = Gashapon.get_random_target(gashapon, rarity)
                    target.rarit = rarity
                    rand = random.randint(0, len(data_list) - 1)
                    data_list[rand] = target

            for data in data_list:
                if data.gashapon_hero:
                    include_hero = True
                    break

            if not include_hero:
                rarity = Gashapon.get_random_rarity(
                    gashapon, rarity=gashapon.topreward_rarity, quality=0)
                target = Gashapon.get_random_target(gashapon, rarity)
                target.rarit = rarity
                rand = random.randint(0, len(data_list) - 1)
                data_list[rand] = target

        for target in data_list:
            info = u"%s" % (gashapon.name)
            if target.gashapon_hero:
                # if player.firstIn == 0 and target.target_id in Static.HERO_INIT_ACQUIRE:
                #     target.target_id =random.choice(Static.HERO_REPLACE_IDS)
                #     player.firstIn = 2
                # 直接抽出高星级的英雄
                # 和策划约定好后两位代表星级。
                star = int(str(target.target_id)[-2:])
                new_id = target.target_id / 100 * 100

                unit = acquire_hero(player, new_id, info=info, star=star)
            elif target.gashapon_soul:
                unit = acquire_soul(player,
                                    target.target_id,
                                    target.number,
                                    info=info)
            elif target.gashapon_equip:
                unit = acquire_equip(player, target.target_id, info=info)
            elif target.gashapon_item:
                unit = acquire_item(player,
                                    target.target_id,
                                    number=target.number,
                                    info=info)
            elif target.gashapon_artifactfragment:
                unit = acquire_artifactfragment(player,
                                                target.target_id,
                                                number=target.number,
                                                info=info)
            elif target.gashapon_equipfragment:
                unit = acquire_equipfragment(player,
                                             target.target_id,
                                             target.number,
                                             info=info)
            elif target.gashapon_currency:
                if target.is_yuanbo:
                    player.add_yuanbo(target.number, info=info)
                    unit = target
                else:
                    raise
            else:
                raise

            unit = copy.copy(unit)

            if target.gashapon_hero:
                if isinstance(unit, PlayerHero):
                    unit.gashapon_number = target.number
                else:
                    soul = get_soul(unit.soul_id)
                    unit.gashapon_number = soul.breakCost
                    unit.from_hero = True
            else:
                unit.gashapon_number = target.number

            self.count += 1

            if gashapon.topreward_reset:
                if gashapon.topreward_rarity and gashapon.topreward_quality:
                    if target.rarit.rarity == gashapon.topreward_rarity and target.rarit.quality == gashapon.topreward_quality:
                        self.topreward_count = 0

            choices_list.append(unit)

        return choices_list
Exemple #3
0
def create_player(request, *args, **argvs):
    from playerhero.api import acquire_hero

    userid = request.common_request.playerId
    player_id = settings.SERVERID * 1000000000 + userid
    player = Player(pk=player_id, userid=userid, serverid=settings.SERVERID)
    #if settings.OPEN_TUTORIAL:
    #    player.name = u""
    #    player.gold = 5000
    #    player.wood = 5000
    #    player.level = 40
    #    player.yuanbo = settings.DIAMOND
    #    player.vip = settings.VIP_INFO
    #else:
    player.name = u""
    player.vip["chargeCount"] = 0
    player.vip["vipLevel"] = 0
    player.level = 1
    player.firstIn = 1
    player.yuanbo = 0
    player.gold = 2000
    player.wood = 200

    player.channel = request.common_request.channel
    player.init_tasks()
    player.init_seven_days_tasks()

    #主角
    all_h = []
    #if not settings.OPEN_TUTORIAL:
    h1 = acquire_hero(player,
                      111000100,
                      level=1,
                      star=1,
                      upgrade=0,
                      skill1Level=1,
                      skill2Level=1,
                      skill3Level=1,
                      skill4Level=1)
    h15 = acquire_hero(player,
                       115000300,
                       level=1,
                       star=1,
                       upgrade=0,
                       skill1Level=1,
                       skill2Level=1,
                       skill3Level=1,
                       skill4Level=1)
    h22 = acquire_hero(player,
                       114000700,
                       level=1,
                       star=1,
                       upgrade=0,
                       skill1Level=1,
                       skill2Level=1,
                       skill3Level=1,
                       skill4Level=1)

    all_h.append(h1)
    all_h.append(h15)
    all_h.append(h22)

    defenseList = []
    i = 0
    default_poses = Static.HERO_DEFENCE_POS
    for a_h in all_h[0:5]:
        defenseList.append(a_h.id)
        defenseList.append(default_poses[i])
        i += 1
    player.defenseHeroLayout = defenseList
    defenseHeroIds = player.defenseHeroLayout[0:len(player.defenseHeroLayout
                                                    ):2]
    # dd.append(1120004)
    player.update_hero_defenseHeroIds(defenseHeroIds)

    player.update_siege_defenseSoldierIds([-1 for i in range(0, 5)])

    unlock_player_instancelevel(player, Static.FIRST_INSTANCE_BOSS_LEVEL_ID)
    unlock_player_instancelevel(player, Static.FIRST_INSTANCE_LEVEL_ID)
    #_debug_open_player_instance_at_instance_id(player, 1100)

    playerbuilding = acquire_building(player,
                                      1001001,
                                      level=1,
                                      centerX=8,
                                      centerY=8,
                                      status=0)
    playerbuilding = acquire_building(player,
                                      1001002,
                                      centerX=8,
                                      centerY=13,
                                      status=0)  # 召唤祭坛
    playerbuilding = acquire_building(player,
                                      1001011,
                                      centerX=13,
                                      centerY=9,
                                      status=0)
    # TODO: 创建城墙
    # playerbuilding = acquire_building(player, 1002002, level = 1 , centerX = 0, centerY = 0, status = 0)

    # 兵营解锁小兵的操作
    building = get_building(1001011)
    player.update_hero_warriorIds(building, 1)
    player.armies.set_horde(True)
    player.update_castlelevel(1)
    player.SiegeBattle.update()
    player.save()

    return player
Exemple #4
0
def create_ai_player(robot):
    """
        TODO : 攻城战的信息要加
    """
    from playerhero.api import acquire_hero

    player = Player(pk=robot.pk, serverid=0)
    while True:
        name = random_name()
        if _check_name(name) == 1:
            player.name = name
            break

    player.level = robot.level

    player.gold = player.level * 500 + 5000
    player.wood = player.level * 200 + 2000
    player.iconId = random.choice(Static.HERO_HERO_ICON_ID)
    player.powerRank = robot.powerRank

    # 新手引导专用机器人,其他类似于建筑物以后再修改
    if player.id == -1:
        # 攻城战保护时间为safedTime unix时间
        pass
        # player.endLockedTime = datetime.datetime.max

    defenseList = []
    powerrank = 0

    #
    # 机器人默认建筑
    # 要塞
    playerbuilding = acquire_building(player,
                                      1001001,
                                      level=robot.cityLevel,
                                      centerX=8,
                                      centerY=8,
                                      status=0)
    # 城墙 攻城战需要城墙血量
    playerbuilding = acquire_building(player,
                                      1002002,
                                      level=1,
                                      centerX=0,
                                      centerY=0,
                                      status=0)

    # 科技树
    player.init_wall_warriorIds()
    for soldier in player.wallWarriorIds:
        if soldier["soldierId"] == Static.HERO_WALL_SOLDIER_IDS[3]:
            # 防御塔
            soldier["soldierLevel"] = robot.towerLevel

    default_poses = Static.HERO_DEFENCE_POS
    i = 0
    for hero in robot.heroes:
        # todo 假数据-----------------------
        playerhero = acquire_hero(
            player,
            int("%s%s" % (hero, str(robot.heroUpgrades[i]).rjust(2, "0"))),
            star=robot.heroStars[i])

        playerhero.level = robot.heroLevels[i]
        playerhero.star = robot.heroStars[i]
        playerhero.upgrade = robot.heroUpgrades[i]
        skillhero = get_heroskill(hero)

        # todo 暂时假设 ,以后修改

        powerrank += playerhero.warrior.hero.powerRank + Static.HERO_STAR_POWERRANKS[
            int(playerhero.star / 5) +
            1][int(playerhero.warrior.hero.quality -
                   3)] * playerhero.level + Static.HERO_UPGRADE_POWERRANKS[int(
                       playerhero.upgrade)]

        for j in range(0, len(skillhero.skillinfo) / 3):
            skillGid, _, upgrade = skillhero.skillinfo[j * 3:(j + 1) * 3]
            if upgrade <= playerhero.upgrade:
                setattr(playerhero, "skill%sLevel" % (j + 1),
                        robot.heroSkillLevels[i])
                if j == 0:
                    powerrank += (robot.heroSkillLevels[i] +
                                  1) * Static.HERO_BIGSPELL_POWERRANK_RATIO
                else:
                    powerrank += (robot.heroSkillLevels[i] +
                                  1) * Static.HERO_SMALLSPELL_POWERRANK_RATIO

            setattr(playerhero, "skill%sGid" % (j + 1), skillGid)

        player.update_hero(playerhero, True)
        defenseList.append(playerhero.pk)
        defenseList.append(default_poses[i])
        i += 1

    player.defenseHeroLayout = defenseList
    defenseHeroIds = player.defenseHeroLayout[0:len(player.defenseHeroLayout
                                                    ):2]
    player.update_hero_defenseHeroIds(defenseHeroIds)
    player.defenseSiegeLayout = defenseList
    defenseHeroIds = player.defenseSiegeLayout[0:len(player.defenseSiegeLayout
                                                     ):2]
    player.update_siege_defenseHeroIds(defenseHeroIds)

    # if player.id > -10000 and player.level >= Static.PVP_LEVEL:
    #     player.PVP.add_score(robot.score-player.PVP.score)

    #player.PVP.update()
    player.save()
    return player
Exemple #5
0
def reward_send(player, reward, info=u"", number=1):
    """
    奖励发放
    """
    _data = {}

    if reward.is_hero:
        for i in range(0, reward.count * number):
            star = int(str(reward.type)[-2:])
            heroId = reward.type / 100 * 100
            playerunit = acquire_hero(player, heroId, info=info, star=star)

            if playerunit.is_hero:
                _data[reward.type] = {"type": reward.type, "count": 1}
            else:
                if reward.type not in _data:
                    _data[playerunit.soul_id] = {
                        "type": playerunit.soul_id,
                        "count": 0
                    }
                _data[playerunit.soul_id]["count"] += playerunit.soul.breakCost
    else:

        if reward.is_equip:
            for i in range(0, reward.count * number):
                acquire_equip(player, reward.type, info=info)
        elif reward.is_equipfragment:
            for i in range(0, reward.count * number):
                acquire_equipfragment(player, reward.type, info=info)
        elif reward.is_artifact:
            for i in range(0, reward.count * number):
                acquire_artifact(player, reward.type, info=info)
        elif reward.is_soul:
            acquire_soul(player, reward.type, reward.count * number, info=info)
        elif reward.is_artifactfragment:
            acquire_artifactfragment(player,
                                     reward.type,
                                     number=reward.count * number,
                                     info=info)
        elif reward.is_item:
            acquire_item(player,
                         reward.type,
                         number=reward.count * number,
                         info=info)
        elif reward.is_gold:
            player.add_gold(reward.count * number, info=info)
        elif reward.is_tower:
            player.add_towerGold(reward.count * number, info=info)
        elif reward.is_yuanbo:
            player.add_yuanbo(reward.count * number, info=info)
        elif reward.is_wood:
            player.add_wood(reward.count * number, info=info)
        elif reward.is_couragepoint:
            player.add_couragepoint(reward.count * number, info=info)
        elif reward.is_guildgold:
            player.guild.add_gold(reward.count * number, info=info)
        elif reward.is_honorpoint:
            player.PVP.add_honor(reward.count * number, info=info)
            player.PVP_change = True
        elif reward.is_xp:
            player.add_xp(reward.count * number)
        elif reward.is_power:
            player.add_power(reward.count * number)
        elif reward.is_army:
            player.armies.acquire(reward.type, reward.count * number)
            player.armies_change = True
        elif reward.is_stamina:
            player.add_stamina(reward.count * number)
        elif reward.is_buildingfragment:
            acquire_buildingfragment(player, reward.type,
                                     reward.count * number)

        _data[reward.type] = {
            "type": reward.type,
            "count": reward.count * number
        }

    return _data