-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.soldier.js
More file actions
55 lines (48 loc) · 1.91 KB
/
Copy pathrole.soldier.js
File metadata and controls
55 lines (48 loc) · 1.91 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
var roleSoldier = {
/** @param {Creep} creep **/
run: function(creep) {
var attackFlag = Game.flags['AttackFlag'];
var healFlag = Game.flags['HealFlag'];
var spawn = creep.pos.findClosestByRange(FIND_MY_SPAWNS);
if(creep.ticksToLive < 100){
if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE){
creep.moveTo(spawn, {visualizePathStyle: {stroke: '#ff0000'}});
}
creep.memory.dying = true;
}
if(creep.memory.attacking && creep.hits < creep.hitsMax){ // 受伤状态
creep.memory.attacking = false;
creep.say('🔄 heal');
}
if(!creep.memory.attacking && creep.hits == creep.hitsMax){ // 非受伤状态
creep.memory.attacking = true;
creep.say('🔫 attack');
}
if(creep.memory.attacking) { // 攻击状态
var target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(target) {
if(creep.attack(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#ff0000'}});
}
}
else{
if(creep.ticksToLive > 1000){
creep.memory.dying = false;
creep.moveTo(attackFlag, {visualizePathStyle: {stroke: '#ff0000'}});
}
else if(creep.memory.dying){
if(spawn.renewCreep(creep) == ERR_NOT_IN_RANGE){
creep.moveTo(spawn, {visualizePathStyle: {stroke: '#ff0000'}});
}
}
else{
creep.moveTo(attackFlag, {visualizePathStyle: {stroke: '#ff0000'}});
}
}
}
else { // 非攻击状态
creep.moveTo(healFlag, {visualizePathStyle: {stroke: '#00ff00'}});
}
}
};
module.exports = roleSoldier;