forked from VladThePaler/screeps.behaviour-action-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creep.action.boosting.js
76 lines (68 loc) · 2.31 KB
/
creep.action.boosting.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
const action = new Creep.Action('boosting');
module.exports = action;
// constructor
action.maxPerAction = 1;
/**
* Check to see if the mineralType has a boost
*/
function isValidMineralType(mineralType) {
for (const category in BOOSTS) {
for (const compound in BOOSTS[category]) {
if (mineralType === compound) return true;
}
}
return false;
}
action.isValidMineralType = isValidMineralType;
/**
* Gets the part type matching the compound's boost
*/
function getBoostPartType(mineralType) {
for (const category in BOOSTS) {
for (const compound in BOOSTS[category]) {
if (mineralType === compound) return category;
}
}
}
action.getBoostPartType = getBoostPartType;
function canBoostType(creep, type) {
return !_(creep.body).filter({type}).every(part => part.boost);
}
action.canBoostType = canBoostType;
function isValidAction(creep) {
// only valid if not every part is boosted
return !_.every(creep.body, part => part.boost);
}
action.isValidAction = isValidAction;
function isValidTarget(target, creep) {
// target is lab
return target instanceof StructureLab &&
// target has the minimum energy and mineral
target.energy >= LAB_BOOST_ENERGY && target.mineralAmount >= LAB_BOOST_MINERAL;
}
action.isValidTarget = isValidTarget;
const super_isAddableTarget = action.isAddableTarget;
function isAddableTarget(target, creep) {
const boostPartType = this.getBoostPartType(target.mineralType);
// mineralType is a boosting compound
return super_isAddableTarget.apply(this, [target, creep]) && this.isValidMineralType(target.mineralType) &&
// creep has active body parts matching the mineralType's boost
creep.hasActiveBodyparts(boostPartType) &&
// can further boost parts of the mineralType's boost
this.canBoostType(creep, boostPartType);
}
action.isAddableTarget = isAddableTarget;
function newTarget(creep) {
return _(creep.room.structures.all)
.filter(this.isValidTarget)
.min(lab => creep.pos.getRangeTo(lab));
}
action.newTarget = newTarget;
function work(creep) {
return creep.target.boostCreep(creep);
}
action.work = work;
function onAssignment(creep) {
if (SAY_ASSIGNMENT) creep.say(ACTION_SAY.BOOSTING, SAY_PUBLIC);
}
action.onAssignment = onAssignment;