炼器堂,练兵场,事件开启,redlock注释
This commit is contained in:
@@ -64,7 +64,7 @@ export class GuildTrainHandler {
|
||||
trainReports.map(({ reports: resReports, trainId: resTrainId})=>{
|
||||
if (resTrainId != trainId) {
|
||||
let lenNum = resReports.length;
|
||||
resReports = resReports.splice(lenNum - GUILD_REPORT_NUM - 1, GUILD_REPORT_NUM);
|
||||
resReports = resReports.splice(lenNum - GUILD_REPORT_NUM - 1, GUILD_REPORT_NUM);//获得上场的战报的信息与本次战报合并
|
||||
}
|
||||
reports.push(...resReports);
|
||||
});
|
||||
@@ -79,7 +79,7 @@ export class GuildTrainHandler {
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let guildTrains = await GuildTrainModel.findGuildTrain(code);
|
||||
let guildTrains = await GuildTrainModel.findGuildTrain(code);//获得未失效的宝箱奖励
|
||||
let resTrainBoxs = [];
|
||||
guildTrains.forEach(({trainInstances, trainId}) =>{
|
||||
let { trainInstances: instances } = getArmyTrainJuDian(trainId);
|
||||
@@ -101,7 +101,11 @@ export class GuildTrainHandler {
|
||||
})
|
||||
return resResult(STATUS.SUCCESS, {trainBoxRewards: resTrainBoxs});
|
||||
}
|
||||
|
||||
/**
|
||||
* 挑战练兵副本
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
async trainBattleStart(msg: { hid: number, trainId: number, difficulty: number }, session: BackendSession) {
|
||||
const { hid, difficulty, trainId } = msg;
|
||||
const roleId = session.get('roleId');
|
||||
@@ -139,7 +143,11 @@ export class GuildTrainHandler {
|
||||
}, true);
|
||||
return resResult(STATUS.SUCCESS, { battleCode });
|
||||
}
|
||||
|
||||
/**
|
||||
* 战斗结算
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
async trainBattleEnd(msg: { battleCode: string, isSuccess: boolean}, session: BackendSession) {
|
||||
const { battleCode, isSuccess } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
@@ -160,14 +168,14 @@ export class GuildTrainHandler {
|
||||
}
|
||||
|
||||
if (time < getCurHourPoint(REFRESH_HOUR) && nowSeconds() > getCurHourPoint(REFRESH_HOUR)) {
|
||||
return resResult(STATUS.GUILD_TRAIN_IS_RESETED);//关卡已经重置
|
||||
return resResult(STATUS.GUILD_TRAIN_IS_RESETED);//重置前进入战斗,重置后回调该接口
|
||||
}
|
||||
if (time > getHourPoint(REFRESH_HOUR)) {
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, {}, { trainCount: -1 });
|
||||
userGuild = await UserGuildModel.updateInfo(roleId, {}, { trainCount: -1 });//扣除一次挑战次数
|
||||
}
|
||||
await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
||||
$set: { status: isSuccess?1:2 }
|
||||
}, true);
|
||||
}, true);//设置战斗状态
|
||||
|
||||
let trainId = battleRecord.record.trainId;
|
||||
let hid = battleRecord.record.hid;
|
||||
@@ -187,31 +195,32 @@ export class GuildTrainHandler {
|
||||
|
||||
let { trainInstances, soloRewardRatio } = getArmyTrainJuDian(trainId);
|
||||
let instance = findWhere(trainInstances, { hid });
|
||||
if (!instance) {
|
||||
if (!instance) {//校验是否存在该关卡
|
||||
res.releaseCallback();//解锁
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
let trainSoloReward = getTrainSoloReward(battleRecord.record.difficulty);
|
||||
if (!trainSoloReward) {
|
||||
if (!trainSoloReward) {//获得个人奖励信息
|
||||
res.releaseCallback();//解锁
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
let addScore = Math.floor((isSuccess?trainSoloReward.winScore:trainSoloReward.failScore));
|
||||
let addScore = Math.floor((isSuccess?trainSoloReward.winScore:trainSoloReward.failScore));//个人获得积分,也是压制进度
|
||||
//个人功勋奖励
|
||||
let goods = await addItems(roleId, roleName, sid, [{id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count: (isSuccess?trainSoloReward.failHonour:trainSoloReward.failHonour) * (soloRewardRatio + 100 ) / 100}]);
|
||||
//是否压制
|
||||
let { isComplete, ranks } = guildTrain;
|
||||
let reports = [];
|
||||
let index = findIndex(ranks, {roleId});
|
||||
if (index !== -1) {
|
||||
ranks[index].score += addScore;
|
||||
ranks[index].score += addScore;//更新原有的排名信息
|
||||
} else {
|
||||
ranks.push({score: addScore, roleId});
|
||||
ranks.push({score: addScore, roleId});//新增排名
|
||||
}
|
||||
let needLockNext = false;
|
||||
let report = {roleName, trainId, hid, score: addScore, time: nowSeconds(), type: isSuccess?2:1, difficulty: battleRecord.record.difficulty};//1表示普通战报, 2表示系统战报即:被成功压制
|
||||
let report = {roleName, trainId, hid, score: addScore, time: nowSeconds(), type: isSuccess?2:1, difficulty: battleRecord.record.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})=>{
|
||||
@@ -225,28 +234,35 @@ export class GuildTrainHandler {
|
||||
}
|
||||
let progress = instance.progress;
|
||||
guildTrain = await GuildTrainModel.updateGuildTrainProgress(code, trainId, hid, progress, ranks, isComplete);
|
||||
if (needLockNext) { //
|
||||
if (needLockNext) {
|
||||
//type 1:失败, 2:成功,3:表示系统战报即:被成功压制
|
||||
reports.push({ type: 3, time:nowSeconds(), score: addScore, roleName, trainId, hid, difficulty: battleRecord.record.difficulty });
|
||||
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);
|
||||
await GuildTrainReportModel.pushGuildTrainReports(code, trainId, reports);//增加战报
|
||||
let { trainCount, trainRewards } = userGuild;
|
||||
let result:any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);
|
||||
let result:any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);//战斗后更新练兵场信息
|
||||
result.battleGoods = goods;
|
||||
await addActive(roleId, serverId, GUILD_POINT_WAYS.TRAIN);
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取练兵场宝箱 hid:副本id,index:领取位置
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
async getTrainInstanceBox(msg: { trainId: number , hid: number, index: number}, session: BackendSession) {
|
||||
let { trainId, hid, index } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
@@ -273,6 +289,7 @@ export class GuildTrainHandler {
|
||||
}
|
||||
let trainInstance = findWhere(guildTrain.trainInstances, { hid });
|
||||
if (trainInstance.endTime < nowSeconds()) {
|
||||
//宝箱失效
|
||||
res.releaseCallback();//解锁
|
||||
return resResult(STATUS.GUILD_TRAIN_BOX_IS_OVER_TIME);
|
||||
}
|
||||
@@ -301,7 +318,11 @@ export class GuildTrainHandler {
|
||||
result.goods = goods;
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取练兵试炼等级奖励
|
||||
* @param msg
|
||||
* @param session
|
||||
*/
|
||||
async getTrainLvUpRewards(msg: {trainId: number }, session: BackendSession) {
|
||||
let { trainId } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
Reference in New Issue
Block a user