Skip to content

Plant area of effect component

abhat0 edited this page Oct 17, 2023 · 6 revisions

Description

This component allows plants to have an area that can detect other entities and effect them. The unique effects that plants have are based on the type of plant it is applied to and the current growth stage of the plant. The effects include a healing, poison, eating, sound, and dead/decay. This component is very similar to the InteractionDetector component but it has been specialised just for plants.

Functionality Breakdown

The plant AOE effects are dependent on the current weather conditions in the game. The current weather event will change the effect by adding or subtracting a plantAoeWeatherModifier integer from the existing effect.

Summary of the effects that each plant can have an other entities.

Firstly, these two effects are shared by all plants:

  • Decay: When this plant is in a state of decay, the health of all plants around it in a 1 tile radius is decremented every 5 minutes of in game time. The rate at which the health of the surrounding plants is decremented depends on the current weather in the game. Under normal weather conditions, the health is decremented 4 points. If there is a weather event happening in game, then the rate at which the health is decreased is 4 - plantAoeWeatherModifier.
  • sound: Play a sound once an hour if the player is in range of the plant.

Summary of specialised effects:

Plant Name Plant Type Aoe Effect Description Entities effected Aoe effect value
Hammer Plant REPAIR health: Heal the Player, Plants and Animals with approximately a one tile radius of the Hammer Plant. Player, Bat, Astrolotl, dragonfly, chicken, oxygen eater, cow Health of other plants in incremented by 4 + plantAoeWeatherModifier
Space Snapper DEFENCE eat: Eat any animal NPC that comes comes within approximately a one tile radius of the Space Snapper. Bat, Astrolotl, dragonfly, chicken, oxygen eater, cow This effect just destroys the animal that comes too close.
Deadly Nightshade DEADLY poison: Poison the player and any animals that come within a one tile radius of the Deadly Nightshade. The poison effect will reduce the health of the entity within the radius every 5 minutes of in game time until the entity leaves the radius. Player, Bat, Astrolotl, dragonfly, chicken, oxygen eater, cow Animals: The health of animals is 'increased' by, -5 - plantAoeWeatherModifier. Player: The health of the player is 'increased' by, -1 - plantAoeWeatherModifier.

Variables

  • private float radius: The radius of the area of effect.
  • private String effectType: The type of effect to be implemented.
  • private List<Entity> entitiiesInRange: List of entities within range.
  • private CircleShape shape: Circle shape of the area.

Methods

  • public PlantAreaOfEffectComponent(float radius, String effectType): Constructor for the component, initialises the radius and effect type variables.
  • public void create(): Sets up a radius for the collider and listens to relevant services.
  • private void hourlyEffect(): Triggered every hour of in game time and checks if any hourly effects need to be executed.
  • private void minuteUpdate(): Triggered every minute of in game time and checks if any effects need to be executed.
  • private void onCollisionStart(Fixture me, Fixture other): Adds entity to entitiesInRange on collision start.
  • private void onCollisionEnd(Fixture me, Fixture other): Removes an entity from the entities in range list on collision end.
  • public List<Entity> getEntitiesInRange(): Get the list of entities in range.
  • private void decayAndDeadEffect(): Effect that is triggered when a plant has entered the decaying or dead growth stage.
  • private void healthEffect(): Effect that increases/decreases the health of plants, animals and the player.
  • private void poisonEffect(): Effect that poisons the player and any animals in the area.
  • private void eatEffect(): Effect that allows the space snapper to eat any animals.
  • private void soundEffect(): Plays a nearby sound if the player comes near the plant.
  • public void setEffectType(): Update the current effect being executed.

Usage

To incorporate the PlantAreaOfEffectComponent into the plant system:

1. Import the necessary classes

import com.csse3200.game.components.plants.PlantAreaOfEffectComponent;

**2. Add the PlantAreaOfEffectComponent to a plant entity **

plant.addComponent(new PlantAreaOfEffectComponent(2f, "decay"));

image

Test Plan

  • Verify that the PlantAreaOfEffectComponent object is initialized correctly with a radius of 1f and an empty effect type string.
  • Ensure that the mock Fixture and Entity objects are created for testing purposes.
  • Radius and Effect Getter and Setter tests to verify the correctly set and retrieve the correct values:
  • Collision Handling Tests: verify that it behaves as expected when the fixture "me" is mocked, ensuring that no entities are added/removed to the range.
Clone this wiki locally