Exemplo n.º 1
0
def treasure_generator(maxloops, maxitem_lvl, item_gen, hero):
    '''
    generates list with random items, maxloops - max number of generated items,
    maxitem_lvl = max item level (from "items Class")
    that is allowed (if None - filter is off)
    item_gen = allowed item genre from "items Class"
    (ex. "weapon", if None - filter is off)
    '''
    if maxloops != 0:
        treasure_list = []
        if maxitem_lvl is None:
            maxitem_lvl = 1
        if maxloops is None:
            maxloops = 1
        if maxloops > 0:
            for i in range(random.randint(1, maxloops)):
                # randomly generates item level for each loop:
                random_level = random.randint(1, maxitem_lvl)
                generated_item = import_item(lvl=random_level, gen=item_gen)
                if generated_item.genre != "quest":  # block quest items
                    treasure_list.append(generated_item.name)

        # transform treasure list to dict:
        # then update hero's inventory:
        add_remove_items_dict = mod_hero.items_list_to_dict(treasure_list)
        mod_hero.inventory_update(hero, add_remove_items_dict)
        mod_display.display_looted_items(add_remove_items_dict)
        mod_display.pause()

        return hero

    else:  # if nothing added to hero inventory (bag)
        print('\n- więcej skarbów nie znaleziono...')
        mod_display.pause()
Exemplo n.º 2
0
def win_fight(hero, enemy):
    print(
        "Zwycięstwo,", enemy.name,
        "został pokonany! Sława i doświadczenie są Twoje,\
        \n...a może jeszcze jakiś łup bitewny?")

    # check if there are some treasures in enemy inventory:
    if len(enemy.treasure_dict) > 0:
        mod_display.pause()
        print("\nTak!\n")
        add_remove_items_dict = enemy.treasure_dict
        # display treasures from enemy inventory:
        mod_display.display_looted_items(add_remove_items_dict)
        mod_hero.inventory_update(hero, add_remove_items_dict)
        mod_display.pause()
    mod_display.clear_screen()
    print("Może coś jeszcze?", end=''), mod_display.dot_loop()
    looted_gold = mod_enemy.enemy_gold_reward(enemy)
    if looted_gold > 0:
        print("\n\nzdobyto", looted_gold, "sztuk złota\n")
        hero.gold += looted_gold
    # and some random generated items:
    mod_items.treasure_generator(
        maxloops=enemy.maxdrop, maxitem_lvl=enemy.maxdrop_lvl,
        item_gen=None, hero=hero
        )
    mod_display.display_info_about_next_map_portal(hero=hero)

    return hero
Exemplo n.º 3
0
def shop_hero_buy(hero, items_to_buy):
    '''
    buy item in shop
    '''
    # first element in expression (constant):
    exp_start = ' <-- wybierz '
    # last element in expression (constant):
    exp_end = ", 'w' - wyjście, <enter> - zatwierdza wybór"
    # specify range of player choice (number of items):
    exp_var = str(len(items_to_buy))
    exp_middle = "numer przedmiotu do zakupu (1-" + exp_var + ")"
    expression = exp_start + exp_middle + exp_end
    # condition: item number in range items_to_buy dict or 'W' (exit):
    condition = [str(number + 1)
                 for number in range(len(items_to_buy))] + ['W']
    user_choice = user_choice_input(condition, expression)
    if user_choice == 'W':

        return user_choice  # break shop loop

    item_number = user_choice  # item (key) in items_to_buy dict
    item_name = items_to_buy[item_number][0]
    shop_margin = 1.2  # item price + 20%
    # final price = item price + 20% (shop margin):
    price = int(int(items_to_buy[item_number][1]) * shop_margin)
    if hero.gold < price:  # if hero has not enough gold
        print('\nNie posiadasz wystarczającej ilości złota.\n'), pause()

        return user_choice  # back to loop

    else:  # if hero has enough gold
        print('\nWybrano:', item_name + ', cena:',
              str(price) + ', Twoje złoto:',
              str(hero.gold) + ', czy potwierdzasz?\n\n')

        exp_middle = "'t' - tak, 'n' - nie"
        expression = exp_start + exp_middle + exp_end
        condition = ('T', 'N', 'W')
        user_choice = user_choice_input(condition, expression)
        if user_choice == 'N':

            return user_choice

        elif user_choice == 'T':
            hero.gold -= int(price)  # subtract price
            # add item to hero inventory:
            add_remove_items_dict = {item_name: 1}
            mod_hero.inventory_update(hero, add_remove_items_dict)
            display_looted_items(add_remove_items_dict)
            print('Twoja sakwa jest lżejsza, wydałeś', price, 'sztuk złota!\n')
            pause()

            return hero

        else:
            user_choice = 'W'  # exit from shop

            return user_choice
Exemplo n.º 4
0
def display_event_quest(hero, npc=None):
    '''
    display quest info, dialogs, info about quest result
    '''
    # random speach is short npc's 'small talk'
    random_speach = "".join('\n' + npc.name + " do Ciebie: " +
                            random.choice(npc.speach_list))
    print(random_speach)
    # if quest is not completed yet:
    if npc.quest_name not in hero.quest_completed_list:
        # display npc's statement associated with quest:
        elements = ''  # stores npc's statments to display
        # element is npc statement connected with quest:
        for element in hero.quest_info[npc.quest_name]:
            if element not in hero.quest_blocked_list:
                # quest_blocked_list stores statement,
                # that have been already used by npc
                elements += '\n' + element
                # block already displayed statements:
                hero.quest_blocked_list.append(element)

        quest_name_to_display = ("Zadanie: ", npc.quest_name,
                                 " (przywołaj dziennikiem zadań)..")
        # quest is not finished:
        if npc.quest_condition not in hero.quest_condition_list:
            # display info about quest and quest log:
            print('\n' + elements)
            print("".join(quest_name_to_display))

        # quest is finished:
        else:
            # add quest name to hero quest completed list
            # (block this quest in future):
            hero.quest_completed_list.append(npc.quest_name)
            # display info if quest is completed:
            print('\n' + elements)  # display statement
            print("".join(quest_name_to_display))
            print("\r - wykonane.")
            print("\n\nGratulacje, zdobyto: " + str(npc.xp_reward) +
                  " punktów doświadczenia!")
            pause()
            # xp points reward for completion quest:
            hero.actualExp += npc.xp_reward
            items_dict = {}  # create empty dict used below:
            # check if quest condition is related
            # with handing out items (to npc):
            if len(npc.quest_items) > 0:
                # give items to npc
                # (result is items_dict winth negative values)
                items_dict = npc.quest_items
            # if there is extra reward: recieve items from npc inventory:
            add_remove_items_dict = mod_hero.dict_update(
                items_dict, add_remove_items_dict=npc.inventory_dict)

            # check if it is some items to remove or add to hero inventory
            if len(add_remove_items_dict) > 0:
                # update inventory:
                mod_hero.inventory_update(hero, add_remove_items_dict)
                # display result:
                display_looted_items(add_remove_items_dict)

    # check if there is special reward for quest:
    # teleport to next level (map),
    # display info about opened portal:
    mod_event.check_if_portal(hero, npc=npc)
    display_info_about_next_map_portal(hero=hero)

    return hero
Exemplo n.º 5
0
def shop_hero_sell(hero):
    '''
    sell item in shop
    '''
    # hero inventory is empty:
    if len(hero.inventory_dict.keys()) == 0:
        print('\ntorba jest pusta, nie masz niczego na sprzedaż.. \n\n')
        pause()

        return hero

    # hero has items in inventory:
    else:
        exp_start = ' <-- wybierz '  # first element in expression (constant)
        exp_end = ", 'w' - wyjście, <enter> - zatwierdza wybór"
        # specify range of player choice (number of items):
        exp_var = str(len(hero.inventory_dict.keys()))
        exp_middle = "numer przedmiotu do sprzedaży (1-" + exp_var + ")"
        expression = exp_start + exp_middle + exp_end
        # condition: item number in range items_to_buy dict or 'W' (exit):
        condition = (
            [str(num + 1)
             for num in range(len(hero.inventory_dict.keys()))] + ['W'])
        user_choice = user_choice_input(condition, expression)
        if user_choice == 'W':

            return user_choice  # exit shop

        else:
            # make dict with hero items
            # (key is number, value is list with item attributes:
            # name, price, quantity):
            items_to_sell = mod_items.generate_items_to_sell(hero)
            item_name = items_to_sell[user_choice][0]
            item_price = int(items_to_sell[user_choice][1])
            if item_price == 0:
                print('\nNie kupię tego, przedmiot', item_name,
                      'jest dla mnie bezwartościowy.\n')
                pause()

                return hero  # back to main choice

            # quantity of specified item (user_choice) in hero inventory:
            item_quantity = int(items_to_sell[user_choice][2])
            if item_quantity == 1:
                quantity = '1'  # used in printing at the end of function
                gold_earned = item_price

            else:  # quantity of specified item in hero inventory > 1..
                print('\nJaką ilość chcesz sprzedać?\n')

                exp_var = str(item_quantity)  # quanitity of item limit
                exp_middle = "z przedziału (1-" + exp_var + ")"
                expression = exp_start + exp_middle + exp_end
                # condition is list of item number
                # in range quanitity of item limit or 'W' (exit):
                condition = ([str(num + 1)
                              for num in range(item_quantity)] + ['W'])
                user_choice = user_choice_input(condition, expression)

                if user_choice == 'W':  # exit

                    return user_choice  # break shop loop

                else:
                    quantity = user_choice
                    gold_earned = item_price * int(user_choice)

            print('\nWybrano:',
                  item_name + ', ilość:', quantity + ', otrzymasz:',
                  str(gold_earned), 'sztuk złota. Czy powierdzasz?\n\n')
            exp_middle = "'t' - tak, 'n' - nie"
            expression = exp_start + exp_middle + exp_end
            condition = ('T', 'N', 'W')
            user_choice = user_choice_input(condition, expression)
            if user_choice == 'W':

                return user_choice  # exit shop

            elif user_choice == 'N':

                return user_choice  # back to begining

            else:  # selling is confirmed
                hero.gold += gold_earned
                # remove item to hero inventory:
                add_remove_items_dict = {item_name: -(int(quantity))}
                mod_hero.inventory_update(hero, add_remove_items_dict)
                display_looted_items(add_remove_items_dict)
                print('Twoja sakwa jest cięższa, przybyło', str(gold_earned),
                      'sztuk złota!\n')
                pause()

                return hero