Ejemplo n.º 1
0
def options_edit(options):
    """The actual edit interface for options"""
    edited: UserOptions = UserOptions()
    clear_screen()
    typed_print(f'You chose to edit {options}, here are the current values:')
    print()

    conn = db_create_connection()
    pulled_options = db_return_class_object(conn, 'useroptions', 'type',
                                            options, UserOptions)
    conn.close()

    field_dict = print_class_data(pulled_options, "<15", '')

    print()
    typed_print(
        f'Enter a field to edit or (C) to return to options menu. '
        f'Example {cb}[Type_print]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input()
        print(ce, end='')
        if menu_choice in field_dict:
            edited_options = edit_class_data(pulled_options, menu_choice,
                                             field_dict, UserOptions)
            edited = edited_options[0]
            success = edited_options[1]
            if success is True:
                print()
                typed_print(
                    f"Value was updated, enter another to edit, (C) to cancel,"
                    f" or (S) to save: {cb}",
                    new_line=False)
            else:
                typed_print(
                    f'That did not work. Enter a field to edit, or (C) to return to Races menu. '
                    f'Example {cb}[Type_speed]{ce}:{cb} ',
                    new_line=False)
            continue
        elif menu_choice.lower() == 'c':
            return options_menu()
        elif menu_choice.lower() == 's':
            conn = db_create_connection()
            with conn:
                db_update_class_in_table(conn, edited, 'useroptions', 'type',
                                         'User Options')
            conn.close()
            return options_menu()
        else:
            typed_print(
                f'Value entered: {cb}{menu_choice}{ce} is not valid, please reenter: {cb} ',
                new_line=False)
Ejemplo n.º 2
0
def item_admin_menu():
    """Menu for editing, creating, or deleting items"""
    clear_screen()
    conn = db_create_connection()
    item_list = []
    pulled_items = db_select_values(conn, 'items', 'name')
    for row in pulled_items:
        item_list.append(row['name'])
    item_dict = list_to_num_dict(item_list)
    typed_print('This is the administration menu for Items.')
    print()
    print_list(item_dict, var_type='dict')
    print()
    typed_print(
        f'Choose an item above, ({cb}n{ce})ew to create new item,  or ({cb}c{ce})ancel to return to '
        f'the admin menu{cb}[?, n, c]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input().lower()
        print(ce, end='')
        if menu_choice in item_dict.keys():
            return item_admin_edit(item_dict[menu_choice])
        elif menu_choice == 'c':
            return admin_menu()
        elif menu_choice == 'n':
            return item_admin_edit(Items(), new=True)
        else:
            typed_print(
                f'Invalid option! Enter a number, n, or c to return to admin menu! '
                f'{cb}[?,c]{ce}:{cb} ',
                new_line=False)
Ejemplo n.º 3
0
def archetype_admin_menu():
    """Menu for editing, creating, or deleting archetypes"""
    clear_screen()
    options_list = []
    conn = db_create_connection()
    results = db_select_values(conn, 'archetype', 'name')
    for row in results:
        options_list.append(row['name'])
    conn.close()
    item_dict = list_to_num_dict(options_list)
    typed_print('This is the administration menu for Archetypes.')
    print()
    print_list(item_dict, var_type='dict')
    print()
    typed_print(
        f'Choose a choice above, (N) to create new Archetype,  or (C) to return to the admin menu'
        f' {cb}[?, c]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input().lower()
        print(ce, end='')
        if menu_choice in item_dict.keys():
            return archetype_admin_edit(item_dict[menu_choice])
        elif menu_choice == 'c':
            return admin_menu()
        elif menu_choice == 'n':
            return archetype_admin_edit(Archetype(), new=True)
        else:
            typed_print(
                f'Invalid option! Enter a number or c to return to admin menu! '
                f'{cb}[?,c]{ce}:{cb} ',
                new_line=False)
Ejemplo n.º 4
0
def options_menu():
    clear_screen()
    typed_print(f'Options menu:')
    print()
    options_list = []
    conn = db_create_connection()
    results = db_select_values(conn, 'useroptions', 'type')
    for row in results:
        options_list.append(row['type'])
    conn.close()
    item_dict = list_to_num_dict(options_list)
    print_list(item_dict, 'dict')
    print()
    typed_print(
        f'Enter options menu to view, or (C) to return to start menu {cb}[?,c]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input().lower()
        print(ce, end='')
        if menu_choice in item_dict.keys():
            return options_edit(item_dict[menu_choice])
        elif menu_choice == 'c':
            return start_menu()
        else:
            typed_print(
                f'Invalid option! Enter a number or c to return to admin menu! '
                f'{cb}[?,c]{ce}:{cb} ',
                new_line=False)
Ejemplo n.º 5
0
def char_class_choice(char_build: Player):
    clear_screen()
    pulled_archetypes = []
    conn = db_create_connection()
    archetype_returned = db_select_values(conn, 'archetype', 'name')
    for row in archetype_returned:
        pulled_archetypes.append(row['name'])
    conn.close()
    item_dict = list_to_num_dict(pulled_archetypes)
    typed_print(f'Now choose an Archetype for your {char_build.Player_race}!')
    print()
    print_list(item_dict, var_type='dict')
    print()
    typed_print(
        f'Please choose a class or ({cb}C{ce})ancel character creation {cb}[?,c]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input().lower()
        print(ce, end='')
        if menu_choice in item_dict.keys():
            return char_class_build(char_build, item_dict[menu_choice])

        elif menu_choice == 'c':
            return {'Success': False}
        else:
            typed_print(
                f'Invalid option! Enter a number or ({cb}C{ce})ancel character creation! '
                f'{cb}[?,c]{ce}:{cb} ',
                new_line=False)
Ejemplo n.º 6
0
def char_creation():
    clear_screen()
    races_list = []
    conn = db_create_connection('db/dnd.db')
    results = db_select_values(conn, 'races', 'name')
    for row in results:
        races_list.append(row['name'])
    conn.close()
    item_dict = list_to_num_dict(races_list)
    typed_print("Now let's pick a race!")
    print()
    print_list(item_dict, var_type='dict')
    print()
    typed_print(
        f'Please choose one of the above or cancel character creation {cb}[?,c]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input().lower()
        print(ce, end='')
        if menu_choice in item_dict.keys():
            return new_char_race(item_dict[menu_choice])
        elif menu_choice == 'c':
            return menu.start_menu()
        else:
            typed_print(
                f'Invalid option! Enter a number or c to return to admin menu! '
                f'{cb}[?,c]{ce}:{cb} ',
                new_line=False)
Ejemplo n.º 7
0
def pull_options():
    conn = db_create_connection('db/dnd.db')
    with conn:
        user_option = db_return_class_object(conn, 'useroptions', 'type',
                                             'User Options', UserOptions)
    conn.close()
    return user_option
Ejemplo n.º 8
0
def saved_game_menu():
    """List all saved games"""
    clear_screen()
    saves_list = []
    conn = db_create_connection()
    pulled_saves = db_select_values(conn, 'saves', 'player_name')
    if len(pulled_saves) > 0:
        for row in pulled_saves:
            saves_list.append(row['player_name'])
    else:
        typed_print(
            'There are no saved games yet, hit enter key to return to start menu......',
            new_line=False)
        input()
        return start_menu()

    item_dict = list_to_num_dict(saves_list)
    typed_print('Here are the current saved games:')
    print()
    print_list(item_dict, var_type='dict')
    print()
    typed_print(
        f'Select a saved game above or (C) to cancel {cb}[?, c]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input()
        print(ce, end='')
        if menu_choice in item_dict.keys():
            return load_saved(item_dict[menu_choice])
        elif menu_choice == 'c':
            return start_menu()
        else:
            typed_print(
                f'Invalid option! Enter a number or c to return to admin menu! '
                f'{cb}[?,c]{ce}:{cb} ',
                new_line=False)
Ejemplo n.º 9
0
def load_saved(saved_game: str):
    clear_screen()

    typed_print(f'Here are the current values for {cy}{saved_game}{ce}:')
    print()

    # char_build: Player
    conn = db_create_connection()
    char_build: Player = db_return_class_object(conn, 'saves', 'player_name',
                                                saved_game, Player)
    char_build.Race_details = db_return_class_object(conn, 'races', 'name',
                                                     char_build.Player_race,
                                                     Race)
    char_build.Arch_details = db_return_class_object(conn, 'archetype', 'name',
                                                     char_build.Player_type,
                                                     Archetype)
    char_build.Inventory = db_create_inventory_dict(conn,
                                                    char_build.Player_name)
    conn.close()

    typed_print(
        f"You are a {cb}{char_build.Player_race} {char_build.Player_type}{ce}"
        f" named {cy}{char_build.Player_name}{ce}.")
    print()
    typed_print(f"{'Level:':<14} {cb}{char_build.Level}{ce}")
    typed_print(f"{'XP:':<14} {cb}{char_build.XP}{ce}")
    typed_print(f"{'Height:':<14} {cb}{char_build.Height}{ce}")
    typed_print(f"{'Weight:':<14} {cb}{char_build.Weight} lbs{ce}")
    typed_print(f"{'Age:':<14} {cb}{char_build.Age}{ce}")
    typed_print(f"{'Hit points:':<14} {cb}{char_build.Current_HP}{ce}")
    typed_print(f"{'Armor Class:':14} {cb}{char_build.AC}{ce}")
    typed_print(
        f"{'Load/Max Load:':14} {cb}{char_build.Current_weight}/{char_build.Carry_weight}{ce}"
    )
    print()
    typed_print(f"{cbol}{lg}{'Attribute':<14} {'Stat':<4} Mod{ce}")
    typed_print('-----------------------')
    typed_print(
        f"{'Strength:':<14} {cb}{char_build.Str:<4}{ce} {stat_bonus(char_build.Str, colored=True)}"
    )
    typed_print(
        f"{'Dexterity:':<14} {cb}{char_build.Dex:<4}{ce} {stat_bonus(char_build.Dex, colored=True)}"
    )
    typed_print(
        f"{'Constitution:':<14} {cb}{char_build.Con:<4}{ce} {stat_bonus(char_build.Con, colored=True)}"
    )
    typed_print(
        f"{'Wisdom:':<14} {cb}{char_build.Wis:<4}{ce} {stat_bonus(char_build.Wis, colored=True)}"
    )
    typed_print(
        f"{'Intelligence:':<14} {cb}{char_build.Int:<4}{ce} {stat_bonus(char_build.Int, colored=True)}"
    )
    typed_print(
        f"{'Charisma:':<14} {cb}{char_build.Cha:<4}{ce} {stat_bonus(char_build.Cha, colored=True)}"
    )
    print()
    typed_print(
        f'Type ({cb}l{ce})oad, ({cb}c{ce})ancel, or ({cb}d{ce})elete '
        f'to continue: {cb}[l, d, c]{ce}:{cb} ',
        new_line=False)

    while True:
        load_response = input()
        print(ce, end='')
        if load_response.lower() == 'l':
            return curses.wrapper(start_main, char_build)
        elif load_response.lower() == 'd':
            typed_print(
                f'{cr}WARNING!!!{ce} are you SURE you wish to delete saved game {cy}{saved_game}{ce}?'
                f' {cb}[Yes,no]{ce}:{cb} ',
                new_line=False)
            delete = input()
            print(ce, end='')
            if delete.lower() == 'yes':
                conn = db_create_connection()
                db_delete_row(conn, 'saves', 'player_name', saved_game)
                conn.close()
            return saved_game_menu()
        elif load_response.lower() == 'c':
            return saved_game_menu()
        else:
            typed_print(
                f'Invalid response: "{cb}{load_response}{ce}". Type ({cb}l{ce})oad'
                f', ({cb}c{ce})ancel, or ({cb}d{ce})elete to continue: {cb}[l, d, c]{ce}:{cb} ',
                new_line=False)
            continue
Ejemplo n.º 10
0
def item_admin_edit(item, new=False):
    """The actual edit interface for items"""
    edited: Items = Items()
    clear_screen()
    if new:
        typed_print(f"You've chosen to create a new Item.")
    else:
        typed_print(
            f'You chose to edit {cb}{item}{ce}, here are the current values:')
    print()
    if not new:
        conn = db_create_connection()
        pulled_item = db_return_class_object(conn, 'items', 'name', item,
                                             Items)
    else:
        pulled_item = item
    field_dict = print_class_data(pulled_item, col_one='<12', col_two='<30')
    print()
    typed_print(
        f'Enter a field to edit, ({cb}d{ce})elete to delete item, or ({cb}c{ce})ancel to return'
        f' to Items menu. Example {cb}[Name]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input()
        print(ce, end='')
        edited: Items
        if menu_choice in field_dict:
            edited_item = edit_class_data(pulled_item, menu_choice, field_dict,
                                          Items)
            edited = edited_item[0]
            success = edited_item[1]
            if success is True:
                print()
                typed_print(
                    f"{cy}SUCCESS!{ce}, enter another to edit, ({cb}C{ce}) to cancel,"
                    f" or ({cb}S{ce}) to save: {cb}",
                    new_line=False)
            else:
                typed_print(
                    f'There was an error. Enter a field to edit, or ({cb}C{ce}) to return to Items menu. '
                    f'Example {cb}[Name]{ce}:{cb} ',
                    new_line=False)
            continue
        elif menu_choice.lower() == 'c':
            return item_admin_menu()
        elif menu_choice.lower() == 's':
            conn = db_create_connection()
            if new:
                db_insert_class_in_table(conn, edited, 'items')
            else:
                db_update_class_in_table(conn, edited, 'items', 'name',
                                         edited.Name)
            conn.close()
            return item_admin_menu()
        elif menu_choice.lower() == 'd':
            result = input(
                f'Are you SURE you wish to {cr}DELETE{ce} item: {cb}{item}{ce} [yes,n]? '
            )
            if result.lower() == 'yes':
                conn = db_create_connection()
                db_delete_row(conn, 'items', 'name', item)
                return item_admin_menu()
            else:
                input(
                    f'Item: {cb}{item}{ce} was not deleted. Press enter to continue...'
                )
                return item_admin_menu()
        else:
            typed_print(
                f'Value entered: {cb}{menu_choice}{ce} is not valid, please reenter: {cb} ',
                new_line=False)
Ejemplo n.º 11
0
def archetype_admin_edit(archetype, new=False):
    """The actual edit interface for archetype"""
    edited: Archetype = Archetype()
    clear_screen()
    if new:
        typed_print(f"You've chosen to create a new Archetype.")
    else:
        typed_print(
            f'You chose to edit {archetype}, here are the current values:')
    print()

    if not new:
        conn = db_create_connection()
        pulled_archetype = db_return_class_object(conn, 'archetype', 'name',
                                                  archetype, Archetype())
    else:
        pulled_archetype = archetype

    field_dict = print_class_data(pulled_archetype)
    print()
    typed_print(
        f'Enter a field to edit, (D) to delete race, or (C) to return to Races menu. '
        f'Example {cb}[Str]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input()
        print(ce, end='')
        if menu_choice in field_dict:
            edited_archetype = edit_class_data(pulled_archetype, menu_choice,
                                               field_dict, Archetype)
            edited = edited_archetype[0]
            success = edited_archetype[1]
            if success is True:
                print()
                typed_print(
                    f"Value was updated, enter another to edit or (S) to save: {cb}",
                    new_line=False)
            else:
                typed_print(
                    f'There was an error. Enter a field to edit, or (C) to return to Races menu. '
                    f'Example {cb}[Str]{ce}:{cb} ',
                    new_line=False)
            continue
        elif menu_choice.lower() == 'c':
            return archetype_admin_menu()
        elif menu_choice.lower() == 's':
            conn = db_create_connection()
            if new:
                db_insert_class_in_table(conn, edited, 'archetype')
            else:
                db_update_class_in_table(conn, edited, 'archetype', 'name',
                                         edited.Name)
            conn.close()
            return archetype_admin_menu()
        elif menu_choice.lower() == 'd':
            result = input(
                f'Are you SURE you wish to {cr}DELETE{ce} Archetype: {cb}{archetype}{ce} [yes,n]? '
            )
            if result.lower() == 'yes':
                conn = db_create_connection()
                db_delete_row(conn, 'archetype', 'name', archetype)
                conn.close()
                return archetype_admin_menu()
            else:
                input(
                    f'Archetype: {cb}{archetype}{ce} not deleted! Press enter to continue...'
                )
                return archetype_admin_menu()
        else:
            typed_print(
                f'Value entered: {cb}{menu_choice}{ce} is not valid, please reenter: {cb} ',
                new_line=False)
Ejemplo n.º 12
0
def races_admin_edit(dataclass, table, race=None, new=False):
    """The actual edit interface for races"""

    edited: dataclass = dataclass
    clear_screen()
    if new:
        typed_print(f"You've chosen to create a new Race.")
    else:
        typed_print(
            f'You chose to edit {cb}{race}{ce}, here are the current values:')
    print()

    if not new:
        conn = db_create_connection()
        pulled_race = db_return_class_object(conn, table, 'name', race,
                                             dataclass)
        conn.close()
    else:
        pulled_race = dataclass

    field_dict = print_class_data(pulled_race)
    print()
    typed_print(
        f'Enter a field to edit, ({cb}d{ce}) to delete race, or ({cb}c{ce}) to return to Races menu. '
        f'Example {cb}[Name]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input()
        print(ce, end='')
        if menu_choice in field_dict:
            edited_race = edit_class_data(pulled_race, menu_choice, field_dict,
                                          dataclass)
            edited = edited_race[0]
            success = edited_race[1]
            if success is True:
                print()
                typed_print(
                    f"{cy}SUCCESS!{ce}, enter another to edit, ({cb}C{ce}) to cancel,"
                    f" or ({cb}S{ce}) to save: {cb}",
                    new_line=False)
            else:
                typed_print(
                    f'There was an error. Enter a field to edit, or ({cb}C{ce}) to return to Races menu. '
                    f'Example {cb}[Str]{ce}:{cb} ',
                    new_line=False)
            continue
        elif menu_choice.lower() == 'c':
            return races_admin_menu()
        elif menu_choice.lower() == 's':
            conn = db_create_connection()
            if not new:
                db_update_class_in_table(conn, edited, table, 'name',
                                         edited.Name)
            else:
                db_insert_class_in_table(conn, edited, table)
            conn.close()
            return races_admin_menu()
        elif menu_choice.lower() == 'd':
            result = input(
                f'Are you SURE you wish to {cr}DELETE{ce} Race: {cb}{race}{ce} [yes,n]? '
            )
            if result.lower() == 'yes':
                conn = db_create_connection()
                db_delete_row(conn, table, 'name', race)
                conn.close()
                return races_admin_menu()
            else:
                input(
                    f'Race: {cb}{race}{ce} was not deleted. Press enter to continue...'
                )
                return races_admin_menu()
        else:
            typed_print(
                f'Value entered: {cb}{menu_choice}{ce} is not valid, please reenter: {cb} ',
                new_line=False)
Ejemplo n.º 13
0
def races_admin_menu():
    """Menu for editing, creating, or deleting races"""
    conn = db_create_connection()
    clear_screen()
    print('What type of race do you wish to work with?')
    print()

    race_type = {1: 'Player Character (PC)', 2: 'Non-Player Character (NPC)'}
    print_list(race_type, var_type='dict')

    print()
    print(f'Choose an option or ({cb}c{ce}) to cancel: {cb}', end='')

    while True:
        type_choice = input()
        print(ce, end='')

        if type_choice == '1' or type_choice == '2':
            races_list = []
            if type_choice == '1':
                dataclass_type = Race()
                table = 'races'
                results = db_select_values(conn, 'races', 'name')
                for row in results:
                    races_list.append(row['name'])
            else:
                dataclass_type = NPCRace()
                table = 'npcraces'
                results = db_select_values(conn, 'npcraces', 'name')
                for row in results:
                    races_list.append(row['name'])
            conn.close()
            item_dict = list_to_num_dict(races_list)
            break
        elif type_choice == 'c':
            return admin_menu()
        else:
            print(
                f'{cb}{type_choice}{ce} was not a valid choice, try again: {cb}',
                end='')

    clear_screen()

    typed_print(
        f'This is the administration menu for {"Player" if type_choice == "1" else "NPC"} Races.'
    )
    print()
    print_list(item_dict, var_type='dict')
    print()
    typed_print(
        f'Choose a Race above, ({cb}N{ce}) to create new race,  or ({cb}C{ce}) to return to the admin menu'
        f' {cb}[?, n, c]{ce}:{cb} ',
        new_line=False)

    while True:
        menu_choice = input().lower()
        print(ce, end='')
        if menu_choice in item_dict.keys():
            return races_admin_edit(dataclass_type, table,
                                    item_dict[menu_choice])
        elif menu_choice.lower() == 'c':
            return admin_menu()
        elif menu_choice.lower() == 'n':
            return races_admin_edit(dataclass_type, table, new=True)
        else:
            typed_print(
                f'Invalid option! Enter a number or c to return to admin menu! '
                f'{cb}[?,c]{ce}:{cb} ',
                new_line=False)
Ejemplo n.º 14
0
def new_char_race(race):
    # This creates the new_char_stats dictionary, pulls the race settings from the races.py file
    # and randomly creates the details of the character using the parameters specified in the races file.

    conn = db_create_connection('db/dnd.db')
    pulled_race: Race = db_return_class_object(conn, 'races', 'name', race,
                                               Race)
    conn.close()

    first_run: bool = True

    def roll_char():
        pre_char_build = Player(Player_race=pulled_race.Name)
        pre_char_build.Str = dice(6, rolls=3,
                                  reroll_ones=True) + pulled_race.Str
        pre_char_build.Dex = dice(6, rolls=3,
                                  reroll_ones=True) + pulled_race.Dex
        pre_char_build.Con = dice(6, rolls=3,
                                  reroll_ones=True) + pulled_race.Con
        pre_char_build.Wis = dice(6, rolls=3,
                                  reroll_ones=True) + pulled_race.Wis
        pre_char_build.Int = dice(6, rolls=3,
                                  reroll_ones=True) + pulled_race.Int
        pre_char_build.Cha = dice(6, rolls=3,
                                  reroll_ones=True) + pulled_race.Cha
        pre_char_build.Height = feet_inch(
            randint(int(pulled_race.Height[0]), int(pulled_race.Height[1])))
        pre_char_build.Weight = randint(pulled_race.Weight[0],
                                        pulled_race.Weight[1])
        pre_char_build.Age = randint(pulled_race.Age[0], pulled_race.Age[1])

        # Here we figure out what the modifiers are for the above rolled stats
        str_bonus = stat_bonus(int(pre_char_build.Str), colored=True)
        dex_bonus = stat_bonus(int(pre_char_build.Dex), colored=True)
        con_bonus = stat_bonus(int(pre_char_build.Con), colored=True)
        wis_bonus = stat_bonus(int(pre_char_build.Wis), colored=True)
        int_bonus = stat_bonus(int(pre_char_build.Int), colored=True)
        cha_bonus = stat_bonus(int(pre_char_build.Cha), colored=True)
        clear_screen()

        # Here we start printing out the created character stats
        typed_print('Here are your characters stats:')
        print()
        typed_print(f"Race: {cb}{pre_char_build.Player_race}{ce}")
        typed_print(f"Height: {cb}{pre_char_build.Height}{ce}")
        typed_print(f"Weight: {cb}{pre_char_build.Weight} lbs{ce}")
        typed_print(f"Age: {cb}{pre_char_build.Age}{ce}")
        print()
        typed_print(f"{'Attribute':<14} {'Stat':<4} Mod")
        typed_print('-----------------------')
        typed_print(
            f"{'Strength:':<14} {cb}{pre_char_build.Str:<4}{ce} {str(str_bonus):>2}"
        )
        typed_print(
            f"{'Dexterity:':<14} {cb}{pre_char_build.Dex:<4}{ce} {str(dex_bonus):>2}"
        )
        typed_print(
            f"{'Constitution:':<14} {cb}{pre_char_build.Con:<4}{ce} {str(con_bonus):>2}"
        )
        typed_print(
            f"{'Wisdom:':<14} {cb}{pre_char_build.Wis:<4}{ce} {str(wis_bonus):>2}"
        )
        typed_print(
            f"{'Intelligence:':<14} {cb}{pre_char_build.Int:<4}{ce} {str(int_bonus):>2}"
        )
        typed_print(
            f"{'Charisma:':<14} {cb}{pre_char_build.Cha:<4}{ce} {str(cha_bonus):>2}"
        )
        print()
        typed_print(
            f"Do you want to {cb}(C){ce}ancel creation, {cb}(R){ce}eroll, "
            f"or {cb}(A){ce}ccept these stats? {cb}[c,r,a]{ce}:{cb} ",
            new_line=False)

        return pre_char_build

    char_build: Player = Player()
    if first_run:
        first_run ^= first_run
        char_build = roll_char()

    while True:
        reroll = input()
        print(ce, end='')
        if reroll.lower() == "r":
            char_build = roll_char()
            continue
        elif reroll.lower() == 'c':
            return menu.start_menu()
        elif reroll.lower() == 'a':
            return char_class_choice(char_build)
        else:
            typed_print(
                'Invalid choice! Choose (C)ancel creation, (R)eroll, or (A)ccept! [c,r,a]:  '
            )
Ejemplo n.º 15
0
def char_class_build(char_build: Player, player_choice: str) -> dict:
    conn = db_create_connection()
    pulled_archetype: Archetype = db_return_class_object(
        conn, 'archetype', 'name', player_choice, Archetype)
    char_build.Player_type = pulled_archetype.Name

    # Here we're going to roll for hit points, breaking the processes out into the different parts so we can
    # lay it all out for the user then add the total hit points rolled into the dictionary
    try:
        hit_die = pulled_archetype.Hit_die
        con_mod = stat_bonus(char_build.Con)
        dex_mod = stat_bonus(char_build.Dex)
        hp_roll = dice(hit_die, reroll_ones=True)
        tot_hp = hp_roll + con_mod + 8
        this_class = char_build.Player_type
        this_race = char_build.Player_race
        char_build.Max_HP = tot_hp

        # Now well figure out the base AC (10 + Dex mod) and add that to the dataclass
        char_build.AC = 10 + stat_bonus(char_build.Dex)

        # And the carry weight
        char_build.Carry_weight = 10 * char_build.Str

        clear_screen()
        typed_print(f'You have chosen to become a {this_race} {this_class}!')
        print()
        typed_print(f'Every race starts with {cb}8{ce} hit points. ')
        typed_print(
            f'You rolled a {cb}d{hit_die}{ce} for class hit points getting a roll of {cb}{hp_roll}{ce}.'
        )
        typed_print(
            f'With your constitution modifier of {cb if con_mod >= 0 else cr}{con_mod}{ce} '
            f'your total hit points are now {cb}{tot_hp}{ce}')
        print()
        typed_print(
            f'Your base armor class will be {cb}{char_build.AC}{ce}. '
            f'(10 + Dexterity modifier of {cb if dex_mod >= 0 else cr}{dex_mod}{ce})'
        )
        print()
        typed_print(
            f'Your carry weight will be {cb}{char_build.Carry_weight} lbs{ce} This is figured by'
            f'(10 x Strength)')
        typed_print(
            'Now enter a name for your character, then review character creation: ',
            new_line=False)
        char_build.Player_name = input()

        clear_screen()

        # Here we figure out what the final stats and modifiers are
        typed_print('Here are your final characters stats:')
        print()
        typed_print(
            f"You are a {cb}{char_build.Player_race} {char_build.Player_type}{ce}"
            f" named {cy}{char_build.Player_name}{ce}.")
        print()
        typed_print(f"{'Height:':<14} {cb}{char_build.Height}{ce}")
        typed_print(f"{'Weight:':<14} {cb}{char_build.Weight} lbs{ce}")
        typed_print(f"{'Age:':<14} {cb}{char_build.Age}{ce}")
        typed_print(f"{'Hit points:':<14} {cb}{char_build.Max_HP}{ce}")
        typed_print(f"{'Armor Class:':<14} {cb}{char_build.AC}{ce}")
        typed_print(f"{'Max Load:':14} {cb}{char_build.Carry_weight}{ce}")
        print()
        typed_print(f"{cbol}{lg}{'Attribute':<14} {'Stat':<4} Mod{ce}")
        typed_print('-----------------------')
        typed_print(
            f"{'Strength:':<14} {cb}{char_build.Str:<4}{ce} {stat_bonus(char_build.Str, colored=True)}"
        )
        typed_print(
            f"{'Dexterity:':<14} {cb}{char_build.Dex:<4}{ce} {stat_bonus(char_build.Dex, colored=True)}"
        )
        typed_print(
            f"{'Constitution:':<14} {cb}{char_build.Con:<4}{ce} {stat_bonus(char_build.Con, colored=True)}"
        )
        typed_print(
            f"{'Wisdom:':<14} {cb}{char_build.Wis:<4}{ce} {stat_bonus(char_build.Wis, colored=True)}"
        )
        typed_print(
            f"{'Intelligence:':<14} {cb}{char_build.Int:<4}{ce} {stat_bonus(char_build.Int, colored=True)}"
        )
        typed_print(
            f"{'Charisma:':<14} {cb}{char_build.Cha:<4}{ce} {stat_bonus(char_build.Cha, colored=True)}"
        )
        print()
        typed_print(
            'Choose (A)ccept to continue with this character or (C) to try again [a,c]: ',
            new_line=False)

        while True:
            final_choice = input()
            if final_choice.lower() == 'a':
                char_build.Current_HP = char_build.Max_HP
                # Figure out what the starting inventory is
                starting_inv = {}
                num = 0
                conn = db_create_connection()
                for each in pulled_archetype.Items:
                    item = db_return_class_object(conn, 'items', 'name', each,
                                                  Items)
                    starting_inv[num] = map_items_to_inventory(
                        item, char_build.Player_name)
                    num += 1
                # write it all off to the DB
                db_insert_class_in_table(conn, char_build, 'saves')
                db_insert_inventory_char_creation(conn, starting_inv)
                conn.close()
                return curses.wrapper(start_main, char_build)
            elif final_choice.lower() == 'c':
                conn.close()
                return menu.start_menu()
            else:
                typed_print('Choice was not valid. Enter A or C! [a,c]: ',
                            new_line=False)
    except Exception as ex:
        print(f'Something went wrong in final character creation: {ex}')
        input('Press enter to continue to start menu....')
        return menu.start_menu()