-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.js
40 lines (36 loc) · 1.29 KB
/
role.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
let harvester = require("role.harvester");
let archer = require("role.archer");
let builder = require("role.builder");
let warrior = require("role.warrior");
let explorer = require("role.explorer");
let support = require("role.support");
let statusCreep = require("status.creep");
module.exports = {
roleConstants: {
"harvester": harvester,
"archer": archer,
"builder": builder,
"warrior": warrior,
"explorer": explorer,
"support": support
},
/**
*
* @param {Creep} creep
*/
standardAction: function (creep) {
if ((creep.ticksToLive - 10) <= statusCreep.ticksToSpawn(creep)) {
creep.memory.status = "renew";
creep.say("Going to " + creep.memory.status);
creep.moveTo(creep.room.find(FIND_MY_SPAWNS)[0]);
}
if (creep.memory.status === "renew") {
if (creep.transfer(creep.room.find(FIND_MY_SPAWNS)[0], RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.find(FIND_MY_SPAWNS)[0]);
}
}
else if (creep.memory.status === "work" || creep.memory.status === "return") {
this.roleConstants[creep.memory.role].standardAction(creep); //evaluates the role variable to one of the variables above.
}
}
};