# What component should hold the bool attack and vector target?

I am having trouble thinking of what component should hold the attack and target data. In the below code components are holding a redundant data which I want to eliminate.

public class PlayerComponent implements Component {
public boolean attack = false;
public Vector2 target = new Vector2();
}

public class PoliceComponent implements Component {
public boolean attack = false;
public Vector2 target = new Vector2();
}

public class CriminalComponent implements Component {
public boolean attack = false;
public Vector2 target = new Vector2();
}


I ended up creating an CombatComponent that holds the both attack and target, but I doubt there is more better way. The purpose is to have a weapon system the check if the player or enemy trigger attack and get its target.

private void processWeapon() {
for (Entity weapon: weaponEntities) {
AttachmentComponent attachment = Mapper.attachment.get(weapon);
if(playerFamily.matches(attachment.owner)) {
PlayerComponent player = Mapper.player.get(attachment.owner);
CombatComponent combat = Mapper.combat.get(attachment.owner);
if( combat.attack ) {
WeaponComponent weaponComponent = Mapper.weapon.get(weapon);
weaponComponent.use = true;
weaponComponent.target.set(player.target);
}
}
}
}


or the another way calling the WeaponSystem to use the owner weapon.

getEngine().getSystem(WeaponSystem.class).useWeapon(ownerEntity, targetPosition);

• Seems OK to me. Maybe it could make sense to merge WeaponComponent and CombatComponent into one. But that depends on what these two components actually do. – Philipp Sep 7 '16 at 8:14
• @Philipp because WeaponComponent is an object, it doesn't attack itself right? So I need a Component that controls that weapon. – ronscript Sep 7 '16 at 10:32

The notion of a target I believe can go beyond the scope of just combat.
In either of the above scenarios, there is the concept an TradeSystem and InteractionSystem that are all based around what the player currently has targetted (selected).
Not sure if this exactly meets your needs, but you could also create a separate POJO that encapsulates attack and target and use this inside {Player|Police|Criminal}Component (composition!). You'd still have a little duplication (instantiating this POJO in each of the three classes), but not all duplication is bad, and it's just one line.