-
Notifications
You must be signed in to change notification settings - Fork 1
Items
All existing items are subclasses of the Abstract Item class which manages the item's properties and provides players special effects to improve their game performance i.e. improve their stats and restore their health and hunger when convenient. Items will represent in-game items a player can hold in their inventory or around the map. Here is an overview of how the Items are structured:
-
AbstractItems: The abstract class with variables and methods to supply information about the items. This includes the item's
name
,itemCode
,limit
andquantity
. These fields will be used to differentiate each item and categorise them in the Inventory and hotbar -
ConsumableItem: A class that overrides AbstrcatItems to implement the generic functionality of the function
useItems
, This class is for expendable items and is used to improve players' stat performance. -
TimedUsedItem: Overides methods from the ConsumableClass to implement temporary effects towards player's stats. This class introduces a field
effectAmount
- the amount to be applied towards their designated player stat. - ItemProximityTask - This is the list of actions the player must take to pick up an item on the map. It detects when a player is in proximity to the item
-
ConsumedException: Throws an error if the item has no
quantity
left to use the item. - ItemUsageContext: This class is used to keep track of the items usage activity through the game
- ItemFactory: A factory class for creating various item entities in the game.
Concrete subclasses (actual in-game items) include various Food classes and the healing potion class. Food classes include:
TimedUsedItems classes include:
The function useItems()
originally defined in, AbstractItem handles the usage of an item and is overridden by other classes such as ConsumableItems, TimedUsedItems and Food as they apply their applicable effects and decrease their quantity per usage. This function can also be called in CombatActions as is considered a combat move in the combat context. useItem
can also be restricted from use depending on the conditions the player are:
- Defense and attack potions are prohibited to be used outside of combat
- Speed potions are prohibited from being used in Combat
A example of how useItem()
is implemented:
@Override
public void useItem(ItemUsageContext context) {
if (super.isEmpty()) {
throw new ConsumedException();
}
this.quantity--;
}
@Override
public void useItem(ItemUsageContext context) {
super.useItem(context);
effectStartTime = gameTime.getTime();
}
An item can be created by overriding the useItem()
function to apply its effects and add additional parameters to include its effects. For instance, food inherits from AbstractFood which inherits from AbstractFood
public static class Apple extends AbstractFood {
private final static String path = "images/foodtextures/apple.png";
/**
* Constructs an Apple class while assigning fields with set values.
*/
public Apple(int quantity) {
super("Apple", 11, 1, quantity, 2);
this.setTexturePath(path);
this.setDescription("This is an apple");
}
}
To create and set up item entities to spawn on the map:
public static Entity createItem(Entity target, AbstractItem item) {
AITaskComponent aiComponent = new AITaskComponent()
.addTask(new ItemProximityTask(target,20, 1f, item));
Entity itemEntity = new Entity().addComponent(new TextureRenderComponent(item.getTexturePath()))
.addComponent(new PhysicsComponent())
.addComponent(aiComponent);
itemEntity.getComponent(PhysicsComponent.class).setBodyType(BodyDef.BodyType.StaticBody);
return itemEntity;
}
`
```java
public static Entity createHealthPotion(Entity target) {
return createItem(target, new HealingPotion(1));
}
The test plan is as follows:
- Creation: Ensures the items have been created with the correct fields
- Interaction: Ensures the items can be picked up on the map and interact with the Inventory Display. They can also interact with the player stats to apply their effects to their stat.
The expected interaction between the player and items is that when a user comes in a certain range (2.0f) of the item the functionality @pickUpItem
can be activated which is also displayed as a pop-up dialogue to inform the user can pick up the certain item in range using key command "P". This is all handled in ItemProximityTask
and ItemFactory
this is the Item sequence diagram
This diagram represents the overview of the Items and their action in the game and their interaction with the display and player stats
* package com.csse3200.game.inventory.items.food
* package com.csse3200.game.inventory.items
This package contains all the item classes required for the game
AbstractItems: An abstract class that contains the fields that are used to identify each item and their details of usage and applications
Attributes
-
useItem()
- This method is to be defined by other subclasses as some items may have different functionality and effects when this function is triggered -
isEmpty()
- Checks if the the item's quantity has been depleted -
setTexturePath()
- Sets a texture path for the items to be displayed on the map -
getTexturePath()
- retrieves the texture path of the item