-
Notifications
You must be signed in to change notification settings - Fork 0
/
pr.role.claimer.js
77 lines (67 loc) · 2.02 KB
/
pr.role.claimer.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Module code goes here. Use 'module.exports' to export things:
* module.exports.thing = 'a thing';
*
* You can import it from another modules like this:
* var mod = require('pr.role.claimer');
* mod.thing == 'a thing'; // true
*/
var logger = require("screeps.logger");
logger = new logger("pr.role.filler");
let processClass = require("INeRT.process");
let threadClass = require("INeRT.thread");
let baseRole = require("pr.role.base");
class claimer extends baseRole {
init() {
super.init();
this.enabledEnergyTasks = [
];
this.enabledWorkTasks = [
];
this.creepClass = "claimer";
this.creepRole = "claimer";
this.spawnPriority = 3;
this.requiredParts = {
CLAIM:1
};
this.totalNeededParts = 1;
this.totalParts = 0;
}
initThreads() {
return [
this.createThread("initTick", "init"),
this.createThread("run", "creepAct"),
];
}
initTick() {
super.initTick();
this.requiredParts = {
CLAIM:1
};
}
run() {
logger.log("running claim creeps")
//handle working flag and refil task
for(let c in this.creeps) {
let creep = this.creeps[c];
if (creep.spawning)
return;
let flag = Game.flags[this.data.flagName];
if (!flag) {
//flag is gone, die
return threadClass.DONE;
}
logger.log(creep.name, "movin to", flag);
let moveRes = global.creepActions.moveTo(creep, flag);
logger.log(creep.name, "move res", moveRes);
if (moveRes) {
let claimRes = creep.claimController(creep.room.controller);
logger.log(creep.name, "claim res", claimRes);
flag.remove();
return threadClass.DONE;
}
}
this.handleSpawning();
}
}
module.exports = claimer;