Example #1
0
 def rebuild_monster(self, data):
     """Create new monster from data about monster"""
     #create monster
     newmonster=Monster(data["uuid"])
     #newmonster.uuid=data["uuid"]
     newmonster.name=data["name"]
     newmonster.desc=data["desc"]
     newmonster.hp=data["hp"][:]
     newmonster.stats=data["stats"][:]
     newmonster.exp=data["exp"]
     newmonster.drop=data["drop"][:]
     return newmonster
Example #2
0
 def drop(self, item):
     """Drop an item."""
     item = Object.obj_dict[item]
     Monster.drop(self, item)
     message('You dropped the ' + item.name + '.')
Example #3
0
 def drop(self, item):
     """Drop an item."""
     item = Object.obj_dict[item]
     Monster.drop(self, item)
     message('You dropped the ' + item.name + '.')
Example #4
0
    def battle_engine(self, name):
        '''
		Speed determines who moves first.
		Damage dealt by monsters are within a fixed range.
		Player damage = random(attack*weapon*0.8, attack*weapon*1.2)
		Options for player in battle:
		1. Attack 2. Block 3. Run
		'''
        valid = ['1', '2',
                 '3']  # valid options for the player -> reduces hard coding
        victor = ''
        turn = -1
        monster = Monster(name)
        first = 0
        if (self.player.speed > monster.speed):  # who moves first
            first = 1
        while (self.player.battle):
            turn += 1
            flush()
            monster.display_stats()
            print()
            self.player.battle_ui()
            while (1):  # getting the player's action
                option = input('>')
                if (option not in valid): print("Invalid option!")
                else:
                    if (option == '1'):
                        if (not self.player.weapon):
                            print("You have no weapons!"
                                  )  # if player has no weapons to attack
                        else:
                            break
                    elif (option == '2'):  # attempts a block
                        if (self.player.cooldown):
                            print(
                                "You are too exhausted to attempt another block!"
                            )
                        else:
                            break
                    elif (option == '3'):  # run from battles
                        print("You live to fight another day...")
                        self.player.battle = 0
                        self.player.location = self.player.prev  # sets player location to where it came from before the battle
                        flush()
                        break
            if (not self.player.battle):
                self.show_description()
                break  # if the player abandons the battle
            player_damage = 0
            monster_damage = 0
            monster_move = monster.pattern[turn % 3]
            if (monster_move == 'b' and option == '2'
                ):  # in the event that both player and monster try blocking
                print("You both attempt blocking... cowards.")
                self.player.cooldown = 1
                continue
            if (self.player.cooldown == 1):  # increments cooldown
                self.player.cooldown += 1
            elif (self.player.cooldown == 2):
                self.player.cooldown = 0
            if (first):  # if the player goes first
                '''---player actions---'''
                if (option == '1'):
                    player_damage = self.player.get_damage()
                if (monster_move == 'b'):
                    monster.show_message(
                        1)  # block has higher priority, thus it is shown first
                    player_damage //= 3
                if (option == '1'):
                    self.player.show_message()
                    print("Your attack deals {} damage!".format(
                        int(player_damage)))
                    monster.hp -= player_damage
                self.damage_to += player_damage
                if (monster.hp <= 0):
                    victor = 'p'
                    self.player.battle = 0
                    break  # additional break to fix a bug where the battle was not ending
                '''---monster actions---'''
                if (monster_move == 'b'): continue
                monster_damage = monster.fight()
                if (option == '2'):
                    self.player.block()
                    monster_damage //= 3
                monster.show_message(0)
                print("The {}\'s attack deals {} damage!".format(
                    name, monster_damage))
                self.player.hp -= monster_damage
                self.damage_from += monster_damage
                if (self.player.hp <= 0):
                    victor = 'm'
                    self.player.battle = 0

            else:
                '''---monster actions---'''
                if (monster_move == 'a'):
                    monster_damage = monster.fight()
                if (option == '2'):
                    self.player.block()
                    monster_damage //= 3
                '''---player actions---'''
                if (option == '1'):
                    player_damage = self.player.get_damage()
                if (monster_move == 'b'):
                    player_damage //= 3
                if (monster_move == 'a'):
                    monster.show_message(0)
                    print("The {}\'s attack deals {} damage!".format(
                        name, monster_damage))
                else:
                    monster.show_message(1)
                self.player.hp -= monster_damage
                self.damage_from += monster_damage
                if (self.player.hp <= 0):
                    victor = 'm'
                    self.player.battle = 0
                    break
                if (option == '1'):
                    self.player.show_message()
                    print("Your attack deals {} damage!".format(
                        int(player_damage)))
                    monster.hp -= player_damage
                self.damage_to += player_damage
                if (monster.hp <= 0):
                    victor = 'p'
                    self.player.battle = 0
        self.player.cooldown = 0  # reset block cooldown after every battle
        if (victor == 'p'):
            print("You have slained the {}.\n".format(name))
            self.player.battle_history[self.player.location] = 1
            if (name == "Minotaur"):
                return  # Minotaur has no drops, prevents key error
            drops = monster.drop()
            for i in drops:
                self.player.add_item(i)
            self.show_description()
        elif (victor == 'm'):
            print("You have been slained by the {}...".format(name))
            self.player.die = 1