Class ShopManager

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.shop.ShopManager

public class ShopManager extends Component
Handles shop-related operations such as validating purchases, charging players, and updating their inventories.

A ShopManager depends on a CatalogService to resolve purchasable items, and coordinates with the player's InventoryComponent to ensure space, funds, and item limits are respected.

  • Constructor Details

    • ShopManager

      public ShopManager(CatalogService catalog)
      Creates a ShopManager that uses the given catalog service.
      Parameters:
      catalog - the catalog of items available for purchase (must not be null)
  • Method Details

    • getCatalog

      public CatalogService getCatalog()
      Gets the underlying catalog service.
      Returns:
      the catalog service storing available items
    • purchase

      public PurchaseResult purchase(Entity player, CatalogEntry item, int amount)
      Attempts to purchase a given catalog entry for a player.

      The purchase process checks that:

      • The player has an InventoryComponent.
      • The item exists in the catalog and is enabled.
      • The player has sufficient funds (processors).
      • The item can be added/stacked in the player's inventory.

      On success, the player is charged and their inventory updated. On failure, a "purchaseFailed" event is triggered on this entity.

      Parameters:
      player - the entity attempting the purchase (must have an InventoryComponent)
      item - the catalog entry being purchased
      amount - the quantity to purchase
      Returns:
      a PurchaseResult indicating success or failure and the reason