-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRole_Guard.js
49 lines (48 loc) · 1.79 KB
/
Role_Guard.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
const logger = require('utils.log').getLogger("Guard");
module.exports = ({
//战备状态
source: creep => {
const roomName = creep.getTemplateConfig("roomName")
//如果没有回到出生房间
if (creep.room.name != roomName) {
creep.moveTo(new RoomPosition(25, 25, roomName));
} else {
creep.selfFix();
}
},
//战时状态
target: creep => {
const targetRoomName = creep.memory.TargetRoom;
// 如果没有抵达目标房间
if (creep.room.name != targetRoomName) {
creep.moveTo(new RoomPosition(25, 25, targetRoomName));
} else {
let target = creep.pos.findClosestByRange(FIND_HOSTILE_STRUCTURES);
if (!target) {
target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
}
if (target) {
logger.info(`[${creep.name}]:骑兵连,进攻!!!`)
if (creep.attack(target) === ERR_NOT_IN_RANGE) {
creep.say("🗡️")
creep.moveTo(target);
}
} else {
logger.debug(creep.name + ":目标房间[" + creep.room.name + "]已肃清!");
creep.memory.Target = "No";
}
}
},
// 状态切换条件
switch: creep => {
//没有发现守卫房间有入侵出现,进入战备状态
if ((!creep.memory.Target || creep.memory.Target === "No") && creep.memory.working) {
creep.memory.working = false
}
//发现有入侵出现,进入战时状态
if ((creep.memory.Target && creep.memory.Target === "Yes") && !creep.memory.working) {
creep.memory.working = true
}
return creep.memory.working
}
})