Esempio n. 1
0
 def _check_space(self):
     """ Mark the Inventory as full or not full."""
     if len(self) + 1 <= self.limit:
         self.full = False
     else:
         self.full = True
         print_centre("Inventory limit reached.")
         common.sleep()
Esempio n. 2
0
 def transfer_gold_exp(self):
     """ Transfer gold and exp from enemy to hero if enemy is dead."""
     if self.enemy.dead:
         msg = "{} recieved {} exp and {} gold!"
         msg = msg.format(self.hero.name, self.enemy.exp, self.enemy.gold)
         print_centre(msg)
         self.hero.exp += self.enemy.exp
         self.hero.gold += self.enemy.gold
         common.sleep()
Esempio n. 3
0
    def sell(self, item):
        """ Removes the item from the heros inventory and adds
            the sell price of the item to the players sell attr.

        Args:
            item (Item): item to remove.
        """
        self.hero.inventory.remove_item(item.name)
        self.hero.gold += item.sell
        print_centre("Thank you for selling your {} to me!".format(item.name))
        common.sleep()
Esempio n. 4
0
 def handle_options(self):
     """ Extract and execute a method from self.options."""
     try:
         print_centre(self.choices)
         choice = input(">> ")
         item = self.options[choice]
         return item
     except KeyError:
         msg = "{} is not a valid choice. Try again.\n"
         print_centre(msg.format(choice))
         sleep()
         return self.handle_options()
Esempio n. 5
0
    def _communicate_stat_change(self, stat, operator, value):
        """ Print character stat changes.

        Args:
            stat (str): hp, mp, st or ag.
            operator (str): '+' or '-'.
            value (int): number to alter the stat by.
        """
        upordown = "increases" if operator == "+" else "decreases"
        msg = "{} {} {} by {}\n".format(self.name, stat.upper(), upordown,
                                        value)
        print_centre(msg)
        sleep()
Esempio n. 6
0
    def execute_submenu(self, submenu):
        """ Executes player submenu choice and target selection.

        Args:
            submenu (Menu): am item or magic submenu"""
        self.construct_battle_screen()
        submenu_selection = submenu.handle_options()
        if submenu_selection != self.main_menu:
            target = self.select_target()
            if submenu == self.main_menu.item_menu:
                self.use_item(submenu_selection, target)
            else:
                submenu_selection(target)
            common.sleep()
        else:
            return self.main_menu
Esempio n. 7
0
    def purchase(self, item):
        """ Transfers the item to the hero inventory and deducts
            the cost from the players gold attr.

        Args:
            item (Item): item to transfer.
        """
        deduction = self.hero.gold - item.cost
        if deduction >= 0:
            self.hero.inventory.add_items(item)
            if self.hero.inventory.full is False:
                self.hero.gold = deduction
                print_centre("Enjoy your {}!".format(item.name))
                common.sleep()
        else:
            print_centre("You don't have enough gold to purchase that!")
            common.sleep()
Esempio n. 8
0
    def _adjust_value_around_max(self, stat, value):
        """ Adjusts the parsed value such that it cannot increase
            the stat value above its maximum limit.

        Args:
            stat (str): hp, mp, st or ag.
            value (int): number to increase the stat by.
        """
        max_stat = getattr(self, "_max_{}".format(stat))
        current_stat = getattr(self, stat)
        if current_stat == max_stat:
            msg = "{} is already at the maximum value\n"
            print_centre(msg.format(stat.upper()))
            sleep()
            return 0
        elif value + current_stat > max_stat:
            return max_stat - current_stat
        else:
            return value
Esempio n. 9
0
    def ai(self, target):
        """ Enemy action determined by if else block.

        Args:
            target (Character): object to target.
        """
        if not self.dead:
            actions = {"attack": 10, "magic": 3}
            action = common.weighted_choice(actions)
            if self.mp > 1 and action == "magic":
                spells = {"big_attack": 10, "buff": 2, "debuff": 1}
                choice = common.weighted_choice(spells)
                spell = getattr(self.magic, choice)
                target = target if choice != "buff" else self
                spell(target)
                common.sleep()
            else:
                self.attack(target)
                common.sleep()
Esempio n. 10
0
 def flee(self):
     """ Attempt to run from battle."""
     print_centre("{} attempts to flee!".format(self.hero.name))
     common.sleep()
     # 20% chance of fleeing
     weighted_success = {True: 2, False: 8}
     flee_success = common.weighted_choice(weighted_success)
     if flee_success:
         print_centre("{} successfully ran away!\n".format(self.hero.name))
         common.sleep()
         return True
     else:
         print_centre("{} couldn't get away!\n".format(self.hero.name))
         common.sleep()
         return False
Esempio n. 11
0
 def gold(self, amount):
     if amount < 0:
         print_centre("You do not have enough gold.")
         sleep()
     else:
         self._gold = amount
Esempio n. 12
0
 def _use_msg(self):
     print_centre("Lets BRO DOWN with a {}!\n".format(self.name))
     sleep()
Esempio n. 13
0
 def _use_msg(self):
     print_centre("You slammed a {}!\n".format(self.name[:-1]))
     sleep()
Esempio n. 14
0
 def _use_msg(self):
     print_centre("You shrieked into a {}!!!\n".format(self.name))
     sleep()
Esempio n. 15
0
 def _use_msg(self):
     print_centre("You uncorked a bottle of {}.\n".format(self.name))
     sleep()
Esempio n. 16
0
 def _use_msg(self):
     print_centre("You threw a {}!\n".format(self.name))
     sleep()
Esempio n. 17
0
 def _use_msg(self):
     print_centre("{} has been used!\n".format(self.name.title()))
     sleep()
Esempio n. 18
0
 def attack(self):
     """ Attack enemy."""
     self.hero.attack(self.enemy)
     common.sleep()