GM后台修改status code
This commit is contained in:
@@ -1,30 +1,7 @@
|
||||
import { Service } from 'egg';
|
||||
import * as pubUtils from '../pubUtils/util';
|
||||
import * as pubGamedata from '../pubUtils/gamedata'
|
||||
const csprng = require('csprng');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
var gamedata = {};
|
||||
|
||||
function initData () {
|
||||
fs.readdirSync(__dirname + '/../resource/jsons')
|
||||
.filter(function(file) {
|
||||
return (file.indexOf(".") !== 0) && (file !== "index.js");
|
||||
})
|
||||
//筛选有文件名且不是index进行遍历
|
||||
.forEach(function(file) {
|
||||
var name = file.split('.')[0];
|
||||
try {
|
||||
gamedata[name] = JSON.parse(
|
||||
fs.readFileSync(path.resolve(__dirname, "../resource/jsons/" + file))
|
||||
);
|
||||
} catch(e) {
|
||||
console.error('【文件缺少】:' + file);
|
||||
gamedata[name] = [];
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
initData();
|
||||
|
||||
/**
|
||||
* Utils Service
|
||||
@@ -39,84 +16,31 @@ export default class Utils extends Service {
|
||||
return `${csprng(len, radix)}`;
|
||||
}
|
||||
|
||||
public genCode(len) {
|
||||
const chars = '123456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
const charArr = chars.split('');
|
||||
let code = '';
|
||||
for (let i = 0; i < len; i++) {
|
||||
code += charArr[Math.floor(Math.random() * charArr.length)];
|
||||
}
|
||||
return code;
|
||||
public genCode(len: number) {
|
||||
return pubUtils.genCode(len)
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成指定长度的随机数
|
||||
* @param len 随机数长度
|
||||
*/
|
||||
public generateNum(len: number) {
|
||||
let code = '';
|
||||
for (let i = 0; i < len; i++) {
|
||||
code += parseInt(`${Math.random() * 10}`);
|
||||
}
|
||||
return code;
|
||||
public getGamedata(key: string) {
|
||||
return pubGamedata.getGamedata(key);
|
||||
}
|
||||
|
||||
public exceptionResult(status) {
|
||||
const { code, simStr } = status;
|
||||
return { status: code, data: simStr };
|
||||
public getHeroById(hid: number) {
|
||||
return pubGamedata.getHeroInfoById(hid);
|
||||
}
|
||||
public getWarById(warid: number) {
|
||||
return pubGamedata.getWarById(warid);
|
||||
}
|
||||
|
||||
public getGamedata(key) {
|
||||
return gamedata[key];
|
||||
}
|
||||
|
||||
public getHeroById(hid) {
|
||||
let heros = gamedata['dic_zyz_hero']||[];
|
||||
return heros.find(cur => {
|
||||
return cur.heroId == hid;
|
||||
});
|
||||
}
|
||||
public getWarById(warid) {
|
||||
const wars = ['dic_zyz_gk_main', 'dic_zyz_gk_mainElite', 'dic_zyz_gk_daily', 'dic_zyz_gk_event']; // 关卡相关的表
|
||||
let result;
|
||||
for(let filename of wars) {
|
||||
let warInfo = gamedata[filename]||[];
|
||||
for(let war of warInfo) {
|
||||
if(war.war_id == warid) {
|
||||
result = war; break;
|
||||
}
|
||||
}
|
||||
if(result) break;
|
||||
}
|
||||
return result||[];
|
||||
}
|
||||
|
||||
public getGoodById(gid) {
|
||||
console.log(gid)
|
||||
let goodsInfo = gamedata['goods']||[];
|
||||
return goodsInfo.find(cur => {
|
||||
return cur.good_id == gid
|
||||
});
|
||||
public getGoodById(gid: number) {
|
||||
return pubGamedata.getGoodById(gid);
|
||||
}
|
||||
|
||||
public calculateCE(heroInfo: {hid: number, lv: number }) {
|
||||
|
||||
let { hid, lv } = heroInfo;
|
||||
// 假设所有属性和等级的关系是简单的线性关系
|
||||
let dicHero = this.getGamedata('dic_zyz_hero');
|
||||
let curDicHero = dicHero.find(cur => cur.heroId == hid);
|
||||
return pubUtils.calculateCE(heroInfo)
|
||||
}
|
||||
|
||||
let { atk, matk, def, mdef, agi, luk, atk_up, matk_up, def_up, mdef_up, agi_up, luk_up } = curDicHero;
|
||||
atk += lv * atk_up;
|
||||
matk += lv * matk_up;
|
||||
def += lv * def_up;
|
||||
mdef += lv * mdef_up;
|
||||
agi += lv * agi_up;
|
||||
luk += lv * luk_up;
|
||||
|
||||
// 假设战力为所有属性的简单加法
|
||||
|
||||
let ce = atk + matk + def + mdef + agi + luk;
|
||||
return ce;
|
||||
public resResult(status: {code: number, simStr: string}, data?, customMsg?: string) {
|
||||
return pubUtils.resResult(status, data, customMsg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user