104 lines
3.1 KiB
TypeScript
104 lines
3.1 KiB
TypeScript
// 物品表
|
|
import {decodeArrayListStr, readJsonFile, parseReward} from '../util'
|
|
import { FILENAME, IT_TYPE } from '../../consts/consts'
|
|
import { RewardInter } from '../interface';
|
|
import { ABI_TYPE } from '../../consts';
|
|
|
|
export interface DicGoods {
|
|
// 物品id
|
|
readonly good_id: number;
|
|
// 物品名
|
|
readonly name: string;
|
|
// 等级限制
|
|
readonly lvLimted: number;
|
|
// 合成装备需要的碎片数
|
|
readonly pieces: number;
|
|
// 合成材料
|
|
readonly composeMaterial: Array<RewardInter>;
|
|
// 分解所得
|
|
readonly decomposeItem: Array<RewardInter>;
|
|
// 物品品质
|
|
readonly quality: number;
|
|
// 洞数
|
|
readonly hole: number;
|
|
// 类型id
|
|
readonly itid: number;
|
|
// 物品类型
|
|
readonly goodType: number;
|
|
// 将魂对应武将id
|
|
readonly hid: number;
|
|
// 属性
|
|
readonly goodsAbility:Map<number, number>;
|
|
// 强化属性
|
|
readonly goodsAbilityUp:Map<number, number>;
|
|
// 套装id
|
|
readonly setid: number;
|
|
// 特殊属性
|
|
readonly specialAttr: Map<number, number>;
|
|
// 属性外加的值,经验,好感
|
|
readonly value: number;
|
|
|
|
}
|
|
|
|
const str = readJsonFile(FILENAME.DIC_GOODS);
|
|
let arr = JSON.parse(str);
|
|
|
|
export const dicGoods = new Map<number, DicGoods>();
|
|
export const blueprt = new Map<number, Array<number>>();
|
|
|
|
arr.forEach(o => {
|
|
o.goodsAbility = parseAbility(o);
|
|
o.goodsAbilityUp = parseAbilityUp(o);
|
|
o.composeMaterial = parseReward(o.composeMaterial);
|
|
o.decomposeItem = parseReward(o.decomposeItem);
|
|
o.specialAttr = parseSpecialAttr(o.specialAttr);
|
|
dicGoods.set(o.good_id, o);
|
|
|
|
if(o.itid == IT_TYPE.BLUEPRT) {
|
|
let arr = blueprt.get(o.quality)||new Array<number>();
|
|
arr.push(o.good_id);
|
|
blueprt.set(o.quality, arr);
|
|
}
|
|
|
|
});
|
|
|
|
function parseSpecialAttr(str: string) {
|
|
let specialAttr = new Map<number, number>();
|
|
if(str) {
|
|
let decodeArr = decodeArrayListStr(str);
|
|
for(let [type, count] of decodeArr) {
|
|
if(isNaN(parseInt(type)) || isNaN(parseInt(count))) {
|
|
throw new Error('data table format wrong');
|
|
}
|
|
|
|
specialAttr.set(parseInt(type), parseInt(count));
|
|
}
|
|
}
|
|
return specialAttr;
|
|
}
|
|
|
|
function parseAbility(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_MATK, json.matk||0);
|
|
map.set(ABI_TYPE.ABI_DEF, json.def||0);
|
|
map.set(ABI_TYPE.ABI_MDEF, json.mdef||0);
|
|
map.set(ABI_TYPE.ABI_AGI, json.agi||0);
|
|
map.set(ABI_TYPE.ABI_LUK, json.luk||0);
|
|
map.set(ABI_TYPE.ABI_SPEED, json.speed||0);
|
|
return map
|
|
}
|
|
|
|
function parseAbilityUp(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_MATK, json.matk_up||0);
|
|
map.set(ABI_TYPE.ABI_DEF, json.def_up||0);
|
|
map.set(ABI_TYPE.ABI_MDEF, json.mdef_up||0);
|
|
map.set(ABI_TYPE.ABI_AGI, json.agi_up||0);
|
|
map.set(ABI_TYPE.ABI_LUK, json.luk_up||0);
|
|
map.set(ABI_TYPE.ABI_SPEED, json.speed_up||0);
|
|
return map
|
|
} |