-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.structure.js
78 lines (71 loc) · 2.37 KB
/
handler.structure.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
// Export module
module.exports =
{
/*
* Perform Structure Actions
* Perform actions for each structure
*/
performStructureActions: function()
{
// Towers
var towers = Game.rooms.E11N58.find(FIND_STRUCTURES, {
filter: (s) => s.structureType == STRUCTURE_TOWER
});
for (let tower of towers)
{
var hostileTarget = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
var structsToRepair = Game.spawns['Spawn_1'].room.find(FIND_STRUCTURES, {
filter: (s) => (s.hits < (s.hitsMax * 0.7)) && (s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_EXTENSION || s.structureType == STRUCTURE_STORAGE)
});
var wallsToRepair = Game.spawns['Spawn_1'].room.find(FIND_STRUCTURES, {
filter: (s) => (s.hits < 5000) && (s.structureType == STRUCTURE_WALL)
});
var rampartsToRepair = Game.spawns['Spawn_1'].room.find(FIND_STRUCTURES, {
filter: (s) => (s.hits < 10000) && (s.structureType == STRUCTURE_RAMPART)
});
var roadsToRepair = Game.spawns['Spawn_1'].room.find(FIND_STRUCTURES, {
filter: (s) => (s.hits < 2000) && (s.structureType == STRUCTURE_ROAD)
});
// Perform tower actions
if (hostileTarget) {
tower.attack(hostileTarget);
}
else if (structsToRepair[0]) {
tower.repair(structsToRepair[0]);
}
else if (wallsToRepair[0]) {
tower.repair(wallsToRepair[0]);
}
else if (rampartsToRepair[0]) {
tower.repair(rampartsToRepair[0]);
}
else if (roadsToRepair[0]) {
tower.repair(roadsToRepair[0]);
}
}
var mainRoom = Game.spawns['Spawn_1'].room;
// Enemies in room?
var enemiesInRoom = mainRoom.find(FIND_HOSTILE_CREEPS, {
filter: (c) => c.body.includes(ATTACK) || c.body.includes(RANGED_ATTACK)
});
// Being attacked?
if (enemiesInRoom[0])
{
// Get room controller
var roomController = mainRoom.find(FIND_STRUCTURES, {
filter: (s) => s.structureType == STRUCTURE_CONTROLLER
});
// Get first element of array
roomController = roomController[0];
// Has safemode available?
if (roomController.safeModeAvailable)
{
// Already have safemode active?
if (roomController.safeMode > 0)
{
roomController.activateSafeMode();
}
}
}
}
};