-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap-exp.es
75 lines (63 loc) · 2.09 KB
/
map-exp.es
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
import _ from 'lodash'
import { generalComparator } from 'subtender'
import { readJsonSync } from 'fs-extra'
import { join } from 'path-extra'
import { Ternary, ExpValue, BaseExp, Method } from './structs'
const mapExpTable = readJsonSync(join(__dirname, 'assets', 'map_exp.json'))
const availableMapIds = _.keys(mapExpTable).map(Number).sort(generalComparator)
const getMapExpInfo = mapId => mapExpTable[mapId]
const sortedMapIds =
_.sortBy(_.keys(mapExpTable).map(Number), _.identity)
const expValueFromBaseExp =
BaseExp.toExpValueWithGetter(mapId => getMapExpInfo(mapId).baseExp)
const rankTable = {
S: 1.2,
A: 1.0,
B: 1.0,
C: 0.8,
D: 0.7,
E: 0.5,
}
const computeExp = (base,flagship,mvpFlag,rank) => {
const mvpFactor =
rank === 'E' ? 1 : (mvpFlag ? 2 : 1)
const rankFactor = rankTable[rank]
const flagshipFactor = flagship ? 1.5 : 1
return Math.floor(base * mvpFactor * rankFactor * flagshipFactor)
}
// returns a sorted array of possible exp obtained from the specified leveling method
const computePossibleExps = Method.destruct({
sortie: (flagship,mvp,ranks,baseExp) => {
const flagshipFlags = Ternary.toArray(flagship)
const baseExps = ExpValue.toArray(expValueFromBaseExp(baseExp))
const mvpFlags = Ternary.toArray(mvp)
return _.uniq(
_.flatMap(baseExps, baseExpNum =>
_.flatMap(mvpFlags, mvpFlag =>
_.flatMap(flagshipFlags, flagshipFlag =>
_.flatMap(ranks, rank =>
computeExp(baseExpNum,flagshipFlag,mvpFlag,rank)))))
.sort((x,y) => x-y))
},
custom: exp => ExpValue.toArray(exp),
})
// purge a sorted non-empty array
// - keeps singleton intact
// - if there are more than one value,
// only the first and the last are kept
const purgeNonEmpty = ne => {
if (ne.length === 0)
console.error('expecting non-empty array')
return ne.length === 1 ? ne : [ne[0], ne[ne.length-1]]
}
const computeExpRange = method =>
purgeNonEmpty(computePossibleExps(method))
export {
availableMapIds,
getMapExpInfo,
expValueFromBaseExp,
computeExp,
computePossibleExps,
computeExpRange,
sortedMapIds,
}