Forager Worker Unit - UQdeco2800/2022-studio-3 GitHub Wiki

Foragers are a worker unit that is responsible for taking wood attributes from a resource.

How to create a Forager

Foragers are created by ForagerFactory.java which uses WorkerFactory.java to create the worker. So, Foragers have components from WorkerFactory as well. Here is how to create a Forager entity:

Entity newForager = ForagerFactory.createForager();

How Foragers Collect Wood from Resource Entities

Foragers have a component called WorkerInventoryComponent which stores all resource types such as stone, metal, and wood that have been collected by the forager. The resource entity itself has a component called ResourceStatsComponent which is the number of each resource types it possesses. The process of adding the amount of stone/metal/wood in Miner's inventory and reducing the amount of stone/metal/wood in a resource is mainly implemented in ResourceCollectComponent.

How Forager flee from enemies by retreating to base

Forager has the same retreat mechanism like Miner Worker Unit.

Unit Tests Written for Foragers

The unit tests for foragers tests each of the components it possesses when its instantiated in ForagerFactory. There are 3 unit tests performed for the Forager:

  • shouldDetectForagerComponents() : Check whether ForagerComponent could be added to Forager. ForagerComponent is used by ResourceCollectComponent to perform verification for calling collectStone() and collectMetal.
  • shouldDetectCollectStatsComponent : Check whether CollectStatsComponent is working properly.
  • shouldCollectAndUnloadResources() : Check whether the Forager unit can functionally obtain wood from a tree and load it to the base.
⚠️ **GitHub.com Fallback** ⚠️