Skip to content

Commit b2cd1e8

Browse files
committed
WIP: best-bond-farm script
1 parent e83ef33 commit b2cd1e8

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

src/best-bond-farm/script.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { parseArgs } from "util";
2+
import { freeQuestsCache, warsCache } from "~/cache";
3+
import { listToMap } from "~/utils/listToMap";
4+
import { log, logger, timer } from "~/utils/logger";
5+
6+
const getTime = timer();
7+
const { values: args } = parseArgs({
8+
args: process.argv.slice(2),
9+
options: {
10+
verbose: { type: "boolean", short: "v", default: false },
11+
top: { type: "string", short: "t", default: "5" }
12+
}
13+
});
14+
15+
const evalFreeQuest = (() => {
16+
const cache = new Map<FreeQuest, number>();
17+
return function evalFreeQuest(freeQuest: FreeQuest) {
18+
const cached = cache.get(freeQuest);
19+
if (cached) return cached;
20+
21+
// BUG: Atlas API seems to be giving the incorrect value for freeQuest.bond
22+
const res = freeQuest.bond / freeQuest.apCost;
23+
cache.set(freeQuest, res);
24+
return res;
25+
};
26+
})();
27+
28+
async function main() {
29+
// DEBUG
30+
if (args.verbose) logger.setLogLevel("Debug");
31+
log.debug(args);
32+
33+
// parse arg
34+
let bestN = args.top ? parseInt(args.top) : 5;
35+
if (isNaN(bestN) || bestN < 1) {
36+
log.error(
37+
`Could not parse argument for --top '${args.top}'. Argument must integer > 0`
38+
);
39+
log.warn("Using '5' as fallback value for --top");
40+
bestN = 5;
41+
}
42+
43+
// get data
44+
const [freeQuestList, warsList] = await Promise.all([
45+
freeQuestsCache.read(),
46+
warsCache.read()
47+
]);
48+
const warsMap = listToMap(warsList);
49+
50+
// sort
51+
const sortedList = freeQuestList.toSorted((a, b) => {
52+
return evalFreeQuest(b) - evalFreeQuest(a);
53+
});
54+
55+
// TEMP
56+
console.table(
57+
sortedList.slice(0, bestN).map(fq => ({
58+
id: fq.id,
59+
eval: Math.round(evalFreeQuest(fq)),
60+
name: fq.name,
61+
war: warsMap[fq.war].longName
62+
}))
63+
);
64+
}
65+
66+
main()
67+
.then(() => log.success(`Completed in ${getTime()}`))
68+
.catch(e => log.fatal(e));

0 commit comments

Comments
 (0)