Class TimedUseItem
java.lang.Object
com.csse3200.game.inventory.items.AbstractItem
com.csse3200.game.inventory.items.ConsumableItem
com.csse3200.game.inventory.items.TimedUseItem
- Direct Known Subclasses:
AttackPotion
,DefensePotion
,SpeedPotion
The
AbstractPotion
class serves as abstract base class for all-potion types items in the game
A potion is a type of consumable item that can apply one or more effects to a player's animal
This class provides common functionality for managing and applying effects, as well as handling the number of uses as potion has. Specific potion types (e.g., Healing Potion) should extend create their own class to apply effects
The AbstractPotion
class also inherits the general properties of a consumable item from
the ConsumableItem
class, such as the number of uses and whether the item is consumed upon use.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
A list of possible effects that this potion can apply when used.protected long
protected GameTime
protected String
Fields inherited from class com.csse3200.game.inventory.items.AbstractItem
description, itemCode, limit, name, onlyCombatItem, onlyMapItem, quantity
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
TimedUseItem
(String name, int itemCode, int limit, int quantity, int effectAmount, long duration, String warn) Constructs a newPotion
with the specified quantity and a list of possible effects. -
Method Summary
Modifier and TypeMethodDescriptionlong
return the duration of the effectReturn warning message for potions that cant be used in certain environmentabstract void
update
(ItemUsageContext context) Updates the potion state.void
useItem
(ItemUsageContext context) Uses the potion by applying its effects and decreasing its number of uses.Methods inherited from class com.csse3200.game.inventory.items.AbstractItem
add, getDescription, getItemCode, getLimit, getName, getQuantity, getTexturePath, isEmpty, numAddable, onlyCombatItem, onlyMapItem, setDescription, setTexturePath
-
Field Details
-
effectAmount
protected int effectAmountA list of possible effects that this potion can apply when used. -
gameTime
-
effectStartTime
protected long effectStartTime -
warn
-
-
Constructor Details
-
TimedUseItem
protected TimedUseItem(String name, int itemCode, int limit, int quantity, int effectAmount, long duration, String warn) Constructs a newPotion
with the specified quantity and a list of possible effects.- Parameters:
quantity
- the number of times this potion can be used potion can apply
-
-
Method Details
-
getGameTime
- Returns:
- the game time object used to check the time this item should be used for.
-
getWarning
Return warning message for potions that cant be used in certain environment- Returns:
- warning message
-
getDuration
public long getDuration()return the duration of the effect- Returns:
- the duration of the effect
-
useItem
Uses the potion by applying its effects and decreasing its number of uses. If no uses are left, the potion is marked as empty.- Overrides:
useItem
in classConsumableItem
- Parameters:
context
- the context in which the item is used (contains a Player to use on)
-
update
Updates the potion state. this function is to be defined in other functionality- Parameters:
context
- the context in which the item is used (contains a Player to use on)
-