-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrole.janitor.js
172 lines (163 loc) · 4.68 KB
/
role.janitor.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* Janitor drone */
module.exports.role = "janitor";
/* sType */
module.exports.sType = "normal";
/* Spawn Roster */
module.exports.roster = {
1: 1,
2: 1,
3: 1,
4: 1,
5: 1,
6: 1,
7: 1,
8: 1,
};
/* Costs */
module.exports.cost = {
1 : 300,
2 : 550,
3 : 800,
4 : 800,
5 : 800,
6 : 800,
7 : 800,
8 : 800,
};
module.exports.body = {
1 : [
WORK,WORK,
CARRY,
MOVE
],
2 : [
WORK,WORK,WORK,
CARRY,
MOVE,MOVE,MOVE,MOVE
],
3 : [
WORK,WORK,WORK,WORK,
CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,MOVE
],
4 : [
WORK,WORK,WORK,WORK,
CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,MOVE
],
5 : [
WORK,WORK,WORK,WORK,
CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,MOVE
],
6 : [
WORK,WORK,WORK,WORK,
CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,MOVE
],
7 : [
WORK,WORK,WORK,WORK,
CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,MOVE
],
8 : [
WORK,WORK,WORK,WORK,
CARRY,CARRY,
MOVE,MOVE,MOVE,MOVE,MOVE,MOVE
],
};
module.exports.enabled = function (room, debug = false) {
return false;
var items = 0;
// Define the room we're in
var _room = Game.rooms[room];
// Search for all targets that are walls or ramparts below their global max, or anything else with less hits than max
// const targets = _room.find(FIND_STRUCTURES, {
// filter: (i) => (i.structureType === STRUCTURE_RAMPART && i.hits <= RAMPART_MAX) ||
// (i.structureType === STRUCTURE_WALL && i.hits <= WALL_MAX) ||
// ((i.structureType !== STRUCTURE_WALL && i.structureType != STRUCTURE_RAMPART) && i.hits < i.hitsMax)
// });
const targets = _room.find(FIND_STRUCTURES, {
filter: (i) => (i.structureType === STRUCTURE_ROAD && i.hits < i.hitsMax)
});
// Do we have any?
if (targets.length > 0) {
return true;
}
return false;
}
module.exports.visuals = function (items, room, debug = false) {
var _room = Game.rooms[room];
// _room.visual.clear();
for (var i in items) {
var item = items[i];
var percent = 100;
if(item.structureType === STRUCTURE_RAMPART) {
percent = (item.hits/RAMPART_MAX)*100;
} else if (item.structureType == STRUCTURE_WALL) {
percent = (item.hits/WALL_MAX)*100;
} else {
percent = (item.hits/item.hitsMax)*100;
}
var r = Math.round(255 - ((255/100)*(percent/100)*100));
var g = Math.round((255/100)*(percent/100)*100);
var b = 0;
var _color = "#" + hex(r) + hex(g) + hex(b);
_room.visual.circle(item.pos, {
fill: _color,
radius:0.35,
opacity:0.05,
stroke:_color
}).text(percent.toFixed(2) + "%", item.pos, {
color:_color,
font:0.5,
align:"left",
stroke:"rgba(0,0,0,0.5)",
opacity:0.6,
});
}
}
/**
* Janitor Role
*/
module.exports.run = function(creep) {
creep.suicide();
// If spawning or fatigued
if (creep.spawning || creep.fatigue > 0) { return; }
// If we have only a few ticks to live we should set to dying
if (creep.ticksToLive < 100) { creep.memory.dying = true; }
// If we're sapping and have run out of energy
if(creep.memory.sapping && creep.carry.energy === 0) {
// clear sapping flag
creep.memory.sapping = false;
creep.say(global.sayGet);
}
// Are we full?
if(!creep.memory.sapping && creep.carryCapacity > 0 && creep.carry.energy === creep.carryCapacity) {
// Yes set sapping flag to true
creep.memory.sapping = true;
creep.say(global.sayPUT);
}
// Are we in pickup energy mode?
if (!creep.memory.sapping && creep.getNearbyEnergy(true) === ERR_FULL) {
delete creep.memory.energyPickup;
creep.memory.sapping = true;
}
// Are we sapping?
if(creep.memory.sapping) {
delete creep.memory.energyPickup;
let result = creep.repairStructures(true,false,false);
switch (creep.repairStructures(true,false,false)) {
case ERR_FULL: // We have completed this fill
delete creep.memory.repairTarget;
delete creep.memory.targetmaxHP;
break;
case ERR_NOT_ENOUGH_ENERGY: // We have run out of energy
delete creep.memory.repairTarget;
delete creep.memory.targetmaxHP;
creep.memory.sapping == false;
break;
default: // Nothing to do here
}
}
}