-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrole.hopper.js
53 lines (49 loc) · 1.74 KB
/
role.hopper.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
const movement = require("helper.movement");
// Hop into a room to take some damage, but go out before it is too late
// Goal is to drain energy out of the room using hostile towers
module.exports = {
name: "hopper",
configs: function() {
var configs = [];
for(var toughness = 25; toughness >= 10; toughness -= 1) {
let config = Array(toughness).fill(TOUGH).concat(Array(toughness).fill(MOVE));
configs.push(config);
}
return configs;
},
run: function(creep) {
if(creep.ticksToLive == CREEP_LIFE_TIME - 1) creep.notifyWhenAttacked(false);
let targetName = creep.memory.room;
if(creep.room.name !== targetName) {
if(creep.hits == creep.hitsMax) {
movement.moveToRoom(creep, targetName);
} else {
movement.leaveExit(creep);
}
} else {
let damageTaken = creep.memory.lastHits - creep.hits;
if(creep.hits <= damageTaken * 3) {
this.moveOut(creep);
} else {
movement.leaveExit(creep);
}
}
creep.memory.lastHits = creep.hits;
},
moveOut: function(creep) {
if(creep.pos.x == 1) {
creep.move(LEFT);
} else if(creep.pos.x == 48) {
creep.move(RIGHT);
} else if(creep.pos.y == 1) {
creep.move(TOP);
} else if(creep.pos.y == 48) {
creep.move(BOTTOM);
} else {
// creep somehow got deeper than expected
creep.move(creep.pos.getDirectionTo(creep.pos.findClosestByRange(FIND_EXIT)));
}
}
};
const profiler = require("screeps-profiler");
profiler.registerObject(module.exports, 'hopper');