-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.get.js
56 lines (51 loc) · 1.53 KB
/
task.get.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
/*
creep.memory.task ={
type = "get",
target = {
id,
pos={
room,
x,
y
}
}
}
*/
let Export = {
run: function (creep) {
/*task dependance*/
if (creep.store.getFreeCapacity() == 0) {
delete creep.memory.task;
return;
}
/*task dependance*/
if (creep.room.name == creep.memory.task.target.pos.room) {
let target = Game.getObjectById(creep.memory.task.target.id);
if (target == null) {
delete creep.memory.task;
return;
}
/* task main */
if (Math.abs(creep.pos.x - target.pos.x) <= 1 && Math.abs(creep.pos.y - target.pos.y) <= 1) {
if (target.structureType || "deathTime" in target) {
if (creep.withdraw(target, RESOURCE_ENERGY) != OK) {
delete creep.memory.task;
}
} else {
if (creep.harvest(target) != OK) {
delete creep.memory.task;
}
}
} else {
if (creep.moveTo(target) == ERR_NO_PATH) {
delete creep.memory.task;
}
}
/* task main */
} else {
let target = new RoomPosition(creep.memory.task.target.pos.x, creep.memory.task.target.pos.y, creep.memory.task.target.pos.room);
creep.moveTo(target);
}
}
}
module.exports = Export;