-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnight.java
More file actions
executable file
·54 lines (42 loc) · 1.69 KB
/
Knight.java
File metadata and controls
executable file
·54 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import bc.MapLocation;
import bc.Team;
import bc.Unit;
import bc.VecUnit;
public class Knight extends Attacker {
public Knight(int id) {
super(id);
}
public void run() {
this.runAttacker();
}
/**
* Attacks the weakest enemy that it can, will move towards if unreachable
* @return true if nothing to attack false if attacked or has enemy in range
*/
@Override
public boolean runBattleAction() {
Team otherTeam = Player.team == Team.Blue ? Team.Red : Team.Blue;
VecUnit enemyUnits = Player.gc.senseNearbyUnitsByTeam(this.getLocation(), getVisionRange(), otherTeam);
if (enemyUnits.size() == 0) {
return true;
}
if (Player.gc.isAttackReady(this.getId())) {
Unit closestUnit = this.getClosestEnemy(enemyUnits);
int closestDistanceToUnit = (int)this.getLocation().distanceSquaredTo(closestUnit.location().mapLocation());
if (closestDistanceToUnit > this.getAttackRange()) {
if (Player.gc.isMoveReady(this.getId())) {
this.inCombatMove(true, closestUnit.location().mapLocation());
}
}
if (Player.gc.canAttack(this.getId(), closestUnit.id())) {
Player.gc.attack(this.getId(), closestUnit.id());
}
}
// Recalculate the closest unit in case you can javelin in this turn too
Unit closestUnit = this.getClosestEnemy(enemyUnits);
if (Player.gc.canJavelin(this.getId(), closestUnit.id()) && Player.gc.isJavelinReady(this.getId())) {
Player.gc.javelin(this.getId(), closestUnit.id());
}
return false;
}
}