Usable items - UQcsse3200/2024-studio-1 GitHub Wiki

Overview

Usable items are immediately added to the player inventory upon pickup. As a result, they can be used at any time by the player. The usable items have different effects on the player, including the player's health, the player's damage (creating a shield), as well as having effects on other items (effect of the reroll item).

Key Features of usable items

  • The specification: Unlike buff items, the specification includes "item:" plus the item specification
  • Picking up a usable item: Upon pickup, the ItemPickupComponent class calls the pickup() method of the usable item, which then calls the addItem() method of the inventory, thus adding the item to the inventory.
  • Item type: The item type of UsableItems is Type.ITEM
  • Usable item effect: An item is used when its associated keyboard press is used. This is handled in the use() method in PlayerActions. Upon usage, the item's associated apply() method is called.

Relevant Classes

  • UsableItem.java: An abstract class for all UsableItems
  • PlayerActions.java: Handles the key presses to use an item. Refer to use().
  • ItemPickupComponent.java: Calls the pickup() method of the usable item

Class usage and details

Reroll item

Reroll creation

  • The reroll item is created using...
CollectibleFactory collectibleFactory = new CollectibleFactory()
Entity collectible = collectibleFactory.createCollectibleEntity("item:reroll")
//Creates a usable reroll item

Relevant classes

  • Reroll.java: The class for a reroll item
  • ItemPickupComponent.java: Contains a method handleReroll() that handles the reroll item effect. It spawns another item in place of the other item in collision. The random newly spawned item is handled in the randomItemGenerator() method of this class.

Important features

  • Key presses: Unlike most UsableItems, the reroll item is "used" by pressing "R" when in collision with another item

Testing

This item is currently only tested manually.