Files
ZYZ/shared/pubUtils/dictionary/DicWar.ts
2021-11-12 16:57:07 +08:00

162 lines
5.8 KiB
TypeScript

// 关卡表
import {decodeArrayListStr, decodeArrayStr, parseNumberList, readFileAndParse} from '../util'
import { WAR_RELATE_TABLES, WAR_TYPE } from '../../consts';
import { isString } from 'underscore'
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;
// 显示章节名
readonly detailUIBg: string[];
// 寻宝匹配json
readonly dispatchJsonId: number;
// 寻宝奖励
readonly jackpotReward: Array<{id: number, weight: number}>;
// 寻宝队友奖励
readonly teammateReward: Array<{id: number, count: number}>;
// 镇念塔禁用角色
readonly fobiddenCharactor: Array<{type: number, id: number}>;
// 远征随机buff
readonly mapseid: number[];
// 秘境类型
readonly movePoint: number;
// 战前剧本
readonly scriptBefore: string;
// 战后剧本
readonly scriptAfter: string;
}
export const dicWar = new Map<number, DicWar>();
export const dicWarPvp = new Array<DicWar>();
export const dicDailyWarByType = new Map<number, DicWar[]>();
export function loadWar() {
dicWar.clear();
dicDailyWarByType.clear();
dicWarPvp.splice(0, dicWarPvp.length);
for(let filename of WAR_RELATE_TABLES) {
let arr = readFileAndParse(filename);
arr.forEach(o => {
o.fixReward = parseFixReward(o.fixReward);
o.conditionReward = parseConditionReward(o.conditionReward);
o.randomReward = parseRandomReward(o.RandomReward||o.randomReward);
o.detailUIBg = parseDetailUIBg(o.detailUIBg);
o.jackpotReward = parseJackpotReward(o.jackpotReward);
o.teammateReward = parseFixReward(o.teammateReward);
o.fobiddenCharactor = parseForbiddenChara(o.fobiddenCharactor);
o.mapseid = parseNumberList(o.mapseid);
if(o.script_id && isString(o.script_id)) {
let scripts = o.script_id?.split('&')||[];
for(let script of scripts) {
if(script.indexOf('R_') != -1) {
o.scriptBefore = script;
} else if (script.indexOf('RE_') != -1) {
o.scriptAfter = script;
}
}
}
dicWar.set(o.war_id, o);
if(o.warType == WAR_TYPE.PVP) {
dicWarPvp.push(o);
} else if (o.warType == WAR_TYPE.DAILY) {
if(!dicDailyWarByType.has(o.dailyType)) {
dicDailyWarByType.set(o.dailyType, []);
}
dicDailyWarByType.get(o.dailyType).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
}
function parseDetailUIBg(str: string = '') {
let result = new Array<string>();
if(!str) return result;
let decodeArr = decodeArrayStr(str, '_');
return decodeArr;
}
function parseJackpotReward(str: string = '') {
let result = new Array<{id: number, weight: number}>();
if(!str) return result;
let decodeArr = decodeArrayListStr(str);
for(let [id, weight] of decodeArr) {
if(isNaN(parseInt(id)) || isNaN(parseInt(weight))) {
throw new Error('data table format wrong');
}
result.push({id: parseInt(id), weight: parseInt(weight)});
}
return result
}
function parseForbiddenChara(str: string = '') {
let result = new Array<{type: number, id: number}>();
if(!str) return result;
let decodeArr = decodeArrayListStr(str);
for(let [type, id] of decodeArr) {
if(isNaN(parseInt(type)) || isNaN(parseInt(id))) {
throw new Error('data table format wrong');
}
result.push({type: parseInt(type), id: parseInt(id)});
}
return result
}