练兵接口调整,新增获得宝箱和战报
This commit is contained in:
@@ -12,7 +12,7 @@ import { MailModel, MailType } from '../db/Mail';
|
||||
import { getRandomByLen, resResult } from '../pubUtils/util';
|
||||
import { getRedis } from './redisService';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
|
||||
import { GuildTrainReportModel } from '../db/GuildTrainReport'
|
||||
export async function getUserGuild(roleId: string, serverId: number) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'trainCount trainTime trainRewards guildCode');
|
||||
if (!userGuild)
|
||||
@@ -57,57 +57,32 @@ export function getGuildTrainRewards (guildTrain) {
|
||||
isComplete = true;
|
||||
return {hid, recordBoxs: trainBoxs, trainId: guildTrain.trainId, endTime, isComplete};
|
||||
})
|
||||
return { trainBoxs};
|
||||
return { trainBoxs };
|
||||
}
|
||||
|
||||
export function getGuildTrainInfo (guildTrains: Array<GuildTrainType>, roleId: string, trainCount:number, trainRewards: Array<number>, trainIds:Array<number>) {
|
||||
let guildTrain;
|
||||
guildTrains.map(({trainId, isComplete, trainInstances, ranks, reports})=>{
|
||||
if (trainIds.indexOf(trainId) == -1) {
|
||||
return;
|
||||
}
|
||||
ranks.sort(function(a, b) {
|
||||
return b.score - a.score;
|
||||
});
|
||||
let myRank = {};
|
||||
let resRanks = ranks.map(({roleId: rankRoleId, score}, index)=>{
|
||||
if (roleId == rankRoleId)
|
||||
myRank = {roleId: rankRoleId, score, rankLv: index+1};
|
||||
return {roleId: rankRoleId, score, rankLv: index+1};
|
||||
});
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
let resTrainBoxs = [];
|
||||
let resTrainInstances = trainInstances.map(({hid, progress, endTime, trainBoxs})=>{
|
||||
let instance = findWhere(instances, { hid });
|
||||
let isComplete = false;
|
||||
if ( progress >= instance.progress)
|
||||
isComplete = true;
|
||||
resTrainBoxs.push({hid, recordBoxs: trainBoxs, trainId, endTime, isComplete});
|
||||
return {hid, progress, endTime, isComplete};
|
||||
})
|
||||
let lastGuildTrain = findWhere(guildTrains, { trainId: trainId - 1});
|
||||
if (!!lastGuildTrain) {
|
||||
let lenNum = lastGuildTrain.reports.length;
|
||||
if (lenNum < GUILD_REPORT_NUM)
|
||||
reports = [...lastGuildTrain.reports, ...reports];
|
||||
else {
|
||||
let trainReports = lastGuildTrain.reports.splice(lenNum - GUILD_REPORT_NUM - 1, GUILD_REPORT_NUM);
|
||||
reports = [...trainReports, ...reports];
|
||||
}
|
||||
let flag = false;
|
||||
let lastTrainBoxs = lastGuildTrain.trainInstances.map(({hid, endTime, trainBoxs}) => {
|
||||
if (endTime < nowSeconds()) {
|
||||
flag = true;
|
||||
}
|
||||
return {hid, recordBoxs: trainBoxs, trainId: lastGuildTrain.trainId, endTime, isComplete: true};
|
||||
});
|
||||
if (flag) {
|
||||
resTrainBoxs.push(...lastTrainBoxs);
|
||||
}
|
||||
}
|
||||
guildTrain = {trainId, isComplete, trainInstances: resTrainInstances, trainBoxs: resTrainBoxs, reports, myRank, ranks: resRanks};
|
||||
export function getGuildTrainInfo (guildTrain: GuildTrainType, roleId: string, trainCount:number, trainRewards: Array<number>) {
|
||||
let { trainId, isComplete, trainInstances, ranks } = guildTrain;
|
||||
|
||||
ranks.sort(function(a, b) {
|
||||
return b.score - a.score;
|
||||
});
|
||||
return { guildTrain, trainCount, trainRewards};
|
||||
let myRank = {};
|
||||
let resRanks = ranks.map(({roleId: rankRoleId, score}, index)=>{
|
||||
if (roleId == rankRoleId)
|
||||
myRank = {roleId: rankRoleId, score, rankLv: index+1};
|
||||
return {roleId: rankRoleId, score, rankLv: index+1};
|
||||
});
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
let resTrainInstances = trainInstances.map(({hid, progress, endTime})=>{
|
||||
let instance = findWhere(instances, { hid });
|
||||
let isComplete = false;
|
||||
if ( progress >= instance.progress)
|
||||
isComplete = true;
|
||||
return {hid, progress, endTime, isComplete};
|
||||
});
|
||||
let resGuildTrain = {trainId, isComplete, trainInstances: resTrainInstances, myRank, ranks: resRanks};
|
||||
|
||||
return { guildTrain: resGuildTrain, trainCount, trainRewards};
|
||||
}
|
||||
|
||||
export async function unlockTrain(code: string, trainId: number) {
|
||||
@@ -127,6 +102,7 @@ export async function unlockTrain(code: string, trainId: number) {
|
||||
return t;
|
||||
});
|
||||
guildTrain = await GuildTrainModel.openGuildTrain(code, trainId, instances);
|
||||
await GuildTrainReportModel.resetGuildTrainReport(code, trainId);
|
||||
await GuildModel.updateInfo(code, {trainId}, {});
|
||||
|
||||
return guildTrain;
|
||||
@@ -136,7 +112,9 @@ export async function resetTrain(code: string, serverId: number) {
|
||||
let res:any = await lockData(serverId, GUILD_DATA_NAME.GUILD, code);//加锁
|
||||
if (!!res.err)
|
||||
return;
|
||||
let guild = await GuildModel.resetGuildTrain(code, serverId);
|
||||
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
|
||||
let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.TRAIN});
|
||||
let guild = await GuildModel.resetGuildTrain(code, serverId, lv);
|
||||
if (!guild) {
|
||||
res.releaseCallback();//解锁
|
||||
return;
|
||||
@@ -161,6 +139,7 @@ export async function resetTrain(code: string, serverId: number) {
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
for (let trainId = 1; trainId < guild.trainId; trainId++) {
|
||||
let { jinjieReward } = getArmyTrainJuDian(trainId);
|
||||
if (trainRewards.indexOf(trainId)) {
|
||||
|
||||
Reference in New Issue
Block a user