-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrole.upgrader.js
69 lines (59 loc) · 2.83 KB
/
role.upgrader.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
66
67
68
69
var room_dest;
var roleUpgrader = {
run: function (creep) {
var spawn = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return structure.structureType === STRUCTURE_SPAWN
}
});
if (creep.ticksToLive < 50 && !creep.memory.renew_process) {
creep.memory.renew_process = true;
}
if (creep.ticksToLive > 500 && creep.memory.renew_process) {
creep.memory.renew_process = false;
}
if (creep.memory.room_dest != null && creep.room.name !== creep.memory.room_dest && !creep.memory.renew_process) {
room_dest = creep.memory.room_dest;
var roomName = String(room_dest);
creep.moveTo(new RoomPosition(25, 25, roomName));
} else {
if (creep.memory.building && creep.store.getUsedCapacity([RESOURCE_ENERGY]) === 0) {
creep.memory.building = false;
}
if (!creep.memory.building && creep.store.getUsedCapacity([RESOURCE_ENERGY]) === creep.store.getCapacity([RESOURCE_ENERGY])) {
creep.memory.building = true;
}
if (creep.memory.building) {
creep.say("⏏");
if (creep.upgradeController(creep.room.controller) === ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller, {visualizePathStyle: {stroke: '#00B200'}, reusePath:10});
}
/*if (creep.signController(creep.room.controller, "Gebiet des Deutschen Kaiserreich") == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller, {visualizePathStyle: {stroke: '#00B200'}});
}*/
} else {
if (!creep.memory.renew_process) {
creep.say("⛏");
var sources = creep.pos.findClosestByPath(FIND_SOURCES);
if (creep.room.storage && creep.room.storage.store.energy > 10000) {
creep.moveTo(creep.room.storage, {visualizePathStyle: {stroke: '#ffaa00'}});
creep.withdraw(creep.room.storage, RESOURCE_ENERGY);
} else if (creep.harvest(sources) === ERR_NOT_IN_RANGE) {
creep.moveTo(sources, {visualizePathStyle: {stroke: '#ffaa00'}});
}
} else {
if (creep.moveTo(spawn[0]) === ERR_NOT_IN_RANGE) {
creep.moveTo(spawn[0], {visualizePathStyle: {stroke: '#ffffff'}});
} else {
if (creep.room.energyAvailable > 500) {
creep.suicide();
} else {
spawn[0].renewCreep(creep)
}
}
}
}
}
}
};
module.exports = roleUpgrader;