From 3d48c43886223503587407e0b857d85816e113f2 Mon Sep 17 00:00:00 2001 From: eichhornchen Date: Sun, 10 Jan 2021 17:10:00 +0100 Subject: [PATCH] Player can now dance! Closes #69. --- squirrelbattle/entities/items.py | 2 +- squirrelbattle/entities/player.py | 27 +++++++++++++++++++++++++++ squirrelbattle/enums.py | 3 +++ squirrelbattle/game.py | 4 ++++ squirrelbattle/interfaces.py | 6 ++++++ squirrelbattle/settings.py | 1 + 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/squirrelbattle/entities/items.py b/squirrelbattle/entities/items.py index 94a9e36..ac502ea 100644 --- a/squirrelbattle/entities/items.py +++ b/squirrelbattle/entities/items.py @@ -498,7 +498,7 @@ class ScrollofDamage(Item): class ScrollofWeakening(Item): """ - A scroll that, when used, reduces the damage of the ennemies for 3 turn. + A scroll that, when used, reduces the damage of the ennemies for 3 turns. """ def __init__(self, name: str = "scroll_of_weakening", price: int = 13, *args, **kwargs): diff --git a/squirrelbattle/entities/player.py b/squirrelbattle/entities/player.py index 5b788b2..b3cb986 100644 --- a/squirrelbattle/entities/player.py +++ b/squirrelbattle/entities/player.py @@ -7,6 +7,7 @@ from math import log from .items import Item from ..interfaces import FightingEntity, InventoryHolder +from ..translations import gettext as _, Translator class Player(InventoryHolder, FightingEntity): @@ -62,6 +63,32 @@ class Player(InventoryHolder, FightingEntity): self.recalculate_paths() self.map.compute_visibility(self.y, self.x, self.vision) + def dance(self) -> None: + """ + Dancing has a certain probability or making ennemies unable + to fight for 2 turns. That probability depends on the player's + charisma. + """ + diceroll = randint(1, 10) + found = False + if diceroll <= self.charisma: + for entity in self.map.entities: + if entity.is_fighting_entity() and not entity == self \ + and entity.distance(self)<=3: + found = True + entity.confused = 1 + entity.effects.append(["confused", 1, 3]) + if found: + self.map.logs.add_message(_( + "It worked! Nearby ennemies will be confused for 3 turns.")) + else: + self.map.logs.add_message(_( + "It worked, but there is no one nearby...")) + else: + self.map.logs.add_message( + _("The dance was not effective...")) + + def level_up(self) -> None: """ Add as many levels as possible to the player. diff --git a/squirrelbattle/enums.py b/squirrelbattle/enums.py index b6b4bcd..42bd643 100644 --- a/squirrelbattle/enums.py +++ b/squirrelbattle/enums.py @@ -50,6 +50,7 @@ class KeyValues(Enum): WAIT = auto() LADDER = auto() LAUNCH = auto() + DANCE = auto() @staticmethod def translate_key(key: str, settings: Settings) -> Optional["KeyValues"]: @@ -88,4 +89,6 @@ class KeyValues(Enum): return KeyValues.LADDER elif key == settings.KEY_LAUNCH: return KeyValues.LAUNCH + elif key == settings.KEY_DANCE: + return KeyValues.DANCE return None diff --git a/squirrelbattle/game.py b/squirrelbattle/game.py index 56ab6ed..73d45eb 100644 --- a/squirrelbattle/game.py +++ b/squirrelbattle/game.py @@ -179,6 +179,9 @@ class Game: self.map.tick(self.player) elif key == KeyValues.LADDER: self.handle_ladder() + elif key == KeyValues.DANCE: + self.player.dance() + self.map.tick(self.player) def handle_ladder(self) -> None: """ @@ -291,6 +294,7 @@ class Game: if self.player.equipped_main: self.player.equipped_main.throw(direction) + def handle_key_pressed_inventory(self, key: KeyValues) -> None: """ In the inventory menu, we can interact with items or close the menu. diff --git a/squirrelbattle/interfaces.py b/squirrelbattle/interfaces.py index 60a7c82..3832cef 100644 --- a/squirrelbattle/interfaces.py +++ b/squirrelbattle/interfaces.py @@ -707,6 +707,7 @@ class FightingEntity(Entity): constitution: int level: int critical: int + confused: int # Seulement 0 ou 1 def __init__(self, maxhealth: int = 0, health: Optional[int] = None, strength: int = 0, intelligence: int = 0, charisma: int = 0, @@ -723,6 +724,7 @@ class FightingEntity(Entity): self.level = level self.critical = critical self.effects = [] # effects = temporary buff or weakening of the stats. + self.confused = 0 @property def dead(self) -> bool: @@ -750,6 +752,10 @@ class FightingEntity(Entity): The entity deals damage to the opponent based on their respective stats. """ + if self.confused: + return _("{name} is confused, it can not hit {opponent}.")\ + .format(name=_(self.translated_name.capitalize()), + opponent=_(opponent.translated_name)) diceroll = randint(1, 100) damage = max(0, self.strength) string = " " diff --git a/squirrelbattle/settings.py b/squirrelbattle/settings.py index 92a8b37..3fd27c5 100644 --- a/squirrelbattle/settings.py +++ b/squirrelbattle/settings.py @@ -36,6 +36,7 @@ class Settings: self.KEY_WAIT = ['w', 'Key used to wait'] self.KEY_LADDER = ['<', 'Key used to use ladders'] self.KEY_LAUNCH = ['l', 'Key used to use a bow'] + self.KEY_DANCE = ['y', 'Key used to dance'] self.TEXTURE_PACK = ['ascii', 'Texture pack'] self.LOCALE = [locale.getlocale()[0][:2], 'Language']