练兵接口调整,新增获得宝箱和战报
This commit is contained in:
@@ -7,7 +7,7 @@ import { nowSeconds, getHourPoint, getCurHourPoint } from '../../../pubUtils/tim
|
||||
import { getUserGuild, getGuildTrainInfo, unlockTrain, resetTrain, getGuildTrainRewards} from '../../../services/guildTrainService';
|
||||
import { findIndex, findWhere, indexBy } from 'underscore'
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { GUILD_DATA_NAME, REFRESH_HOUR } from '../../../consts/constModules/guildConst';
|
||||
import { GUILD_DATA_NAME, REFRESH_HOUR, GUILD_REPORT_NUM } from '../../../consts/constModules/guildConst';
|
||||
import { UserGuildModel } from '../../../db/UserGuild';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { getArmyTrainJuDian, getTrainSoloReward, getTrainBaseByLv } from '../../../pubUtils/data';
|
||||
@@ -15,7 +15,7 @@ import { CURRENCY_BY_TYPE, CURRENCY_TYPE } from '../../../consts/constModules/it
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
import { addActive } from '../../../services/guildService';
|
||||
import { GUILD_STRUCTURE } from '../../../consts/constModules/guildConst';
|
||||
import { GuildTrainReportModel } from '../../../db/GuildTrainReport';
|
||||
export default function (app: Application) {
|
||||
return new GuildTrainHandler(app);
|
||||
}
|
||||
@@ -34,22 +34,70 @@ export class GuildTrainHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let { trainId } = await GuildModel.findGuild(code, serverId, 'trainId');
|
||||
let trainIds = [trainId];
|
||||
if (trainId - 1 > 0) {
|
||||
trainIds.push(trainId - 1);
|
||||
}
|
||||
let guildTrains = await GuildTrainModel.findGuildTrainByTrainIds(code, trainIds);
|
||||
if (!guildTrains || !findWhere(guildTrains, {trainId})) {
|
||||
let guildTrain = await unlockTrain(code, trainId);
|
||||
if (!guildTrains) {
|
||||
guildTrains.push(guildTrain);
|
||||
}
|
||||
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId);
|
||||
if (!guildTrain ) {
|
||||
guildTrain = await unlockTrain(code, trainId);
|
||||
}
|
||||
let { trainCount, trainRewards, buyTrainCount } = userGuild;
|
||||
let result:any = getGuildTrainInfo(guildTrains, roleId, trainCount, trainRewards, [trainId]);
|
||||
let result:any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);
|
||||
result.buyTrainCount = buyTrainCount;
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
//获得试炼战报
|
||||
async getTrainReports(msg: {}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let trainIds = [];
|
||||
let { trainId } = await GuildModel.findGuild(code, serverId, 'trainId');
|
||||
trainIds.push(trainId);
|
||||
if (trainId > 1)
|
||||
trainIds.push(trainId - 1);
|
||||
let trainReports = await GuildTrainReportModel.findGuildTrainByTrainIds(code, trainIds);
|
||||
let reports = [];
|
||||
trainReports.map(({ reports: resReports, trainId: resTrainId})=>{
|
||||
if (resTrainId != trainId) {
|
||||
let lenNum = resReports.length;
|
||||
resReports = resReports.splice(lenNum - GUILD_REPORT_NUM - 1, GUILD_REPORT_NUM);
|
||||
}
|
||||
reports.push(...resReports);
|
||||
});
|
||||
return resResult(STATUS.SUCCESS, {reports});
|
||||
}
|
||||
|
||||
//获得试炼宝箱
|
||||
async getTrainBoxs(msg: {}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
let userGuild = await getUserGuild(roleId, serverId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let guildTrains = await GuildTrainModel.findGuildTrain(code);
|
||||
let resTrainBoxs = [];
|
||||
let { trainId: curTrainId } = await GuildModel.findGuild(code, serverId, 'trainId');
|
||||
guildTrains.forEach(({trainInstances, trainId}) =>{
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
let flag = false;
|
||||
let boxRewards = []
|
||||
trainInstances.map(({hid, progress, endTime, trainBoxs})=>{
|
||||
let instance = findWhere(instances, { hid });
|
||||
let isComplete = false;
|
||||
if ( progress >= instance.progress)
|
||||
isComplete = true;
|
||||
if (endTime > nowSeconds())
|
||||
flag = true;
|
||||
boxRewards.push({hid, recordBoxs: trainBoxs, trainId, endTime, isComplete});
|
||||
});
|
||||
if (flag || trainId == curTrainId) {
|
||||
resTrainBoxs.push(...boxRewards);
|
||||
}
|
||||
})
|
||||
return resResult(STATUS.SUCCESS, {trainBoxs: resTrainBoxs});
|
||||
}
|
||||
|
||||
async trainBattleStart(msg: { hid: number, trainId: number, difficulty: number }, session: BackendSession) {
|
||||
const { hid, difficulty, trainId } = msg;
|
||||
@@ -141,10 +189,9 @@ export class GuildTrainHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
let addScore = Math.floor((isSuccess?trainSoloReward.winScore:trainSoloReward.failScore) * (soloRewardRatio + 100 ) / 100);
|
||||
let goods = await addItems(roleId, roleName, sid, [{id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count: isSuccess?trainSoloReward.failHonour:trainSoloReward.failHonour}]);
|
||||
let guildTrains = [];
|
||||
let trainIds = [];
|
||||
//是否压制
|
||||
let { isComplete, reports, ranks } = guildTrain;
|
||||
let { isComplete, ranks } = guildTrain;
|
||||
let reports = [];
|
||||
let index = findIndex(ranks, {roleId});
|
||||
if (index !== -1) {
|
||||
ranks[index].score += addScore;
|
||||
@@ -152,11 +199,10 @@ export class GuildTrainHandler {
|
||||
ranks.push({score: addScore, roleId});
|
||||
}
|
||||
let needLockNext = false;
|
||||
let resGuildTrain;
|
||||
let report = {roleId, trainId, hid, score: addScore, time: nowSeconds(), isSuccessed: isSuccess, type: 1};//1表示普通战报, 2表示系统战报即:被成功压制
|
||||
let report = {roleName, trainId, hid, score: addScore, time: nowSeconds(), isSuccessed: isSuccess, type: 1};//1表示普通战报, 2表示系统战报即:被成功压制
|
||||
reports.push(report);
|
||||
if (trainInstance.progress < instance.progress ) {
|
||||
if (trainInstance.progress + addScore >= instance.progress) {
|
||||
reports.push(...[{isSuccessed: true, type: 2, time:nowSeconds(), score: addScore, roleId, trainId, hid},report]);
|
||||
if (!isComplete) {
|
||||
isComplete = true;
|
||||
guildTrain.trainInstances.forEach(({hid: otherHid, progress})=>{
|
||||
@@ -169,33 +215,24 @@ export class GuildTrainHandler {
|
||||
}
|
||||
}
|
||||
let progress = instance.progress;
|
||||
resGuildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, reports, isComplete);
|
||||
guildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, isComplete);
|
||||
if (needLockNext) { //
|
||||
let nextResGuildTrain = await unlockTrain(code, trainId + 1);
|
||||
trainIds.push(nextResGuildTrain.trainId);
|
||||
guildTrains.push(nextResGuildTrain);
|
||||
reports.push({ isSuccessed: true, type: 2, time:nowSeconds(), score: addScore, roleName, trainId, hid });
|
||||
guildTrain = await unlockTrain(code, trainId + 1);
|
||||
}
|
||||
res.releaseCallback();//解锁
|
||||
} else {
|
||||
let progress = trainInstance.progress + addScore;
|
||||
resGuildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, reports, isComplete);
|
||||
guildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, isComplete);
|
||||
res.releaseCallback();//解锁
|
||||
}
|
||||
} else {
|
||||
reports.push(report);
|
||||
resGuildTrain = await GuildTrainModel.updateGuildTrain(code, trainId, {reports, ranks});
|
||||
guildTrain = await GuildTrainModel.updateGuildTrain(code, trainId, { ranks});
|
||||
res.releaseCallback();//解锁
|
||||
}
|
||||
if (!needLockNext) {
|
||||
if (trainId - 1 > 0 ) {
|
||||
let lastGuildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId - 1);
|
||||
guildTrains.push(lastGuildTrain);
|
||||
}
|
||||
trainIds.push(resGuildTrain.trainId);
|
||||
}
|
||||
guildTrains.push(resGuildTrain);
|
||||
await GuildTrainReportModel.pushGuildTrainReports(code, trainId, reports);
|
||||
let { trainCount, trainRewards } = userGuild;
|
||||
let result:any = getGuildTrainInfo(guildTrains, roleId, trainCount, trainRewards, trainIds);
|
||||
let result:any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);
|
||||
result.battleGoods = goods;
|
||||
await addActive(roleId, serverId, 2, 1);
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
@@ -211,13 +248,12 @@ export class GuildTrainHandler {
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
|
||||
let stru = findWhere(structure, {id: 4});
|
||||
let { trainLv } = await GuildModel.findGuild(code, serverId, 'structure');
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.TRAIN_BOX, code + '_' + trainId);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
|
||||
let { shilianRewardRatio } = getTrainBaseByLv(GUILD_STRUCTURE.TRAIN);
|
||||
let { shilianRewardRatio } = getTrainBaseByLv(trainLv);
|
||||
let { heroRewards, trainInstances } = getArmyTrainJuDian(trainId);
|
||||
let { progress } = findWhere(trainInstances, {hid});
|
||||
let guildTrain = await GuildTrainModel.findTrainInstanceBoxByIndex(code, roleId, trainId, hid, index, progress, nowSeconds());
|
||||
|
||||
Reference in New Issue
Block a user