Class ShopManager
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.shop.ShopManager
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.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionShopManager
(CatalogService catalog) Creates aShopManager
that uses the given catalog service. -
Method Summary
Modifier and TypeMethodDescriptionGets the underlying catalog service.purchase
(Entity player, CatalogEntry item, int amount) Attempts to purchase a given catalog entry for a player.Methods inherited from class com.csse3200.game.components.Component
create, dispose, earlyUpdate, getEntity, getPrio, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
ShopManager
Creates aShopManager
that uses the given catalog service.- Parameters:
catalog
- the catalog of items available for purchase (must not benull
)
-
-
Method Details
-
getCatalog
Gets the underlying catalog service.- Returns:
- the catalog service storing available items
-
purchase
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 anInventoryComponent
)item
- the catalog entry being purchasedamount
- the quantity to purchase- Returns:
- a
PurchaseResult
indicating success or failure and the reason
- The player has an
-