军团表逻辑
This commit is contained in:
@@ -3,6 +3,7 @@ import { getJobInfoById } from '../pubUtils/gamedata';
|
||||
import { getTodayZeroPoint, nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { GUILD_REPORT_NUM } from '../consts/constModules/guildConst';
|
||||
import { GuildTrainType, GuildTrainModel } from '../db/GuildTrain';
|
||||
import { GuildModel } from '../db/Guild';
|
||||
import { findWhere } from 'underscore';
|
||||
export async function getUserGuild(roleId: string, code: string) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(roleId,'trainCount trainTime trainRewards');
|
||||
@@ -28,31 +29,64 @@ export async function recordUserGuild(roleId: string, code: string) {
|
||||
return userGuild;
|
||||
}
|
||||
|
||||
export function getGuildTrain (guildTrains, trainCount:number, trainRewards: Array<number>) {
|
||||
let list = [];
|
||||
list = guildTrains.map(({trainId, isComplete})=>{
|
||||
return ({trainId, isComplete, });
|
||||
});
|
||||
return { list, trainCount, trainRewards};
|
||||
}
|
||||
|
||||
export function getGuildTrainInfo (guildTrains: Array<GuildTrainType>, roleId: string, trainCount:number, trainRewards: Array<number>) {
|
||||
guildTrains.forEach(({trainId, isComplete, trainScripts, ranks, reports})=>{
|
||||
export function getGuildTrainRewards (guildTrain) {
|
||||
let trainBoxs = guildTrain.trainScripts.map(({hid, trainBoxs})=>{
|
||||
return {hid, recordBoxs: 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, trainScripts, ranks, reports})=>{
|
||||
if (trainIds.indexOf(trainId) == -1) {
|
||||
return;
|
||||
}
|
||||
ranks.sort(function(a, b) {
|
||||
return b.score - a.score;
|
||||
});
|
||||
let myRank = {};
|
||||
ranks.forEach(({roleId: rankRoleId, score}, index)=>{
|
||||
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 guildTrain = findWhere(guildTrains, { trainId: trainId - 1});
|
||||
if (!!guildTrain) {
|
||||
let lenNum = guildTrain.reports.length;
|
||||
let resTrainBoxs = [];
|
||||
let resTrainScripts = trainScripts.map(({hid, progress, time, trainBoxs})=>{
|
||||
resTrainBoxs.push({hid, recordBoxs: trainBoxs});
|
||||
return {hid, progress, time};
|
||||
})
|
||||
let lastGuildTrain = findWhere(guildTrains, { trainId: trainId - 1});
|
||||
if (!!lastGuildTrain) {
|
||||
let lenNum = lastGuildTrain.reports.length;
|
||||
if (lenNum < GUILD_REPORT_NUM)
|
||||
reports = [...guildTrain.reports, ...reports]
|
||||
reports = [...lastGuildTrain.reports, ...reports];
|
||||
else {
|
||||
let trainReports = guildTrain.reports.splice(lenNum - GUILD_REPORT_NUM - 1, GUILD_REPORT_NUM);
|
||||
reports = [...trainReports, ...reports]
|
||||
let trainReports = lastGuildTrain.reports.splice(lenNum - GUILD_REPORT_NUM - 1, GUILD_REPORT_NUM);
|
||||
reports = [...trainReports, ...reports];
|
||||
}
|
||||
let flag = false;
|
||||
let lastTrainBoxs = lastGuildTrain.trainScripts.map(({hid, time, trainBoxs}) => {
|
||||
if (time + 24 * 60 * 60 < nowSeconds()) {
|
||||
flag = true;
|
||||
}
|
||||
return {};
|
||||
});
|
||||
if (flag) {
|
||||
resTrainBoxs.push(...lastTrainBoxs);
|
||||
}
|
||||
}
|
||||
return {trainId, isComplete, trainScripts, reports, myRank, ranks};
|
||||
guildTrain = {trainId, isComplete, trainScripts: resTrainScripts, trainBoxs: resTrainBoxs, reports, myRank, ranks: resRanks};
|
||||
});
|
||||
return { list: guildTrains, trainCount, trainRewards};
|
||||
return { guildTrain, trainCount, trainRewards};
|
||||
}
|
||||
|
||||
export async function lockTrain(code: string, trainId: number) {
|
||||
@@ -60,5 +94,8 @@ export async function lockTrain(code: string, trainId: number) {
|
||||
if (!!guildTrain) {
|
||||
return;
|
||||
}
|
||||
|
||||
let trainScripts;
|
||||
guildTrain = await GuildTrainModel.openGuildTrain(code, trainId, trainScripts);
|
||||
await GuildModel.updateInfo(code, {trainId});
|
||||
return guildTrain;
|
||||
}
|
||||
Reference in New Issue
Block a user