-
Notifications
You must be signed in to change notification settings - Fork 9
/
income-calc.es
228 lines (191 loc) · 6.28 KB
/
income-calc.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
Resource income-related calculations:
- Daihatsu-related landing craft calculation
+ (as of Apr 11, 2022) https://wikiwiki.jp/kancolle/%E8%A3%85%E5%82%99%E6%9C%80%E5%A4%A7%E5%80%A4/%E5%A4%A7%E7%99%BA%E7%B3%BB%E8%A3%85%E5%82%99%E6%97%A9%E8%A6%8B%E8%A1%A8/%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB
+ Reference: (as of Mar 27, 2017)
- wikia: http://kancolle.wikia.com/wiki/Expedition
- wikiwiki: http://wikiwiki.jp/kancolle/?%C6%C3%C2%E7%C8%AF%C6%B0%C4%FA
When there are inconsistencies between two sources (this happens when
there are at least 3 Toku Daihatsus), wikiwiki source takes precedence
as it seems to be more complete than the other
(for the Toku Daihatsu-Normal Daihatsu interaction on caps)
- Consumption regarding marriage
Reference: (as of Mar 27, 2017)
- wikiwiki: http://wikiwiki.jp/kancolle/?%A5%B1%A5%C3%A5%B3%A5%F3%A5%AB%A5%C3%A5%B3%A5%AB%A5%EA
*/
/*
Reference: https://twitter.com/Ex_witch/status/797446805847822341
*/
const computeTokuBonus = (normalCount, tokuCount) => {
if (tokuCount <= 2)
return 0.02 * tokuCount
if (tokuCount === 3) {
return normalCount <= 1 ? 0.05 :
normalCount === 2 ? 0.052 :
/* normalCount > 2 */ 0.054
}
// tokuCount > 3
return normalCount === 0 ? 0.054 :
normalCount === 1 ? 0.056 :
normalCount === 2 ? 0.058 :
normalCount === 3 ? 0.059 :
/* normalCount > 3 */ 0.06
}
/*
Returns a structure:
{ impLvlCount:
improvement level count of daihatsu-class equipments
, dhtCount:
# of daihatsu-type equipments
, normalBonus:
bonus granted by all Daihatsu-type equipments and Kinu K2
without taking into account improvements
referred to as "B_1" by wikia
, normalBonusStar:
bouns granted by improvement levels and normalBonus,
referred to as "B_star" by wikia
, tokuBonus:
extra bonus factor granted by Toku Daihatsus.
referred to as "B_2 + ?" part by wikia
(however this part is computed according to wikiwiki
because which seems to be more accurate)
}
Ref: wikiwiki (see comment in header)
*/
const computeBonus = fleet => {
/*
Basic bonus table
Ref: https://en.kancollewiki.net/Expeditions#Base_Daihatsu_Bonus (as of Jun 20, 2023)
- 大発動艇: 5%
- 特大発動艇: 5%
- 武装大発: 3%
- 大発動艇(八九式中戦車&陸戦隊): 2%
- 装甲艇(AB艇): 2%
- 大発動艇(II号戦車/北アフリカ仕様): 2%
- 特大発動艇+一式砲戦車: 2%
- 特二式内火艇: 1%
Note: DLC bonus seems to be an equipment-specific thing so getting access to
equip type won't help much, instead we just update the lookup table for the time being.
*/
/*
Now count equipments by bonus bucket (variable names should be self-explanatory).
*/
let countBns05 = 0
let countBns03 = 0
let countBns02 = 0
let countBns01 = 0
let tokuCount = 0
/*
Number of special ships (only applicable to Kinu K2 for now)
that grant +5% income (before-cap)
*/
let spShipCount = 0
let impLvlCount = 0
// one pass to count them all!
// um, we could do some "pure functional" stuff
// but I'm sure that'll be awkward.
fleet.map(ship => {
// Kinu K2
if (ship.mstId === 487)
++spShipCount
ship.equips.map(equip => {
if ([
// 大発動艇
68,
// 特大発動艇
193,
].includes(equip.mstId)) {
if (equip.mstId === 193) {
++tokuCount
}
++countBns05
} else if (
// 武装大発
equip.mstId === 409
) {
++countBns03
} else if ([
// 大発動艇(八九式中戦車&陸戦隊)
166,
// 装甲艇(AB艇)
408,
// 大発動艇(II号戦車/北アフリカ仕様)
436,
// 特大発動艇+一式砲戦車
449,
].includes(equip.mstId)) {
++countBns02
} else if (
// 特二式内火艇
equip.mstId === 167
) {
++countBns01
} else {
// early return for equipments whose imp level don't matter.
return
}
impLvlCount += equip.level
})
})
const dhtCount = countBns05 + countBns03 + countBns02 + countBns01
const aveImp = dhtCount === 0 ? 0 : impLvlCount / dhtCount
const b1BeforeCap = (
5 * (countBns05 + spShipCount) +
3 * countBns03 +
2 * countBns02 +
countBns01
) / 100
const b1 = Math.min(0.2, b1BeforeCap)
const bStar = b1 * aveImp / 100
/*
Since countBns05 is just counting 大発動艇 + 特大発動艇, we have enough info to refer to
tokuBonus table.
Ref: https://bbs.nga.cn/read.php?pid=616486588&opt=128
*/
const tokuBonus = computeTokuBonus(countBns05 - tokuCount, tokuCount)
return {
dhtCount,
impLvlCount,
normalBonus: b1,
normalBonusStar: bStar,
tokuBonus,
}
}
// "shipResupplyCost(ship)(fuelCostFactor,ammoCostFactor)" returns a structure:
// { fuelCost: <fuel cost>, ammoCost: <ammo cost> }
// results are guaranteed to be properly rounded given that input does so as well.
const shipResupplyCost = ship => {
// "after marriage modifier":
// - if there's no consumption before marriage, no consumption applied after marriage either.
// - consumption is applied with 0.85 and then floor is taken, with a minimum cost of 1
const applyAfterMarriage =
v => (v === 0) ? 0 : Math.max(1, Math.floor(v*0.85))
const modifier = ship.level >= 100 ? applyAfterMarriage : (x => x)
return (fuelCostFactor, ammoCostFactor) => {
const fuelCost = Math.floor( ship.maxFuel * fuelCostFactor )
const ammoCost = Math.floor( ship.maxAmmo * ammoCostFactor )
return {
fuelCost: modifier(fuelCost),
ammoCost: modifier(ammoCost),
}
}
}
// "fleetResupplyCost(ship)(fuelCostFactor,ammoCostFactor)"
// is the same as "shipResupplyCost"
// but for an array of ship representation
const fleetResupplyCost = fleet => {
const ks = fleet.map( shipResupplyCost )
const mergeCost = (x,y) => ({
fuelCost: x.fuelCost + y.fuelCost,
ammoCost: x.ammoCost + y.ammoCost,
})
return (fFactor,aFactor) =>
ks.map(x => x(fFactor,aFactor))
.reduce(mergeCost, {fuelCost: 0, ammoCost: 0})
}
const daihatsu = { computeBonus }
export {
daihatsu,
shipResupplyCost,
fleetResupplyCost,
}