Skip to content

Commit

Permalink
Revert "text - New function to display shopkeeper balance, modified S…
Browse files Browse the repository at this point in the history
…TR_THIS_ITEM_CANT_BE_SOLD to better fit context"

This reverts commit d6d7c79.
  • Loading branch information
Sonny-Cao committed Feb 11, 2024
1 parent d6d7c79 commit 694a3cf
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 23 deletions.
7 changes: 2 additions & 5 deletions data/en/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def f_LEVEL_NUMBER_AND_NAME(number: int, name: str):
STR_END_TURN = "End turn"
STR_DEFAULT_DIARY_BODY_CONTENT = "No event has been recorded yet"


# Reward menu
STR_REWARD_CONGRATULATIONS = "Congratulations! Objective has been completed!"

Expand Down Expand Up @@ -89,10 +90,6 @@ def f_UR_GOLD(gold):
return f"Your gold: {gold}"


def f_SHOP_GOLD(shop_balance):
return f"Shopkeeper gold: {shop_balance}"


# Trade menu
STR_50G_TO_RIGHT = "50G ->"
STR_200G_TO_RIGHT = "200G ->"
Expand Down Expand Up @@ -259,7 +256,7 @@ def f_YOU_RECEIVED_ITEM(item):
)
STR_NOT_ENOUGH_GOLD_TO_BY_THIS_ITEM = "Not enough gold to buy this item."
STR_THE_ITEM_HAS_BEEN_SOLD = "The item has been sold."
STR_THIS_ITEM_CANT_BE_SOLD = "The vendor lacks the funds to buy from you !"
STR_THIS_ITEM_CANT_BE_SOLD = "This item can't be sold !"
STR_THIS_HOUSE_SEEMS_CLOSED = "This house seems closed..."


Expand Down
12 changes: 4 additions & 8 deletions src/game_entities/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Shop(Building):
stock -- the data structure containing all the available items to be bought with their associated quantity
menu -- the shop menu displaying all the items that could be bought
gold_sfx -- the sound that should be started when an item is sold or bought
shop_balance -- the amount of gold the shop has
"""

interaction_callback = None
Expand All @@ -51,18 +50,16 @@ def __init__(
name: str,
position: Position,
sprite_link: str,
shop_balance: int,
stock: list[dict[str, any]],
interaction: Optional[dict[str, any]] = None,
sprite: Optional[pygame.Surface] = None,
) -> None:
super().__init__(name, position, sprite_link, interaction, sprite)
self.shop_balance = 500
self.current_visitor: Optional[Character] = None
self.stock: list[dict[str, any]] = stock
self.interaction: dict[str, any] = interaction
self.menu: InfoBox = menu_creator_manager.create_shop_menu(
Shop.interaction_callback, self.stock, 0, shop_balance
Shop.interaction_callback, self.stock, 0
)
self.gold_sfx: pygame.mixer.Sound = pygame.mixer.Sound(
os.path.join("sound_fx", "trade.ogg")
Expand All @@ -88,7 +85,7 @@ def update_shop_menu(self, gold: int) -> None:
gold -- the new gold amount for the player that should be displayed
"""
self.menu = menu_creator_manager.create_shop_menu(
Shop.interaction_callback, self.stock, gold, self.shop_balance
Shop.interaction_callback, self.stock, gold
)

def interact(self, actor: Character) -> list[list[BoxElement]]:
Expand Down Expand Up @@ -130,9 +127,9 @@ def buy(self, item: Item) -> str:
if self.current_visitor.gold >= item.price:
if len(self.current_visitor.items) < self.current_visitor.nb_items_max:
pygame.mixer.Sound.play(self.gold_sfx)

self.current_visitor.gold -= item.price
self.current_visitor.set_item(copy(item))
self.shop_balance += item.price

entry: Optional[dict[str, any]] = self.get_item_entry(item)
entry["quantity"] -= 1
Expand All @@ -156,10 +153,9 @@ def sell(self, item: Item) -> tuple[bool, str]:
actor -- the actor selling the item
item -- the item that is being sold
"""
if 0 < item.resell_price < self.shop_balance:
if item.resell_price > 0:
self.current_visitor.remove_item(item)
self.current_visitor.gold += item.resell_price
self.shop_balance -= item.resell_price

# Update shop screen content (gold total amount has been augmented)
self.update_shop_menu(self.current_visitor.gold)
Expand Down
2 changes: 1 addition & 1 deletion src/scenes/level_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def load_level_content(self) -> None:
self.entities.chests = tmx_loader.load_chests(self.tmx_data, gap_x, gap_y)
self.entities.allies = tmx_loader.load_allies(self.tmx_data, gap_x, gap_y)
self.entities.buildings = tmx_loader.load_buildings(
self.tmx_data, DATA_PATH + self.directory, gap_x, gap_y, self.active_shop.shop_balance
self.tmx_data, DATA_PATH + self.directory, gap_x, gap_y
)
self.entities.breakables = tmx_loader.load_breakables(
self.tmx_data, gap_x, gap_y
Expand Down
3 changes: 1 addition & 2 deletions src/services/load_from_tmx_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def load_events(


def load_buildings(
tmx_data: pytmx.TiledMap, directory: str, horizontal_gap: int, vertical_gap: int, shop_balance: int
tmx_data: pytmx.TiledMap, directory: str, horizontal_gap: int, vertical_gap: int
) -> list[Building]:
buildings = []
for tile_object in tmx_data.get_layer_by_name("dynamic_data"):
Expand Down Expand Up @@ -364,7 +364,6 @@ def load_buildings(
tile_object.name,
position,
tile_object.properties["sprite_link"],
shop_balance,
stock,
interaction,
image,
Expand Down
5 changes: 2 additions & 3 deletions src/services/load_from_xml_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,13 +728,12 @@ def load_door_from_save(door, gap_x, gap_y):
return loaded_door


def load_building_from_save(building, gap_x, gap_y, shop_balance=None):
def load_building_from_save(building, gap_x, gap_y):
"""
:param building:
:param gap_x:
:param gap_y:
:shop_balance:
:return:
"""
# Static data
Expand Down Expand Up @@ -775,7 +774,7 @@ def load_building_from_save(building, gap_x, gap_y, shop_balance=None):
"quantity": int(item.find("quantity").text.strip()),
}
stock.append(entry)
loaded_building = Shop(name, position, sprite, shop_balance, stock, interaction_element)
loaded_building = Shop(name, position, sprite, stock, interaction_element)
else:
print("Error : building type isn't recognized : ", type)
raise SystemError
Expand Down
5 changes: 1 addition & 4 deletions src/services/menu_creator_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,13 @@ def create_shop_menu(
interaction_callback: Callable,
stock: Sequence[dict[str, Union[Item, int]]],
gold: int,
shop_balance: int) -> InfoBox:
) -> InfoBox:
"""
Return the interface of a shop menu with user as the buyer.
Keyword arguments:
stock -- the collection of items that are available in the shop, with the quantity of each one
gold -- the amount of gold that should be displayed at the bottom
shop_balance -- the amount of gold that shopkeeper has
"""
element_grid = []
row = []
Expand Down Expand Up @@ -97,8 +96,6 @@ def create_shop_menu(
# Gold at end
player_gold_line = [TextElement(f_UR_GOLD(gold), font=fonts["ITEM_DESC_FONT"])]
element_grid.append(player_gold_line)
shop_gold_line = [TextElement(f_SHOP_GOLD(shop_balance), font=fonts["ITEM_DESC_FONT"])]
element_grid.append(shop_gold_line)

return InfoBox(
STR_SHOP_BUYING,
Expand Down

0 comments on commit 694a3cf

Please sign in to comment.