-
Notifications
You must be signed in to change notification settings - Fork 0
/
find-teleport-delay.js
93 lines (86 loc) · 2.52 KB
/
find-teleport-delay.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
const fs = require('fs');
const SparkSim = require('./src/bf-spark-sim');
const unitData = JSON.parse(fs.readFileSync('./tests/info-gl.json', 'utf8'));
const sparkSim = new SparkSim({
getUnit: id => unitData[id],
teleporterData: {},
});
let lastPercent;
sparkSim.onProgress(progress => {
const currentPercent = Math.floor(progress.percentComplete);
if (currentPercent !== lastPercent) {
console.log(progress.message);
lastPercent = currentPercent;
}
});
// eslint-disable-next-line no-unused-vars
async function main() {
// otherUnits and teleportingUnit should be as specific as possible
// in order to speed up the calculation time for one delay
const otherUnits = [{
"id": "E",
"position": "top-left",
"type": "",
},
{
"id": "E",
"position": "top-right",
"type": "",
},
{
"id": "10295",
"position": "middle-left",
"type": "",
"bbOrder": 1,
},
{
"id": "E",
"position": "middle-right",
"type": "",
},
{
"id": "X",
"position": "bottom-left",
"type": "",
"bbOrder": 2,
}
];
const teleportingUnit = {
"id": "850568",
"position": "bottom-right",
"type": "sbb",
"bbOrder": 3,
};
let currentDelay = 0;
const targetSparks = 24;
const delays = [];
while (currentDelay <= 5000) {
console.log('testing delay', currentDelay);
teleportingUnit.delay = currentDelay++;
delete teleportingUnit.unitData;
delete teleportingUnit.battleFrames;
const result = await sparkSim.run(otherUnits.concat([teleportingUnit,]), { sortResults: true, threshold: 0.01, });
if (result.length === 0) {
continue;
}
const resultTeleporter = result[0].squad.filter(unit => unit.delay !== undefined);
// if (resultTeleporter[0].actualSparks > 0) console.log(resultTeleporter);
console.log(resultTeleporter);
if (resultTeleporter[0].actualSparks === targetSparks) {
delays.push(result[0]);
}
}
fs.writeFileSync('output.json', JSON.stringify(delays, null, 2), 'utf8');
console.log('Done');
}
// eslint-disable-next-line no-unused-vars
function getTeleporterUnits() {
const teleportingUnits = Object.values(unitData)
// only get OE teleporting units
.filter(unit => +unit.movement.skill['move type'] === 2 && +unit.rarity === 8)
.map(({id, name, }) => ({ id, name, }));
fs.writeFileSync('teleporters.json', JSON.stringify(teleportingUnits, null, 2), 'utf8');
console.log('Done getting teleporting units');
}
// getTeleporterUnits();
main();