-
Notifications
You must be signed in to change notification settings - Fork 0
/
attacker_2creep_team.js
72 lines (64 loc) · 3.6 KB
/
attacker_2creep_team.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
const attacker_body = [TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,RANGED_ATTACK,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE];
const healer_body = [TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,TOUGH,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,HEAL,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE,MOVE];
module.exports = {
run: function(spawnRoomName, target, type) {
const creepName_attacker = 'attacker_2creep_' + spawnRoomName;
const creepName_healer = 'healer_2creep_' + spawnRoomName;
var attacker = Game.creeps[creepName_attacker];
var healer = Game.creeps[creepName_healer];
if (!attacker) {autoSpawnCreep(creepName_attacker, spawnRoomName, attacker_body);}
if (!healer) {autoSpawnCreep(creepName_healer, spawnRoomName, healer_body);}
if(attacker && healer){
AutoBoostCreep(attacker);
AutoBoostCreep(healer);
const attacker_hp = attacker.hits;
const healer_hp = healer.hits;
if(attacker_hp < healer_hp) healer.heal(attacker);
else healer.heal(healer);
if(type == 'MOVE') {
if(attacker.pos.getRangeTo(healer) == Infinity){
healer.moveTo(Game.flags[target], {visualizePathStyle: {stroke: '#f6b352', opacity: .5}, bypassHostileCreeps: false});
}
if(attacker.pos.inRangeTo(healer, 1) == true && attacker.fatigue == 0) {
healer.moveTo(Game.flags[target], {visualizePathStyle: {stroke: '#f6b352', opacity: .5}, bypassHostileCreeps: false});
}
attacker.moveTo(healer, {visualizePathStyle: {stroke: '#f6b352', opacity: .5}});
}
if(type == 'ATTACK') {
//var str = attacker.room.lookForAt(LOOK_STRUCTURES, Game.flags[target]);
var hostile = Game.getObjectById('5ef3304c7aae9c06b9b3b883');
if(attacker.rangedAttack(hostile) == ERR_NOT_IN_RANGE) {
if(healer.pos.inRangeTo(attacker, 1) == true && healer.fatigue == 0) {
attacker.moveTo(Game.flags[target], {visualizePathStyle: {stroke: '#f6b352', opacity: .5}, bypassHostileCreeps: false});
}
healer.moveTo(attacker, {visualizePathStyle: {stroke: '#f6b352', opacity: .5}, bypassHostileCreeps: false});
}
}
}
}
};
function autoSpawnCreep(creepName, spawnRoomName, body) {
var spawn = getAvaliableSpawn(spawnRoomName);
if (spawn) {
spawn.spawnCreep(body, creepName, {memory: {role: 'attacker_2creep_team' }});
}
}
function getAvaliableSpawn(room) {
for (var spawnname in Game.spawns) {
var spawn = Game.spawns[spawnname];
if (spawn.room.name == room && spawn.spawning == null) {
return spawn;
}
}
return null;
}
function AutoBoostCreep(creep) {
var labs = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return structure.structureType == STRUCTURE_LAB;
}
});
for (var lab in labs) {
labs[lab].boostCreep(creep);
}
}