✨ feat(军团): 练兵场添加扫荡
This commit is contained in:
@@ -255,7 +255,7 @@ export class GuildTrainHandler {
|
||||
|
||||
await GuildTrainReportModel.pushGuildTrainReports(code, trainId, reports);//增加战报
|
||||
let { trainCount, trainRewards } = userGuild;
|
||||
let result: any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);//战斗后更新练兵场信息
|
||||
let result: any = await getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);//战斗后更新练兵场信息
|
||||
result.battleGoods = goods;
|
||||
result.createdAt = time;
|
||||
await addActive(roleId, serverId, GUILD_POINT_WAYS.TRAIN);
|
||||
@@ -270,6 +270,119 @@ export class GuildTrainHandler {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 练兵场扫荡
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
async trainBattleSweep(msg: guildInter & { hid: number, difficulty: number, trainId: number, battleId: number }, session: BackendSession) {
|
||||
|
||||
const { hid, difficulty, trainId, battleId, myUserGuild } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = parseInt(session.get('serverId'));
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid: string = session.get('sid');
|
||||
|
||||
let userGuild = await refreshTrain(myUserGuild, roleId, serverId);
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
if (userGuild.trainCount - 1 < 0) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
let hasPassed = await BattleRecordModel.getBattleRecordByIdAndStatus(roleId, battleId, 1);
|
||||
if(!hasPassed) return resResult(STATUS.GUILD_TRAIN_CANNOT_SWEEP);
|
||||
|
||||
let { trainLv } = await GuildModel.findGuild(code, serverId, 'trainLv');
|
||||
let maxTrainId = gameData.lastGuildTrainIdOfLv.get(trainLv);
|
||||
let res: any = await lockData(serverId, DATA_NAME.TRAIN, code + '_' + trainId);//加锁
|
||||
if (!!res.err)
|
||||
return resResult(STATUS.REDLOCK_ERR);
|
||||
|
||||
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId);
|
||||
if (!guildTrain) {
|
||||
res.releaseCallback();//解锁
|
||||
return resResult(STATUS.GUILD_TRAIN_SCRIPT_NOT_OPENED);
|
||||
}
|
||||
let trainInstance = findWhere(guildTrain.trainInstances, { hid });
|
||||
if (!trainInstance) {
|
||||
res.releaseCallback();//解锁
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
let { trainInstances } = getArmyTrainJuDian(trainId);
|
||||
let dicWar = gameData.war.get(battleId);
|
||||
if(!dicWar) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
|
||||
let instance = findWhere(trainInstances, { hid });
|
||||
if (!instance) {//校验是否存在该关卡
|
||||
res.releaseCallback();//解锁
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, {}, { trainCount: -1 });//扣除一次挑战次数
|
||||
let score = dicWar.winReward.get(TRAIN_REWARD_TYPE.SCORE);
|
||||
let item = dicWar.winReward.get(TRAIN_REWARD_TYPE.ITEM);
|
||||
let addScore = Math.floor(<number>score);//个人获得积分,也是压制进度
|
||||
//个人功勋奖励
|
||||
let goods = await addItems(roleId, roleName, sid, <RewardInter[]>item, ITEM_CHANGE_REASON.TRAIN_BATTLE_END);
|
||||
let { isComplete, ranks } = guildTrain;
|
||||
let reports = [];
|
||||
let needLockNext = false;
|
||||
let report = { roleName, trainId, hid, score: addScore, time: nowSeconds(), type: 2, difficulty };//type 1:失败, 2:成功,3:表示系统战报即:被成功压制
|
||||
reports.push(report);
|
||||
if (trainInstance.progress < instance.progress) {
|
||||
if (trainInstance.progress + addScore >= instance.progress) {
|
||||
//压制成功
|
||||
if (!isComplete) {
|
||||
isComplete = true;
|
||||
guildTrain.trainInstances.forEach(({ hid: otherHid, progress }) => {
|
||||
if (hid != otherHid && progress != instance.progress) {
|
||||
isComplete = false;
|
||||
}
|
||||
});
|
||||
if (isComplete) { //解锁下一关
|
||||
needLockNext = true;
|
||||
}
|
||||
}
|
||||
let progress = instance.progress;
|
||||
guildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, isComplete);
|
||||
|
||||
//type 1:失败, 2:成功,3:表示系统战报即:被成功压制
|
||||
reports.push({ type: 3, time: nowSeconds(), score: addScore, roleName, trainId, hid, difficulty });
|
||||
pushGuildTrainSucMsg(roleId, roleName, code, hid);
|
||||
|
||||
|
||||
if (needLockNext && maxTrainId > trainId) {
|
||||
guildTrain = await unlockTrain(code, trainId + 1);
|
||||
}
|
||||
res.releaseCallback();//解锁
|
||||
} else {
|
||||
//压制失败,更新排行榜进度等信息
|
||||
let progress = trainInstance.progress + addScore;
|
||||
guildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, isComplete);
|
||||
res.releaseCallback();//解锁
|
||||
}
|
||||
} else {
|
||||
// //玩家结算前已经完成进度,修改玩家的排名
|
||||
// guildTrain = await GuildTrainModel.updateGuildTrain(code, trainId, { ranks });
|
||||
res.releaseCallback();//解锁
|
||||
}
|
||||
|
||||
await GuildTrainReportModel.pushGuildTrainReports(code, trainId, reports);//增加战报
|
||||
let { trainCount, trainRewards } = userGuild;
|
||||
let result: any = await getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);//战斗后更新练兵场信息
|
||||
result.goods = goods;
|
||||
await addActive(roleId, serverId, GUILD_POINT_WAYS.TRAIN);
|
||||
|
||||
// 任务
|
||||
await checkTaskInGuildTrain(serverId, roleId, sid, battleId, true, isComplete);
|
||||
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取练兵场宝箱 hid:副本id,index:领取位置
|
||||
* @param msg
|
||||
|
||||
Reference in New Issue
Block a user