Exemple #1
0
def inventory_menu(player, header):
    """
    Show a menu with each item of the inventory as an option.
    """
    if len(player.inventory) == 0:
        renderer.menu(header, 'Inventory is empty.', INVENTORY_WIDTH)
        return None

    options = []
    for obj in player.inventory:
        text = obj.name
        # Show additional information, in case it's equipped.
        if obj.item.count > 1:
            text = text + ' (x' + str(obj.item.count) + ')'
        if obj.equipment and obj.equipment.is_equipped:
            text = text + ' (' + obj.equipment.slot + ')'
        options.append(text)

    (char, index) = renderer.menu(header, options, INVENTORY_WIDTH)

    if index is not None:
        return player.inventory[index].item

    if char == ord('x'):
        (c2, i2) = renderer.menu('Press the key next to an item to examine it, or any other to cancel.\n', options, INVENTORY_WIDTH)
        if i2 is not None and player.inventory[i2].item.description is not None:
            # renderer.msgbox(player.inventory[i2].item.description)
            log.message(player.inventory[i2].item.description)

    return None
def inventory_menu(player, header):
    """
    Show a menu with each item of the inventory as an option.
    """
    if len(player.inventory) == 0:
        renderer.menu(header, 'Inventory is empty.', INVENTORY_WIDTH)
        return None

    options = []
    for obj in player.inventory:
        text = obj.name
        # Show additional information, in case it's equipped.
        if obj.item.count > 1:
            text = text + ' (x' + str(obj.item.count) + ')'
        if obj.equipment and obj.equipment.is_equipped:
            text = text + ' (on ' + obj.equipment.slot + ')'
        options.append(text)

    (char, index) = renderer.menu(header, options, INVENTORY_WIDTH)

    if index is not None:
        return player.inventory[index].item

    if char == ord('x'):
        (c2, i2) = renderer.menu('Press the key next to an item to examine it, or any other to cancel.\n', options, INVENTORY_WIDTH)
        if i2 is not None and player.inventory[i2].item.description is not None:
            # renderer.msgbox(player.inventory[i2].item.description)
            log.message(player.inventory[i2].item.description)

    return None
Exemple #3
0
def inventory_menu(player, header):
    if len(player.inventory) == 0:
        renderer.menu(header, 'Inventory is empty.', config.INVENTORY_WIDTH)
        return None
    else:
        options = [item.name for item in player.inventory]

    index = renderer.menu(header, options, config.INVENTORY_WIDTH)
    return player.inventory[index].item
Exemple #4
0
def increase_player_skills(player):
    while True:
        options = [
            s.name + ': currently ' +
            str(player.fighter.skills.get(s.name, 0)) + ', costs ' +
            str(s.cost) + ' sp' for s in skill_list
        ]

        # Make sure log.message() displays as we loop
        renderer.render_all(player, None)
        (key, target) = renderer.menu(
            'Choose skill to increase, or x to explain:\n' + '(' +
            str(player.skill_points) + ' skill points available)\n', options,
            INVENTORY_WIDTH)
        if key == ord('x'):
            (c2, i2) = renderer.menu(
                'Choose skill to describe, or any other to cancel.\n\n',
                options, INVENTORY_WIDTH)
            if i2 is not None:
                log.message(skill_list[i2].name + ': ' +
                            skill_list[i2].description)

        if target is None:  # 0 *is* a valid target
            return

        if skill_list[target].cost > player.skill_points:
            log.message(skill_list[target].name.capitalize() + ' costs ' +
                        str(skill_list[target].cost) +
                        ' skill points, you only have ' +
                        str(player.skill_points))
            continue

        value = player.fighter.skills.get(skill_list[target].name, 10)
        if value >= 250:
            log.message(skill_list[target].name.capitalize() +
                        ' is already at its maximum.')
            continue

        player.skill_points -= skill_list[target].cost
        if value < 100:
            value += libtcod.random_get_int(0, 1, 8)
        elif value < 150:
            value += libtcod.random_get_int(0, 1, 4)
        elif value < 200:
            value += libtcod.random_get_int(0, 1, 2)
        elif value < 250:
            value += 1
        player.fighter.skills[skill_list[target].name] = value
        log.message('Increased ' + skill_list[target].name + ' to ' +
                    str(value))
def check_level_up(player):
    """
    If the player has enough experience, level up immediately.
    """
    level_up_xp = LEVEL_UP_BASE + player.level * LEVEL_UP_FACTOR
    if player.fighter.xp >= level_up_xp:
        player.level += 1
        player.fighter.xp -= level_up_xp
        log.message('Your battle skills grow stronger! You reached level ' + str(player.level) + '!', libtcod.yellow)

        choice = None
        while choice is None:
            (char, choice) = renderer.menu(
                'Level up! Choose a stat to raise:\n',
                ['Constitution (+20 HP, from ' + str(player.fighter.max_hp) + ')',
                 'Strength (+1 attack, from ' + str(player.fighter.power) + ')',
                 'Agility (+1 defense, from ' + str(player.fighter.defense) + ')'],
                LEVEL_SCREEN_WIDTH)

        if choice == 0:
            player.fighter.base_max_hp += 20
            player.fighter.hp += 20
        elif choice == 1:
            player.fighter.base_power += 1
        elif choice == 2:
            player.fighter.base_defense += 1
Exemple #6
0
def increase_player_skills(player):
    while True:
        options = [s.name + ': currently ' + str(player.fighter.skills.get(s.name, 0)) +
                   ', costs ' + str(s.cost) + ' sp'
            for s in skill_list]

        # Make sure log.message() displays as we loop
        renderer.render_all(player, None)
        (key, target) = renderer.menu('Choose skill to increase, or x to explain:\n' +
                                      '(' + str(player.skill_points) + ' skill points available)\n',
                                      options, INVENTORY_WIDTH)
        if key == ord('x'):
            (c2, i2) = renderer.menu('Choose skill to describe, or any other to cancel.\n\n', options, INVENTORY_WIDTH)
            if i2 is not None:
                log.message(skill_list[i2].name + ': ' + skill_list[i2].description)
            
        if target is None:  # 0 *is* a valid target
            return

        if skill_list[target].cost > player.skill_points:
            log.message(skill_list[target].name.capitalize() + ' costs ' + str(skill_list[target].cost) +
                        ' skill points, you only have ' + str(player.skill_points))
            continue

        value = player.fighter.skills.get(skill_list[target].name, 10)
        if value >= 250:
            log.message(skill_list[target].name.capitalize() + ' is already at its maximum.')
            continue

        player.skill_points -= skill_list[target].cost
        if value < 100:
            value += libtcod.random_get_int(0, 1, 8)
        elif value < 150:
            value += libtcod.random_get_int(0, 1, 4)
        elif value < 200:
            value += libtcod.random_get_int(0, 1, 2)
        elif value < 250:
            value += 1
        player.fighter.skills[skill_list[target].name] = value
        log.message('Increased ' + skill_list[target].name + ' to ' + str(value))