Add item description, closes #59

This commit is contained in:
Yohann D'ANELLO 2021-01-08 11:55:25 +01:00
parent 2b3a8279b8
commit e56bdc16c2
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 30 additions and 0 deletions

View File

@ -172,6 +172,7 @@ class PlayerInventoryDisplay(MenuDisplay):
and self.selected else f" {rep} " and self.selected else f" {rep} "
self.addstr(self.pad, i + 1, 0, selection self.addstr(self.pad, i + 1, 0, selection
+ " " + item.translated_name.capitalize() + " " + item.translated_name.capitalize()
+ (f" ({item.description})" if item.description else "")
+ (": " + str(item.price) + " Hazels" + (": " + str(item.price) + " Hazels"
if self.store_mode else "")) if self.store_mode else ""))
@ -217,6 +218,7 @@ class StoreInventoryDisplay(MenuDisplay):
and self.selected else f" {rep} " and self.selected else f" {rep} "
self.addstr(self.pad, i + 1, 0, selection self.addstr(self.pad, i + 1, 0, selection
+ " " + item.translated_name.capitalize() + " " + item.translated_name.capitalize()
+ (f" ({item.description})" if item.description else "")
+ ": " + str(item.price) + " Hazels") + ": " + str(item.price) + " Hazels")
price = f"{self.pack.HAZELNUT} {self.menu.merchant.hazel} Hazels" price = f"{self.pack.HAZELNUT} {self.menu.merchant.hazel} Hazels"

View File

@ -24,6 +24,13 @@ class Item(Entity):
self.held_by = held_by self.held_by = held_by
self.price = price self.price = price
@property
def description(self) -> str:
"""
In the inventory, indicate the usefulness of the item.
"""
return ""
def drop(self) -> None: def drop(self) -> None:
""" """
The item is dropped from the inventory onto the floor. The item is dropped from the inventory onto the floor.
@ -109,6 +116,10 @@ class Heart(Item):
super().__init__(name=name, price=price, *args, **kwargs) super().__init__(name=name, price=price, *args, **kwargs)
self.healing = healing self.healing = healing
@property
def description(self) -> str:
return "HP+5"
def hold(self, entity: InventoryHolder) -> None: def hold(self, entity: InventoryHolder) -> None:
""" """
When holding a heart, the player is healed and When holding a heart, the player is healed and
@ -217,6 +228,10 @@ class Weapon(Item):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.damage = damage self.damage = damage
@property
def description(self) -> str:
return f"STR+{self.damage}" if self.damage else super().description
def save_state(self) -> dict: def save_state(self) -> dict:
""" """
Saves the state of the weapon into a dictionary Saves the state of the weapon into a dictionary
@ -261,6 +276,11 @@ class Armor(Item):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.constitution = constitution self.constitution = constitution
@property
def description(self) -> str:
return f"CON+{self.constitution}" if self.constitution \
else super().description
def equip(self) -> None: def equip(self) -> None:
super().equip() super().equip()
self.held_by.constitution += self.constitution self.held_by.constitution += self.constitution
@ -375,6 +395,14 @@ class Ring(Item):
self.critical = critical self.critical = critical
self.experience = experience self.experience = experience
@property
def description(self) -> str:
fields = [("MAX HP", self.maxhealth), ("STR", self.strength),
("INT", self.intelligence), ("CHR", self.charisma),
("DEX", self.dexterity), ("CON", self.constitution),
("CRI", self.critical), ("XP", self.experience)]
return ", ".join(f"{key}+{value}" for key, value in fields if value)
def equip(self) -> None: def equip(self) -> None:
super().equip() super().equip()
self.held_by.maxhealth += self.maxhealth self.held_by.maxhealth += self.maxhealth