添加保存R剧本接口

This commit is contained in:
luying
2020-10-22 11:05:49 +08:00
parent 3d031088b7
commit 318d45e50e
8 changed files with 202 additions and 37 deletions
@@ -3,15 +3,18 @@ import { BattleRecordModel } from '../../../db/BattleRecord';
import { BattleSweepRecordModel } from '../../../db/BattleSweepRecord';
import { getWarById, } from '../../../pubUtils/gamedata';
import { genCode } from '../../../pubUtils/util';
import { WAR_TYPE, EVENT_START_BATTLE } from '../../../consts/consts';
import { WAR_TYPE } from '../../../consts/consts';
import { checkDaily, checkDailyAndIncrease } from '../../../services/dailyBattleService';
import { checkTowerWar, towerBattleEnd, roleLevelup } from '../../../services/battleService';
import { checkTowerWar, towerBattleEnd } from '../../../services/battleService';
import { WarReward } from '../../../services/warRewardService';
import { getAp, setAp } from '../../../services/actionPointService';
import { setBattleStatus, startEvent } from '../../../services/eventSercive';
import { setBattleStatus } from '../../../services/eventSercive';
import { STATUS } from '../../../consts/statusCode';
import { resResult } from '../../../pubUtils/util';
import { HeroModel } from '../../../db/Hero';
import { RoleModel } from '../../../db/Role';
import { RScriptRecordModel } from '../../../db/RScriptRecord';
import { updateWarStar, checkBattleHeroes, roleLevelup } from '../../../services/normalBattleService';
export default function(app: Application) {
return new NormalBattleHandler(app);
@@ -47,6 +50,9 @@ export class NormalBattleHandler {
if(!preBattle) return resResult(STATUS.BATTLE_NEED_PREVIOUS_GK);
}
let checkHeroes = checkBattleHeroes(roleId, heroes);
if(!checkHeroes) return resResult(STATUS.BATTLE_HERO_NOT_FOUND);
let dailyNum = {};
let towerData = {};
if(warInfo.warType == WAR_TYPE.DAILY) {
@@ -86,14 +92,40 @@ export class NormalBattleHandler {
const { type } = msg;
let roleId = session.get('roleId');
const BattleRecord = await BattleRecordModel.getBattleList(roleId, type);
let role = await RoleModel.findByRoleId(roleId);
let {warStar} = role;
let scripts = await RScriptRecordModel.findbyRole(roleId, type);
let result = []; // 去重
for(let br of BattleRecord) {
let index = result.findIndex(cur => cur.battleId == br.battleId);
if(index == -1) {
result.push(br);
for(let {battleId, scriptBefore = '', scriptAfter = ''} of scripts) {
result.push({
battleId,
status: 0,
star: 0,
scriptBefore,
scriptAfter
});
}
for(let {id, star, warType} of warStar) {
if(warType == type) {
let curResult = result.find(cur => cur.battleId == id);
if(curResult) {
curResult.status = 1;
curResult.star = star;
} else {
result.push({
battleId: id,
status: 1,
star,
scriptBefore: '',
scriptAfter: ''
});
}
}
}
result = result.sort((a, b) => {return a.battleId - b.battleId});
return resResult(STATUS.SUCCESS, {
list: result
@@ -181,6 +213,8 @@ export class NormalBattleHandler {
}, true);
let { status } = updateResult;
await updateWarStar(roleId, battleId, warInfo.warType, star);
let actordata = await roleLevelup(roleId, warInfo.kingExp)// 主公升级经验
let curHeroes = [];
@@ -189,12 +223,6 @@ export class NormalBattleHandler {
curHeroes.push(hero);
}
// 主线关卡某个关卡触发事件开启
let eventStatus = session.get('eventStatus')||0;
if(battleId == EVENT_START_BATTLE && eventStatus == 0) {
// console.log('*******startEvent')
await startEvent(this.app, session);
}
// 返回值:
// towerStatus: false-本层未通过, true-本层已通过
// towerBonus: 天梯每隔几层的额外宝箱
@@ -269,4 +297,38 @@ export class NormalBattleHandler {
});
}
async saveScript(msg: {battleId: number, type: number, script: string }, session: BackendSession) {
const { battleId, type, script } = msg;
let roleId = session.get('roleId');
let warInfo = getWarById(battleId);
let result = await RScriptRecordModel.setScript(roleId, battleId, warInfo.warType, type, script);
if(result) {
if(!result.scriptBefore) result.scriptBefore = '';
if(!result.scriptAfter) result.scriptAfter = '';
return resResult(STATUS.SUCCESS, result);
} else {
console.error('script not created');
return resResult(STATUS.INTERNAL_ERR);
}
}
async getScriptByBattle(msg: {battleIds: Array<number> }, session: BackendSession) {
const { battleIds } = msg;
let roleId = session.get('roleId');
let list = new Array();
for(let battleId of battleIds) {
let result = await RScriptRecordModel.findbyRoleAndBattle(roleId, battleId);
if(result) {
let {scriptBefore = '', scriptAfter = ''} = result;
list.push({battleId, scriptBefore, scriptAfter});
} else {
list.push({battleId, scriptBefore: '', scriptAfter: ''});
}
}
return resResult(STATUS.SUCCESS, { list });
}
}