-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.creepClasses.js
147 lines (124 loc) · 3.51 KB
/
util.creepClasses.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
* 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('util.creepClasses');
* mod.thing == 'a thing'; // true
*/
let logger = require("screeps.logger");
logger = new logger("util.creepClasses");
//logger.color = COLOR_YELLOW;
//logger.enabled = false;
class baseCreepClass {
constructor() {
this.name = "base"
this.requiredBody = [];
this.extendedBody = [];
this.maxBodies = 50;
this.minBodies = 0;
this.orderWeights = {
HEAL:-1,
MOVE: 0,
CLAIM:1,
CARRY:2,
WORK:3,
RANGED_ATTACK:4,
ATTACK:5,
TOUGH:6
};
}
getBody(maxEnergy) {
var body = global.utils.buildCreepBody(this.requiredBody, this.extendedBody, maxEnergy, this.maxBodies, this.minBodies)
body = this.sortBody(body);
//logger.log(this.roomName, "====",JSON.stringify(body))
return body.reverse();
}
sortBody(body) {
//logger.log(this.roomName, "====", creepData.role,JSON.stringify(body))
var req = this;
body = _.sortBy(body, function(p) {
//logger.log(req.orderWeights[p], p, JSON.stringify(req.orderWeights))
return req.orderWeights[p.toUpperCase()];
})
return body;
}
}
class workerClass extends baseCreepClass {
constructor() {
super();
this.name = "worker";
this.requiredBody = [WORK, CARRY, MOVE, MOVE];
this.extendedBody = [WORK, CARRY, MOVE, MOVE];
}
}
class minerClass extends baseCreepClass {
constructor() {
super();
this.name = "miner";
this.requiredBody = [WORK, WORK, CARRY, MOVE];
this.extendedBody = [WORK, WORK, MOVE];
this.maxBodies = 4;
}
}
class remoteMinerClass extends baseCreepClass {
constructor() {
super();
this.name = "remoteMiner";
this.requiredBody = [WORK, WORK, CARRY, MOVE];
this.extendedBody = [WORK, WORK, MOVE, MOVE];
this.maxBodies = 4;
}
}
class builderClass extends baseCreepClass {
constructor() {
super();
this.name = "builder";
// this.requiredBody = [WORK, WORK, CARRY, MOVE];
// this.extendedBody = [WORK, WORK, CARRY, MOVE];
this.requiredBody = [WORK, CARRY, MOVE];
this.extendedBody = [WORK, CARRY, MOVE];
}
}
class transporterClass extends baseCreepClass {
constructor() {
super();
this.name = "transporter";
this.requiredBody = [CARRY, MOVE, CARRY, MOVE];
this.extendedBody = [CARRY, MOVE];
}
}
class fillerClass extends baseCreepClass {
constructor() {
super();
this.name = "filler";
this.requiredBody = [CARRY, CARRY, MOVE];
this.extendedBody = [CARRY, CARRY, MOVE];
}
}
class claimerClass extends baseCreepClass {
constructor() {
super();
this.name = "claimer";
this.requiredBody = [CLAIM, MOVE];
this.extendedBody = [];
this.maxBodies = 1;
}
}
let classes = [
workerClass,
minerClass,
builderClass,
transporterClass,
remoteMinerClass,
fillerClass,
claimerClass
];
let exp = {};
for(let claz in classes) {
let clazz = classes[claz];
let classObj = new clazz();
logger.log(classObj.name)
exp[classObj.name] = classObj;
}
module.exports = exp;