-
Notifications
You must be signed in to change notification settings - Fork 0
/
squadMedic.js
114 lines (110 loc) · 2.75 KB
/
squadMedic.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
module.exports = function(creep, flag) {
if(flag.color == COLOR_CYAN) {
rally(creep,flag);
}
else if(flag.color == COLOR_RED) {
rally(creep,flag);
}
else if(flag.color == COLOR_YELLOW) {
rally(creep,flag);
}
else if(flag.color == COLOR_GREY) {
if(creep.room != flag.room) {
creep.moveTo(flag);
}
else {
creep.moveTo(flag.room.controller);
creep.claimController(flag.room.controller);
}
}
else if(flag.color == COLOR_WHITE) {
holdPosition(creep,flag);
}
else if(flag.color == COLOR_BLUE) {
rally(creep,flag);
}
};
function holdPosition(creep,flag) {
var order = flag.name.split('-')[1];
var x = flag.pos.x;
var y = flag.pos.y;
if(creep.room != flag.room){
creep.moveTo(flag);
return;
}
if(order == "Top"){
y +=1
while(flag.room.lookForAt('creep',x,y) != undefined && flag.room.lookForAt('creep',x,y) != creep) {
x++;
}
}
else if(order == "Bottom") {
y += 1;
while(flag.room.lookForAt('creep',x,y) != undefined && flag.room.lookForAt('creep',x,y) != creep) {
x++;
}
}
else if(order == "Left") {
x += 1;
while(flag.room.lookForAt('creep',x,y) != undefined && flag.room.lookForAt('creep',x,y) != creep) {
y++;
}
}
else if(order == "Right"){
x +=1;
while(flag.room.lookForAt('creep',x,y) != undefined && flag.room.lookForAt('creep',x,y) != creep) {
y++;
}
}
if(creep.pos.x == x && creep.pos.y == y) {
var target = creep.pos.findClosest(FIND_MY_CREEPS, {filter:function(object) {
if(object.memory.squad == creep.memory.squad && object.hits < object.hitsMax && object != creep) {
creep.memory.target = object;
return object;
}
}});
if(target != undefined && target != null) {
if(creep.pos.isNearTo(target)) {
creep.heal(target);
}
else {
creep.rangedHeal(target);
}
}
}
else {
creep.moveTo(x,y);
}
}
function rally(creep,flag) {
var target = creep.pos.findClosest(FIND_MY_CREEPS, {filter:function(object) {
if((object.memory.squad == creep.memory.squad || object.owner.username == 'hesto2') && object.hits < object.hitsMax && object != creep && object.memory.task != 'medic') {
creep.memory.target = object;
return object;
}
}});
if(target == undefined || creep.memory.target == "none") {
target = creep.pos.findClosest(FIND_MY_CREEPS, {filter:function(object) {
if(object.hits < object.hitsMax && object != creep) {
creep.memory.target = object;
return object;
}
}});
}
if(target == undefined || creep.memory.target == "none") {
if(creep.pos.inRangeTo(flag,3) == false) {
creep.moveTo(flag, {reusePath:20});
}
creep.memory.target = "none";
if(creep.hits < creep.hitsMax)creep.heal(creep)
}
else {
creep.moveTo(target);
if(creep.pos.isNearTo(target)) {
creep.heal(target);
}
else {
creep.rangedHeal(target);
}
}
}