-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtower.controller.js
More file actions
77 lines (67 loc) · 3.15 KB
/
Copy pathtower.controller.js
File metadata and controls
77 lines (67 loc) · 3.15 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
/*
The towers will keep a reserve of 300 to only be used if under attack
The towers prioritize walls and ramparts differently than other buildings
NOTES:
- towers will only expand walls if they have 600 energy or more so that they don't let ramparts die
TODO:
- make the towers have different health quotas at different phases
*/
var towerController = {
/** @param {Tower} tower **/
run: function(tower) {
var intruder= tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS,{filter: (c)=> !(_.contains(Memory.allies,c.owner.username))});
if (intruder){
console.log(intruder.owner.username);
console.log(!(_.contains(Memory.allies,intruder.owner.username)));
}
var safeMode= (tower.room.controller.safeMode != undefined);
if(intruder && !safeMode){
console.log("INTRUDER IN "+ tower.room.name+"!!!");
result= tower.attack(intruder);
if (result!= OK){
console.log("tower error: " + result);
}
}
else if( tower.energy >300){
// basically so that the ramparts don't despawn
var lowRampart= tower.pos.findClosestByRange(FIND_STRUCTURES,{
filter: (s)=> (s.hits <1000) && (s.structureType == STRUCTURE_RAMPART)});
var target = tower.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => {
return structure.hitsMax*0.9>=structure.hits &&
(structure.structureType != STRUCTURE_WALL) &&
(structure.structureType != STRUCTURE_CONTROLLER) &&
((structure.structureType != STRUCTURE_RAMPART)|| (structure.hits < 2000)) ;
}
});
var wall = tower.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => {
return structure.hitsMax*0.9>=structure.hits &&
(structure.structureType != STRUCTURE_CONTROLLER) &&
((structure.structureType != STRUCTURE_WALL)|| (structure.hits < 100000)) &&
((structure.structureType != STRUCTURE_RAMPART)|| (structure.hits < 100000)) ;
}
});
if(lowRampart){
result=tower.repair(lowRampart);
if(result != OK){
console.log(result); // no clue when this would happen
}
}
else if(target) {
result=tower.repair(target);
if(result != OK){
console.log(result); // no clue when this would happen
}
}
else if(wall&& tower.energy >600 && Memory[tower.room.name].phase>2){
// don't waste energy on brand new rooms
result=tower.repair(wall);
if(result != OK){
console.log(result);
}
}
}
}
};
module.exports = towerController;