Targeters - Terasology/GooeyDefence GitHub Wiki
Targeters have two components on top of the standard block and prefab requirements. These are the component that will contain the configurable values, and the system used to implement the logic. Both of these are vital for a targeter to function properly.
See Tower Block Base for details on how to make the tower block and corresponding entity. This guide will assume you have completed those steps first.
First is the component. This should be a class that extends the TowerTargeter
class. It can either do this directly, like SingleTargeter
and AoeTargeter
or it can extend a class that in turn extends TowerTargeter
. This is what classes like MissileTargeter
do as it allows you to use fields from the other subclasses.
TowerTargeter is the base class for all Targeters and has a number of default fields on it. Namely these are:
-
drain
: How much power this Targeter will take. -
attackSpeed
: How long between attacks. Given in milliseconds. eg, 500ms means it will attack twice per second. -
range
: The radius of this Targeter's range. Given in blocks.
Additionally there is an abstract method called getMultiplier
that the component will need to implement. This method returns a float that is passed to the Effectors each attack. It should be used as a balancing tool to make sure that the different targeters are all correctly balanced.
Of particular note is the SingleTargeter
as this is a base class for all bar one implementations. It has an additional field called selectionMethod
. This is a value from the SelectionMethod
enum that provides the player with control over how the targeter selects it's targets.
Here example of what a targeter called HeightTargeter
that added a float field minHeight
, and extended SingleTargeter might look:
public class SingleTargeterComponent extends SingleTargeterComponent {
public float minHeight = 0.5f;
@Override
public float getMultiplier() {
return 1.2f;
}
}
The second half of this is the system. This will implement the actual selection of enemies using the component detailed in the prior section. Unlike the component, this system does not need to extend any special classes and can be a plain system. It can even have other responsibilities and functionality just like all systems. It is recommended to extend the BaseTargeterSystem
however, for reasons explained below.
When a targeter is called to select it's targets, the SelectEnemiesEvent
is sent. The event handler should simply use the addToList
methods to add enemies to the event. Managers such as EnemyManager
have some useful methods which will help in selecting enemies. Additionally the system, BaseTargeterSystem
, has a number of useful helper methods which can simplify the process.
Any visual effects should also be triggered in this event, helper methods for which are located in InWorldRenderer
.
As an example here is the entirety of AoeTargeterSystem
, minus javadoc, which serves as one of the simpler implementations:
@RegisterSystem
public class AoeTargeterSystem extends BaseTargeterSystem {
@In
private EnemyManager enemyManager;
@In
private InWorldRenderer inWorldRenderer;
@ReceiveEvent
public void onSelectEnemies(SelectEnemiesEvent event, EntityRef entity, LocationComponent locationComponent, AoeTargeterComponent targeterComponent) {
Set<EntityRef> targets = enemyManager.getEnemiesInRange(locationComponent.getWorldPosition(), targeterComponent.range);
event.addToList(targets);
if (!targets.isEmpty()) {
inWorldRenderer.displayExpandingSphere(locationComponent.getWorldPosition(), (float) targeterComponent.attackSpeed / 1000, targeterComponent.range * 2 + 1);
}
}
}
Name | Description | Files | Tile |
---|---|---|---|
AoeTargeter | This targeter attacks every single enemy within range. It has greatly reduced power in return. Useful for applying an effect over a large area. |
blocks/targeters/AoeTargeter.prefab , AoeTargeterComponent .java, AoeTargeterSystem .java
|
|
ChainTargeter | Targets a enemy and chains the effect to nearby enemies. |
blocks/targeters/ChainTargeter.prefab , ChainTargeterComponent.java , ChainTargeterSystem.java
|
|
MissileTargeter | Targets an enemy far away and effects all enemies nearby the target |
blocks/targeters/MissileTargeter.prefab , MissileTargeterComponent.java , MissileTargeterSystem.java
|
|
SingleTargeter | Targets a single enemy within range. The basic targeter block. |
blocks/targeters/SingleTargeter.prefab , SingleTargeterComponent.java , SingleTargeterCSystem.java
|
|
SniperTargeter | This targeter has high range and power, at the cost of a slow attack speed and an inability to hit close by targets. It is ideal for taking out strong units from range |
blocks/targeters/SniperTargeter.prefab , SniperTargeterComponent.java , SniperTargeterSystem.java
|
|
SplashTargeter | Targets a single enemy and applies the effect to all enemies close by the target. |
blocks/targeters/SplashTargeter.prefab , SplashTargeterComponent.java , SplashTargeterSystem.java
|