Player can now dance! Closes #69.
This commit is contained in:
		@@ -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):
 | 
			
		||||
 
 | 
			
		||||
@@ -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.
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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.
 | 
			
		||||
 
 | 
			
		||||
@@ -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 = " "
 | 
			
		||||
 
 | 
			
		||||
@@ -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']
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user