-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrole.guard.js
202 lines (199 loc) · 5.54 KB
/
role.guard.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/* Specialist Miner Drone */
module.exports.role = 'guard';
/* SType */
module.exports.sType = 'specialist';
/* Costs */
module.exports.cost = {
1 : 260,
2 : 260,
3 : 380,
4 : 510,
5 : 510,
6 : 510,
7 : 410,
8 : 260,
/*
2 : 380,
3 : 480,
4 : 700,
5 : 700,
6 : 700,
7 : 700,
8 : 700,
*/
};
/* Body parts */
module.exports.body = {
1 : [
ATTACK,ATTACK,
MOVE,MOVE,
],
2 : [
ATTACK,ATTACK,
MOVE,MOVE,
],
3 : [
TOUGH,TOUGH,
MOVE,MOVE,MOVE,
ATTACK,ATTACK,
MOVE,
],
4 : [
TOUGH,TOUGH,
MOVE,MOVE,MOVE,MOVE,
ATTACK,ATTACK,ATTACK,
MOVE,
],
5 : [
TOUGH,TOUGH,
MOVE,MOVE,MOVE,MOVE,
ATTACK,ATTACK,ATTACK,
MOVE,
],
6 : [
TOUGH,TOUGH,
MOVE,MOVE,MOVE,MOVE,
ATTACK,ATTACK,ATTACK,
MOVE,
],
7 : [
TOUGH,TOUGH,
MOVE,MOVE,MOVE,MOVE,
ATTACK,ATTACK,ATTACK,
MOVE,
],
8 : [
TOUGH,TOUGH,
MOVE,MOVE,MOVE,MOVE,
ATTACK,ATTACK,ATTACK,
MOVE,
],
/*
2 : [
TOUGH,TOUGH, // 2 Toughs = 20
MOVE,MOVE,MOVE,MOVE, // 4 Moves = 200
ATTACK,ATTACK, // 2 Attacks = 160 = 60h/t
],
3 : [
TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH, // 2 Toughs = 20
MOVE,MOVE,MOVE,MOVE, // 4 Moves = 200
ATTACK,ATTACK, // 2 Attacks = 160 = 60h/t
],
4 : [
TOUGH,TOUGH,TOUGH,TOUGH,TOUGH, // 5 Toughs = 50
MOVE,MOVE,MOVE,MOVE,MOVE, // 5 Moves = 250
ATTACK,ATTACK,ATTACK,ATTACK,ATTACK, // 5 Attacks = 400 = 150h/t
],
5 : [
TOUGH,TOUGH,TOUGH,TOUGH,TOUGH, // 5 Toughs = 50
MOVE,MOVE,MOVE,MOVE,MOVE, // 5 Moves = 250
ATTACK,ATTACK,ATTACK,ATTACK,ATTACK, // 5 Attacks = 400 = 150h/t
],
6 : [
TOUGH,TOUGH,TOUGH,TOUGH,TOUGH, // 5 Toughs = 50
MOVE,MOVE,MOVE,MOVE,MOVE, // 5 Moves = 250
ATTACK,ATTACK,ATTACK,ATTACK,ATTACK, // 5 Attacks = 400 = 150h/t
],
7 : [
TOUGH,TOUGH,TOUGH,TOUGH,TOUGH, // 5 Toughs = 50
MOVE,MOVE,MOVE,MOVE,MOVE, // 5 Moves = 250
ATTACK,ATTACK,ATTACK,ATTACK,ATTACK, // 5 Attacks = 400 = 150h/t
],
8 : [
TOUGH,TOUGH,TOUGH,TOUGH,TOUGH, // 5 Toughs = 50
MOVE,MOVE,MOVE,MOVE,MOVE, // 5 Moves = 250
ATTACK,ATTACK,ATTACK,ATTACK,ATTACK, // 5 Attacks = 400 = 150h/t
],
*/
};
/* Spawn Roster */
module.exports.roster = {
1: 3,
2: 3,
3: 3,
4: 3,
5: 10,
6: 10,
7: 10,
8: 3,
};
/**
* Individual check for a room to check if this creep type should be enabled or not
*/
module.exports.enabled = function (room, debug = false) {
// define the room
var _room = Game.rooms[room];
// Is this room in guard mode?
if (_room.memory.mode === 'guard' || _room.memory.war) {
// yep lets go spawn guards!
return true;
}
// Nope room is not in guard mode
return false;
}
/* Okay, lets code the creep */
module.exports.run = function (creep, debug = false) {
if (creep.isTired()) { return; }
// Functional check!
if (!creep.canDo(ATTACK)) {
if (debug) { console.log('[' +creep.name+'] Creep damaged seeking repair:' + JSON.stringify(creep.pos)); }
return;
}
if (creep.memory.idle >= 100) {
// No targets.. head back to the room spawn
var spawn = creep.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (i) => i.structureType === STRUCTURE_SPAWN && i.my
});
if (spawn.recycleCreep(creep) === ERR_NOT_IN_RANGE) {
creep.travelTo(spawn);
creep.say(global.sayWhat);
return;
}
}
// Get a target
var target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS, {
filter: (i) => !(global.friends.indexOf(i.owner.username) > -1)
});
if (!target) {
target = creep.pos.findClosestByRange(FIND_HOSTILE_STRUCTURES, {
filter: (i) => !(global.friends.indexOf(i.owner.username) > -1) && i.structureType === STRUCTURE_TOWER
});
}
if (!target) {
target = creep.pos.findClosestByRange(FIND_HOSTILE_STRUCTURES, {
filter: (i) => !(global.friends.indexOf(i.owner.username) > -1) && i.structureType === STRUCTURE_SPAWN
});
}
if (!target) {
target = creep.pos.findClosestByRange(FIND_HOSTILE_STRUCTURES, {
filter: (i) => !(global.friends.indexOf(i.owner.username) > -1) && i.structureType !== STRUCTURE_CONTROLLER
});
}
// var target = false; // uncomment to override hostiles and go to flags
if (target) {
creep.memory.idle = 0;
if (!creep.pos.inRangeTo(target,1)) {
creep.travelTo(target);
creep.say(global.sayMove);
}
if (creep.pos.inRangeTo(target,1)) {
creep.attack(target);
creep.say(global.sayAttack);
}
} else {
var flag = Game.flags['attack'];
if (!flag) {
flag = Game.flags['stage'];
}
if (!flag) {
creep.memory.idle++;
creep.say(creep.memory.idle);
return;
} else {
// If we're more than 1 tile away attempt to move there
if (!creep.pos.inRangeTo(flag,1)) {
creep.travelTo(flag);
}
}
}
}