关卡:星级记录
This commit is contained in:
@@ -12,7 +12,7 @@ import { STATUS } from '../../../consts/statusCode';
|
|||||||
import { resResult } from '../../../pubUtils/util';
|
import { resResult } from '../../../pubUtils/util';
|
||||||
import { RoleModel } from '../../../db/Role';
|
import { RoleModel } from '../../../db/Role';
|
||||||
import { RScriptRecordModel } from '../../../db/RScriptRecord';
|
import { RScriptRecordModel } from '../../../db/RScriptRecord';
|
||||||
import { updateWarStar, checkBattleHeroes, roleLevelup, getBattleList } from '../../../services/normalBattleService';
|
import { checkBattleHeroes, roleLevelup, getBattleList, calculateWarStar } from '../../../services/normalBattleService';
|
||||||
import { checkDungeonNum, checkDungeonAndIncrease, saveDungeonFirst } from '../../../services/dungeonService';
|
import { checkDungeonNum, checkDungeonAndIncrease, saveDungeonFirst } from '../../../services/dungeonService';
|
||||||
// import { switchOnFunc } from '../../../services/funcSwitchService';
|
// import { switchOnFunc } from '../../../services/funcSwitchService';
|
||||||
import { gameData } from '../../../pubUtils/data';
|
import { gameData } from '../../../pubUtils/data';
|
||||||
@@ -123,8 +123,8 @@ export class NormalBattleHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 关卡结算,记录使用的武将,获得奖励
|
// 关卡结算,记录使用的武将,获得奖励
|
||||||
async battleEnd(msg: { battleCode: string, battleId: number, isSuccess: boolean, star: number, heroes: Array<any>, activityId: number, pageIndex: number }, session: BackendSession) {
|
async battleEnd(msg: { battleCode: string, battleId: number, isSuccess: boolean, stars: number[], heroes: Array<any>, activityId: number, pageIndex: number }, session: BackendSession) {
|
||||||
const { battleCode, battleId, isSuccess, heroes = [], star, activityId, pageIndex } = msg;
|
const { battleCode, battleId, isSuccess, heroes = [], stars = [], activityId, pageIndex } = msg;
|
||||||
let roleId = session.get('roleId');
|
let roleId = session.get('roleId');
|
||||||
let roleName = session.get('roleName');
|
let roleName = session.get('roleName');
|
||||||
let sid = session.get('sid');
|
let sid = session.get('sid');
|
||||||
@@ -169,7 +169,7 @@ export class NormalBattleHandler {
|
|||||||
let dungeonNum = {};
|
let dungeonNum = {};
|
||||||
|
|
||||||
if (warInfo.warType == WAR_TYPE.DAILY) {
|
if (warInfo.warType == WAR_TYPE.DAILY) {
|
||||||
let checkResult = await checkDailyAndIncrease(roleId, [{ id: battleId, star, warType: warInfo.warType }, ...warStar], battleId, 1, false);
|
let checkResult = await checkDailyAndIncrease(roleId, warStar, battleId, 1, false, stars);
|
||||||
if (checkResult.status == -1) {
|
if (checkResult.status == -1) {
|
||||||
return checkResult.resResult;
|
return checkResult.resResult;
|
||||||
}
|
}
|
||||||
@@ -228,6 +228,8 @@ export class NormalBattleHandler {
|
|||||||
skipReward = !isFirst;
|
skipReward = !isFirst;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let curWarStar = warStar.find(cur => cur.id == battleId);
|
||||||
|
let { newWarStars, newStar } = calculateWarStar(warStar, battleId, stars);
|
||||||
|
|
||||||
if (isSuccess) { // 挑战胜利
|
if (isSuccess) { // 挑战胜利
|
||||||
// 是否首通
|
// 是否首通
|
||||||
@@ -239,11 +241,13 @@ export class NormalBattleHandler {
|
|||||||
pushVestigeFirstMsg(roleId, roleName, serverId, warInfo.warType, warInfo.war_id);
|
pushVestigeFirstMsg(roleId, roleName, serverId, warInfo.warType, warInfo.war_id);
|
||||||
}
|
}
|
||||||
// 是否首次3星
|
// 是否首次3星
|
||||||
if (star == 3 && (!condition1 || condition1.star != 3)) {
|
if (newStar == 3 && (!condition1 || condition1.star != 3)) {
|
||||||
warReward.setCondition(1, true);
|
warReward.setCondition(1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
await updateWarStar(roleId, battleId, warInfo.warType, star);
|
if (newStar > (curWarStar?.star||0)) {
|
||||||
|
await RoleModel.updateRoleInfo(roleId, { warStar: newWarStars });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let reward = null;
|
let reward = null;
|
||||||
@@ -252,13 +256,13 @@ export class NormalBattleHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const updateResult = await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
const updateResult = await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
||||||
$set: { status: isSuccess ? 1 : 2, star, record: { heroes } }
|
$set: { status: isSuccess ? 1 : 2, star: newStar, stars, record: { heroes } }
|
||||||
}, true);
|
}, true);
|
||||||
let { status } = updateResult;
|
let { status } = updateResult;
|
||||||
|
|
||||||
let actordata = await roleLevelup(KING_EXP_RATIO_TYPE.BATTLE, roleId, isSuccess ? warInfo.kingExp : 0, session);// 主公升级经验
|
let actordata = await roleLevelup(KING_EXP_RATIO_TYPE.BATTLE, roleId, isSuccess ? warInfo.kingExp : 0, session);// 主公升级经验
|
||||||
|
|
||||||
await checkTaskInBattleEnd(serverId, roleId, sid, battleId, dbHeroes, star);
|
await checkTaskInBattleEnd(serverId, roleId, sid, battleId, dbHeroes, newStar);
|
||||||
// 返回值:
|
// 返回值:
|
||||||
// towerStatus: false-本层未通过, true-本层已通过
|
// towerStatus: false-本层未通过, true-本层已通过
|
||||||
return resResult(STATUS.SUCCESS, {
|
return resResult(STATUS.SUCCESS, {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { gameData } from '../pubUtils/data';
|
|||||||
import { DicWar } from '../pubUtils/dictionary/DicWar';
|
import { DicWar } from '../pubUtils/dictionary/DicWar';
|
||||||
import { WarStar } from '../domain/dbGeneral';
|
import { WarStar } from '../domain/dbGeneral';
|
||||||
import * as dicParam from '../pubUtils/dicParam';
|
import * as dicParam from '../pubUtils/dicParam';
|
||||||
|
import { calculateWarStar } from './normalBattleService';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取全部每日关卡列表
|
* 获取全部每日关卡列表
|
||||||
@@ -86,11 +87,13 @@ export async function checkDaily(roleId: string, battleId: number, inc: number)
|
|||||||
* @param isRef 在计算之前是否检查每日的刷新
|
* @param isRef 在计算之前是否检查每日的刷新
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export async function checkDailyAndIncrease(roleId: string, warStar: WarStar[], battleId: number, inc: number, isRef: boolean) {
|
export async function checkDailyAndIncrease(roleId: string, warStar: WarStar[], battleId: number, inc: number, isRef: boolean, stars = []) {
|
||||||
|
let { newWarStars } = calculateWarStar(warStar, battleId, stars);
|
||||||
|
|
||||||
let dailyWar = gameData.war.get(battleId);
|
let dailyWar = gameData.war.get(battleId);
|
||||||
if(!dailyWar) return { status: -1, resResult: resResult(STATUS.DAILY_WAR_NOT_FOUND) };
|
if(!dailyWar) return { status: -1, resResult: resResult(STATUS.DAILY_WAR_NOT_FOUND) };
|
||||||
let type = dailyWar.dailyType;
|
let type = dailyWar.dailyType;
|
||||||
let war = getDailyWarStatus(dailyWar, warStar);
|
let war = getDailyWarStatus(dailyWar, newWarStars);
|
||||||
|
|
||||||
let curDaily = gameData.daily.find(cur => cur.dailyType == type);
|
let curDaily = gameData.daily.find(cur => cur.dailyType == type);
|
||||||
if(!curDaily) return { status: -1, resResult: resResult(STATUS.DAILY_TYPE_NOT_FOUND) };
|
if(!curDaily) return { status: -1, resResult: resResult(STATUS.DAILY_TYPE_NOT_FOUND) };
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { RScriptRecordModel } from '../db/RScriptRecord';
|
|||||||
import { setAp } from './actionPointService';
|
import { setAp } from './actionPointService';
|
||||||
import { resResult } from '../pubUtils/util';
|
import { resResult } from '../pubUtils/util';
|
||||||
import { LineupParam } from '../domain/rank';
|
import { LineupParam } from '../domain/rank';
|
||||||
|
import { WarStar } from '../domain/dbGeneral';
|
||||||
|
|
||||||
export async function roleLevelup(type: KING_EXP_RATIO_TYPE, roleId: string, kingExp: number = 0, session: BackendSession) {
|
export async function roleLevelup(type: KING_EXP_RATIO_TYPE, roleId: string, kingExp: number = 0, session: BackendSession) {
|
||||||
const serverId = session.get('serverId');
|
const serverId = session.get('serverId');
|
||||||
@@ -114,19 +115,30 @@ export async function checkBattleHeroesByHid(roleId: string, heroes: Array<numbe
|
|||||||
return { isOK: flag, heroes: findHeroes };
|
return { isOK: flag, heroes: findHeroes };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateWarStar(roleId: string, battleId: number, warType: number, star: number) {
|
export function calculateWarStar(warStar: WarStar[], battleId: number, stars: number[]) {
|
||||||
let role = await RoleModel.findByRoleId(roleId);
|
let newWarStars: WarStar[] = [];
|
||||||
let { warStar = new Array<{ id: number, warType: number, star: number }>() } = role;
|
let newStars: number[] = [], newStar = 0;
|
||||||
let curStar = warStar.find(cur => cur.id == battleId);
|
let hasFound = false;
|
||||||
let result: Role;
|
for(let curWarStar of warStar) {
|
||||||
if (curStar) {
|
if(curWarStar.id == battleId) {
|
||||||
if (star > curStar.star) {
|
for(let i = 0; i < 3; i++) {
|
||||||
result = await Role.updateWarStar(roleId, battleId, star);
|
let isOn = (curWarStar.stars[i] == 1)||(stars[i] == 1);
|
||||||
|
newStars.push(isOn? 1: 0);
|
||||||
|
if(isOn) newStar++;
|
||||||
|
}
|
||||||
|
newWarStars.push({...curWarStar, star: newStar, stars: newStars});
|
||||||
|
hasFound = true;
|
||||||
|
} else {
|
||||||
|
newWarStars.push(curWarStar);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
result = await RoleModel.pushWarStar(roleId, battleId, warType, star);
|
|
||||||
}
|
}
|
||||||
return result
|
if(!hasFound) {
|
||||||
|
newStar = stars.filter(cur => cur == 1).length;
|
||||||
|
newStars = stars;
|
||||||
|
let dicWar = gameData.war.get(battleId);
|
||||||
|
newWarStars.push({ id: battleId, warType: dicWar.warType, star: newStar, stars: newStars});
|
||||||
|
}
|
||||||
|
return { newWarStars, newStars, newStar };
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getBattleListOfMain(role: RoleType) {
|
export async function getBattleListOfMain(role: RoleType) {
|
||||||
@@ -151,21 +163,24 @@ export async function getBattleList(role: RoleType, type: number) {
|
|||||||
battleId,
|
battleId,
|
||||||
status: 0,
|
status: 0,
|
||||||
star: 0,
|
star: 0,
|
||||||
|
stars: [],
|
||||||
scriptBefore,
|
scriptBefore,
|
||||||
scriptAfter
|
scriptAfter
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
for (let { id, star, warType } of warStar) {
|
for (let { id, star, stars = [], warType } of warStar) {
|
||||||
if (warType == type) {
|
if (warType == type) {
|
||||||
let curResult = result.find(cur => cur.battleId == id);
|
let curResult = result.find(cur => cur.battleId == id);
|
||||||
if (curResult) {
|
if (curResult) {
|
||||||
curResult.status = 1;
|
curResult.status = 1;
|
||||||
curResult.star = star;
|
curResult.star = star;
|
||||||
|
curResult.stars = stars;
|
||||||
} else {
|
} else {
|
||||||
result.push({
|
result.push({
|
||||||
battleId: id,
|
battleId: id,
|
||||||
status: 1,
|
status: 1,
|
||||||
star,
|
star,
|
||||||
|
stars,
|
||||||
scriptBefore: '',
|
scriptBefore: '',
|
||||||
scriptAfter: ''
|
scriptAfter: ''
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ export default class BattleRecord extends BaseModel {
|
|||||||
@prop({ required: true, default: 0 })
|
@prop({ required: true, default: 0 })
|
||||||
status: number; // 关卡状态 0-挑战中 1-挑战成功 2-挑战失败
|
status: number; // 关卡状态 0-挑战中 1-挑战成功 2-挑战失败
|
||||||
@prop({ required: true, default: 0 })
|
@prop({ required: true, default: 0 })
|
||||||
star: number; // 关卡状态 0-挑战中 1-挑战成功 2-挑战失败
|
star: number; // 星级
|
||||||
|
@prop({ required: true, default: 0 })
|
||||||
|
stars: number[]; // 达成星星
|
||||||
@prop({ required: true, _id: false })
|
@prop({ required: true, _id: false })
|
||||||
record: Record; // 使用的武将等记录
|
record: Record; // 使用的武将等记录
|
||||||
|
|
||||||
|
|||||||
+2
-15
@@ -67,6 +67,8 @@ export class WarStar {
|
|||||||
warType: number; // 关卡类型
|
warType: number; // 关卡类型
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
star: number; // 星级
|
star: number; // 星级
|
||||||
|
@prop({ required: true, type: Number })
|
||||||
|
stars: number[]; // 星级
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Teraph {
|
export class Teraph {
|
||||||
@@ -460,21 +462,6 @@ export default class Role extends BaseModel {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async pushWarStar(roleId: string, battleId: number, warType: number, star: number, lean = true) {
|
|
||||||
let result: RoleType = await RoleModel.findOneAndUpdate({ roleId }, { $addToSet: { warStar: { id: battleId, warType, star } } }, { "new": true, "upsert": true }).lean(lean);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async updateWarStar(roleId: string, battleId: number, star: number, lean = true) {
|
|
||||||
let result: RoleType = await RoleModel.findOneAndUpdate(
|
|
||||||
{ roleId, 'warStar.id': battleId },
|
|
||||||
{ $set: { 'warStar.$.star': star } },
|
|
||||||
{ "new": true, "upsert": true }
|
|
||||||
).lean(lean);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static async hangUpSpdUp(roleId: string, cnt: number, curTime: Date) {
|
public static async hangUpSpdUp(roleId: string, cnt: number, curTime: Date) {
|
||||||
if (cnt < 0) return null;
|
if (cnt < 0) return null;
|
||||||
|
|||||||
@@ -188,6 +188,8 @@ export class WarStar {
|
|||||||
warType: number; // 关卡类型
|
warType: number; // 关卡类型
|
||||||
@prop({ required: true })
|
@prop({ required: true })
|
||||||
star: number; // 星级
|
star: number; // 星级
|
||||||
|
@prop({ required: true, type: Number })
|
||||||
|
stars: number[]; // 星级
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Teraph {
|
export class Teraph {
|
||||||
|
|||||||
Reference in New Issue
Block a user