-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.builder.js
More file actions
82 lines (77 loc) · 2.73 KB
/
role.builder.js
File metadata and controls
82 lines (77 loc) · 2.73 KB
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
var helper = require('helper');
var roleHarvester = {
/** @param {Creep} creep **/
run: function (creep) {
// this.getPath(creep);
if (creep.memory.working && creep.carry.energy == 0) {
creep.memory.working = false;
}
if (!creep.memory.working && creep.carry.energy == creep.carryCapacity) {
console.log('search');
creep.memory.working = true;
this.getPath(creep);
}
if (creep.memory.working) {
if(creep.memory.moving==true)
{
if(creep.memory.object==undefined || creep.memory.range<=1)
{
creep.memory.moving=false;
}
creep.memory.range = creep.memory.range -1;
creep.moveByPath(creep.memory.path);
}
else
{
switch (creep.memory.lastfind)
{
case 'construction':
var result = creep.build(Game.getObjectById(creep.memory.object));
if(result!=OK)
{
this.getPath(creep);
}
break;
case 'repair':
var result = creep.repair(Game.getObjectById(creep.memory.object));
if(Game.getObjectById(creep.memory.object).hits > Game.getObjectById(creep.memory.object).hitsMax*0.95)
{
this.getPath(creep);
}
if(result!=OK)
{
this.getPath(creep);
}
break;
case 'controller':
var result = creep.upgradeController(creep.room.controller);
if(result!=OK)
{
this.getPath(creep);
}
break;
}
}
}
else {
var source = Game.getObjectById(creep.memory.sourceId);
if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
creep.moveTo(source);
}
}
},
getPath: function (creep) {
creep.memory.moving = true;
result = helper.getTarget(creep, 'construction');
if (result === false) {
result = helper.getTarget(creep, 'repair');
if (result === false) {
result = helper.getTarget(creep, 'controller');
if (result === false) {
console.log('error');
}
}
}
}
};
module.exports = roleHarvester;