✨ feat(军团): 练兵场添加扫荡
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { UserGuildModel, UserGuildType } from '../db/UserGuild';
|
||||
import { getArmyTrainJuDian, getGuildTrainGkInfo, getTrainBaseByLv } from '../pubUtils/data';
|
||||
import { nowSeconds, getZeroPoint, isToday, getSeconds } from '../pubUtils/timeUtil';
|
||||
import { GUILD_STRUCTURE, PUSH_ROUTE, SHOP_REFRESH_TYPE } from '../consts';
|
||||
import { nowSeconds, getZeroPoint, isToday, getSeconds, getZeroPointD } from '../pubUtils/timeUtil';
|
||||
import { GUILD_STRUCTURE, PUSH_ROUTE, SHOP_REFRESH_TYPE, WAR_TYPE } from '../consts';
|
||||
import { GuildTrainType, GuildTrainModel, TrainInstance } from '../db/GuildTrain';
|
||||
import { GuildModel, GuildType } from '../db/Guild';
|
||||
import { findWhere } from 'underscore';
|
||||
@@ -18,6 +18,7 @@ import { MAIL_TYPE } from '../consts';
|
||||
import { getGuildChannelSid } from './chatChannelService';
|
||||
import { sendMessageToGuildWithSuc } from './pushService';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
import { BattleRecordModel } from '../db/BattleRecord';
|
||||
/**
|
||||
* 获得userGuild,并检查,是否需要每日重置购买挑战次数和今日挑战次数,已经检查是否需要每周重置练兵场
|
||||
* @param roleId
|
||||
@@ -125,25 +126,29 @@ export function getGuildTrainRewards (guildTrain) {
|
||||
* @param trainCount
|
||||
* @param trainRewards
|
||||
*/
|
||||
export function getGuildTrainInfo (guildTrain: GuildTrainType, roleId: string, trainCount:number, trainRewards: Array<number>) {
|
||||
export async 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;
|
||||
// });
|
||||
// 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, trainLv } = getArmyTrainJuDian(trainId);
|
||||
let { trainInstances: dicInstances, trainLv } = getArmyTrainJuDian(trainId);
|
||||
|
||||
let battleIds: number[] = [];
|
||||
for(let { hid } of dicInstances) {
|
||||
let trainInfo = getGuildTrainGkInfo(trainId, hid);
|
||||
if(trainInfo) battleIds.push(...trainInfo.difficulty);
|
||||
}
|
||||
|
||||
let battleRecords = await BattleRecordModel.findByBattleIds(roleId, battleIds, 1);
|
||||
|
||||
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 dicInstance = dicInstances.find(cur => cur.hid == hid);
|
||||
if(!dicInstance) return { hid, progress, endTime, isComplete: false, passedDifficult: [] }
|
||||
|
||||
let trainInfo = getGuildTrainGkInfo(trainId, hid);
|
||||
let passedDifficult = trainInfo.difficulty.filter(warId => {
|
||||
let battleRecord = battleRecords.find(record => record.battleId == warId);
|
||||
return !!battleRecord;
|
||||
})
|
||||
let isComplete = progress >= dicInstance.progress;
|
||||
return {hid, progress, endTime, isComplete, passedDifficult };
|
||||
});
|
||||
let resGuildTrain = {trainId, isComplete, trainInstances: resTrainInstances, myRank: 0, ranks: [] };
|
||||
|
||||
@@ -285,7 +290,7 @@ export async function getGuildTrainInstance(roleId: string, guild: GuildType, us
|
||||
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId);
|
||||
if (!guildTrain) return null
|
||||
let { trainCount, trainRewards, buyTrainCount } = userGuild;
|
||||
let result: any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);
|
||||
let result: any = await getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);
|
||||
result.buyTrainCount = buyTrainCount || 0;
|
||||
result.trainLv = trainLv;
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user