-
Notifications
You must be signed in to change notification settings - Fork 0
/
reserver.js
48 lines (42 loc) · 1.54 KB
/
reserver.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
const body = [CLAIM,CLAIM,MOVE,MOVE];
module.exports = {
run: function (roomName, spawnRoomName) {
const creepName = 'reserver_' + roomName;
var creep = Game.creeps[creepName];
if (!creep) {
autoSpawnCreep(creepName, spawnRoomName);
}
else {
if(!creep.pos.inRangeTo(new RoomPosition(25, 25, roomName),24)) creep.moveTo(new RoomPosition(25, 25, roomName));
else {
if(creep.room.controller) {
if(!creep.room.controller.my && creep.room.controller.owner != undefined) {
if(creep.attackController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
}
else{
if(creep.reserveController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
}
}
}
}
}
}
function autoSpawnCreep(creepName, spawnRoomName) {
var spawn = getAvaliableSpawn(spawnRoomName);
if (spawn) {
spawn.spawnCreep(body, creepName, {memory: {role: 'reserver' }});
}
}
function getAvaliableSpawn(room) {
for (var spawnname in Game.spawns) {
var spawn = Game.spawns[spawnname];
if (spawn.room.name == room && spawn.spawning == null) {
return spawn;
}
}
return null;
}