Implement the monocle of truth, closes #62
This commit is contained in:
		@@ -3,10 +3,10 @@
 | 
			
		||||
 | 
			
		||||
import curses
 | 
			
		||||
 | 
			
		||||
from ..entities.items import Monocle
 | 
			
		||||
from ..entities.player import Player
 | 
			
		||||
from ..game import Game
 | 
			
		||||
from ..interfaces import FriendlyEntity
 | 
			
		||||
from ..settings import Settings
 | 
			
		||||
from ..interfaces import FightingEntity
 | 
			
		||||
from ..translations import gettext as _
 | 
			
		||||
from .display import Display
 | 
			
		||||
 | 
			
		||||
@@ -87,16 +87,40 @@ class StatsDisplay(Display):
 | 
			
		||||
            self.addstr(self.pad, self.height - 2, 0, msg,
 | 
			
		||||
                        italic=True, reverse=True)
 | 
			
		||||
 | 
			
		||||
        self.update_entities_stats()
 | 
			
		||||
 | 
			
		||||
    def update_entities_stats(self) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        Display information about a near entity if we have a monocle.
 | 
			
		||||
        """
 | 
			
		||||
        for dy, dx in [(-1, 0), (0, -1), (0, 1), (1, 0)]:
 | 
			
		||||
            for entity in self.player.map.find_entities(FriendlyEntity):
 | 
			
		||||
            for entity in self.player.map.find_entities(FightingEntity):
 | 
			
		||||
                if entity == self.player:
 | 
			
		||||
                    continue
 | 
			
		||||
 | 
			
		||||
                if entity.y == self.player.y + dy \
 | 
			
		||||
                        and entity.x == self.player.x + dx:
 | 
			
		||||
                    msg = _("Move to the friendly entity to talk to it") \
 | 
			
		||||
                        if self.game.waiting_for_friendly_key else \
 | 
			
		||||
                        _("Use {key} then move to talk to the entity") \
 | 
			
		||||
                        .format(key=self.game.settings.KEY_CHAT.upper())
 | 
			
		||||
                    self.addstr(self.pad, self.height - 1, 0, msg,
 | 
			
		||||
                                italic=True, reverse=True)
 | 
			
		||||
                    if entity.is_friendly():
 | 
			
		||||
                        msg = _("Move to the friendly entity to talk to it") \
 | 
			
		||||
                            if self.game.waiting_for_friendly_key else \
 | 
			
		||||
                            _("Use {key} then move to talk to the entity") \
 | 
			
		||||
                            .format(key=self.game.settings.KEY_CHAT.upper())
 | 
			
		||||
                        self.addstr(self.pad, self.height - 1, 0, msg,
 | 
			
		||||
                                    italic=True, reverse=True)
 | 
			
		||||
 | 
			
		||||
                    if isinstance(self.player.equipped_secondary, Monocle):
 | 
			
		||||
                        # Truth monocle
 | 
			
		||||
                        message = f"{entity.translated_name.capitalize()} " \
 | 
			
		||||
                                  f"{self.pack[entity.name.upper()]}\n" \
 | 
			
		||||
                                  f"STR {entity.strength}\n" \
 | 
			
		||||
                                  f"INT {entity.intelligence}\n" \
 | 
			
		||||
                                  f"CHR {entity.charisma}\n" \
 | 
			
		||||
                                  f"DEX {entity.dexterity}\n" \
 | 
			
		||||
                                  f"CON {entity.constitution}\n" \
 | 
			
		||||
                                  f"CRI {entity.critical}%"
 | 
			
		||||
                        self.addstr(self.pad, 17, 0, message)
 | 
			
		||||
                    # Only display one entity
 | 
			
		||||
                    break
 | 
			
		||||
 | 
			
		||||
    def display(self) -> None:
 | 
			
		||||
        self.pad.erase()
 | 
			
		||||
 
 | 
			
		||||
@@ -84,6 +84,7 @@ TexturePack.ASCII_PACK = TexturePack(
 | 
			
		||||
    HEDGEHOG='*',
 | 
			
		||||
    HELMET='0',
 | 
			
		||||
    MERCHANT='M',
 | 
			
		||||
    MONOCLE='ô',
 | 
			
		||||
    PLAYER='@',
 | 
			
		||||
    RABBIT='Y',
 | 
			
		||||
    RING_OF_CRITICAL_DAMAGE='o',
 | 
			
		||||
@@ -121,6 +122,7 @@ TexturePack.SQUIRREL_PACK = TexturePack(
 | 
			
		||||
    HELMET='⛑️ ',
 | 
			
		||||
    PLAYER='🐿️ ️',
 | 
			
		||||
    MERCHANT='🦜',
 | 
			
		||||
    MONOCLE='🧐',
 | 
			
		||||
    RABBIT='🐇',
 | 
			
		||||
    RING_OF_CRITICAL_DAMAGE='💍',
 | 
			
		||||
    RING_OF_MORE_EXPERIENCE='💍',
 | 
			
		||||
 
 | 
			
		||||
@@ -86,8 +86,8 @@ class Item(Entity):
 | 
			
		||||
        """
 | 
			
		||||
        Returns the list of all item classes.
 | 
			
		||||
        """
 | 
			
		||||
        return [BodySnatchPotion, Bomb, Heart, Shield, Sword,
 | 
			
		||||
                Chestplate, Helmet, RingCritical, RingXP]
 | 
			
		||||
        return [BodySnatchPotion, Chestplate, Bomb, Heart, Helmet, Monocle,
 | 
			
		||||
                Shield, Sword, RingCritical, RingXP]
 | 
			
		||||
 | 
			
		||||
    def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool:
 | 
			
		||||
        """
 | 
			
		||||
@@ -453,3 +453,9 @@ class RingXP(Ring):
 | 
			
		||||
                 experience: float = 2, *args, **kwargs):
 | 
			
		||||
        super().__init__(name=name, price=price, experience=experience,
 | 
			
		||||
                         *args, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Monocle(Item):
 | 
			
		||||
    def __init__(self, name: str = "monocle", price: int = 10,
 | 
			
		||||
                 *args, **kwargs):
 | 
			
		||||
        super().__init__(name=name, price=price, *args, **kwargs)
 | 
			
		||||
 
 | 
			
		||||
@@ -345,7 +345,7 @@ class Game:
 | 
			
		||||
        try:
 | 
			
		||||
            self.map_index = d["map_index"]
 | 
			
		||||
            self.maps = [Map().load_state(map_dict) for map_dict in d["maps"]]
 | 
			
		||||
        except KeyError:
 | 
			
		||||
        except KeyError as e:
 | 
			
		||||
            self.message = _("Some keys are missing in your save file.\n"
 | 
			
		||||
                             "Your save seems to be corrupt. It got deleted.")
 | 
			
		||||
            os.unlink(ResourceManager.get_config_path("save.json"))
 | 
			
		||||
 
 | 
			
		||||
@@ -635,24 +635,26 @@ class Entity:
 | 
			
		||||
        from squirrelbattle.entities.friendly import Merchant, Sunflower, \
 | 
			
		||||
            Trumpet
 | 
			
		||||
        from squirrelbattle.entities.items import BodySnatchPotion, Bomb, \
 | 
			
		||||
            Heart, Sword, Shield, Chestplate, Helmet, RingCritical, RingXP
 | 
			
		||||
            Heart, Monocle, Sword, Shield, Chestplate, Helmet, \
 | 
			
		||||
            RingCritical, RingXP
 | 
			
		||||
        return {
 | 
			
		||||
            "Tiger": Tiger,
 | 
			
		||||
            "Bomb": Bomb,
 | 
			
		||||
            "Chestplate": Chestplate,
 | 
			
		||||
            "Heart": Heart,
 | 
			
		||||
            "BodySnatchPotion": BodySnatchPotion,
 | 
			
		||||
            "Eagle": GiantSeaEagle,
 | 
			
		||||
            "Hedgehog": Hedgehog,
 | 
			
		||||
            "Rabbit": Rabbit,
 | 
			
		||||
            "TeddyBear": TeddyBear,
 | 
			
		||||
            "Helmet": Helmet,
 | 
			
		||||
            "Player": Player,
 | 
			
		||||
            "Merchant": Merchant,
 | 
			
		||||
            "Monocle": Monocle,
 | 
			
		||||
            "Sunflower": Sunflower,
 | 
			
		||||
            "Sword": Sword,
 | 
			
		||||
            "Trumpet": Trumpet,
 | 
			
		||||
            "Eagle": GiantSeaEagle,
 | 
			
		||||
            "Shield": Shield,
 | 
			
		||||
            "Chestplate": Chestplate,
 | 
			
		||||
            "Helmet": Helmet,
 | 
			
		||||
            "TeddyBear": TeddyBear,
 | 
			
		||||
            "Tiger": Tiger,
 | 
			
		||||
            "Rabbit": Rabbit,
 | 
			
		||||
            "RingCritical": RingCritical,
 | 
			
		||||
            "RingXP": RingXP,
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ msgid ""
 | 
			
		||||
msgstr ""
 | 
			
		||||
"Project-Id-Version: squirrelbattle 3.14.1\n"
 | 
			
		||||
"Report-Msgid-Bugs-To: squirrel-battle@crans.org\n"
 | 
			
		||||
"POT-Creation-Date: 2021-01-08 15:04+0100\n"
 | 
			
		||||
"POT-Creation-Date: 2021-01-08 15:15+0100\n"
 | 
			
		||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 | 
			
		||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 | 
			
		||||
"Language-Team: LANGUAGE <LL@li.org>\n"
 | 
			
		||||
@@ -49,40 +49,40 @@ msgstr "BESTAND"
 | 
			
		||||
msgid "STALL"
 | 
			
		||||
msgstr "STAND"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:46
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:44
 | 
			
		||||
msgid "Inventory:"
 | 
			
		||||
msgstr "Bestand:"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:63
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:61
 | 
			
		||||
msgid "Equipped main:"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:67
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:65
 | 
			
		||||
msgid "Equipped secondary:"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:72
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:70
 | 
			
		||||
msgid "Equipped chestplate:"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:76
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:74
 | 
			
		||||
msgid "Equipped helmet:"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:83
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:81
 | 
			
		||||
msgid "YOU ARE DEAD"
 | 
			
		||||
msgstr "SIE WURDEN GESTORBEN"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:87
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:85
 | 
			
		||||
#, python-brace-format
 | 
			
		||||
msgid "Use {key} to use the ladder"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:96
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:94
 | 
			
		||||
msgid "Move to the friendly entity to talk to it"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:98
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:96
 | 
			
		||||
#, python-brace-format
 | 
			
		||||
msgid "Use {key} then move to talk to the entity"
 | 
			
		||||
msgstr ""
 | 
			
		||||
@@ -347,3 +347,7 @@ msgstr ""
 | 
			
		||||
#: squirrelbattle/tests/translations_test.py:82
 | 
			
		||||
msgid "ring of more experience"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/tests/translations_test.py:84
 | 
			
		||||
msgid "monocle"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ msgid ""
 | 
			
		||||
msgstr ""
 | 
			
		||||
"Project-Id-Version: squirrelbattle 3.14.1\n"
 | 
			
		||||
"Report-Msgid-Bugs-To: squirrel-battle@crans.org\n"
 | 
			
		||||
"POT-Creation-Date: 2021-01-08 15:04+0100\n"
 | 
			
		||||
"POT-Creation-Date: 2021-01-08 15:15+0100\n"
 | 
			
		||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 | 
			
		||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 | 
			
		||||
"Language-Team: LANGUAGE <LL@li.org>\n"
 | 
			
		||||
@@ -49,40 +49,40 @@ msgstr "INVENTORIO"
 | 
			
		||||
msgid "STALL"
 | 
			
		||||
msgstr "PUESTO"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:46
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:44
 | 
			
		||||
msgid "Inventory:"
 | 
			
		||||
msgstr "Inventorio :"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:63
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:61
 | 
			
		||||
msgid "Equipped main:"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:67
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:65
 | 
			
		||||
msgid "Equipped secondary:"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:72
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:70
 | 
			
		||||
msgid "Equipped chestplate:"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:76
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:74
 | 
			
		||||
msgid "Equipped helmet:"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:83
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:81
 | 
			
		||||
msgid "YOU ARE DEAD"
 | 
			
		||||
msgstr "ERES MUERTO"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:87
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:85
 | 
			
		||||
#, python-brace-format
 | 
			
		||||
msgid "Use {key} to use the ladder"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:96
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:94
 | 
			
		||||
msgid "Move to the friendly entity to talk to it"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:98
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:96
 | 
			
		||||
#, python-brace-format
 | 
			
		||||
msgid "Use {key} then move to talk to the entity"
 | 
			
		||||
msgstr ""
 | 
			
		||||
@@ -346,3 +346,7 @@ msgstr ""
 | 
			
		||||
#: squirrelbattle/tests/translations_test.py:82
 | 
			
		||||
msgid "ring of more experience"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/tests/translations_test.py:84
 | 
			
		||||
msgid "monocle"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ msgid ""
 | 
			
		||||
msgstr ""
 | 
			
		||||
"Project-Id-Version: squirrelbattle 3.14.1\n"
 | 
			
		||||
"Report-Msgid-Bugs-To: squirrel-battle@crans.org\n"
 | 
			
		||||
"POT-Creation-Date: 2021-01-08 15:04+0100\n"
 | 
			
		||||
"POT-Creation-Date: 2021-01-08 15:15+0100\n"
 | 
			
		||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 | 
			
		||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 | 
			
		||||
"Language-Team: LANGUAGE <LL@li.org>\n"
 | 
			
		||||
@@ -43,40 +43,40 @@ msgstr "INVENTAIRE"
 | 
			
		||||
msgid "STALL"
 | 
			
		||||
msgstr "STAND"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:46
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:44
 | 
			
		||||
msgid "Inventory:"
 | 
			
		||||
msgstr "Inventaire :"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:63
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:61
 | 
			
		||||
msgid "Equipped main:"
 | 
			
		||||
msgstr "Équipement principal :"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:67
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:65
 | 
			
		||||
msgid "Equipped secondary:"
 | 
			
		||||
msgstr "Équipement secondaire :"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:72
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:70
 | 
			
		||||
msgid "Equipped chestplate:"
 | 
			
		||||
msgstr "Plastron équipé :"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:76
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:74
 | 
			
		||||
msgid "Equipped helmet:"
 | 
			
		||||
msgstr "Casque équipé :"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:83
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:81
 | 
			
		||||
msgid "YOU ARE DEAD"
 | 
			
		||||
msgstr "VOUS ÊTES MORT"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:87
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:85
 | 
			
		||||
#, python-brace-format
 | 
			
		||||
msgid "Use {key} to use the ladder"
 | 
			
		||||
msgstr "Appuyez sur {key} pour utiliser l'échelle"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:96
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:94
 | 
			
		||||
msgid "Move to the friendly entity to talk to it"
 | 
			
		||||
msgstr "Avancez vers l'entité pour lui parler"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:98
 | 
			
		||||
#: squirrelbattle/display/statsdisplay.py:96
 | 
			
		||||
#, python-brace-format
 | 
			
		||||
msgid "Use {key} then move to talk to the entity"
 | 
			
		||||
msgstr "Appuyez sur {key} puis déplacez-vous pour parler"
 | 
			
		||||
@@ -341,3 +341,7 @@ msgstr "anneau de coup critique"
 | 
			
		||||
#: squirrelbattle/tests/translations_test.py:82
 | 
			
		||||
msgid "ring of more experience"
 | 
			
		||||
msgstr "anneau de plus d'expérience"
 | 
			
		||||
 | 
			
		||||
#: squirrelbattle/tests/translations_test.py:84
 | 
			
		||||
msgid "monocle"
 | 
			
		||||
msgstr "monocle"
 | 
			
		||||
 
 | 
			
		||||
@@ -66,6 +66,7 @@ class TestGame(unittest.TestCase):
 | 
			
		||||
 | 
			
		||||
        new_state = self.game.save_state()
 | 
			
		||||
        self.assertEqual(old_state, new_state)
 | 
			
		||||
        self.assertIsNone(self.game.message)
 | 
			
		||||
 | 
			
		||||
        # Ensure that the bomb is loaded
 | 
			
		||||
        self.assertTrue(self.game.player.inventory)
 | 
			
		||||
 
 | 
			
		||||
@@ -81,3 +81,4 @@ class TestTranslations(unittest.TestCase):
 | 
			
		||||
                         "anneau de coup critique")
 | 
			
		||||
        self.assertEqual(_("ring of more experience"),
 | 
			
		||||
                         "anneau de plus d'expérience")
 | 
			
		||||
        self.assertEqual(_("monocle"), "monocle")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user