-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmount.creep.js
More file actions
57 lines (54 loc) · 2.01 KB
/
Copy pathmount.creep.js
File metadata and controls
57 lines (54 loc) · 2.01 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
56
57
const roles = {
carrier: require('role.carrier'),
carrierCenter: require('role.carrierCenter'),
digger: require('role.digger'),
diggerLink: require('role.diggerLink'),
recycler: require('role.recycler'),
upgrader: require('role.upgrader2'), // CAUTION
worker: require('role.worker'),
miner: require('role.miner'),
claimer: require('role.claimer'),
reserver: require('role.reserver'),
basic_upgrader: require('role.basic_upgrader'),
basic_harvester: require('role.basic_harvester'),
outer_harvester: require('role.outer_harvester'),
};
Creep.prototype.work = function() {
const creepConfig = creepApi.get(this.memory.configName);
// 检查 creep 内存中的配置是否存在
if (!creepConfig) {
console.log(`creep ${this.name} 携带了一个无效的配置项 ${this.memory.configName}`);
// this.say('找不到配置!');
return;
}
const creepLogic = roles[creepConfig.role](creepConfig.args);
if (!this.memory.ready) {
// 有准备阶段配置则执行
// 没有就直接准备完成
if (creepLogic.prepare) {
this.memory.ready = creepLogic.prepare(this);
} else {
this.memory.ready = true;
}
return;
}
var stateChange = true, wait = false;
// 执行对应阶段
// 阶段执行结果返回 true 就说明需要更换 working 状态
// 要求 source, target 返回 true 时不改变游戏状态(在开始阶段判定)
if (this.memory.working) {
if (creepLogic.target) stateChange = creepLogic.target(this);
if (stateChange) wait = creepLogic.source(this);
} else {
if (creepLogic.source) stateChange = creepLogic.source(this);
if (stateChange) wait = creepLogic.target(this);
}
// 状态变化了就切换工作阶段
if (wait) {
stateChange = false;
if (creepLogic.wait) creepLogic.wait(this);
}
if (stateChange) {
this.memory.working = !this.memory.working;
}
};