// 列传内的条目 import {decodeArrayListStr, parseNumberList, readFileAndParse} from '../util' import { FILENAME } from '../../consts' import { RewardInter } from '../interface'; const _ = require('lodash'); export interface DicAuthorsBookSub { // 列传id readonly bookId: number; // 条目id readonly subId: number; // 星级 readonly star: number; // 星级 readonly maxStar: number; // 所需的英灵 readonly spirits: RewardInter[]; // 每升一颗星可以获得的进度 readonly value: number; // 到这个节点可得的属性 readonly attr: { id: number, val: number }[] } type KeysEnum = { [P in keyof Required]: true }; const DicAuthorsBookSubKeys: KeysEnum = { bookId: true, subId: true, star: true, maxStar: true, spirits: true, value: true, attr: true, } export const dicAuthorsBookSubStar = new Map(); export const dicAuthorsBookSubs = new Map(); export const dicAuthorsBookMaxProgress = new Map(); // bookId => maxProgress export function loadAuthorsBookSub() { dicAuthorsBookSubStar.clear(); dicAuthorsBookSubs.clear(); dicAuthorsBookMaxProgress.clear(); let arr = readFileAndParse(FILENAME.DIC_AUTHORS_BOOK_SUB); arr.forEach(o => { o.attr = parseAttribute(o.attr); o.spirits = parseSpirit(o.goodsId); dicAuthorsBookSubStar.set(`${o.bookId}_${o.subId}_${o.star}`, _.pick(o, Object.keys(DicAuthorsBookSubKeys))); if(!dicAuthorsBookSubs.has(o.bookId)) dicAuthorsBookSubs.set(o.bookId, []); if(dicAuthorsBookSubs.get(o.bookId).indexOf(o.subId) == -1) dicAuthorsBookSubs.get(o.bookId).push(o.subId); if(!dicAuthorsBookMaxProgress.has(o.bookId)) dicAuthorsBookMaxProgress.set(o.bookId, 0); dicAuthorsBookMaxProgress.set(o.bookId, dicAuthorsBookMaxProgress.get(o.bookId) + o.value); }); arr = undefined; } function parseAttribute(str: string) { let result = new Array<{ id: number, val: number }>(); if (!str) return result; let decodeArr = decodeArrayListStr(str); for (let [id, val] of decodeArr) { if (isNaN(parseInt(id)) || isNaN(parseInt(val))) { throw new Error('data table format wrong'); } result.push({ id: parseInt(id), val: parseInt(val) }); } return result } function parseSpirit(str: string): RewardInter[] { let arr = parseNumberList(str); return arr.map(id => ({ id, count: 1 })); }