-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.ranger.js
65 lines (57 loc) · 2.49 KB
/
role.ranger.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
65
/*
* Module code goes here. Use 'module.exports' to export things:
* module.exports.thing = 'a thing';
*
* You can import it from another modules like this:
* var mod = require('role.ranger');
* mod.thing == 'a thing'; // true
*/
require('prototype.Creep')();
var Cache = require('help.cache');
var WarManager = require('goto.war');
/*///////////////// Needs From WarManager ///////////////
WarManager.timeToAttack (creep, cache)
WarManager.stackOnRoomEntrance(creep, cache)
WarManager.getTargetFor (creep, cache)
///////////////////////////////////////////////////////*/
module.exports = {
run: function(creep, cache) {
if(!creep.memory.target)
creep.memory.target = WarManager.getTargetFor(creep, cache);
var target = creep.memory.target;
if(!target)return;
target = _.merge(target, RoomPosition.prototype);
if(!WarManager.timeToAttack(creep)){
WarManager.stackOnRoomEntrance(creep);
}
else{
creep.moveTo(target);
var mobileTargets = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 3);
var staticTargets = creep.pos.findInRange(FIND_HOSTILE_STRUCTURES, 3);
if (mobileTargets || staticTargets) {creep.rangedMassAttack();}
if(! Utils.posEquals(creep.pos, target))
creep.moveTo(target.x, target.y, {ignoreDestructibleStructures: true});
if(mobileTargets.length + staticTargets.length > 3)
creep.rangedMassAttack();
if(mobileTargets.length)
creep.rangedAttack(creep.pos.findClosestByRange(mobileTargets));
else if(staticTargets.length)
creep.rangedAttack(creep.pos.findClosestByRange(staticTargets));
}
}
};
/*
creep.moveTo(target);
var mobileTargets = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 3);
var staticTargets = creep.pos.findInRange(FIND_HOSTILE_STRUCTURES, 3);
if (mobileTargets || staticTargets) {creep.rangedMassAttack();}
if(! Utils.posEquals(creep.pos, target))
creep.moveTo(target.x, target.y, {ignoreDestructibleStructures: true});
if(mobileTargets.length + staticTargets.length > 3)
creep.rangedMassAttack();
if(mobileTargets.length)
creep.rangedAttack(creep.pos.findClosestByRange(mobileTargets));
else if(staticTargets.length)
creep.rangedAttack(creep.pos.findClosestByRange(staticTargets));
}
*/