Class PlantComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.plants.PlantComponent
All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable

public class PlantComponent extends Component
Class for all plants in the game.
  • Constructor Details

    • PlantComponent

      public PlantComponent(int health, String name, String plantType, String plantDescription, float idealWaterLevel, int adultLifeSpan, int maxHealth, CropTileComponent cropTile)
      Constructor used for plant types that have no extra properties. This is just used for testing.
      Parameters:
      health - - health of the plant
      name - - name of the plant
      plantType - - type of the plant
      plantDescription - - description of the plant
      idealWaterLevel - - The ideal water level for a plant
      adultLifeSpan - - How long a plant will live for once it becomes an adult
      maxHealth - - The maximum health a plant can reach as an adult
      cropTile - - The cropTileComponent where the plant will be located.
    • PlantComponent

      public PlantComponent(int health, String name, String plantType, String plantDescription, float idealWaterLevel, int adultLifeSpan, int maxHealth, CropTileComponent cropTile, int[] growthStageThresholds)
      Constructor used for plant types that have growthStageThresholds different from the default values.
      Parameters:
      health - - health of the plant
      name - - name of the plant
      plantType - - type of the plant
      plantDescription - - description of the plant
      idealWaterLevel - - The ideal water level for a plant
      adultLifeSpan - - How long a plant will live for once it becomes an adult
      maxHealth - - The maximum health a plant can reach as an adult
      cropTile - - The cropTileComponent where the plant will be located.
      growthStageThresholds - - A list of three integers that represent the growth thresholds.
  • Method Details

    • create

      public void create()
      Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished.
      Overrides:
      create in class Component
    • minuteUpdate

      public void minuteUpdate()
      Functionality for the plant that needs to update every minute.
    • incrementOxygen

      public void incrementOxygen()
      Changes the oxygen level of the planet based on the plant and growth stage
    • hourUpdate

      public void hourUpdate()
      Functionality for the plant that needs to update every hour.
    • dayUpdate

      public void dayUpdate()
      Functionality for the plant that needs to update every day.
    • adultLifeSpanCheck

      public void adultLifeSpanCheck()
      Check if the plant has exceeded its adult lifespan.
    • decayCheck

      public void decayCheck()
      Check if the plant is already decaying and needs to die. Also check if the plant has died before reaching adult growth stage.
    • setAreaOfEffectRadius

      public void setAreaOfEffectRadius()
      Set the area of effect radius based on the type of plant.
    • updateGrowthStage

      public void updateGrowthStage()
      Update the growth stage of a plant based on its current growth level. This method is called every (in game) day at midday (12pm) and midnight. If the currentGrowthLevel exceeds the corresponding growth threshold, then the plant will advance to the next growth stage. When a plant becomes an adult, it has an adult life span. Also, if the plant is in a state of decay then decrease the health every hour.
    • digestion

      public void digestion()
      Check if the space snapper is currently eating. If it is then implement a cool down period before the plant is ready to eat again.
    • getPlantHealth

      public int getPlantHealth()
      Returns the current plant health
      Returns:
      current plant health
    • setPlantHealth

      public void setPlantHealth(int health)
      Set the current plant health
      Parameters:
      health - - current plant health
    • getMaxHealth

      public int getMaxHealth()
      Returns the max health of the plant
      Returns:
      current max health
    • increasePlantHealth

      public void increasePlantHealth(int plantHealthIncrement)
      Increase (or decrease) the plant health by some value
      Parameters:
      plantHealthIncrement - - plant health affected value
    • getPlantName

      public String getPlantName()
      Returns the name of the plant
      Returns:
      name of the plant
    • getPlantType

      public String getPlantType()
      Returns the type of the plant
      Returns:
      type of the plant
    • getPlantDescription

      public String getPlantDescription()
      Returns the plant description
      Returns:
      plant description
    • setDecay

      public void setDecay()
      Set the plant to decaying stage.
    • isDecay

      public boolean isDecay()
      Find out if the plant is decaying or not.
      Returns:
      If the plant is in a state of decay or not
    • getIdealWaterLevel

      public float getIdealWaterLevel()
      Get the ideal water level of a plant
      Returns:
      ideal water level
    • getGrowthStage

      public PlantComponent.GrowthStage getGrowthStage()
      Get the current growth stage of a plant
      Returns:
      current growth stage
    • setGrowthStage

      public void setGrowthStage(int newGrowthStage)
      Set the growth stage of a plant.
      Parameters:
      newGrowthStage - - The updated growth stage of the plant, between 1 and 6.
    • getAdultLifeSpan

      public int getAdultLifeSpan()
      Get the adult life span of a plant
      Returns:
      adult life span
    • setAdultLifeSpan

      public void setAdultLifeSpan(int adultLifeSpan)
      Set the adult life span of a plant.
      Parameters:
      adultLifeSpan - The number of days the plant will exist as an adult plant
    • increaseGrowthStage

      public void increaseGrowthStage(int growthIncrement)
      Increment the current growth stage of a plant by 1
      Parameters:
      growthIncrement - The number of growth stages the plant will increase by
    • getCurrentGrowthLevel

      public int getCurrentGrowthLevel()
      Return the current growth level of the plant.
      Returns:
      The current growth level
    • setCurrentGrowthLevel

      public void setCurrentGrowthLevel(int currentGrowthLevel)
      Set the currentGrowthLevel of the plant. This is used for testing purposes.
      Parameters:
      currentGrowthLevel - - Desired growth level of the plant.
    • getCurrentMaxHealth

      public int getCurrentMaxHealth()
      Retrieves the current maximum health value of the plant.
      Returns:
      The current maximum health of the plant.
    • getNumOfDaysAsAdult

      public int getNumOfDaysAsAdult()
      Retrieves the number of days the plant has been an adult.
      Returns:
      The number of days the plant has been in its adult stage.
    • setNumOfDaysAsAdult

      public void setNumOfDaysAsAdult(int numOfDaysAsAdult)
      Sets the number of days the plant has been an adult.
      Parameters:
      numOfDaysAsAdult - The number of days to set the plant's adult stage duration to.
    • getAdultEffect

      public String getAdultEffect()
      Getter for adultEffect
      Returns:
      the adult effect
    • getHarvestYields

      public Map<String,Integer> getHarvestYields()
      Gets the harvest yield of this plant.
      Returns:
      Map of item names to drop quantities.
    • setHarvestYields

      public void setHarvestYields(Map<String,Integer> harvestYields)
      Sets the harvest yield of this plant.

      This will store an unmodifiable copy of the given map. Modifications made to the given map after being set will not be reflected in the plant.

      Parameters:
      harvestYields - Map of item names to drop quantities.
    • setSounds

      public void setSounds(EffectSoundFile clickSound, EffectSoundFile clickLoreSound, EffectSoundFile decaySound, EffectSoundFile decayLoreSound, EffectSoundFile destroySound, EffectSoundFile destroyLoreSound, EffectSoundFile nearbySound, EffectSoundFile nearbyLoreSound)
      Sets the sound effects this plant will play.
      Parameters:
      clickSound - Normal sound effect to play when clicked.
      clickLoreSound - Lore sound effect to play when clicked.
      decaySound - Normal sound effect to play when decaying.
      decayLoreSound - Lore sound effect to play when decaying.
      destroySound - Normal sound effect to play when destroyed.
      destroyLoreSound - Lore sound effect to play when destroyed.
      nearbySound - Normal sound effect to play when nearby.
      nearbyLoreSound - Lore sound effect to play when nearby.
    • isDead

      public boolean isDead()
      Check if a plant is dead
      Returns:
      if the plant is fully decayed
    • updateMaxHealth

      public void updateMaxHealth()
      Update the maximum health of the plant based on its current growth stage. Called whenever the growth stage is changed
    • updateTexture

      public void updateTexture()
      Update the texture of the plant based on its current growth stage.
    • playSound

      public void playSound(EffectSoundFile normalSound, EffectSoundFile loreSound)
      Plays one of the given sound effects. The normal sound effects will be played 99% of the time, while the lore sound effect will be played 1% of the time.
      Parameters:
      normalSound - Normal sound effect to play (99% chance of being played).
      loreSound - Lore sound effect to play (1% chance of being played).
    • playSound

      public void playSound(EffectSoundFile sound)
      Plays the given sound effect.
      Parameters:
      sound - Sound effect to play.
    • getCurrentAge

      public float getCurrentAge()
    • setCurrentAge

      public void setCurrentAge(float age)
    • getCropTile

      public CropTileComponent getCropTile()
      Return the cropTile where the plant is located.
      Returns:
      the cropTile.
    • getIsEating

      public boolean getIsEating()
      Is the plant eating right now.
      Returns:
      isEating
    • setIsEating

      public void setIsEating()
      Tell the plant it is now eating an animal.
    • forceSeedling

      public void forceSeedling()
      Function used when debugging. Allows for the plant to instantly become a seedling from any growth stage.
    • forceSprout

      public void forceSprout()
      Function used when debugging. Allows for the plant to instantly become a sprout from any growth stage.
    • forceJuvenile

      public void forceJuvenile()
      Function used when debugging. Allows for the plant to instantly become a juvenile from any growth stage.
    • forceAdult

      public void forceAdult()
      Function used when debugging. Allows for the plant to instantly become an adult from any growth stage.
    • forceDecay

      public void forceDecay()
      Function used when debugging. Allows for the plant to instantly start decaying from any growth stage.
    • forceDead

      public void forceDead()
      Function used when debugging. Allows for the plant to instantly die from any growth stage.
    • forceGrowthStage

      public void forceGrowthStage(String growthStage)
      For debugging. Changes the plants growth stage by force.
      Parameters:
      growthStage - the current growth stage of the plant
    • currentInfo

      public String currentInfo()
      Return a string will all the relevant information about this plant. The returned string must be formatted such that each piece of information is on a new line.
      Returns:
      - Formatted string with all relevant information about the plant.
    • setPlayerInProximity

      public void setPlayerInProximity(boolean bool)
      Indicates when the player is in the plants proximity for playing sounds or not.
      Parameters:
      bool - - If the player is/(is not) in proximity.
    • addAoeAnimatorEntity

      public void addAoeAnimatorEntity(Entity animator)
      add animations for area of effect
      Parameters:
      animator - area of effect animations
    • getAoeAnimatorEntity

      public Entity getAoeAnimatorEntity()
      Getter for the area of effect animations
      Returns:
      area of effect animations
    • write

      public void write(com.badlogic.gdx.utils.Json json)
      Specified by:
      write in interface com.badlogic.gdx.utils.Json.Serializable
      Overrides:
      write in class Component
    • read

      public void read(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue plantData)
      Specified by:
      read in interface com.badlogic.gdx.utils.Json.Serializable
      Overrides:
      read in class Component