-
Notifications
You must be signed in to change notification settings - Fork 7
/
UpgradeCost.ts
27 lines (21 loc) · 851 Bytes
/
UpgradeCost.ts
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
import { JsonReader, JsonObject } from "config_file.js";
import { Material } from "./Material";
import { EnkaClient } from "../../client/EnkaClient";
import { nonNullable } from "../../utils/ts_utils";
export class UpgradeCost {
readonly enka: EnkaClient;
readonly coin: number;
readonly items: { material: Material, count: number }[];
constructor(coinCost: number, costItems: JsonObject[], enka: EnkaClient) {
this.enka = enka;
this.coin = coinCost;
const itemsJson = new JsonReader(costItems);
this.items = itemsJson.mapArray((_, cost) => {
if (!cost.has("id")) return null;
return {
material: Material.getMaterialById(cost.getAsNumber("id"), enka),
count: cost.getAsNumber("count"),
};
}).filter(nonNullable);
}
}