def stun(self): raw_damage = int( System.calculate_percentage(total=new_player.max_health, percentage=5)) new_player.take_damage(raw_damage, armour_absorption=False) clear() print( f"{self.name_string}{Colours.fg.orange} stunned you for {Colours.fg.red}{raw_damage}{Colours.fg.orange} damage." ) print( f"{self.name_string}{Colours.fg.lightblue} gained an extra turn.") sleep_and_clear(2) self.attack()
def update_attribute(self, attribute, operate, percentage): if attribute == "current_health": self.heal(percentage) else: #Getting the original value total = self.get_attribute("original", attribute) update_by = System.calculate_percentage(percentage=percentage, total=total) numbers_to_round = ("weapon.accuracy", "weapon.crit_chance") if attribute in numbers_to_round: update_by = round(update_by) object_chain = attribute.split(".") #Incrementing/Decrementing the current value #Rounding to avoid nums like 0.800000000002 self.attributes[object_chain[0]].attributes[ object_chain[1]] = round( operate(self.get_attribute(attribute=attribute), update_by), 2)
def choose_combat_action(self): #Boss if isinstance(self, Boss): rdm_int = random.randint(1, 100) if rdm_int in self.attacking_chance: self.attack() else: #Heal 50% health if self.current_health <= System.calculate_percentage( total=self.max_health, percentage=50) and self.has_healed == False: self.heal(50) self.has_healed = True #Stun player (10 damage + extra turn) else: self.stun() #Normal Enemy else: self.attack()
def heal(self, percentage_to_heal): if isinstance(self, Player): entity = "You" possessive_pronoun = "your" else: entity = self.name_string possessive_pronoun = "its" value_to_heal = System.calculate_percentage(percentage_to_heal, total=self.max_health) self.current_health += value_to_heal if self.current_health > self.max_health: self.current_health = self.max_health self.current_health = round(self.current_health) clear() print( f"{Colours.fg.cyan}{entity} {Colours.fg.cyan}regained {Colours.fg.red + Colours.underline}{percentage_to_heal}%{Colours.reset + Colours.fg.cyan} of {possessive_pronoun} {Colours.fg.green}health{Colours.fg.cyan}." ) sleep_and_clear(2)