63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { Application, BackendSession } from 'pinus';
|
|
import { DailyRecordModel } from '../../../db/DailyRecord';
|
|
import { BattleRecordModel } from '../../../db/BattleRecord';
|
|
import { getGamedata } from '../../../pubUtils/gamedata';
|
|
import { WAR_TYPE } from '../../../consts/consts';
|
|
|
|
export default function(app: Application) {
|
|
return new DailyBattleHandler(app);
|
|
}
|
|
|
|
export class DailyBattleHandler {
|
|
constructor(private app: Application) {
|
|
}
|
|
|
|
// 获取关卡列表
|
|
async getData(msg: { }, session: BackendSession) {
|
|
let roleId = session.get('roleId');
|
|
|
|
const BattleRecord = await BattleRecordModel.getBattleList(roleId, WAR_TYPE.DAILY);
|
|
|
|
let dicDaily = getGamedata('dic_zyz_daily');
|
|
let dicDailyWar = getGamedata('dic_zyz_gk_daily');
|
|
|
|
let result = new Array();
|
|
for(let {dailyType: type, name, timesPerDay: sum} of dicDaily) {
|
|
let refreshResult = await DailyRecordModel.refreshRecord(roleId, type);
|
|
let {count} = refreshResult;
|
|
let wars = new Array();
|
|
for(let {war_id, dailyType, cost, gk_name, previousGk } of dicDailyWar) {
|
|
if(dailyType == type) {
|
|
let status = 0, star = 0;
|
|
let curBattle = BattleRecord.find(cur => cur.battleId == war_id);
|
|
if(curBattle) {
|
|
status = 2;
|
|
star = curBattle.star;
|
|
} else {
|
|
if (previousGk) {
|
|
let preBattleRecord = BattleRecord.find(cur => cur.battleId == previousGk);
|
|
if(preBattleRecord) {
|
|
status = 1;
|
|
} else {
|
|
status = 0;
|
|
}
|
|
} else {
|
|
status = 1;
|
|
}
|
|
}
|
|
wars.push({
|
|
battleId: war_id, cost, star, status, name: gk_name
|
|
});
|
|
}
|
|
}
|
|
|
|
result.push({
|
|
type, count, sum, name,
|
|
wars
|
|
});
|
|
}
|
|
|
|
return { code: 200, data: result }
|
|
}
|
|
|
|
} |