Files
ZYZ/shared/pubUtils/dictionary/DicWar.ts
2021-01-06 17:16:15 +08:00

87 lines
2.9 KiB
TypeScript

// 关卡表
import {decodeArrayListStr, readJsonFile} from '../util'
import { WAR_RELATE_TABLES, WAR_TYPE } from '../../consts';
export interface DicWar {
// 关卡id
readonly war_id: number;
// 关卡固定奖励
readonly fixReward: Array<{id: number, count: number}>;
// 关卡条件奖励
readonly conditionReward: Array<{id: number, count: number, condition: number}>;
// 关卡随机奖励
readonly randomReward: Array<{id: number, count: number, frequency: number}>;
// 关卡类型
readonly warType: number;
// 关卡名
readonly gk_name: string;
// 胜利后获得的君主经验
readonly kingExp: number;
// 进入战场所需的最低等级
readonly lvLimited: number;
// 消耗的体力
readonly cost: number;
// 前置关卡
readonly previousGk: number;
// 每日任务下的小类型
readonly dailyType: number;
}
export const dicWar = new Map<number, DicWar>();
export const dicWarPvp = new Array<DicWar>();
for(let filename of WAR_RELATE_TABLES) {
const str = readJsonFile(filename);
let arr = JSON.parse(str);
arr.forEach(o => {
o.fixReward = parseFixReward(o.fixReward);
o.conditionReward = parseConditionReward(o.conditionReward);
o.parseRandomReward = parseRandomReward(o.parseRandomReward);
dicWar.set(o.war_id, o);
if(o.warType == WAR_TYPE.PVP) {
dicWarPvp.push(o);
}
});
}
function parseFixReward(str: string = '') {
let result = new Array<{id: number, count: number}>();
if(!str) return result;
let decodeArr = decodeArrayListStr(str);
for(let [id, count] of decodeArr) {
if(isNaN(parseInt(id)) || isNaN(parseInt(count))) {
throw new Error('data table format wrong');
}
result.push({id: parseInt(id), count: parseInt(count)});
}
return result
}
function parseConditionReward(str: string = '') {
let result = new Array<{id: number, count: number, condition: number}>();
if(!str) return result;
let decodeArr = decodeArrayListStr(str);
for(let [id, count, condition] of decodeArr) {
if(isNaN(parseInt(id)) || isNaN(parseInt(count)) || isNaN(parseInt(condition))) {
throw new Error('data table format wrong');
}
result.push({id: parseInt(id), count: parseInt(count), condition: parseInt(condition)});
}
return result
}
function parseRandomReward(str: string = '') {
let result = new Array<{id: number, count: number, frequency: number}>();
if(!str) return result;
let decodeArr = decodeArrayListStr(str);
for(let [id, count, frequency] of decodeArr) {
if(isNaN(parseInt(id)) || isNaN(parseInt(count)) || isNaN(parseInt(frequency))) {
throw new Error('data table format wrong');
}
result.push({id: parseInt(id), count: parseInt(count), frequency: parseInt(frequency)});
}
return result
}