-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreep.common.js
More file actions
74 lines (65 loc) · 2.27 KB
/
Copy pathcreep.common.js
File metadata and controls
74 lines (65 loc) · 2.27 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var util = require('util');
var creepCommon = {
// 定义若干常用的方法
waitGotoPark: (creep) => {
creep.moveTo(util.parkPosition(), { range: 1 });
},
waitGotoPark2: () => (creep) => {
if (creep.room == util.myRoom()) {
creep.moveTo(util.parkPosition(), { range: 1 });
} else {
creep.moveTo(util.parkPosition2(), { range: 1 });
}
},
prepareGotoPosition: (creep, pos) => {
if (!creep.pos.isEqualTo(pos)) {
creep.moveTo(pos, {visualizePathStyle: {stroke: '#ffaa00'}});
return false;
}
return true;
},
prepareGotoPosition2: (posXY) => (creep) => {
const pos = creep.room.getPositionAt(...posXY);
if (!creep.pos.isEqualTo(pos)) {
creep.moveTo(pos, {visualizePathStyle: {stroke: '#ffaa00'}});
return false;
}
return true;
},
prepareGotoObject: (id) => (creep) => {
const obj = Game.getObjectById(id);
if (!creep.pos.inRangeTo(obj.pos, 0)) {
creep.moveTo(obj, {visualizePathStyle: {stroke: '#ffaa00'}});
return false;
}
return true;
},
prepareGotoObjectInRange: (id, range) => (creep) => {
const obj = Game.getObjectById(id);
if (!creep.pos.inRangeTo(obj.pos, range)) {
creep.moveTo(obj, {visualizePathStyle: {stroke: '#ffaa00', range: range}});
return false;
}
return true;
},
sourceById: sourceId => creep => {
const source = Game.getObjectById(sourceId);
const type = util.getObjectType(source);
if (creep.store.getUsedCapacity() == creep.store.getCapacity() ||
(type == 'source' && source.energy == 0) ||
(type.indexOf('storage') != -1 && source.store[RESOURCE_ENERGY] <= util.constant.storage_safe_energy)) {
return true;
}
if (creep.pos.inRangeTo(source, 1)) {
if (type != 'source') {
creep.withdraw(source, RESOURCE_ENERGY);
} else {
creep.harvest(source);
}
} else {
creep.moveTo(source, {visualizePathStyle: {stroke: '#ffaa00', range: 1}});
}
return false;
},
};
module.exports = creepCommon;