Linting
This commit is contained in:
parent
b9b776b7ad
commit
98b5dd64a8
|
@ -3,7 +3,7 @@ from ..translations import gettext as _
|
||||||
from .player import Player
|
from .player import Player
|
||||||
from .items import Item
|
from .items import Item
|
||||||
from random import choice
|
from random import choice
|
||||||
from typing import Dict, Tuple, Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
class Merchant(FriendlyEntity):
|
class Merchant(FriendlyEntity):
|
||||||
|
@ -51,7 +51,7 @@ class Merchant(FriendlyEntity):
|
||||||
d = super().save_state()
|
d = super().save_state()
|
||||||
d["inventory"] = [item.save_state() for item in self.inventory]
|
d["inventory"] = [item.save_state() for item in self.inventory]
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def add_to_inventory(self, obj: Any) -> None:
|
def add_to_inventory(self, obj: Any) -> None:
|
||||||
"""
|
"""
|
||||||
Adds an object to inventory
|
Adds an object to inventory
|
||||||
|
|
|
@ -17,8 +17,8 @@ class Item(Entity):
|
||||||
held_by: Optional[Player]
|
held_by: Optional[Player]
|
||||||
price: int
|
price: int
|
||||||
|
|
||||||
def __init__(self, held: bool = False, held_by: Optional[Player] = None, price : int=2,
|
def __init__(self, held: bool = False, held_by: Optional[Player] = None,
|
||||||
*args, **kwargs):
|
price: int = 2, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.held = held
|
self.held = held
|
||||||
self.held_by = held_by
|
self.held_by = held_by
|
||||||
|
@ -66,27 +66,30 @@ class Item(Entity):
|
||||||
def get_all_items() -> list:
|
def get_all_items() -> list:
|
||||||
return [BodySnatchPotion, Bomb, Heart, Sword]
|
return [BodySnatchPotion, Bomb, Heart, Sword]
|
||||||
|
|
||||||
def be_sold(self, buyer: Entity, seller: Entity, game : Any) -> bool:
|
def be_sold(self, buyer: Entity, seller: Entity, game: Any) -> bool:
|
||||||
"""
|
"""
|
||||||
Does all necessary actions when an object is to be sold.
|
Does all necessary actions when an object is to be sold.
|
||||||
Is overwritten by some classes that cannot exist in the player's inventory
|
Is overwritten by some classes that cannot exist in the player's
|
||||||
|
inventory
|
||||||
"""
|
"""
|
||||||
if buyer.hazel>=self.price :
|
if buyer.hazel >= self.price:
|
||||||
buyer.add_to_inventory(self)
|
buyer.add_to_inventory(self)
|
||||||
seller.remove_from_inventory(self)
|
seller.remove_from_inventory(self)
|
||||||
buyer.change_hazel_balance(-self.price)
|
buyer.change_hazel_balance(-self.price)
|
||||||
seller.change_hazel_balance(self.price)
|
seller.change_hazel_balance(self.price)
|
||||||
return True
|
return True
|
||||||
else :
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class Heart(Item):
|
class Heart(Item):
|
||||||
"""
|
"""
|
||||||
A heart item to return health to the player
|
A heart item to return health to the player
|
||||||
"""
|
"""
|
||||||
healing: int
|
healing: int
|
||||||
|
|
||||||
def __init__(self, name: str = "heart", healing: int = 5, price: int = 3, *args, **kwargs):
|
def __init__(self, name: str = "heart", healing: int = 5, price: int = 3,
|
||||||
|
*args, **kwargs):
|
||||||
super().__init__(name=name, price=price, *args, **kwargs)
|
super().__init__(name=name, price=price, *args, **kwargs)
|
||||||
self.healing = healing
|
self.healing = healing
|
||||||
|
|
||||||
|
@ -105,20 +108,21 @@ class Heart(Item):
|
||||||
d["healing"] = self.healing
|
d["healing"] = self.healing
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def be_sold(self, buyer: Entity, seller: Entity, game: Any) -> str:
|
def be_sold(self, buyer: Entity, seller: Entity, game: Any) -> bool:
|
||||||
"""
|
"""
|
||||||
Does all necessary actions when an object is to be sold.
|
Does all necessary actions when an object is to be sold.
|
||||||
Is overwritten by some classes that cannot exist in the player's inventory
|
Is overwritten by some classes that cannot exist in the player's
|
||||||
|
inventory
|
||||||
"""
|
"""
|
||||||
if buyer.hazel>=self.price :
|
if buyer.hazel >= self.price:
|
||||||
self.hold(buyer)
|
self.hold(buyer)
|
||||||
seller.remove_from_inventory(self)
|
seller.remove_from_inventory(self)
|
||||||
buyer.change_hazel_balance(-self.price)
|
buyer.change_hazel_balance(-self.price)
|
||||||
seller.change_hazel_balance(self.price)
|
seller.change_hazel_balance(self.price)
|
||||||
return True
|
return True
|
||||||
else :
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
class Bomb(Item):
|
class Bomb(Item):
|
||||||
"""
|
"""
|
||||||
|
@ -212,7 +216,8 @@ class BodySnatchPotion(Item):
|
||||||
other entity.
|
other entity.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, name: str = "body_snatch_potion", price: int = 14, *args, **kwargs):
|
def __init__(self, name: str = "body_snatch_potion", price: int = 14,
|
||||||
|
*args, **kwargs):
|
||||||
super().__init__(name=name, price=price, *args, **kwargs)
|
super().__init__(name=name, price=price, *args, **kwargs)
|
||||||
|
|
||||||
def use(self) -> None:
|
def use(self) -> None:
|
||||||
|
|
|
@ -195,7 +195,7 @@ class Game:
|
||||||
if key == KeyValues.ENTER:
|
if key == KeyValues.ENTER:
|
||||||
item = self.store_menu.validate()
|
item = self.store_menu.validate()
|
||||||
flag = item.be_sold(self.player, self.store_menu.merchant, self)
|
flag = item.be_sold(self.player, self.store_menu.merchant, self)
|
||||||
if not flag :
|
if not flag:
|
||||||
self.message = _("You do not have enough money")
|
self.message = _("You do not have enough money")
|
||||||
self.display_actions(DisplayActions.UPDATE)
|
self.display_actions(DisplayActions.UPDATE)
|
||||||
# Ensure that the cursor has a good position
|
# Ensure that the cursor has a good position
|
||||||
|
|
Loading…
Reference in New Issue