def battle(self, counter):
        actors = []
        for player in self.players:
            if counter % player.INIT == 0:  # and player.INIT <= counter:
                actors.append((player, self.players.index(player)))
        for enemy in self.enemies:
            if counter % enemy.INIT == 0:  #and enemy.INIT <= counter
                actors.append((enemy, self.enemies.index(enemy)))

        for act in actors:
            actor, actor_index = act
            if actor not in self.enemies and actor not in self.players:
                continue
            printf('It is {}s turn to attack! [HP: ({}/{})]'.format(
                actor.name, actor.HP, actor.MAX_HP))
            target, t_id, t_index = self.choose_target(actor)
            skill = self.choose_skill(actor)
            if type(skill) == int:
                return 0
            dmg, buff, debuff = self.act(actor, skill, target)

            self.apply(actor, actor_index, target, t_index, dmg, buff, debuff)
            time.sleep(2)

            self.check_for_dead()

        self.reduce_cooldown()
    def check_for_dead(self):
        for player in self.players:
            if player.HP <= 0:
                printf('Oh no! Player {} died!\n'.format(player.name))
                self.players.remove(player)
                player.HP = 1
                self.all_players[player.name] = player

        for enemy in self.enemies:
            if enemy.HP <= 0:
                printf('Ha! Enemy {} died!\n'.format(enemy.name))
                self.enemies.remove(enemy)
    def _show_stats(self, player):
        import copy
        printf(player)
        a = copy.deepcopy(self.inventory.get_assignments()[player.name])
        for key, value in a.items():
            if value:
                a[key] = a[key].id

        string = f"Assignments: \nLeft hand: {a['left_hand']},\nRight hand: {a['right_hand']},\n" \
                 f"Head: {a['head']},\nBody: {a['body']},\nBoots: {a['boots']},\nRing: {a['ring']},\n" \
                 f"Earring: {a['earring']},\nOther: {a['other']}."

        printf(string)
    def observe_items(self):
        while True:
            dec = input('Do you want to inspect a specific item? (y/n)\n')
            if dec == 'n' or dec == 'no':
                return 0

            item = self.get_item('all')
            if not item:
                return 0
            if item in self.inventory.useables:
                printf(self.inventory.useables[item])
            elif item in self.inventory.equippables:
                printf(self.inventory.equippables[item])
示例#5
0
def quest_line():

    subfolders = [
        f.name for f in os.scandir('classes/world/story') if f.is_dir()
    ]
    counter = []
    for i, folder in enumerate(subfolders):
        printf(f"[{i}] : ", folder)
        counter.append(f'{i}')

    quest = input('What questline do you wanna choose? ')
    quest = inp.test_quest(quest, counter)

    return subfolders[quest]
    def make_decision(self):
        while True:
            dec = input(
                'What do you want to do?\nView [0] --- Equip [1] --- Strip [2] --- Use [3] --- Check [4] --- Exit [5]\n'
            )
            try:
                mode = int(dec)
                break
            except:
                printf(
                    'Your decision was not understood. Use the numbers associated.'
                )

        return mode
示例#7
0
    def run(self):
        endpoint = False
        while not endpoint:
            story = self.world.next(self.flag)
            printf(story['prestring'])
            action = act.ActionManager(story['action'])
            self.players, loot, alive = action.start(self.players)
            for l in loot:
                self.inventory.add_item(l)
            if not alive:
                printf('you dead, no game anymore')
                endpoint = True
                continue

            decision = story['decision']
            keys = [key for key in decision.keys()]
            printf(story['poststring'])
            endpoint = story['Endpoint']

            if not endpoint:
                self.players = self.inventory.manage(self.players)
                for key in keys:
                    printf(key, ':', decision[key])
                inp = input(f'What will you choose? {keys} ')
                inp = test.test_decision(inp, keys)
                self.flag = self.flag + inp
    def get_player(self, players):
        while True:
            player_id = input('Specify the player: \n')
            if player_id == 'exit':
                return False
            try:
                player = players[player_id]
                break
            except:
                player_names = [name for name in players.keys()]
                printf(
                    f'Your decision was not understood. Use the name of the players ({player_names})'
                )

        return player, player_id
    def _apply_die(self, luck):
        eye = self.die.roll(luck)

        # die policy:
        if eye == 0:
            printf(' That was a weak attack!')
            return 0.75
        elif eye == 20:
            printf(' That was a critical attack!')
            return 1.25
        elif 15 >= eye >= 19:
            return 1.15
        elif 2 >= eye >= 5:
            return 0.85
        else:
            return 1
    def _player_choice(self, target_list):
        flag = True
        while flag:

            string = ''' Select (by name) your target from the list below:\n'''
            for act in target_list:
                s = f'-- Enemy: {act.name} - HP: {act.HP} - Debuff: None - Buff: None\n'
                string += s

            name = input(string)
            try:
                for target in target_list:
                    if target.name == name:
                        break
                flag = False
            except:
                printf('That did not work, wrong name. Try again.')

        return target, target.name, target_list.index(target)
    def choose_skill(self, player):
        if player in self.players:
            act_id = 'player'
        if player in self.enemies:
            act_id = 'enemy'

        skills = player.get_skills()
        skill_dict = {}
        for skill in skills:
            if skill.is_available():
                skill_dict[skill.name] = skill

        if not skill_dict:
            printf('All your skills are on cooldown. You cannot move, fam.\n')
            return 0

        if act_id == 'player':

            flag = True
            while flag:
                string = ''' Select (by name) the skill you want to apply
    from the list below:\n \n'''
                for skill in skill_dict.values():
                    dmg, des, _, _ = skill.get_damage()
                    eff_dmg = dmg + getattr(player, des)
                    string += str(
                        skill
                    ) + f'\n Effective damage (before damage calc): {eff_dmg}\n'

                name = input(string)
                try:
                    skill = skill_dict[name]
                    flag = False
                except:
                    printf('That did not work, wrong name. Try again.')

            player.apply_cooldown(name)

        elif act_id == 'enemy':
            skill = list(skill_dict.values())[np.random.randint(
                len(skill_dict.values()))]

        return skill
    def run(self):
        counter = 1

        printf('Battle starts!')
        while self.players and self.enemies:
            printf('- Round {}'.format(counter))
            self.battle(counter)
            counter += 1
            for players in self.players:
                self.all_players[players.name] = players

        if self.players:
            printf('Congrats! You won!')

            return self.all_players, True
        elif self.enemies:
            printf('You lost, man.')
            return self.all_players, False
    def apply(self, actor, act_id, target, target_id, dmg, buff, debuff):
        if buff:
            printf('Not yet implemented!')
        if debuff:
            printf('Not yet implemented!')

        #TODO implement dice feature

        if target in self.players:
            self.players[target_id].decrease_stat('HP', dmg)
            current_HP = self.players[target_id].HP

        if target in self.enemies:
            self.enemies[target_id].decrease_stat('HP', dmg)
            current_HP = self.enemies[target_id].HP

        if current_HP < 0:
            current_HP = 0

        printf('\n {} deals {} points of damage to {}. [HP: ({}/{})]\n'.format(
            actor.name, dmg, target.name, current_HP, target.MAX_HP))
    def get_item(self, key='e'):
        while True:
            item_id = input('Specify the item: \n')
            if item_id == 'exit':
                return False
            if key == 'e':
                if item_id in self.inventory.equippables:
                    return item_id
                else:
                    item_list = [
                        name for name in self.inventory.equippables.keys()
                    ]
                    printf(
                        f'Your decision was not understood. Use one of {item_list}.'
                    )
            elif key == 'u':
                if item_id in self.inventory.useables:
                    return item_id
                else:
                    item_list = [
                        name for name in self.inventory.useables.keys()
                    ]
                    printf(
                        f'Your decision was not understood. Use one of {item_list}.'
                    )

            elif key == 'all':
                if item_id in self.inventory.useables or item_id in self.inventory.equippables:
                    return item_id
                else:
                    item_list = [
                        name for name in self.inventory.useables.keys()
                    ]
                    item_list += [
                        name for name in self.inventory.equippables.keys()
                    ]
                    printf(
                        f'Your decision was not understood. Use one of {item_list}.'
                    )
示例#15
0
def intro():
    printf("""You're about to enter the world of Jan and Piwo.
These are the gods of this world. Whatever you do, do not anger them!""")
    def manage(self, players):
        printf('Starting inventory...')
        editting = True
        while editting:
            mode = self.make_decision()
            if mode == 0:
                printf(self.inventory)
                self.observe_items()
            elif mode == 1:
                if not self.inventory.equippables:
                    printf('There are no equippable items.')
                    continue
                player = self.get_player(players)
                if not player:
                    continue
                player, player_id = player
                item = self.get_item()
                if not item:
                    continue
                player = self.inventory.equip_item_to_player(player, item)
                players[player.name] = player
                printf(player)

            elif mode == 2:
                if not self.inventory.equippables:
                    printf('There are no equippable items.')
                    continue
                player = self.get_player(players)
                if not player:
                    continue
                player, player_id = player
                item = self.get_item()
                if not item:
                    continue
                player = self.inventory.remove_item_from_player(item, player)
                players[player.name] = player
                printf('Successfull!')
                printf(player)

            elif mode == 3:
                if not self.inventory.useables:
                    printf('There are no useable items.')
                    continue
                player = self.get_player(players)
                if not player:
                    continue
                player, player_id = player
                item = self.get_item('u')
                if not item:
                    continue

                player = self.inventory.use_item_on_player(player, item)
                players[player.name] = player
                printf('Successfull!')
                printf(player)

            elif mode == 4:
                player = self.get_player(players)
                if not player:
                    continue
                player, player_id = player
                self._show_stats(player)

            elif mode == 5:
                editting = False

        return players