寻宝助战次数限制; 调整寻宝字段
This commit is contained in:
@@ -31,6 +31,8 @@ class ComTeam {
|
||||
ceLimit: number;
|
||||
// boss 血量
|
||||
bossHp: number;
|
||||
// 品质
|
||||
quality: number;
|
||||
}
|
||||
export class ComBattleHandler {
|
||||
constructor(private app: Application) {
|
||||
@@ -39,6 +41,7 @@ export class ComBattleHandler {
|
||||
|
||||
async createTeam(msg: {blueprtId: number, heroes: [ number ], pub: boolean, ceLimit: number}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let sid = session.get('sid');
|
||||
let teamCode = session.get('teamCode');
|
||||
const { blueprtId, heroes, pub, ceLimit } = msg;
|
||||
@@ -54,13 +57,14 @@ export class ComBattleHandler {
|
||||
let blueprt = consumeGoods.find(good => good.id === blueprtId && good.count >= 1);
|
||||
if (!blueprt) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_FOUND);
|
||||
// 检查是否有已创建未结束的寻宝,预先占用一张藏宝图
|
||||
let teams = await ComBattleTeamModel.findTeamByCapAndStatus(roleId, COM_TEAM_STATUS.FIGHTING);
|
||||
let teams = await ComBattleTeamModel.getTeamByCapAndStatus(roleId, COM_TEAM_STATUS.FIGHTING);
|
||||
if (teams && blueprt.count <= teams.length) return resResult(STATUS.COM_BATTLE_BLUEPRT_NOT_ENOUGH);
|
||||
// TODO: 检查武将是否拥有
|
||||
|
||||
// 创建队伍数据结构
|
||||
let comTeam = new ComTeam();
|
||||
comTeam.blueprtId = blueprtId;
|
||||
comTeam.quality = goodData.quality;
|
||||
comTeam.capId = roleId;
|
||||
comTeam.pub = pub;
|
||||
comTeam.teamCode = teamCode;
|
||||
@@ -77,6 +81,7 @@ export class ComBattleHandler {
|
||||
roleStatus.roleId = roleId;
|
||||
roleStatus.isReady = true;
|
||||
roleStatus.totalDmg = 0;
|
||||
roleStatus.roleName = roleName;
|
||||
comTeam.roleStatus = [roleStatus];
|
||||
|
||||
this.teamMap.set(teamCode, comTeam);
|
||||
@@ -96,16 +101,16 @@ export class ComBattleHandler {
|
||||
|
||||
async joinTeam(msg: {teamCode: string, isFrd: boolean}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let sid = session.get('sid');
|
||||
console.log('teamMap:' + JSON.stringify(this.teamMap));
|
||||
let { teamCode, isFrd } = msg;
|
||||
let teamStatus = this.teamMap.get(teamCode);
|
||||
if (!teamStatus || teamStatus.status !== 0 || teamStatus.roleIds.length === 3) return resResult(STATUS.COM_BATTLE_MEMBER_LIMIT);
|
||||
if (teamStatus.roleIds.indexOf(roleId) !== -1) return resResult(STATUS.COM_BATTLE_DUP_ENTER);
|
||||
// TODO: 助战次数限制
|
||||
let { lv, headHid, topFiveCe } = await Role.findByRoleId(roleId);
|
||||
let { quality } = getGoodById(teamStatus.blueprtId);
|
||||
let { assistanceLevel } = getComBtlSetByQuality(quality);
|
||||
let { assistanceLevel, assistanceTime } = getComBtlSetByQuality(quality);
|
||||
if (lv < COM_TEAM_ENABLE_LV) {
|
||||
return resResult(STATUS.COM_BATTLE_LV_NOT_ENOUGH);
|
||||
} else if (lv < assistanceLevel) {
|
||||
@@ -114,12 +119,16 @@ export class ComBattleHandler {
|
||||
return resResult(STATUS.COM_BATTLE_CE_LIMIT);
|
||||
}
|
||||
|
||||
let teams = await ComBattleTeamModel.getTeamByRoleAndTime(roleId, teamStatus.quality, new Date(new Date().setHours(0, 0, 0, 0)));
|
||||
if (teams.length >= assistanceTime) resResult(STATUS.COM_BATTLE_ASSIST_NOT_ENOUGH);
|
||||
|
||||
let roleStatus = new RoleStatus();
|
||||
roleStatus.heroes = [];
|
||||
roleStatus.isCap = false;
|
||||
roleStatus.headHid = headHid || 1;
|
||||
roleStatus.topFiveCe = topFiveCe || 0;
|
||||
roleStatus.roleId = roleId;
|
||||
roleStatus.roleName = roleName;
|
||||
roleStatus.isFrd = isFrd;
|
||||
roleStatus.isReady = false;
|
||||
roleStatus.totalDmg = 0;
|
||||
|
||||
@@ -5,6 +5,8 @@ export class RoleStatus {
|
||||
@prop({ required: true })
|
||||
roleId: string;
|
||||
@prop({ required: true })
|
||||
roleName: string;
|
||||
@prop({ required: true })
|
||||
isCap: boolean;
|
||||
@prop({ required: true, default: 0 })
|
||||
totalDmg: number;
|
||||
@@ -54,6 +56,10 @@ export default class ComBattleTeam extends BaseModel {
|
||||
@prop({ required: true })
|
||||
blueprtId: number;
|
||||
|
||||
// 藏宝图品质
|
||||
@prop({ required: true })
|
||||
quality: number;
|
||||
|
||||
// 战斗状态 0:未开始,1:已开始,2:胜利,3:失败,4:已领奖
|
||||
@prop({ required: true, default: 0 })
|
||||
status: number;
|
||||
@@ -69,7 +75,7 @@ export default class ComBattleTeam extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
ceLimit: number;
|
||||
|
||||
public static async createTeam(teamData: {teamCode: string, roleIds: Array<string>, pub: boolean, blueprtId: number, status: number, roleStatus: Array<RoleStatus>, capId: string}, lean = true) {
|
||||
public static async createTeam(teamData: {teamCode: string, roleIds: Array<string>, pub: boolean, blueprtId: number, quality: number, status: number, roleStatus: Array<RoleStatus>, capId: string, ceLimit: number}, lean = true) {
|
||||
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode: teamData.teamCode }, {$set :{...teamData}}, {upsert: true, new: true}).lean(lean);
|
||||
return team;
|
||||
}
|
||||
@@ -121,7 +127,7 @@ export default class ComBattleTeam extends BaseModel {
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async findTeamByCapAndStatus(roleId: string, status: number, lean = true) {
|
||||
public static async getTeamByCapAndStatus(roleId: string, status: number, lean = true) {
|
||||
const teams = await ComBattleTeamModel.find({capId: roleId, status}).lean(lean);
|
||||
return teams;
|
||||
}
|
||||
@@ -130,6 +136,11 @@ export default class ComBattleTeam extends BaseModel {
|
||||
const teams = await ComBattleTeamModel.find({blueprtId: {$in: blueprtIds}, status, pub}).limit(limit).lean(lean);
|
||||
return teams;
|
||||
}
|
||||
|
||||
public static async getTeamByRoleAndTime(roleId: string, quality: number, time: Date, lean = true) {
|
||||
const teams = await ComBattleTeamModel.find({roleIds: roleId, quality, createdAt: {$gte: time}}).lean(lean);
|
||||
return teams;
|
||||
}
|
||||
}
|
||||
|
||||
export const ComBattleTeamModel = getModelForClass(ComBattleTeam);
|
||||
Reference in New Issue
Block a user