Implement the monocle of truth, closes #62

This commit is contained in:
Yohann D'ANELLO 2021-01-08 15:48:12 +01:00
parent 1270640619
commit a497d08f31
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
10 changed files with 97 additions and 49 deletions

View File

@ -3,10 +3,10 @@
import curses import curses
from ..entities.items import Monocle
from ..entities.player import Player from ..entities.player import Player
from ..game import Game from ..game import Game
from ..interfaces import FriendlyEntity from ..interfaces import FightingEntity
from ..settings import Settings
from ..translations import gettext as _ from ..translations import gettext as _
from .display import Display from .display import Display
@ -87,10 +87,20 @@ class StatsDisplay(Display):
self.addstr(self.pad, self.height - 2, 0, msg, self.addstr(self.pad, self.height - 2, 0, msg,
italic=True, reverse=True) 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 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 \ if entity.y == self.player.y + dy \
and entity.x == self.player.x + dx: and entity.x == self.player.x + dx:
if entity.is_friendly():
msg = _("Move to the friendly entity to talk to it") \ msg = _("Move to the friendly entity to talk to it") \
if self.game.waiting_for_friendly_key else \ if self.game.waiting_for_friendly_key else \
_("Use {key} then move to talk to the entity") \ _("Use {key} then move to talk to the entity") \
@ -98,6 +108,20 @@ class StatsDisplay(Display):
self.addstr(self.pad, self.height - 1, 0, msg, self.addstr(self.pad, self.height - 1, 0, msg,
italic=True, reverse=True) 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: def display(self) -> None:
self.pad.erase() self.pad.erase()
self.update_pad() self.update_pad()

View File

@ -84,6 +84,7 @@ TexturePack.ASCII_PACK = TexturePack(
HEDGEHOG='*', HEDGEHOG='*',
HELMET='0', HELMET='0',
MERCHANT='M', MERCHANT='M',
MONOCLE='ô',
PLAYER='@', PLAYER='@',
RABBIT='Y', RABBIT='Y',
RING_OF_CRITICAL_DAMAGE='o', RING_OF_CRITICAL_DAMAGE='o',
@ -121,6 +122,7 @@ TexturePack.SQUIRREL_PACK = TexturePack(
HELMET='⛑️ ', HELMET='⛑️ ',
PLAYER='🐿️ ', PLAYER='🐿️ ',
MERCHANT='🦜', MERCHANT='🦜',
MONOCLE='🧐',
RABBIT='🐇', RABBIT='🐇',
RING_OF_CRITICAL_DAMAGE='💍', RING_OF_CRITICAL_DAMAGE='💍',
RING_OF_MORE_EXPERIENCE='💍', RING_OF_MORE_EXPERIENCE='💍',

View File

@ -86,8 +86,8 @@ class Item(Entity):
""" """
Returns the list of all item classes. Returns the list of all item classes.
""" """
return [BodySnatchPotion, Bomb, Heart, Shield, Sword, return [BodySnatchPotion, Chestplate, Bomb, Heart, Helmet, Monocle,
Chestplate, Helmet, RingCritical, RingXP] Shield, Sword, RingCritical, RingXP]
def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool: def be_sold(self, buyer: InventoryHolder, seller: InventoryHolder) -> bool:
""" """
@ -453,3 +453,9 @@ class RingXP(Ring):
experience: float = 2, *args, **kwargs): experience: float = 2, *args, **kwargs):
super().__init__(name=name, price=price, experience=experience, super().__init__(name=name, price=price, experience=experience,
*args, **kwargs) *args, **kwargs)
class Monocle(Item):
def __init__(self, name: str = "monocle", price: int = 10,
*args, **kwargs):
super().__init__(name=name, price=price, *args, **kwargs)

View File

@ -345,7 +345,7 @@ class Game:
try: try:
self.map_index = d["map_index"] self.map_index = d["map_index"]
self.maps = [Map().load_state(map_dict) for map_dict in d["maps"]] 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" self.message = _("Some keys are missing in your save file.\n"
"Your save seems to be corrupt. It got deleted.") "Your save seems to be corrupt. It got deleted.")
os.unlink(ResourceManager.get_config_path("save.json")) os.unlink(ResourceManager.get_config_path("save.json"))

View File

@ -635,24 +635,26 @@ class Entity:
from squirrelbattle.entities.friendly import Merchant, Sunflower, \ from squirrelbattle.entities.friendly import Merchant, Sunflower, \
Trumpet Trumpet
from squirrelbattle.entities.items import BodySnatchPotion, Bomb, \ from squirrelbattle.entities.items import BodySnatchPotion, Bomb, \
Heart, Sword, Shield, Chestplate, Helmet, RingCritical, RingXP Heart, Monocle, Sword, Shield, Chestplate, Helmet, \
RingCritical, RingXP
return { return {
"Tiger": Tiger,
"Bomb": Bomb, "Bomb": Bomb,
"Chestplate": Chestplate,
"Heart": Heart, "Heart": Heart,
"BodySnatchPotion": BodySnatchPotion, "BodySnatchPotion": BodySnatchPotion,
"Eagle": GiantSeaEagle,
"Hedgehog": Hedgehog, "Hedgehog": Hedgehog,
"Rabbit": Rabbit, "Helmet": Helmet,
"TeddyBear": TeddyBear,
"Player": Player, "Player": Player,
"Merchant": Merchant, "Merchant": Merchant,
"Monocle": Monocle,
"Sunflower": Sunflower, "Sunflower": Sunflower,
"Sword": Sword, "Sword": Sword,
"Trumpet": Trumpet, "Trumpet": Trumpet,
"Eagle": GiantSeaEagle,
"Shield": Shield, "Shield": Shield,
"Chestplate": Chestplate, "TeddyBear": TeddyBear,
"Helmet": Helmet, "Tiger": Tiger,
"Rabbit": Rabbit,
"RingCritical": RingCritical, "RingCritical": RingCritical,
"RingXP": RingXP, "RingXP": RingXP,
} }

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: squirrelbattle 3.14.1\n" "Project-Id-Version: squirrelbattle 3.14.1\n"
"Report-Msgid-Bugs-To: squirrel-battle@crans.org\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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -49,40 +49,40 @@ msgstr "BESTAND"
msgid "STALL" msgid "STALL"
msgstr "STAND" msgstr "STAND"
#: squirrelbattle/display/statsdisplay.py:46 #: squirrelbattle/display/statsdisplay.py:44
msgid "Inventory:" msgid "Inventory:"
msgstr "Bestand:" msgstr "Bestand:"
#: squirrelbattle/display/statsdisplay.py:63 #: squirrelbattle/display/statsdisplay.py:61
msgid "Equipped main:" msgid "Equipped main:"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:67 #: squirrelbattle/display/statsdisplay.py:65
msgid "Equipped secondary:" msgid "Equipped secondary:"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:72 #: squirrelbattle/display/statsdisplay.py:70
msgid "Equipped chestplate:" msgid "Equipped chestplate:"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:76 #: squirrelbattle/display/statsdisplay.py:74
msgid "Equipped helmet:" msgid "Equipped helmet:"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:83 #: squirrelbattle/display/statsdisplay.py:81
msgid "YOU ARE DEAD" msgid "YOU ARE DEAD"
msgstr "SIE WURDEN GESTORBEN" msgstr "SIE WURDEN GESTORBEN"
#: squirrelbattle/display/statsdisplay.py:87 #: squirrelbattle/display/statsdisplay.py:85
#, python-brace-format #, python-brace-format
msgid "Use {key} to use the ladder" msgid "Use {key} to use the ladder"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:96 #: squirrelbattle/display/statsdisplay.py:94
msgid "Move to the friendly entity to talk to it" msgid "Move to the friendly entity to talk to it"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:98 #: squirrelbattle/display/statsdisplay.py:96
#, python-brace-format #, python-brace-format
msgid "Use {key} then move to talk to the entity" msgid "Use {key} then move to talk to the entity"
msgstr "" msgstr ""
@ -347,3 +347,7 @@ msgstr ""
#: squirrelbattle/tests/translations_test.py:82 #: squirrelbattle/tests/translations_test.py:82
msgid "ring of more experience" msgid "ring of more experience"
msgstr "" msgstr ""
#: squirrelbattle/tests/translations_test.py:84
msgid "monocle"
msgstr ""

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: squirrelbattle 3.14.1\n" "Project-Id-Version: squirrelbattle 3.14.1\n"
"Report-Msgid-Bugs-To: squirrel-battle@crans.org\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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -49,40 +49,40 @@ msgstr "INVENTORIO"
msgid "STALL" msgid "STALL"
msgstr "PUESTO" msgstr "PUESTO"
#: squirrelbattle/display/statsdisplay.py:46 #: squirrelbattle/display/statsdisplay.py:44
msgid "Inventory:" msgid "Inventory:"
msgstr "Inventorio :" msgstr "Inventorio :"
#: squirrelbattle/display/statsdisplay.py:63 #: squirrelbattle/display/statsdisplay.py:61
msgid "Equipped main:" msgid "Equipped main:"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:67 #: squirrelbattle/display/statsdisplay.py:65
msgid "Equipped secondary:" msgid "Equipped secondary:"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:72 #: squirrelbattle/display/statsdisplay.py:70
msgid "Equipped chestplate:" msgid "Equipped chestplate:"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:76 #: squirrelbattle/display/statsdisplay.py:74
msgid "Equipped helmet:" msgid "Equipped helmet:"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:83 #: squirrelbattle/display/statsdisplay.py:81
msgid "YOU ARE DEAD" msgid "YOU ARE DEAD"
msgstr "ERES MUERTO" msgstr "ERES MUERTO"
#: squirrelbattle/display/statsdisplay.py:87 #: squirrelbattle/display/statsdisplay.py:85
#, python-brace-format #, python-brace-format
msgid "Use {key} to use the ladder" msgid "Use {key} to use the ladder"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:96 #: squirrelbattle/display/statsdisplay.py:94
msgid "Move to the friendly entity to talk to it" msgid "Move to the friendly entity to talk to it"
msgstr "" msgstr ""
#: squirrelbattle/display/statsdisplay.py:98 #: squirrelbattle/display/statsdisplay.py:96
#, python-brace-format #, python-brace-format
msgid "Use {key} then move to talk to the entity" msgid "Use {key} then move to talk to the entity"
msgstr "" msgstr ""
@ -346,3 +346,7 @@ msgstr ""
#: squirrelbattle/tests/translations_test.py:82 #: squirrelbattle/tests/translations_test.py:82
msgid "ring of more experience" msgid "ring of more experience"
msgstr "" msgstr ""
#: squirrelbattle/tests/translations_test.py:84
msgid "monocle"
msgstr ""

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: squirrelbattle 3.14.1\n" "Project-Id-Version: squirrelbattle 3.14.1\n"
"Report-Msgid-Bugs-To: squirrel-battle@crans.org\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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -43,40 +43,40 @@ msgstr "INVENTAIRE"
msgid "STALL" msgid "STALL"
msgstr "STAND" msgstr "STAND"
#: squirrelbattle/display/statsdisplay.py:46 #: squirrelbattle/display/statsdisplay.py:44
msgid "Inventory:" msgid "Inventory:"
msgstr "Inventaire :" msgstr "Inventaire :"
#: squirrelbattle/display/statsdisplay.py:63 #: squirrelbattle/display/statsdisplay.py:61
msgid "Equipped main:" msgid "Equipped main:"
msgstr "Équipement principal :" msgstr "Équipement principal :"
#: squirrelbattle/display/statsdisplay.py:67 #: squirrelbattle/display/statsdisplay.py:65
msgid "Equipped secondary:" msgid "Equipped secondary:"
msgstr "Équipement secondaire :" msgstr "Équipement secondaire :"
#: squirrelbattle/display/statsdisplay.py:72 #: squirrelbattle/display/statsdisplay.py:70
msgid "Equipped chestplate:" msgid "Equipped chestplate:"
msgstr "Plastron équipé :" msgstr "Plastron équipé :"
#: squirrelbattle/display/statsdisplay.py:76 #: squirrelbattle/display/statsdisplay.py:74
msgid "Equipped helmet:" msgid "Equipped helmet:"
msgstr "Casque équipé :" msgstr "Casque équipé :"
#: squirrelbattle/display/statsdisplay.py:83 #: squirrelbattle/display/statsdisplay.py:81
msgid "YOU ARE DEAD" msgid "YOU ARE DEAD"
msgstr "VOUS ÊTES MORT" msgstr "VOUS ÊTES MORT"
#: squirrelbattle/display/statsdisplay.py:87 #: squirrelbattle/display/statsdisplay.py:85
#, python-brace-format #, python-brace-format
msgid "Use {key} to use the ladder" msgid "Use {key} to use the ladder"
msgstr "Appuyez sur {key} pour utiliser l'échelle" 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" msgid "Move to the friendly entity to talk to it"
msgstr "Avancez vers l'entité pour lui parler" msgstr "Avancez vers l'entité pour lui parler"
#: squirrelbattle/display/statsdisplay.py:98 #: squirrelbattle/display/statsdisplay.py:96
#, python-brace-format #, python-brace-format
msgid "Use {key} then move to talk to the entity" msgid "Use {key} then move to talk to the entity"
msgstr "Appuyez sur {key} puis déplacez-vous pour parler" 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 #: squirrelbattle/tests/translations_test.py:82
msgid "ring of more experience" msgid "ring of more experience"
msgstr "anneau de plus d'expérience" msgstr "anneau de plus d'expérience"
#: squirrelbattle/tests/translations_test.py:84
msgid "monocle"
msgstr "monocle"

View File

@ -66,6 +66,7 @@ class TestGame(unittest.TestCase):
new_state = self.game.save_state() new_state = self.game.save_state()
self.assertEqual(old_state, new_state) self.assertEqual(old_state, new_state)
self.assertIsNone(self.game.message)
# Ensure that the bomb is loaded # Ensure that the bomb is loaded
self.assertTrue(self.game.player.inventory) self.assertTrue(self.game.player.inventory)

View File

@ -81,3 +81,4 @@ class TestTranslations(unittest.TestCase):
"anneau de coup critique") "anneau de coup critique")
self.assertEqual(_("ring of more experience"), self.assertEqual(_("ring of more experience"),
"anneau de plus d'expérience") "anneau de plus d'expérience")
self.assertEqual(_("monocle"), "monocle")