forked from Garethp/Screeps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roles_archer.js
64 lines (51 loc) · 1.59 KB
/
roles_archer.js
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
53
54
55
56
57
58
59
60
61
62
63
64
var proto = require('role_prototype');
var archer = {
parts: [
[Game.RANGED_ATTACK, Game.RANGED_ATTACK, Game.MOVE, Game.MOVE],
[Game.RANGED_ATTACK, Game.RANGED_ATTACK, Game.RANGED_ATTACK, Game.MOVE, Game.MOVE, Game.MOVE],
[Game.RANGED_ATTACK, Game.RANGED_ATTACK, Game.RANGED_ATTACK, Game.RANGED_ATTACK, Game.MOVE, Game.MOVE, Game.MOVE, Game.MOVE],
[Game.RANGED_ATTACK, Game.RANGED_ATTACK, Game.RANGED_ATTACK, Game.RANGED_ATTACK, Game.RANGED_ATTACK, Game.MOVE, Game.MOVE, Game.MOVE, Game.MOVE, Game.MOVE],
],
/**
* Here we want Archer to automatically scale to however many extensions we have
* @returns {Array}
*/
getParts: function()
{
var _= require('lodash');
var partsAllowed = Game.getRoom('1-1').find(Game.MY_STRUCTURES, {
filter: function(structure)
{
return (structure.structureType == Game.STRUCTURE_EXTENSION && structure.energy >= 200);
}
}).length;
partsAllowed += 5;
var modulo = partsAllowed % 2;
partsAllowed -= modulo;
partsAllowed /= 2;
if(partsAllowed > 5)
partsAllowed = 5;
var parts = [ ];
for(var i = 0; i < partsAllowed; i++) {
parts.unshift(Game.RANGED_ATTACK);
parts.push(Game.MOVE);
}
return parts;
},
/**
* @TODO: We need to get archers to prioritise their targets better
*/
action: function()
{
var creep = this.creep;
var target = this.getRangedTarget();
if(target !== null)
creep.rangedAttack(target);
//If there's not a target near by, let's go search for a target if need be
if(target === null)
return this.rest();
this.kite(target);
creep.rangedAttack(target);
}
};
module.exports = archer;