Forager Worker Unit - UQdeco2800/2022-studio-3 GitHub Wiki
Foragers are a worker unit that is responsible for taking wood attributes from a resource.
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();
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.
Forager has the same retreat mechanism like Miner Worker Unit.
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 callingcollectStone()
andcollectMetal
. -
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.