diff --git a/src/asci_lib.py b/src/asci_lib.py index fc1c9fc..894a9b7 100644 --- a/src/asci_lib.py +++ b/src/asci_lib.py @@ -152,7 +152,7 @@ class Asci: # Display and get answer if event.text: - answer_selected = convert(self.screen.display_text(event.text)) + answer_selected = convert(self.screen.display_text(event.text), True) if event.answer and (0 < answer_selected <= event.answer): self.data[0] += answer_selected def _get_map(self, direction): @@ -167,7 +167,7 @@ class Asci: def mainloop(self, end_game, stat=None, data=None, routine=None, player="@", door="^", walkable=" ", exit_key=9): if exit_key in self._game_keys_mapping: - raise ValueError(f"'{exit_key}' is already assigned to a function.") + raise ValueError("'{}' is already assigned to a function.".format(exit_key)) # Load save ; data = [XP, map_id, x, y] if not stat or type(stat) != list: self.stat = [100] @@ -219,9 +219,11 @@ class Map: self.coords = coords -def convert(string): +def convert(string, force_int=False): try: return int(string) - except: return string + except: + if force_int: return 0 + else: return string def text_formater(string, screen_width=21, screen_height=6): diff --git a/src/asgard.py b/src/asgard.py index 1506d75..c5b8520 100644 --- a/src/asgard.py +++ b/src/asgard.py @@ -125,7 +125,7 @@ def asgard_npc(data, stat): pass def asgard_po(coords): - if coords == (120, 26): return [0, "De hautes montagnes vous entourent de toutes part. Taillées dans la roche enneigee, les marches de l'escalier qui mene a Valaskjalf se decoupent nettement. La grande demeure d'Odin et son toit d'argent domine les environs."] + if coords == (120, 26): return [0, "De hautes montagnes vous entourent de toutes part. Taillees dans la roche enneigee, les marches de l'escalier qui mene a Valaskjalf se decoupent nettement. La grande demeure d'Odin et son toit d'argent domine les environs."] elif coords == (51, 55): return [0, "Tout autour de vous s'etend un riche jardin soigneusement entretenu. Dans l'alignement de l'allee nord, une fontaine complete l'ensemble. Une douce odeur de verdure emplit vos narines, l'ambiance est calme."] @@ -171,7 +171,7 @@ h_10 = (r""" | /____\ \ | | / * | | | | | | - | | ? | | + | | | | | |================/ \=================| | | | | | @@ -183,10 +183,23 @@ h_10 = (r""" |__| |__| |__| |__| |__| |__| /__\ /__\ /__\__^^__/__\ /__\ /__\ """, (29, 23, 0, 116, 14), - (30, 23, 0, 116, 14)) # * : (25, 17) + (30, 23, 0, 116, 14)) # * : (25, 11) def h_10_npc(data, stat): - pass + coords = data[2], data[3] + xp = data[0] + + print(coords) + if coords == (25, 11): + if xp == 0: + stat[3][0] = 5 + return [1, "Je suis Odin, Roi des Ases. Commencons par une premiere quete simple. Nous, les Ases, avons quelques differents avec les Vanes. Vous irez donc porter cette hache a Freyja. Elle comprendra. [ODIN VOUS DONNE UNE HACHE]"] + + else: return { + "base": [0, "Je suis Odin, Roi des Ases, dieux de la Guerre."], + 1: [0, "Deja revenu !?"], + 2: [0, "C'est une declaration de guerre ! [ODIN SE LEVA, FURIEUX]"], + } diff --git a/src/idk.py b/src/idk.py index 4bbcb9b..50f3114 100644 --- a/src/idk.py +++ b/src/idk.py @@ -1,4 +1,6 @@ from asci_lib import Asci, print_text +from random import randint +from math import floor, ceil from asgard import * from vanaheim import * @@ -31,8 +33,9 @@ maps = ( # h_45, h_46, h_47, h_48, # h_49, h_50) - -npc_data = ( +# Asci functions +def npc(data, stat): + npc_data = ( asgard_npc, vanaheim_npc, alfheim_npc, @@ -53,26 +56,36 @@ npc_data = ( # h_49_npc, h_50_npc,) -po_data = ( - asgard_po, - vanaheim_po, - alfheim_po, - midgard_po, - niflheim_po, - jotunheim_po, - nidavellir_po, - muspellheim_po, - helheim_po) - - -def npc(data, stat): event = npc_data[data[1]](data, stat) - if not event: return [0, "Hmm ?"] - else: return event + if not event: + return [0, "Hmm ?"] + + elif type(event) == tuple: + issue = fight(stat, event[0], event[1]) + if issue == 0: + stat[1] += event[2] + return [1, "Vous avez gagne le combat. [+{}PO]".format(event[2])] + elif issue == 1: return [0, "Vous etes mort."] + elif issue == 2: return [0, "Vous avez fuit."] + + else: + return event def point_of_interest(data, stat): + po_data = ( + asgard_po, + vanaheim_po, + alfheim_po, + midgard_po, + niflheim_po, + jotunheim_po, + nidavellir_po, + muspellheim_po, + helheim_po + ) + coords = data[2], data[3] event = po_data[data[1]](coords) @@ -85,7 +98,7 @@ def routine(data, stat): stat[4] = (stat[4] + 1) % 1440 # Mana regeneration - if stat[2][4] < stat[0] // 20 and not (stat[4] % 10): + if stat[2][4] < stat[0] // 2 and not (stat[4] % 60): stat[2][4] += 1 # Leave dialogue @@ -93,15 +106,142 @@ def routine(data, stat): stat[6] = (-1, -1) -def fight(player_stat, opponent_stat): - pass +# Game mecanics +def fight(stat, opponent_stat, opponent_name): + + def player_turn(): + end = False + print_text("Tour de {}".format(stat[5])) + if choice == 1: + damage = 2 * stat_test(player_stat, 2)[2] - opponent_stat[3] + if damage < 0: damage = 0 + + if damage == 0: + print_text("{} bloque l'attaque.".format(opponent_name)) + elif stat_test(opponent_stat[:-1], 1)[0]: + print_text("{} esquive le coup.".format(opponent_name)) + else: + opponent_stat[4] -= damage + print_text("{0} perd {1} PV.".format(opponent_name, damage)) + + elif choice == 2: + if len(stat[8]) == 0: + print_text("Vous ne connaissez pas de sort.") + else: + spell_data = ("Soin", "Flammes", "Givre", "Etincelles", "Fatigue") + spell_level = ("I", "II", "III", "IV", "V") + + spell_choice = 0 + while not spell_choice: + count = 0 + for spell_id, level in stat[8]: + print("{0}. {1} {2}".format(count + 1, spell_data[spell_id], spell_level[level])) + count += 1 + spell_choice = get_input() + if spell_choice < 0 or spell_choice > 3: spell_choice = 0 + + spell_choice -= 1 + spell_name, level = spell_data[stat[8][spell_choice][0]], stat[8][spell_choice][1] + 1 + + if stat[2][4] >= level * 10: + print_text("Vous lancez {0} de niveau {1} [-{2} PM].".format(name, spell_level[level - 1])) + stat[2][4] -= level * 10 + + if stat[8][spell_choice][0] == 0: + stat[0] += 12 * level + elif stat[8][spell_choice][0] == 1: + opponent_stat[4] -= 12 * level + elif stat[8][spell_choice][0] == 2: + opponent_stat[4] -= 12 * level + elif stat[8][spell_choice][0] == 3: + opponent_stat[4] -= 12 * level + elif stat[8][spell_choice][0] == 4: + opponent_stat[0] -= 12 * level + + else: + print_text("Vous ne parvenez pas a lancer le sort.") + + elif choice == 3: + if stat_test(player_stat, 1)[0]: + end = True + else: + print_text("Votre tentative de fuite echoue.") + + return end + + def opponent_turn(): + print_text("Tour de {}".format(opponent_name)) + damage = 2 * stat_test(opponent_stat, 2)[2] - player_stat[3] + if damage < 0: damage = 0 + + if damage == 0: + print_text("{} bloque l'attaque.".format(stat[5])) + elif stat_test(player_stat, 1)[0]: + print_text("{} esquive le coup.".format(stat[5])) + else: + stat[0] -= damage + print_text("{0} perd {1} PV.".format(stat[5], damage)) + + # opponent_stat = [vitesse, agilité, attaque, défense, vie] + # player_stat = [vitesse, agilité, attaque, défense] + player_stat = [stat[2][0], stat[2][1], stat[2][2] + stat[3][0] * 10, stat[2][3] + stat[3][1] * 10] + + player, opponent = 0, 0 + + end = False + while not end: + choice = 0 + while not choice: + print(" Combat ") + print(" | 1. Attaquer |") + print(" | 2. Ensorceler |") + print(" | 3. Fuir |") + print(" | 4. Statistiques |") + print(" ============= ") + choice = get_input() + if choice < 0 or choice > 4: choice = 0 + + if choice == 4: + p_capacities = ["{} ".format(i) if i < 10 else str(i) for i in player_stat] + o_capacities = ["{} ".format(i) if i < 10 else str(i) for i in opponent_stat[:-1]] + + p_health = str(stat[0]) + " " * (3 - len(str(stat[0]))) + o_health = str(opponent_stat[4]) + " " * (3 - len(str(opponent_stat[4]))) + + print(" Joueur | Ennemi") + print("Vit: {0} | {1}".format(p_capacities[0], o_capacities[0])) + print("Agi: {0} | {1}".format(p_capacities[1], o_capacities[1])) + print("Att: {0} | {1}".format(p_capacities[2], o_capacities[2])) + print("Def: {0} | {1}".format(p_capacities[3], o_capacities[3])) + print("Vie: {0} | {1}".format(p_health, o_health)) + input() + choice = 0 + + # Who start + while player == opponent: + player = stat_test(player_stat, 0)[1] + opponent = stat_test(opponent_stat[:-1], 0)[1] + + # Fight + if player > opponent: + end = player_turn() + if end: return 2 + + if opponent_stat[4] > 0: opponent_turn() + else: return 0 + else: + opponent_turn() + if stat[0] > 0: end = player_turn() + else: return 1 + + return 2 -def display_stat(data, stat): +def misc_stat(data, stat): # stat = [0 - PV, 1 - pièces d'or, 2 - [vitesse, agilité, attaque, defense, magie], 3 - [arme, armure], 4 - ticks, 5 - nom, 6 - (temps, xp), 7 - classe, 8 - sorts connus : (id, level)] if data[1] < 9: place = ("Asgard", "Vanaheim", "Alfheim", "Midgard", "Niflheim", "Jotunheim", "Nidavellir", "Muspellheim", "Helheim")[data[1]] - else: place = "Interieur" - health, money, _, _, ticks, _, _, _, _ = stat + else: place = "interieur" + money, ticks, player_class = stat[1], stat[4], stat[7] hours = ticks // 60 if 4 <= hours <= 5: @@ -115,33 +255,56 @@ def display_stat(data, stat): else: hours = " |nuit - {}h".format(hours) - health = " |Vie : {}/100".format(health) - money = " |Argent : {} PO".format(money) + player_class = (" |Guerrier", " |Voleur", " |Moine", " |Mage", " |Assassin")[player_class] - print(" Statistiques ") - print(" |" + place.center(16, " ") + "|") - print(hours + " " * (18 - len(hours)) + "|") - print(health + " " * (18 - len(health)) + "|") - print(money + " " * (18 - len(money)) + "|") - print(" ============ ") + money = " |Argent: {} PO".format(money) + + print(" Informations ") + print(" |" + center(place, 17, " ") + "|") + print(player_class + " " * (19 - len(player_class)) + "|") + print(hours + " " * (19 - len(hours)) + "|") + print(money + " " * (19 - len(money)) + "|") + print(" ============= ") input() +def display_stat(data, stat): + capacities = ["{} ".format(i) if i < 10 else str(i) for i in stat[2]] + + first_line = " |Vit : {0} Agi : {1}|".format(capacities[0], capacities[1]) + second_line = " |Att : {0} Def : {1}|".format(capacities[2], capacities[3]) + health = " |Vie : {} PV".format(stat[0]) + mana = " |Magie : {} PM".format(stat[2][4]) + + print(" {} ".format(center(stat[5], 13, " "))) + print(first_line) + print(second_line) + print(mana + " " * (19 - len(mana)) + "|") + print(health + " " * (19 - len(health)) + "|") + print(" ============= ") + input() + + def inventory(data, stat): - weapon = ("", "dague", "marteau", "masse", "fleau", "hache", "epee", "espadon", "hache double")[stat[3][0]] - shield = ("", "rondache", "pavois", "cote de maille", "broigne", "harnois")[stat[3][1]] + weapon = ("", "Dague", "Marteau", "Masse", "Fleau", "Hache", "Epee", "Espadon", "Hache double")[stat[3][0]] + shield = ("", "Rondache", "Pavois", "Cote de maille", "Broigne", "Harnois")[stat[3][1]] - weapon = " |" + weapon + " " * (16 - len(weapon)) + "|" - shield = " |" + shield + " " * (16 - len(shield)) + "|" + weapon = " |" + weapon + " " * (17 - len(weapon)) + "|" + shield = " |" + shield + " " * (17 - len(shield)) + "|" - print(" Inventaire ") - print(" |- Arme : |\n{}".format(weapon)) - print(" |- Armure : |\n{}".format(shield)) - print(" ============ ") + print(" Inventaire ") + print(" |- Arme : |\n{}".format(weapon)) + print(" |- Armure : |\n{}".format(shield)) + print(" ============= ") input() def sleep(data, stat): + + if 360 < stat[4] < 1140: + print_text("Vous ne pouvez pas dormir de jour.") + return + stat[4] = 360 # If the player is at home @@ -149,21 +312,20 @@ def sleep(data, stat): if stat[0] < 100: stat[0] += 10 stat[2][4] += 2 - print("Vous vous reposez.") - input() + print_text("Vous vous reposez.") def spell(data, stat): spell_data = ("Soin", "Flammes", "Givre", "Etincelles", "Fatigue") spell_level = ("I", "II", "III", "IV", "V") - to_disp = "Magie : {}".format(stat[2][4]) + to_disp = "Magie : {} PM".format(stat[2][4]) print(" Sorts ") print(" |" + to_disp + " " * (16 - len(to_disp)) + "|") for i in range(3): if i < len(stat[8]): - spell_id, level = stat[8] + spell_id, level = stat[8][i] if spell_id >= 0: to_disp = "{0} {1}".format(spell_data[spell_id], spell_level[level - 1]) print(" |" + to_disp + " " * (16 - len(to_disp)) + "|") @@ -175,37 +337,66 @@ def spell(data, stat): events = {"*": npc, "?": point_of_interest} -keys = {4: display_stat, 7: spell, 6: inventory, 9: sleep} +keys = {4: display_stat, 7: spell, 8:misc_stat, 6: inventory, 9: sleep} +# Main function def idk(stat=None, data=None): if not stat: - name = input("Entrez votre nom : ") + name = "" + while len(name) == 0 or len(name) > 13: + name = input("Entrez votre nom :\n>") player_class = 0 while(not player_class): - print("Choisissez votre classe\n1. Guerrier\n2. Voleur\n3. Moine\n4. Mage") - print() - player_class = input(">") - try: player_class = int(player_class) - except: player_class = 0 - - if player_class > 4: player_class = 0 + print("Choisissez une classe\n1. Guerrier\n2. Voleur\n3. Moine\n4. Mage\n5. Assassin") + player_class = get_input() + if player_class < 0 or player_class > 5: player_class = 0 if player_class == 1: stat = [5, 5, 10, 5, 5] elif player_class == 2: stat = [5, 10, 5, 5, 5] - elif player_stat == 3: + elif player_class == 3: stat = [5, 5, 5, 10, 5] - elif player_stat == 4: + elif player_class == 4: stat = [5, 5, 5, 5, 10] + elif player_class == 5: + stat = [10, 5, 5, 5, 5] - stat = [100, 10, stat, [0, 0], 1170, name, (-1, -1), player_class - 1, []] + stat = [100, 10, stat, [0, 0], 360, name, (-1, -1), player_class - 1, []] data = [0, 3, 44, 66] - print_text("Au alentour du Ve siecle, quelque part en Scandinavie. La bataille prenait place dans un champ saccage, les arbres alentours avaient ete abbatus pour les besoins en bois, et la nuit etait tombe depuis quelques heures lorsque l'assaut debuta. Hache levee, a la seule lueur des torches, {0} et sa division se jeterent sur le camp adverse, mais, pris a revers, le combat tourna vite a la defaveur des assaillants qui furent reduit sans autres difficultes. Blesse a plusieurs endroit, {0} se trainait sur le sol, tentant de se refugier dans la nuit lorsqu'une forme humaine portant un espadon dans le dos et une lourde armure d'argent s'arrêta devant lui. La Valkyrie prit {0} dans ses bras. Il senti son ame se dissocier de son corps, il vit son cadavre, le champ de bataille, le pays entier lui apparut, un lueur aveuglante le forca a fermer les yeux et Vahalla lui apparu. Mais Odin avait d'autres plan pour {0} qu'une retraite parmi les meilleurs guerriers, et il renvoya {0} dans le vaste monde avec cet ultimatum : si {0} trouve la voie jusqu'a Asgard et le Valaskjalf, Odin conscent a le garder a son service, sinon il sera condamne a errer dans le monde sans jamais trouver le repos.".format(name)) + print_text("Au alentour du Ve siecle, quelque part en Scandinavie. La bataille prenait place dans un champ saccage, et la nuit etait tombe depuis quelques heures lorsque l'assaut debuta.") + print_text("Hache levee, a la seule lueur des torches, {0} et sa division se jeterent sur le camp adverse, mais, pris a revers, le combat tourna vite a la defaveur des assaillants qui furent reduit sans autres difficultes.".format(name)) + print_text("Blesse a plusieurs endroit, {0} se trainait sur le sol, tentant de se refugier dans la nuit lorsqu'une forme humaine portant un espadon dans le dos et une lourde armure d'argent s'arreta devant lui. La Valkyrie prit {0} dans ses bras. Une lueur aveuglante le forca a fermer les yeux et Vahalla lui apparu.".format(name)) + print_text("Mais Odin avait d'autres plan pour {0} qu'une retraite parmi les meilleurs guerriers, et il le renvoya dans le vaste monde avec cet ultimatum : si il trouve la voie jusqu'a Asgard et le Valaskjalf, Odin conscent a le garder a son service, sinon il sera condamne a errer dans le monde sans jamais trouver le repos.".format(name)) idk_game = Asci(maps, events, keys) stat, data = idk_game.mainloop(100, stat, data, routine=routine, door="^_", walkable=".,`' ", exit_key="q") - print(f"idk({stat}, {data})") + print("idk({0}, {1})".format(stat, data)) + + +# Misc function +def get_input(): + string = input(">") + try: + return int(string) + except: + return 0 + + +def center(string, total_length, symbol): + left = floor((total_length - len(string)) / 2) + right = ceil((total_length - len(string)) / 2) + + return left * symbol + string + right * symbol + + +def stat_test(stat, test_id): + avg = sum(stat) / len(stat) + + score = stat[test_id] + randint(0, ceil(avg / 2)) + return score >= avg, score / avg, score + + diff --git a/src/midgard.py b/src/midgard.py index 629a45a..a87a3f8 100644 --- a/src/midgard.py +++ b/src/midgard.py @@ -121,6 +121,7 @@ def midgard_po(coords): def midgard_npc(data, stat): coords = data[2], data[3] + xp = data[0] if coords == (67, 46): return { "base": [0, "Oui ?..."] @@ -130,9 +131,8 @@ def midgard_npc(data, stat): "base": [0, "Vous cherchez quelqu'un ?"] } - elif coords == (66, 56): return { - "base": [0, "Laissez-moi dormir !"] - } + elif coords == (66, 56): + return [0, "Hein ?"] elif coords == (8, 59): return { "base": [0, "Regardez la mer. Et si vous voyez un bateau, prevenez moi !"] @@ -142,7 +142,11 @@ def midgard_npc(data, stat): "base": [0, "Besoin de quelque chose ?"] } - elif coords == (68, 71): return { + elif coords == (68, 71): + if xp == 0: + return [5, 5, 10, 5, 20], "Frinir", 0 + + else: return { "base": [0, "Frinir, jardinier de Madame."] } @@ -161,7 +165,7 @@ h_25 = (r""" | | | | | |--| |--------| |--| |------| | | -| ---| |--------| |--| |------| +| |--| |--------| |--| |------| | | | | | | | | | | | | @@ -203,22 +207,24 @@ def h_26_npc(data, stat): # Rosahil Green if coords == (27, 6): - if stat[4] >= 1260 and stat[4] <= 300: return [0, "Je suis desolee, nous sommes fermes. Revenez plus tard !"] + if stat[4] >= 1320 and stat[4] <= 340: return [0, "Je suis desolee, nous sommes fermes. Revenez plus tard !"] if stat[6][1] == -1: stat[6] = stat[4], data[0] - return [0, "Rosahil Green, tenanciere de cette auberge. Vous desirez quelque chose ?\n1.Manger [5 PO]\n2.Dormir [10 PO]", 2] + return [0, "Rosahil Green, tenanciere de cette auberge. Vous desirez quelque chose ?\n1.De quoi manger s'il vous plait. [-5 PO]\n2.Je voudrais une chambre pour la nuit. [-10 PO]", 2] elif data[0] == stat[6][1] + 1: - if stat[1] < 5: return [-1, "Reviens quand tu auras assez de pieces d'or."] stat[6] = (-1, -1) + if stat[1] < 5: return [-1, "Reviens quand tu auras assez de pieces d'or."] return [-1, "Et voila pour vous !", 0, (0, 5), (1, -5)] elif data[0] == stat[6][1] + 2: - if stat[1] < 10: return [-2, "Je suis desolee, tu n'as pas assez !"] stat[6] = (-1, -1) - stat[4] = 360 - return [-2, "Suivez-moi, je vais vous montrer votre chambre", 0, (0, 10), (1, -10)] + if stat[1] < 10: return [-2, "Je suis desolee, tu n'as pas assez !"] + elif 360 < stat[4] < 1140: return [-2, "Il est trop tot, reviens vers 19h."] + else: + stat[4] = 360 + return [-2, "Suivez-moi, je vais vous montrer votre chambre. [VOUS SUIVEZ ROSAHIL DANS L'AUBERGE, LA NUIT PASSA.]", 0, (0, 10), (1, -10)] return [0, "Ui hips ?"] diff --git a/src/vanaheim.py b/src/vanaheim.py index 9c2ae20..abba3fe 100644 --- a/src/vanaheim.py +++ b/src/vanaheim.py @@ -140,4 +140,27 @@ h_22 = (r""" (20, 19, 1, 52, 35)) # * : (36, 3) * : (2, 8) def h_22_npc(data, stat): - pass + coords = data[2], data[3] + xp = data[0] + + # Freyja + if coords == (36, 3): + if not (360 <= stat[4] <= 1200): + return [0, "Revenez plus tard s'il vous plait."] + + if xp == 1: + stat[8].append((0, 1)) + return [1, "Hum. [FREYJA REGARDE LA HACHE] Odin me propose la paix... Mais ca ne se passera pas comme ca. [ELLE VOUS REND LA HACHE]. Allez voir Odin, et rendez-lui sa hache. En remerciement de vos services, je vous apprend le sort de Soin. [FREYJA DESSINA DU DOIGT DES RUNES VIOLETTE DANS L'AIR. LES LETTRES LUMINEUSES BRILLERENT UN INSTANT AVANT DE S'ESTOMPER PROGRESSIVEMENT.]"] + + else: return { + "base": [0, "Bonjour, je suis Freyja, deesse de la beaute et de l'erotisme."] + } + + # Freyr + elif coords == (2, 8): + if (not 360 <= stat[4] <= 1200): + return [0, "Hein ? Quoi ? Ca va pas non ? Qu'est-ce qu'il vous a pris de me reveiller comme ca ?"] + + else: return { + "base": [0, "Freyr, dieu de la vie. Bienvenue a Vanaheim"] + }