-
Notifications
You must be signed in to change notification settings - Fork 9
CostComponent
First see Components, Loading Resources.
The CostComponent
is a component used to charge the user the given cost when the entity it is attached to is placed via the StructurePlacementService
. It also refunds the cost when picked up. If there is also a CombatStatsComponent
attached, it will refund an amount proportional to the percentage of health remaining.
It implements the Placeable interface for this functionality.
The CostComponent
takes in an ObjectMap<String, Integer> which contains a map from resource name to amount of resources required.
public CostComponent(ObjectMap<String, Integer> cost)
Before using the CostComponent
you must first include it in your file.
import com.csse3200.game.components.structures.CostComponent;
The CostComponent
can then be added to an entity as follows.
PlaceableEntity entity = new PlaceableEntity();
var cost = new ObjectMap<String, Integer>();
cost.put("resource1", 10);
cost.put("resource2", 25);
entity.addComponent(new CostComponent(cost));
You can then place the entity via the StructurePlacementService
as follows.
var position = new GridPoint2(0,0);
ServiceLocator.getStructurePlacementService().placeStructureAt(entity, position);
When the entity is placed, the specified resources will be taken from the player.
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files