-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.mcv.js
54 lines (47 loc) · 1.62 KB
/
role.mcv.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
const roleMcv = {
creep: null,
targetRoom: null,
run: (creep) => {
//console.log(this);
roleMcv.creep = creep;
roleMcv.targetRoom = Game.flags['deployMCV'] ? Game.flags['deployMCV'].pos : null;
if (roleMcv.creep && roleMcv.targetRoom) {
if (roleMcv.creep.pos.roomName !== roleMcv.targetRoom.roomName) {
roleMcv.moveToRoom();
} else {
roleMcv.conquer();
}
}
},
moveToRoom: () => {
let targetPos = new RoomPosition(roleMcv.targetRoom.x, roleMcv.targetRoom.y, roleMcv.targetRoom.roomName);
let result = roleMcv.creep.moveTo(targetPos);
//console.log(`Result of creep.moveTo(new RoomPosition(${rallyTo.x}, ${rallyTo.y}, '${rallyTo.roomName}')): ${result}`);
if (result === -2) {
const path = creep.room.findPath(creep.pos, targetPos );
//console.log(`Path result was: ${JSON.stringify(path)}`);
}
},
findController: () => {
return roleMcv.creep.room.find(
FIND_STRUCTURES,
{
filter: function(structure) {
if (structure.structureType === STRUCTURE_CONTROLLER) {
return true;
}
return false;
}
}
);
},
conquer: () => {
let controller = roleMcv.findController();
if (controller.length !== 0) {
controller = controller[0];
}
roleMcv.creep.moveTo(controller);
roleMcv.creep.claimController(controller);
}
};
module.exports = roleMcv;