-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.newAttacker.js
56 lines (47 loc) · 2.48 KB
/
role.newAttacker.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
var rolenewAttacker = {
/** @param {Creep} creep **/
run: function(creep) {
var targets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_EXTENSION || structure.structureType == STRUCTURE_SPAWN || structure.structureType == STRUCTURE_TOWER) &&
structure.energy < structure.energyCapacity;
}
});
//if(targets.length > 0) {
//console.log('Creep ' + creep.name + ' delivering:' + creep.memory.delivering + ' on board:' + creep.carry.energy);
if(creep.memory.delivering != true) {
//console.log("I am in room: " + creep.pos.roomName + " but looking for " + creep.memory.remote);
if (creep.pos.roomName == creep.memory.remote) {
//console.log("I think I am in the right room");
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[1]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[1]);
}
if(creep.carry.energy == creep.carryCapacity) {
creep.memory.delivering = true;
// Game.notify('Creep ' + creep.name + ' who is a ' + creep.memory.role + ' started heading to deliver energy at ' + Game.time);
}
} else {
var exit = creep.room.findExitTo(creep.memory.remote);
creep.moveTo(creep.pos.findClosestByRange(exit));
//console.log("Moving to exit");
}
}
else {
if (creep.room.name == creep.memory.home) {
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0]);
}
if(creep.carry.energy == 0) {
creep.memory.delivering = false;
// Game.notify('Creep ' + creep.name + ' who is a ' + creep.memory.role + ' started going to collect energy at ' + Game.time);
}
} else {
var exit = creep.room.findExitTo(creep.memory.home);
creep.moveTo(creep.pos.findClosestByRange(exit));
}
}
//}
}
};
module.exports = rolenewAttacker;