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()
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
def quest_neutral_hostile_npc(hero, npc_name=None): ''' event with npc, which can turn into enemy during the second meeting if hero doesn't fulfill quest condition ''' # first check if NPC not dead already: if npc_name not in hero.enemy_killed: # check if hero has met npc before, import npc by name: npc = mod_npc.npc_settings(name=npc_name, loc=None, gen=None) # if hero has npc statement in quest_blocked_list # (which stores heard npc statement).. # means that hero has met npc before if npc.quest_list[0] in hero.quest_blocked_list: # check if hero has items to finish quest # (if it is quest condition): mod_hero.check_item_condition_quest(hero, npc=npc) # second meeting without quest condition fulfilled means that # NPC transform to enemy: if npc.quest_condition not in hero.quest_condition_list: # call fight function event_fight_spec_enemy(enemy=npc_name, hero=hero) # second meeting with npc, but hero.. # has fulfilled quest condition # npc is friendly/neutral: else: event_quest(npc=npc_name, hero=hero) mod_display.pause() # it is first meeting with npc, NPC is neutral: else: event_quest(npc=npc_name, hero=hero) mod_display.pause()
def event_fight(hero, enemy): ''' event == fight with random enemy ''' # random generate enemy (using filters): enemy = mod_enemy.summon_enemy( name=None, loc=hero.location, lvl=None, gen=None ) print("\n\nZaraz, zaraz... Coś się dzieje!\n"), time.sleep(.3) print("Twój przeciwnik to", end=''), mod_display.dot_loop() print(' ', enemy.name.upper()+'!', '\n') mod_display.pause() mod_display.clear_screen() # pętla walki: combat_end = 0 while combat_end == 0 and hero.actual_life > 0 and enemy.actual_life > 0: # initiative test: attacker = priority_test(hero, enemy=enemy) attacker_change = 0 # if attacker_change == 1, # loop is break and we repeat initiative test while True: mod_display.display_enemy_vs_hero( hero, enemy=enemy, attacker=attacker ) attacker_change = fight(hero, enemy, attacker) mod_display.pause() mod_display.clear_screen() if hero.actual_life < 1: combat_end = 1 hero.actual_life = 0 break elif enemy.actual_life < 1: win_fight(hero, enemy) combat_end = 1 break elif attacker_change == 1: break return hero
def priority_test(hero, enemy=None): ''' who's attacker, who's defender ''' mod_display.clear_screen() mod_display.display_enemy_vs_hero(hero, enemy=enemy, attacker=None) # zwinność, percepcja i inteligencja have influence on this test: hero_test_stats = ( int(hero.attrib_dict["zwinność"]) + int(hero.attrib_dict["percepcja"]) + int(hero.attrib_dict["inteligencja"])) enem_test_stats = ( int(enemy.attrib_dict["zwinność"]) + int(enemy.attrib_dict["percepcja"]) + int(enemy.attrib_dict["inteligencja"])) print("\nKto uzyskał inicjatywę? (test inicjatywy)\n") while True: test_var1 = hero_test_stats + enem_test_stats test_var2 = random.randint(1, test_var1) print('\r\r'+hero.name+":", hero_test_stats) print('\r\r'+enemy.name+":", test_var2) if hero_test_stats > test_var2: print("\nRezultat:", end=''), mod_display.dot_loop() print("\n\natakuje", hero.name+'!') attacker = hero break elif hero_test_stats < test_var2: print("\nRezultat:", end=''), mod_display.dot_loop() print("\n\natakuje", enemy.name+'!') attacker = enemy break mod_display.pause() mod_display.clear_screen() return attacker
def event_question_mark(hero): ''' event == random event when hero on '?' mark on the map small chance to win gold, huge chance to fight with random enemy ''' print("\n\nOtwierasz puszczkę Pandory.. Czy Ci się udało?..\n") mod_display.pause() chance_factor = random.randint(1, 100) if chance_factor < 90: enemy = mod_enemy.summon_enemy(loc=hero.location) event_fight(hero, enemy) else: # looted gold depends on luck, hero level and hero location # (higher level, higher location number == more gold to gain) looted_gold = random.randint(5, 50)*hero.level*hero.location print( '\n\n'+hero.name+", udało Ci się! Zdobywasz:", looted_gold, "sztuk złota\n" ) mod_display.pause() return hero
def event_well_of_life(hero=None): ''' full life regeneration event (healer) ''' # price is 1 gold for every 1 life point to recover price = hero.max_life - hero.actual_life print("Witaj,", hero.name+", jestem uzdrowicielem.") if hero.actual_life == hero.max_life: # ckeck if hero need 'health care' print( "\nWidzę, że nie potrzebujesz leczenia! Nie trwoń mojego czasu.." ) mod_display.pause() else: print("\n\nZa cenę", price, "sztuk złota w pełni Cię uleczę.. ") if hero.gold >= price: while True: player_choice = input( "Jeśli chcesz skorzystać, wpisz 't',\ \njeśli nie, wpisz 'n' i zatwierdź <enter> -->" ) try: if player_choice == 't' or player_choice == 'n': if player_choice == 't': print("Uzupełniono życie!") hero.actual_life = hero.max_life hero.gold -= price mod_display.pause() elif player_choice == 'n': print("Bywaj zatem!") mod_display.pause() break except: pass # just wonna ignore error else: print("\n\nNie posiadasz wystarczającej ilości złota..\n") mod_display.pause() return hero
def next_level_promotion(hero): ''' check if there is hero level promotion allows to player modify one of hero attributes displays result ''' if hero.actualExp > ((50 * hero.level) * 2 * hero.level): while True: player_choice = mod_display.display_next_level_promotion(hero) mod_display.display_hero_chart(hero) print("Awansujesz na kolejny poziom doświadczenia!\n") if player_choice == '1': hero.attrib_dict["siła"] += 1 print("Gratulacje! Wzrosła siła i życie") mod_display.pause() break elif player_choice == '2': hero.attrib_dict["zwinność"] += 1 print("Gratulacje! Wzrosła zwinność i życie") mod_display.pause() break elif player_choice == '3': hero.attrib_dict["percepcja"] += 1 print("Gratulacje! Wzrosła percepcja i życie") mod_display.pause() break elif player_choice == '4': hero.attrib_dict["inteligencja"] += 1 print("Gratulacje! Wzrosła inteligencja i życie") mod_display.pause() break elif player_choice == '5': hero.attrib_dict["siła woli"] += 1 print("Gratulacje! Wzrosła siła woli i życie") mod_display.pause() break else: print("Wybierz numer atrybutu, spróbuj jeszcze raz.. ") mod_display.pause() continue hero.level += 1 hero.max_life += 30 # buff to max life hero.actual_life = hero.max_life # full life regeneration return hero
def event_fight_spec_enemy(enemy=None, hero=None): ''' event == fight with special (quest) enemy ''' # random generate enemy (using filters): enemy = mod_enemy.summon_enemy(name=enemy) if enemy.name not in hero.enemy_killed: print("\n\nZaraz, zaraz... Coś się dzieje!\n"), time.sleep(.3) print( "Szykuj się do walki. Twój przeciwnik to", end='' ), mod_display.dot_loop() print(' ', enemy.name.upper()+'!', '\n') mod_display.pause() mod_display.clear_screen() # fight loop: combat_end = 0 while ( combat_end == 0 and hero.actual_life > 0 and enemy.actual_life > 0 ): # initiative test: attacker = priority_test(hero, enemy=enemy) # if attacker_change == 1: # loop is break and repeat initiative test attacker_change = 0 while True: mod_display.display_enemy_vs_hero( hero, enemy=enemy, attacker=attacker ) attacker_change = fight(hero, enemy, attacker) mod_display.pause() mod_display.clear_screen() if hero.actual_life < 1: hero.actual_life = 0 combat_end = 1 break elif enemy.actual_life < 1: # enemy is dead: enemy.actual_life = 0 hero.quest_condition_list.append(enemy.quest_condition) if enemy.genre == "quest": # quest enemies are unique # block enemy for future: hero.enemy_killed.append(enemy.name) # if it is quest enemy (is either enemy and quest npc): try: # import npc by enemy name (if it is quest enemy): npc = mod_npc.npc_settings( name=enemy.name, loc=None, gen=None ) # info in hero attribute, that quest is completed: hero.quest_completed_list.append(npc.quest_name) # update quest info to display: if npc.quest_name not in hero.quest_info.keys(): hero.quest_info.update( {npc.quest_name: [enemy.quest_info]} ) else: hero.quest_info[npc.quest_name][0] += ( '\n'+str(enemy.quest_info)) # check if there is special reward for quest # (teleport to next level (map)) # if True: return updated hero.new_location # (signal to display info about portal) check_if_portal(hero, npc=npc) except: pass # I just want to ignore potential error if enemy.quest_info: # display statment about quest # (element of enemy quest list): print(enemy.quest_info) win_fight(hero, enemy) combat_end = 1 # combat_end == 1: break fight loop break elif attacker_change == 1: break return hero
def fight(hero, enemy, attacker): ''' fight mechanic = hit ''' # define attacker and defender: if attacker == hero: defender = enemy elif attacker == enemy: defender = hero attacker_change = 0 attack_result = 0 defend_result = 0 print( '\n'+attacker.name, "atakuje: rzuca", attacker.attrib_dict[str(attacker.combat_attribute)], "razy kością K4:" ) for i in range(int(attacker.attrib_dict[str(attacker.combat_attribute)])): attack_var = random.randint(1, 4) print( (str(attack_var)), " ", sep='', end='', flush=True ), time.sleep(0.3) attack_result += attack_var time.sleep(0.3) print( '\n'+defender.name, "broni się: rzuca", str(defender.attrib_dict["zwinność"]), "razy kością K4:" ) for i in range(int(defender.attrib_dict["zwinność"])): defend_var = random.randint(1, 4) print( (str(attack_var)), " ", sep='', end='', flush=True ), time.sleep(0.3) defend_result += defend_var print("\n\nRezultat:", end=''), mod_display.dot_loop() print( '\n\n'+attacker.name+':', attack_result, '+', attacker.attack, "(atak):", attack_result+attacker.attack ) print( defender.name+':', defend_result, '+', defender.defend, "(obrona):", defend_result+defender.defend ) if attack_result+attacker.attack <= defend_result+defender.defend: print('\n'+defender.name, "obronił się!") mod_display.pause() attacker_change = 1 attack = int(attack_result+attacker.attack) counterattack(enemy=enemy, hero=hero, attacker=attacker, attack=attack) return attacker_change else: damage = random.randint(attacker.dmg_list[0], attacker.dmg_list[1]) if damage > defender.actual_life: damage = defender.actual_life print( '\n'+attacker.name, "zadał obrażenia:", defender.name, "stracił", damage, "pkt. życia" ) time.sleep(0.3) defender.actual_life -= damage if attacker == hero: hero.actualExp += damage print(hero.name+", zdobyto doświadczenie:", damage) if defender.actual_life < 0: defender.actual_life = 0 combat_end = 1 time.sleep(0.3) return combat_end