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