Esempio n. 1
0
def generate_temple_robot(robot_uid, server_name, formation_index, rank=0):
    """# robot: 产生一个很拟人的机器人
    """
    import game_config
    robot_int_id = int(robot_uid.split('_')[1])
    robot_config = game_config.temple_robot.get(robot_int_id)
    ######################################################
    # ## card
    from models.cards import Cards
    card_obj = EmptyModelObj(Cards, robot_uid, server_name)

    robot_name = robot_config['name']
    if not rank:
        rank = robot_int_id + robot_config['temple_reward']

    formation_type = robot_config['formation_type'][rank % len(
        robot_config['formation_type'])]

    formation_config = game_config.temple_formation.get(formation_type)

    card_obj.formation = {
        'own': [formation_config['formation_id']],
        'current': formation_config['formation_id'],
    }

    tmp = {
        'skill_level': 1,
        'character_level': 1,
        'evo_level': 0,
        'role_level': 1,
    }

    for k in tmp:
        v = robot_config[k]
        v = range(v[1], v[0] - 1, -1)
        v = v[rank % len(v)]
        tmp[k] = v

    for _ in range(1, tmp['role_level']):
        card_obj.add_position_num(_)

    # 根据玩家等级限制上阵卡牌数量
    position_num = {
        'position_num': card_obj.position_num,
        'alternate_num': card_obj.alternate_num
    }

    formation_offset = (formation_index - 1) * 8

    for i in range(1, 9):
        if i <= 5:
            _tp = 'position_num'
            pos = i
        else:
            _tp = 'alternate_num'
            pos = i + 5

        if position_num[_tp] <= 0:
            continue
        c_id = formation_config['position%s' % (i + formation_offset)]
        if not c_id:
            continue
        card_id = card_obj.new(
            c_id,
            lv=tmp['character_level'],
            evo=tmp['evo_level'],
        )
        for _ in '12345':
            if 's_%s' % _ in card_obj._cards[card_id]:
                card_obj._cards[card_id]['s_%s' % _]['lv'] = tmp['skill_level']

        card_obj.set_alignment(card_id, pos)
        position_num[_tp] -= 1

    # ## card
    ######################################################

    ######################################################
    # ## leader_skill
    from models.skill import Skill
    leader_skill_obj = EmptyModelObj(Skill, robot_uid, server_name)
    for i in '123':
        s = robot_config['leader_skill_%s_key' % i]
        s_level = robot_config['leader_skill_%s_level' % i]
        leader_skill_obj.skill[s] = s_level
        setattr(leader_skill_obj, 'skill_' + i, s)
    # ## leader_skill
    ######################################################

    ######################################################
    # ## equip
    from models.equip import Equip
    equip_obj = EmptyModelObj(Equip, robot_uid, server_name)
    # ## equip
    ######################################################

    ######################################################
    # ## drama
    from models.drama import Drama
    drama_obj = EmptyModelObj(Drama, robot_uid, server_name)
    # ## drama
    ######################################################
    #######################################################
    # ## user
    # uid
    # user_name
    # role
    # level
    # exp

    ######################################################
    # ## arena
    from models.arena import Arena
    arena_obj = EmptyModelObj(Arena, robot_uid, server_name)
    # ## arena
    ######################################################

    from models.user import User as UserM

    user_m = EmptyModelObj(UserM, robot_uid, server_name)
    user_m.name = robot_name
    user_m.role = robot_config['role']
    user_m.level = tmp['role_level']
    user_m.regist_time = time.time() - 3600 * 24 * 10  # 注册时间戳
    user_m.active_time = time.time() - 3600 * 2
    user_m.continue_login_days = 5

    from logics.user import User
    user = User(robot_uid, user_m_obj=user_m)
    user.get = empty_func
    user.exp = user_m.exp
    for i in User._model_property_candidate_list:
        setattr(user, i[0], None)
    user.cards = card_obj
    setattr(card_obj, 'weak_user', weakref.proxy(user))
    user.equip = equip_obj
    setattr(equip_obj, 'weak_user', weakref.proxy(user))
    user.drama = drama_obj
    setattr(drama_obj, 'weak_user', weakref.proxy(user))
    user.leader_skill = leader_skill_obj
    setattr(leader_skill_obj, 'weak_user', weakref.proxy(user))
    user.arena = arena_obj
    setattr(arena_obj, 'weak_user', weakref.proxy(user))
    # ## user
    #######################################################

    return user
Esempio n. 2
0
def pyramid_robot(robot_uid,
                  robot_name,
                  server_name,
                  rank=0,
                  spec_level=0,
                  index=3,
                  evo_level=0):
    """# robot: 产生一个很拟人的机器人  金字塔机器人
    args:
        arg:    ---    arg
        rank:    机器人排名,根据此排名随机相关属性
        spec_level:    指定卡牌、用户、技能 等的级别
        第三个参数  robot_config_name='robot'
    returns:
        0    ---
    formation_type_config = {
        'formation_id': 1,
        'position1': 3800,
        'position2': 5300,
        'position3': 3000,
        'position4': 4100,
        'position5': 4000,
        'position6': 1400,
        'position7': 4700,
        'position8': 1000,
    },
    robot_config = {
        'formation_type': [1,2,3,4,5,6,7,8,9,10],
        'role': 1,
        'role_level': [41,50],
        'character_level': [67,85],
        'evo_level': [10,14],
        'skill_level': [22,23],
        'leader_skill_1_key': 201,
        'leader_skill_1_level': 5,
        'leader_skill_2_key': 212,
        'leader_skill_2_level': 5,
        'leader_skill_3_key': 232,
        'leader_skill_3_level': 4,
    }
    """
    uid = robot_uid.split('_')[index]
    uid = int(uid)
    import game_config
    robot_config = game_config.pyramid_robot.get('robot_%s' % uid)
    ######################################################
    # ## card
    from models.cards import Cards
    card_obj = EmptyModelObj(Cards, robot_uid, server_name)
    if not robot_name:
        formation_type = robot_config['formation_type'][rank % len(
            robot_config['formation_type'])]
    else:
        formation_type = random.choice(robot_config['formation_type'])
    formation_config = game_config.formation_type.get(formation_type)
    card_obj.formation = {
        'own': [formation_config['formation_id']],
        'current': formation_config['formation_id'],
    }

    tmp = {
        'skill_level': 1,
        'character_level': 1,
        'evo_level': 0,
        'role_level': 1,
    }

    if spec_level:  # 指定卡牌、用户等级
        tmp['character_level'] = spec_level
        tmp['role_level'] = spec_level
        tmp['evo_level'] = evo_level
    else:
        for k in tmp:
            v = robot_config[k]
            v = range(v[1], v[0] - 1, -1)
            v = v[rank % len(v)]
            tmp[k] = v

    for _ in range(1, tmp['role_level']):
        card_obj.add_position_num(_)

    # 根据玩家等级限制上阵卡牌数量
    position_num = {
        'position_num': card_obj.position_num,
        'alternate_num': card_obj.alternate_num
    }
    for i in range(1, 9):
        if i <= 5:
            _tp = 'position_num'
            pos = i
        else:
            _tp = 'alternate_num'
            pos = i + 5

        if position_num[_tp] <= 0:
            continue
        c_id = formation_config['position%s' % i]
        if not c_id:
            continue
        card_id = card_obj.new(
            c_id,
            lv=tmp['character_level'],
            evo=tmp['evo_level'],
        )
        for _ in '12345':
            if 's_%s' % _ in card_obj._cards[card_id]:
                card_obj._cards[card_id]['s_%s' % _]['lv'] = tmp['skill_level']

        card_obj.set_alignment(card_id, pos)
        position_num[_tp] -= 1
    # ## card
    ######################################################

    ######################################################
    # ## leader_skill
    from models.skill import Skill
    leader_skill_obj = EmptyModelObj(Skill, robot_uid, server_name)
    for i in '123':
        s = robot_config['leader_skill_%s_key' % i]
        s_level = robot_config['leader_skill_%s_level' % i]
        leader_skill_obj.skill[s] = s_level
        setattr(leader_skill_obj, 'skill_' + i, s)
    # ## leader_skill
    ######################################################

    ######################################################
    # ## equip
    from models.equip import Equip
    equip_obj = EmptyModelObj(Equip, robot_uid, server_name)
    # ## equip
    ######################################################

    ######################################################
    # ## drama
    from models.drama import Drama
    drama_obj = EmptyModelObj(Drama, robot_uid, server_name)
    # ## drama
    ######################################################

    #######################################################
    # ## user
    # uid
    # user_name
    # role
    # level
    # exp

    ######################################################
    # ## arena
    from models.arena import Arena
    arena_obj = EmptyModelObj(Arena, robot_uid, server_name)
    # ## arena
    ######################################################

    from models.user import User as UserM

    first_name = game_config.random_first_name[rank % len(
        game_config.random_first_name)]
    last_name = game_config.random_last_name[rank %
                                             len(game_config.random_last_name)]

    user_m = EmptyModelObj(UserM, robot_uid, server_name)
    # user_m.name = first_name + last_name
    user_m.name = robot_name or first_name + last_name
    user_m.role = robot_config['role']
    user_m.level = tmp['role_level']
    user_m.regist_time = time.time() - 3600 * 24 * 10  # 注册时间戳
    user_m.active_time = time.time() - 3600 * 2
    user_m.continue_login_days = 5

    from logics.user import User
    user = User(robot_uid, user_m_obj=user_m)
    user.get = empty_func
    user.exp = user_m.exp
    for i in User._model_property_candidate_list:
        setattr(user, i[0], None)
    user.cards = card_obj
    setattr(card_obj, 'weak_user', weakref.proxy(user))
    user.equip = equip_obj
    setattr(equip_obj, 'weak_user', weakref.proxy(user))
    user.drama = drama_obj
    setattr(drama_obj, 'weak_user', weakref.proxy(user))
    user.leader_skill = leader_skill_obj
    setattr(leader_skill_obj, 'weak_user', weakref.proxy(user))
    user.arena = arena_obj
    setattr(arena_obj, 'weak_user', weakref.proxy(user))
    # ## user
    #######################################################

    return user