-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpatch.creep.js
35 lines (30 loc) · 1.23 KB
/
patch.creep.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
const CreepMover = require("creepmover");
const PathBuilder = require("pathbuilder");
const ff = require("helper.friendFoeRecognition");
Creep.prototype.goTo = function(target, options) {
// TODO: stop using anything else than newPathing
if(!options || options.newPathing !== false) {
let mover = new CreepMover(this, target, options);
return mover.move();
}
let builder = new PathBuilder();
options = options || {}
if(options.avoidHostiles) {
builder.avoidHostiles = true;
if(_.some(ff.findHostiles(this.room), (c) => _.some(c.parts, (p) => p.type === ATTACK || p.type === RANGED_ATTACK))) {
options.reusePath = 0;
}
}
options.costCallback = builder.getAdditiveCallback();
return this.moveTo(target, options);
}
Creep.prototype.fleeFrom = function(hostiles, range) {
if(!Array.isArray(hostiles)) hostiles = [hostiles];
hostiles = _.map(hostiles, (h) => ({ pos: h.pos, range: range }));
let result = PathFinder.search(this.pos, hostiles, { flee: true });
return this.moveByPath(result.path);
}
Creep.prototype.canAttack = function() {
return _.some(this.body, (p) => p.type === ATTACK || p.type === RANGED_ATTACK);
}
Creep.prototype.isCreep = true;