67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
// 武将表
|
|
|
|
import { ABI_TYPE, FILENAME } from '../../consts'
|
|
import { readJsonFile } from '../util'
|
|
const _ = require('lodash');
|
|
|
|
export interface DicHero {
|
|
// 武将id
|
|
readonly heroId: number;
|
|
// 武将名
|
|
readonly name: string;
|
|
// 初始品质
|
|
readonly quality: number;
|
|
// 阵营
|
|
readonly camp: number;
|
|
// 兵种
|
|
readonly jobid: number;
|
|
// 技能
|
|
readonly skill: number;
|
|
// 武将碎片
|
|
readonly pieceId: number;
|
|
// 初始星级
|
|
readonly initialStars: number;
|
|
// 合成碎片数量
|
|
readonly pieceCount: number;
|
|
// 主属性
|
|
readonly baseAbilityArr:Map<number, number>;
|
|
readonly baseAbilityUpArr:Map<number, number>;
|
|
readonly initialSkin: number;
|
|
// 是否可招募
|
|
readonly recruit: boolean;
|
|
}
|
|
|
|
const str = readJsonFile(FILENAME.DIC_HERO);
|
|
let arr = JSON.parse(str);
|
|
|
|
type KeysEnum<T> = { [P in keyof Required<T>]: true };
|
|
const DicHeroKeys: KeysEnum<DicHero> = {heroId: true, name: true, quality: true, camp: true, jobid: true, skill: true, pieceId: true, initialStars: true, pieceCount: true, baseAbilityArr: true, baseAbilityUpArr: true, initialSkin: true, recruit: true};
|
|
export const dicMyHeroes = new Array<number>();
|
|
export const dicHero = new Map<number, DicHero>();
|
|
arr.forEach(o => {
|
|
if(o.heroId > 0 && o.heroId <= 300) {
|
|
dicMyHeroes.push(o.heroId);
|
|
}
|
|
o.baseAbilityArr = parseBaseAbilityArr(o);
|
|
o.baseAbilityUpArr = parseBaseAbilityUpArr(o);
|
|
o.recruit = parseInt(o.recruit) == 1;
|
|
dicHero.set(o.heroId, _.pick(o, Object.keys(DicHeroKeys)));
|
|
});
|
|
|
|
function parseBaseAbilityArr(json) {
|
|
let map = new Map<number, number>();
|
|
map.set(ABI_TYPE.ABI_HP, json.hp||0);
|
|
map.set(ABI_TYPE.ABI_ATK, json.atk||0);
|
|
map.set(ABI_TYPE.ABI_DEF, json.def||0);
|
|
map.set(ABI_TYPE.ABI_MDEF, json.mdef||0);
|
|
return map
|
|
}
|
|
|
|
function parseBaseAbilityUpArr(json) {
|
|
let map = new Map<number, number>();
|
|
map.set(ABI_TYPE.ABI_HP, json.hp_up||0);
|
|
map.set(ABI_TYPE.ABI_ATK, json.atk_up||0);
|
|
map.set(ABI_TYPE.ABI_DEF, json.def_up||0);
|
|
map.set(ABI_TYPE.ABI_MDEF, json.mdef_up||0);
|
|
return map
|
|
} |