Class MagazineComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.MagazineComponent

public class MagazineComponent extends Component
Stores and manages a given weapon's magazine information
  • Constructor Details

    • MagazineComponent

      public MagazineComponent(int maxAmmo)
      Constructs an magazine component
      Parameters:
      maxAmmo - the maximum amount of ammunition that can be held by the weapon
  • Method Details

    • update

      public void update()
      Updates the reload cooldown
      Overrides:
      update in class Component
    • getCurrentAmmo

      public int getCurrentAmmo()
      Returns current amount of ammo in magazine
      Returns:
      ammo in magazine
    • setCurrentAmmo

      public void setCurrentAmmo(int newAmmo)
      Sets the current ammo to a new value
      Parameters:
      newAmmo - ammunition to be stored in the magazine
    • reload

      public boolean reload(Entity player)
      Reloads the magazine from player's current ammo supply
      Returns:
      true if reload is successful and adds ammunition to the magazine, false otherwise
    • reloading

      public boolean reloading()
      Determines if the weapon is currently reloading
      Returns:
      true if the weapon is undergoing a reload, false otherwise
    • setTimeSinceLastReload

      public void setTimeSinceLastReload(float timeSinceLastReload)
      Sets the time since last reload, used for testing purposes
      Parameters:
      timeSinceLastReload - designated time since last reload