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
Class for all plants in the game.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
The growth stage of the plant -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionPlantComponent
(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.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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAoeAnimatorEntity
(Entity animator) add animations for area of effectvoid
Check if the plant has exceeded its adult lifespan.void
create()
Called when the entity is created and registered.Return a string will all the relevant information about this plant.void
Functionality for the plant that needs to update every day.void
Check if the plant is already decaying and needs to die.void
Check if the space snapper is currently eating.void
Function used when debugging.void
Function used when debugging.void
Function used when debugging.void
forceGrowthStage
(String growthStage) For debugging.void
Function used when debugging.void
Function used when debugging.void
Function used when debugging.Getter for adultEffectint
Get the adult life span of a plantGetter for the area of effect animationsReturn the cropTile where the plant is located.float
int
Return the current growth level of the plant.int
Retrieves the current maximum health value of the plant.Get the current growth stage of a plantGets the harvest yield of this plant.float
Get the ideal water level of a plantboolean
Is the plant eating right now.int
Returns the max health of the plantint
Retrieves the number of days the plant has been an adult.Returns the plant descriptionint
Returns the current plant healthReturns the name of the plantReturns the type of the plantvoid
Functionality for the plant that needs to update every hour.void
increaseGrowthStage
(int growthIncrement) Increment the current growth stage of a plant by 1void
increasePlantHealth
(int plantHealthIncrement) Increase (or decrease) the plant health by some valuevoid
Changes the oxygen level of the planet based on the plant and growth stageboolean
isDead()
Check if a plant is deadboolean
isDecay()
Find out if the plant is decaying or not.void
Functionality for the plant that needs to update every minute.void
playSound
(EffectSoundFile sound) Plays the given sound effect.void
playSound
(EffectSoundFile normalSound, EffectSoundFile loreSound) Plays one of the given sound effects.void
read
(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue plantData) void
setAdultLifeSpan
(int adultLifeSpan) Set the adult life span of a plant.void
Set the area of effect radius based on the type of plant.void
setCurrentAge
(float age) void
setCurrentGrowthLevel
(int currentGrowthLevel) Set the currentGrowthLevel of the plant.void
setDecay()
Set the plant to decaying stage.void
setGrowthStage
(int newGrowthStage) Set the growth stage of a plant.void
setHarvestYields
(Map<String, Integer> harvestYields) Sets the harvest yield of this plant.void
Tell the plant it is now eating an animal.void
setNumOfDaysAsAdult
(int numOfDaysAsAdult) Sets the number of days the plant has been an adult.void
setPlantHealth
(int health) Set the current plant healthvoid
setPlayerInProximity
(boolean bool) Indicates when the player is in the plants proximity for playing sounds or not.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.void
Update the growth stage of a plant based on its current growth level.void
Update the maximum health of the plant based on its current growth stage.void
Update the texture of the plant based on its current growth stage.void
write
(com.badlogic.gdx.utils.Json json) Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
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 plantname
- - name of the plantplantType
- - type of the plantplantDescription
- - description of the plantidealWaterLevel
- - The ideal water level for a plantadultLifeSpan
- - How long a plant will live for once it becomes an adultmaxHealth
- - The maximum health a plant can reach as an adultcropTile
- - 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 plantname
- - name of the plantplantType
- - type of the plantplantDescription
- - description of the plantidealWaterLevel
- - The ideal water level for a plantadultLifeSpan
- - How long a plant will live for once it becomes an adultmaxHealth
- - The maximum health a plant can reach as an adultcropTile
- - 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. -
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
Returns the name of the plant- Returns:
- name of the plant
-
getPlantType
Returns the type of the plant- Returns:
- type of the plant
-
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
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
Getter for adultEffect- Returns:
- the adult effect
-
getHarvestYields
Gets the harvest yield of this plant.- Returns:
- Map of item names to drop quantities.
-
setHarvestYields
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
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
Plays the given sound effect.- Parameters:
sound
- Sound effect to play.
-
getCurrentAge
public float getCurrentAge() -
setCurrentAge
public void setCurrentAge(float age) -
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
For debugging. Changes the plants growth stage by force.- Parameters:
growthStage
- the current growth stage of the plant
-
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
add animations for area of effect- Parameters:
animator
- area of effect animations
-
getAoeAnimatorEntity
Getter for the area of effect animations- Returns:
- area of effect animations
-
write
public void write(com.badlogic.gdx.utils.Json json) -
read
public void read(com.badlogic.gdx.utils.Json json, com.badlogic.gdx.utils.JsonValue plantData)
-