Ejemplo n.º 1
0
    def lvl_up(self, abilities):
        '''Whenever the player's xp reaches a certain point, they will level up'''

        clear()
        if not self.lvl_up_avaliable():
            print('--- Unable to level up')
            return
        while self.lvl_up_avaliable():
            self.xp -= self.lvl_up_threshold()
            self.lvl += 1
            self.health += 50
            self.mana += 25
            self.current_health = self.health
            self.current_mana = self.mana
            self.abi_points += 1
            dialogue(
                f'--- You have leveled up to level {self.lvl}! Your power increases.\n'
            )
            points = 3
            choice = 1
            choices = ['strength', 'intelligence', 'agility', 'defence']
            while points > 0:
                choice_info = [
                    f'{c.capitalize()}: {self.stats[c]}' for c in choices
                ]
                choice = choose(f'You have {points} points.', choice_info,
                                choice)
                self.stats[choices[choice - 1]] += 1
                points -= 1
            while self.abi_points > 0:
                if not self.learn_ability(abilities):
                    break
Ejemplo n.º 2
0
    def learn_ability(self, abilities):
        '''Used whenever the player character can learn a new ability; only used in lvl_up as of current'''

        ability_list = [
            abi for abi in self.abilities
            if abi.max_lvl > abi.lvl and abi.check(self)
        ]
        for abi in abilities:
            if abi.check(self):
                if all(a.name != abi.name for a in self.abilities):
                    ability_list.append(abi)
        if ability_list == []:
            dialogue('--- There are no avaliable abilities to learn/upgrade.')
            return False
        abi_info = [
            f'{abi} ({abi.lvl}/{abi.max_lvl}): {abi.desc}'
            for abi in ability_list
        ]
        ability = ability_list[choose(
            f'--- You have {len(ability_list)} abilities to learn/upgrade.',
            abi_info) - 1]
        if ability.lvl == 0:
            dialogue(f'--- You have learned {ability}.')
            self.abilities.append(ability)
        else:
            dialogue(f'--- You have upgraded {ability}.')
        ability.upgrade()
        self.abi_points -= 1
        return True
Ejemplo n.º 3
0
    def visit(self, player):
        '''Used whenever the player visits the shop'''

        dialogue(f'--- You travel to {self}.')
        dialogue(self.greeting)
        while True:
            choices = self.stock + ('Sell items', 'Leave')
            choice_info = [
                f'{c} - {c.value} gold' if type(c) != str else c
                for c in choices
            ]
            choice = choices[
                choose(f'--- You have {player.gold} gold.', choice_info) - 1]
            if type(choice) != str:
                if choice.value > player.gold:
                    print('--- Insufficient funds')
                    continue
            if choice == 'Sell items':
                while True:
                    choices = [i for i in player.inventory if not i.quest
                               ] + ['Back']
                    choice_info = [
                        f'{c} - {int(c.value * 0.8)} gold'
                        if type(c) != str else c for c in choices
                    ]
                    if choices == ['Back']:
                        print('--- Nothing to sell')
                        break
                    choice = choices[choose(
                        f'--- You have {player.gold} gold.', choice_info) - 1]
                    if choice == 'Back':
                        break
                    else:
                        player.gold += int(choice.value * 0.8)
                        player.inventory.remove(choice)
                        print(
                            f'--- You sold a {choice} for {int(choice.value * 0.8)} gold.'
                        )
            elif choice == 'Leave':
                return
            else:
                player.gold -= choice.value
                player.inventory.append(choice)
                print(f'--- You bought a {choice} for {choice.value} gold.')
Ejemplo n.º 4
0
    def build_char(self):
        '''Used in the beginning to build the player character'''

        self.name = ''
        while self.name == '':
            self.name = clear_input('What is your name, traveller?\n')
            if self.name == '':
                print('You must have have a name in this realm.')
        self.class_type = choose('Choose a class.', classes, ret=True)
        dialogue(
            f'--- You chose the {self.class_type} class, which favors {self.class_type.stat}.'
        )
        self.stats[self.class_type.stat] += 3
        self.inventory.append(self.class_type.weap)
Ejemplo n.º 5
0
def sanctuary_gates_visit(player):
    if player.progress['gates_unlocked']:
        forest_of_mysteries.visit(player)
        return
    elif player.progress['king_dialogue']:
        dialogue('Asathryne Gatekeeper: Halt there, young - ')
        choice = choose(
            'Asathryne Gatekeeper: Oh. You spoke with the King? I suppose my orders are to let you through then. Here, hand me the key.',
            ('Return to Sanctuary', 'Unlock the gates'),
            ret=True)
        if choice == 'Return to Sanctuary':
            dialogue(
                'Asathryne Gatekeeper: Very well. Return to the town square, and come back here when you are ready.'
            )
            dialogue('--- You return to the town square.')
            return
        elif choice == 'Unlock the gates':
            player.item_remove(sanctuary_key)
            dialogue(
                '--- You give the key to the gatekeeper. The gates open, revealing an expansive forest, teeming with otherworldly life.'
            )
            dialogue('Asathryne Gatekeeper: Good luck out there, traveller.')
            player.progress['gates_unlocked'] = True
            forest_of_mysteries.visit(player)
            return
    choice = choose(
        'Asathryne Gatekeeper: Halt there, young traveller! There is a dangerous, dark evil behind these gates. I shall not let you pass, unless you have spoken with the King of Asathryne!',
        ('Meet the king', 'Return to town square'),
        ret=True)
    player.progress['gates_dialogue'] = True
    if choice == 'Meet the king':
        sanctuary_kings_palace.visit(player)
        return
    elif choice == 'Return to town square':
        clear()
        dialogue('--- You return to the town square.')
        return
Ejemplo n.º 6
0
    def visit(self, player):
        '''Used whenever the player visits the area'''

        player.progress['area'] = self
        if self.safe:
            player.current_health = player.health
            player.current_mana = player.mana
        dialogue(f'--- You travel to {self}.')
        choice = 1
        while True:
            choices = self.locations + ('View Character', 'Save') + (
                ('Level up!', ) if player.lvl_up_avaliable() else ())
            choice = choose(self, choices, choice)
            action = choices[choice - 1]
            if action == 'View Character':
                player.view_stats()
            elif action == 'Save':
                player.save()
            elif action == 'Level up!':
                player.lvl_up(abilities)
            else:
                action.visit(player)
Ejemplo n.º 7
0
def main():
    #fixes a stuttering issue
    print('\n' * 10000)
    while True:
        choice = choose(
            f'>>> Asathryne <<< v{__version__}\n(Use arrow keys and press enter to select)',
            ('New game', 'Load game', 'Help'),
            ret=True)
        if choice == 'New game':
            player = PlayerCharacter()
            player.build_char()
            if choose('Skip the tutorial?', ('Yes', 'No'), ret=True) == 'Yes':
                player.equip(player.class_type.weap)
                player.lvl_up(abilities)
            else:
                dialogue(
                    f'Welcome to The Realm of Asathryne, {player}. A kingdom filled with adventure and danger, with much in store for those brave enough to explore it. Of course, nothing a {player.class_type} such as yourself can\'t handle.'
                )
                dialogue(
                    'Oh, of course! Allow me to introduce myself. My name is Kanron, your advisor.'
                )
                dialogue(
                    f'Kanron: You can\'t just go wandering off into Asathryne without a weapon. Every {player.class_type} needs a {player.class_type.weap}!'
                )
                player.equip(player.class_type.weap)
                dialogue(
                    'Kanron: Before you go venturing off into the depths of this realm, you must first master some basic skills.'
                )
                dialogue(
                    'Kanron: Your stats determine your performance in battle, and the abilities you can learn.'
                )
                dialogue(
                    'Kanron: There are 4 main stats: Strength, Intelligence, Agility, and Defense.'
                )
                choice = choose(
                    'Kanron: Do you want to learn more about stats?',
                    ('Yes', 'No'),
                    ret=True)
                if choice == 'Yes':
                    while True:
                        dialogue(
                            'Kanron: Strength increases the amount of damage you deal with physical attacks.'
                        )
                        dialogue(
                            'Kanron: Intelligence increases the potency of your spells.'
                        )
                        dialogue(
                            'Kanron: Agility determines the accuracy of your attacks, and how often you dodge attacks.'
                        )
                        dialogue(
                            'Kanron: Defense determines how much damage you take from physical attacks.'
                        )
                        dialogue(
                            'Kanron: Your mana determines your use of abilities.'
                        )
                        dialogue(
                            'Kanron: Your health determines how much damage you can take before you perish.'
                        )
                        if choose('Kanron: Would you like me to repeat stats?',
                                  ('Yes', 'No'),
                                  ret=True) == 'No':
                            break
                dialogue('Kanron: Let\'s talk about your level.')
                dialogue(
                    'Kanron: Your level represents how powerful you are, and determines the level of your enemies; when you go up a level, you will recieve 3 skill points to spend on any of the 4 stats, and 1 ability point to learn/upgrade abilities. Additionally, your health and mana will automatically increase and regenerate.'
                )
                dialogue(
                    'Kanron: You can gain XP (experience points) in battle; when you have enough, you\'ll go up one level and get to use your skill points.'
                )
                dialogue(
                    'Kanron: Let\'s upgrade your stats. For your class, you recieve an extra 3 skill points in the stat that your class favors, and you will recieve 1 level up.'
                )
                player.lvl_up(abilities)
                dialogue(
                    'Kanron: Great job! Now that you have learned the basics, it is time you start your journey into the Realm of Asathryne.'
                )
            sanctuary.visit(player)
        elif choice == 'Load game':
            saves = []
            for file in os.listdir(os.fsencode(os.getcwd())):
                filename = os.fsdecode(file)
                if 'player_data' in filename:
                    with open(filename, 'r') as file:
                        saves.append(decode(file.read()))
            if saves == []:
                print('No saves found')
                continue
            saves_info = [
                f'{c.name} - Level {c.lvl} {c.class_type}' for c in saves
            ]
            player = saves[choose('Choose your character.', saves_info) - 1]
            try:
                if player.version != __version__:
                    dialogue(
                        f'WARNING: This character was created in version {player.version}. Current version is {__version__}. If you continue, unexpected errors may occur.'
                    )
            except AttributeError:
                dialogue(
                    f'WARNING: This character was created in an older version. Current version is {__version__}. If you continue, unexpected errors may occur.'
                )
            player.progress['area'].visit(player)
        elif choice == 'Help':
            dialogue(
                'To select options in any menu, use the up and down arrow keys to select the desired option and press enter.'
            )
Ejemplo n.º 8
0
def sanctuary_kings_palace_visit(player):
    if player.progress['king_dialogue']:
        dialogue('King Brand: Hello, young traveller.')
        choice = choose(
            'King Brand: Do you wish to hear the story of Asathryne?',
            ('Yes', 'No'),
            ret=True)
        if choice == 'Yes':
            dialogue('King Brand: Very well. Go ahead and have a seat.')
            for line in king_story:
                dialogue(f'King Brand: {line}')
            return
        elif choice == 'No':
            dialogue(
                'King Brand: Oh well, maybe for another day. Fare well, traveller!'
            )
            return
    dialogue(
        f'King Brand: At last, a brave {player.class_type} has arisen once more, here on a quest to save the kingdom of Asathryne from the dark evil that lies beyond the gates.'
    )
    if player.progress['gates_dialogue']:
        choice = choose(
            'King Brand: Tell me young traveller, what do you seek from me?',
            ('I\'m here to learn about Asathryne',
             'The gate keeper has sent me to meet you'),
            ret=True)
    else:
        choice = choose(
            'King Brand: Tell me young traveller, what do you seek from me?',
            ('I\'m here to learn about Asathryne', ),
            ret=True)
    if choice == 'I\'m here to learn about Asathryne':
        dialogue('King Brand: Very well. Go ahead and have a seat.')
        for line in king_story:
            dialogue(f'King Brand: {line}')
        dialogue(
            'King Brand: You will be the one to free us from this crisis.')
        dialogue(
            'King Brand: Here, take this key; you will need it to open the gate into what remains of Asathryne.'
        )
        sanctuary_key.find(player)
        dialogue('King Brand: Fare well, young traveller.')
        player.progress['king_dialogue'] = True
        return
    elif choice == 'The gate keeper has sent me to meet you':
        dialogue(
            'King Brand: Ah, the gate keeper. He forbids anyone entry to the rest of Asathryne, simply because he wants to protect them.'
        )
    choice = choose(
        'King Brand: Let me ask you a question, traveller. Would you like to hear the Story of Asathryne?',
        ('Yes', 'No'),
        ret=True)
    if choice == 'Yes':
        dialogue('King Brand: Very well. Go ahead and have a seat.')
    elif choice == 'No':
        dialogue(
            'King Brand: Nonsense. I must regale this lore, it is my duty!')
    for line in king_story:
        dialogue(f'King Brand: {line}')
    dialogue('King Brand: You will be the one to free us from this crisis.')
    dialogue(
        'King Brand: Here, take this key; you will need it to open the gate into what remains of Asathryne.'
    )
    sanctuary_key.find(player)
    dialogue('King Brand: Fare well, young traveller.')
    player.progress['king_dialogue'] = True
    return
Ejemplo n.º 9
0
    def combat(self, enemy):
        '''Used whenever the player enters combat'''

        self.status = {}

        enemy.current_health = enemy.health
        enemy.current_mana = enemy.mana
        enemy.status = {}

        dialogue(f'You encountered {enemy}!')
        your_turn = True
        while True:
            if your_turn:
                self_info = f'{self}\nHealth - {self.current_health}/{self.health}\nMana - {self.current_mana}/{self.mana}\n'
                enemy_info = f'{enemy}\nHealth - {enemy.current_health}/{enemy.health}\nMana - {enemy.current_mana}/{enemy.mana}\n'
                choice = choose(f'{self_info}\n{enemy_info}',
                                ('Attack', 'Abilities', 'Pass'),
                                ret=True)
                if choice == 'Attack':
                    targets = [enemy]
                    target = choose('Choose a target.', targets, ret=True)
                    dialogue(f'You attack {target} with your weapon!')
                    attack = self.attack(target)
                    if attack.hit:
                        dialogue(
                            f'You hit {target} for {attack.damage} damage!')
                        target.current_health -= attack.damage
                    else:
                        dialogue('You missed!')
                elif choice == 'Abilities':
                    choices = [abi for abi in self.abilities if abi.active
                               ] + ['Back']
                    choice_info = [
                        f'{c} ({c.cost} mana): {c.desc}'
                        if type(c) != str else c for c in choices
                    ]
                    while True:
                        choice = choices[choose('Abilities', choice_info) - 1]
                        if type(choice) != str:
                            if choice.cost > self.current_mana:
                                print('--- Not enough mana')
                                continue
                        break
                    if choice == 'Back':
                        continue
                    elif choice.target == 'enemy' or choice.target == 'ally':
                        if choice.target == 'enemy':
                            targets = [enemy]
                        else:
                            targets = [self]
                        target = choose('Choose a target.', targets, ret=True)
                        choice.use(self, target)
                    elif choice.target == 'all_enemy':
                        pass
                    elif choice.target == 'all_ally':
                        pass
                    elif choice.target == 'all':
                        pass
                    self.current_mana -= choice.cost
                elif choice == 'Pass':
                    dialogue('You passed.')
                your_turn = False
            else:
                dialogue(f'{enemy} attacks!')
                attack = enemy.attack(self)
                if attack.hit:
                    dialogue(f'{enemy} hit {self} for {attack.damage} damage!')
                    self.current_health -= attack.damage
                else:
                    dialogue('It missed!')
                your_turn = True
            if enemy.current_health <= 0:
                dialogue(
                    f'You defeated {enemy}, and gained {enemy.xp} xp and {enemy.gold} gold!'
                )
                self.xp += enemy.xp
                self.gold += enemy.gold
                return True
            if self.current_health <= 0:
                dialogue('You perished.')
                return False