-
Notifications
You must be signed in to change notification settings - Fork 3
/
proto.Tower.js
82 lines (74 loc) · 3 KB
/
proto.Tower.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
/**
* найден вражеский крип, атака
* @returns {boolean}
*/
StructureTower.prototype.defend = function () {
let startCpu = Game.cpu.getUsed();
let elapsed;
let target = this.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
//this.pos.findClosestByRange(FIND_CREEPS, {filter: creep => creep.owner.username !== this.owner.username});
if (target){
this.attack(target);
if( Memory.noticeSettings && Memory.noticeSettings['noticeTowerAttack'] === true) {
console.log('[tower]-> room [' + this.room.name + '], found enemy');
}
elapsed = Game.cpu.getUsed() - startCpu;
if(elapsed > 1.9){
console.log('[CPU]-> tower.attack cpu usage:'+elapsed);
}
return true;
}
if( Memory.noticeSettings && Memory.noticeSettings['noticeCPU'] && Memory.noticeSettings['noticeCPULevel']) {
elapsed = Game.cpu.getUsed() - startCpu;
if (elapsed > Memory.noticeSettings['noticeCPULevel']) {
console.log('[CPU]-> tower.attack cpu usage:' + elapsed);
}
}
return false;
};
/**
* найдено здание, требующее починки (меньше половины hits)
* @returns {boolean}
*/
StructureTower.prototype.doRepair = function () {
let startCpu = Game.cpu.getUsed();
let elapsed;
let closestDamagedStructure;
if(Memory.repair === undefined){
Memory.repair = {};
}
if(Memory.repair !== undefined && Memory.repair[this.room.name]!== undefined){
closestDamagedStructure = Game.getObjectById(Memory.repair[this.room.name]);
if(closestDamagedStructure.hits > (closestDamagedStructure.hitsMax / 2)){
closestDamagedStructure = undefined;
delete Memory.repair[this.room.name];
}
}
if(!closestDamagedStructure){
closestDamagedStructure = this.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) =>
structure.structureType !== STRUCTURE_WALL
&& structure.structureType !== STRUCTURE_RAMPART
&& structure.structureType !== STRUCTURE_ROAD
&& structure.hits < (structure.hitsMax / 2)
});
}
if (closestDamagedStructure) {
Memory.repair[this.room.name] = closestDamagedStructure.id;
this.repair(closestDamagedStructure);
elapsed = Game.cpu.getUsed() - startCpu;
if( Memory.noticeSettings && Memory.noticeSettings['noticeCPU'] && Memory.noticeSettings['noticeCPULevel']) {
if (elapsed > Memory.noticeSettings['noticeCPULevel']) {
console.log('[CPU]-> tower.repair cpu usage:' + elapsed);
}
}
return true;
}
elapsed = Game.cpu.getUsed() - startCpu;
if( Memory.noticeSettings && Memory.noticeSettings['noticeCPU'] && Memory.noticeSettings['noticeCPULevel']){
if(elapsed > Memory.noticeSettings['noticeCPULevel']){
console.log('[CPU]-> tower.repair cpu usage:'+elapsed);
}
}
return false;
};