-
Notifications
You must be signed in to change notification settings - Fork 0
/
prototype.tower.js
70 lines (55 loc) · 2.07 KB
/
prototype.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
module.exports = function() {
StructureTower.prototype.run = function() {
var closestHostile = this.pos.findClosestByRange(FIND_HOSTILE_CREEPS,
{filter: (c) => Memory.rooms[this.room.name].tripwireTriggered == true
|| c.owner.username != 'jueyanyingyu'});
if(closestHostile) {
this.attack(closestHostile);
} else {
var damagedStructures = this.room.find(FIND_STRUCTURES, {
filter: (s) => (s.structureType == STRUCTURE_WALL && s.hits < 1000000)
|| (s.structureType == STRUCTURE_RAMPART && s.hits < 1770000)
|| (s.structureType != STRUCTURE_WALL && s.structureType != STRUCTURE_RAMPART && s.hits < s.hitsMax)
});
if(damagedStructures) {
damagedStructures.sort(function (a, b) {
if (a.hits < b.hits) {
return -1;
}
if (b.hits < a.hits) {
return 1;
}
return 0;
});
this.repair(damagedStructures[0]);
}
}
if(this.energy <= 800){
if(Memory.towers == undefined){
Memory.towers = {};
}
if(Memory.towers[this.id] == undefined){
Memory.towers[this.id] = {};
}
Memory.towers[this.id].needsFillUp = true;
}else if(this.energy == 1000){
if(Memory.towers == undefined){
Memory.towers = {};
}
if(Memory.towers[this.id] == undefined){
Memory.towers[this.id] = {};
}
Memory.towers[this.id].needsFillUp = false;
}
};
StructureTower.prototype.needsFillUp = function(){
if(Memory.towers == undefined){
Memory.towers = {};
}
if(Memory.towers[this.id].needsFillUp){
return true;
}else{
return false;
}
};
};