-
Notifications
You must be signed in to change notification settings - Fork 3
/
proto.Creep.js
156 lines (136 loc) · 4.37 KB
/
proto.Creep.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
/**
* добыча энергии
* @returns {boolean}
*/
Creep.prototype.mineEnergy = function () {
let source;
this.memory.action='mine Energy';
if(this.memory.resID){
source = this.pos.findClosestByPath(FIND_SOURCES_ACTIVE,{filter: s => s.id === this.memory.resID});
}
if(!source){
if(this.memory.badResID){
source = this.pos.findClosestByPath(FIND_SOURCES_ACTIVE,{filter: s => s.id !== this.memory.badResID});
}
if(!source){
source = this.pos.findClosestByPath(FIND_SOURCES_ACTIVE);
}
}
/*if(!source && this.memFlags.length>0){
if(this.moveTo(Game.flags[this.memFlags[0]]) === OK){
this.say('traveling');
source = this.pos.findClosestByPath(FIND_SOURCES_ACTIVE);
}
return false;
}*/
let actResult = this.harvest(source);
if ( actResult === ERR_NOT_IN_RANGE) {
this.moveTo(source);
}
else if(actResult === OK){
delete this.memory.badResID;
this.memory.resID = source.id;
}
else if (actResult === ERR_NOT_ENOUGH_RESOURCES
//|| actResult === ERR_INVALID_TARGET
|| actResult === ERR_NOT_OWNER){
this.memory.badResID = this.memory.resID;
delete this.memory.resID;
}
return this.carry.energy === this.carryCapacity;
};
/**
* абгрейд контроллера
* @returns {boolean}
*/
Creep.prototype.doUpgrade = function () {
if(this.carry.energy === 0){
return false;
}
this.memory.action='upgrading...';
if(this.upgradeController(this.room.controller) === ERR_NOT_IN_RANGE) {
this.moveTo(this.room.controller);
}
return true;
};
/**
* Починка
* @returns {boolean}
*/
Creep.prototype.doRepair = function(){
let targets = [];
if(this.memory.repObj !== undefined && Game.getObjectById(this.memory.repObj).hits <= (Game.getObjectById(this.memory.repObj).hitsMax/1.5)){
targets[0] = Game.getObjectById(this.memory.repObj);
delete this.memory.repObj;
}
if(targets.length<1){
targets = this.room.find(FIND_STRUCTURES, {
filter: object =>
object.structureType !== STRUCTURE_WALL
&& object.structureType !== STRUCTURE_RAMPART
&& object.hits < (object.hitsMax/2)
});
targets.sort((a,b) => a.hits - b.hits);
}
if (targets.length > 0) {
this.memory.action = 'repair';
this.memory.repObj = targets[0].id;
if (this.repair(targets[0]) === ERR_NOT_IN_RANGE) {
this.moveTo(targets[0]);
}
if (targets[0].hits > (targets[0].hitsMax / 2)) {
delete this.memory.repObj;
}
return true;
}
this.memory.action = '?';
return false;
};
/**
* Чинить стены и рампарты
* @returns {boolean}
*/
Creep.prototype.doWallsRampartsRepair = function(){
let targets = [];
if(this.memory.wallID && Game.getObjectById(this.memory.wallID).hits < Game.getObjectById(this.memory.wallID).hitsMax/2){
targets[0] = Game.getObjectById(this.memory.wallID);
}
else{
targets = this.room.find(FIND_STRUCTURES, {
filter: object => (object.structureType === STRUCTURE_RAMPART || object.structureType === STRUCTURE_WALL) && object.hits < (object.hitsMax/2)
});
targets.sort((a,b) => a.hits - b.hits);
}
if(targets.length>0) {
let actResult = this.repair(targets[0]);
if (actResult === ERR_NOT_IN_RANGE) {
this.moveTo(targets[0]);
}
else if(actResult === OK){
this.memory.wallID = targets[0].id;
}
this.memory.action = 'Wall repair';
return true;
}
return false;
};
/**
* Строительство
* @returns {boolean}
*/
Creep.prototype.doBuild = function () {
const target = this.pos.findClosestByRange(FIND_CONSTRUCTION_SITES);
if (target) {
if (this.build(target) === ERR_NOT_IN_RANGE) {
this.moveTo(target);
}
this.memory.action = 'build';
return true;
}
return false;
};
/**
* Массив с комнатами для добычи ресов и лимитами
* @type {Array}
*/
Creep.prototype.resourseRooms = [];