-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtutorial.js
More file actions
90 lines (77 loc) · 3.05 KB
/
tutorial.js
File metadata and controls
90 lines (77 loc) · 3.05 KB
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
'use strict';
const { createSystem, taskFunctions } = require('@node-sc2/core');
const { Alliance } = require('@node-sc2/core/constants/enums');
const { CHARGE } = require('@node-sc2/core/constants/upgrade');
const { combatTypes } = require('@node-sc2/core/constants/groups');
const {
ASSIMILATOR,
CYBERNETICSCORE,
GATEWAY,
NEXUS,
TWILIGHTCOUNCIL,
ZEALOT,
} = require('@node-sc2/core/constants/unit-type');
const { build, upgrade } = taskFunctions;
const eightGateAllIn = createSystem({
name: 'EightGateAllIn',
type: 'build',
defaultOptions: {
state: { armySize: 12 },
},
buildOrder: [
[16, build(ASSIMILATOR)],
[17, build(GATEWAY)],
[20, build(NEXUS)],
[21, build(CYBERNETICSCORE)],
[26, build(TWILIGHTCOUNCIL)],
[34, upgrade(CHARGE)],
[34, build(GATEWAY, 7)],
],
async onStep({ resources }) {
const { units, map, actions, debug } = resources.get();
if (this.state.buildComplete) {
const idleCombatUnits = units.getCombatUnits().filter(u => u.noQueue);
if (idleCombatUnits.length > this.state.armySize) {
this.setState({ armySize: this.state.armySize + 2 });
const [enemyMain, enemyNat] = map.getExpansions(Alliance.ENEMY);
return Promise.all([enemyNat, enemyMain].map((expansion) => {
return actions.attackMove(idleCombatUnits, expansion.townhallPosition, true);
}));
}
}
const idleGateways = units.getById(GATEWAY, { noQueue: true, buildProgress: 1 });
if (idleGateways.length > 0) {
return Promise.all(idleGateways.map(gateway => actions.train(ZEALOT, gateway)));
}
},
async buildComplete() {
this.setState({ buildComplete: true });
},
async onUpgradeComplete({ resources }, upgrade) {
if (upgrade === CHARGE) {
const { units, map, actions } = resources.get();
const combatUnits = units.getCombatUnits();
const [enemyMain, enemyNat] = map.getExpansions(Alliance.ENEMY);
return Promise.all([enemyNat, enemyMain].map((expansion) => {
return actions.attackMove(combatUnits, expansion.townhallPosition, true);
}));
}
},
async onUnitFinished({ resources }, newBuilding) {
if (newBuilding.isGasMine()) {
const { units, actions } = resources.get();
const threeWorkers = units.getClosest(newBuilding.pos, units.getMineralWorkers(), 3);
threeWorkers.forEach(worker => worker.labels.set('gasWorker', true));
return actions.mine(threeWorkers, newBuilding);
}
},
async onUnitCreated({ resources }, newUnit) {
const { actions, map } = resources.get();
if (newUnit.isWorker()) {
return actions.gather(newUnit);
} else if (combatTypes.includes(newUnit.unitType)) {
return actions.attackMove([newUnit], map.getCombatRally());
}
},
});
module.exports = eightGateAllIn;