Class TimedUseItem

Direct Known Subclasses:
AttackPotion, DefensePotion, SpeedPotion

public abstract class TimedUseItem extends ConsumableItem
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 Details

    • effectAmount

      protected int effectAmount
      A list of possible effects that this potion can apply when used.
    • gameTime

      protected GameTime gameTime
    • effectStartTime

      protected long effectStartTime
    • warn

      protected String warn
  • Constructor Details

    • TimedUseItem

      protected TimedUseItem(String name, int itemCode, int limit, int quantity, int effectAmount, long duration, String warn)
      Constructs a new Potion 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

      public GameTime getGameTime()
      Returns:
      the game time object used to check the time this item should be used for.
    • getWarning

      public String 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

      public void useItem(ItemUsageContext context)
      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 class ConsumableItem
      Parameters:
      context - the context in which the item is used (contains a Player to use on)
    • update

      public abstract void update(ItemUsageContext context)
      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)