寻宝:清理匹配成功的玩家信息;修复机器人和匹配条件等bug
This commit is contained in:
@@ -96,18 +96,22 @@ export default class ComBattleTeam extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
ceLimit: number;
|
||||
|
||||
// 队伍中人数
|
||||
@prop({ required: true, default: 1 })
|
||||
roleCnt: number;
|
||||
|
||||
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, roleCnt: teamData.roleIds.length}}, {upsert: true, new: true}).lean(lean);
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async addRole(teamCode: string, roleStatus: RoleStatus, lean = true) {
|
||||
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode }, {$push: {roleIds: roleStatus.roleId, roleStatus}}, {new: true}).lean(lean);
|
||||
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode }, {$push: {roleIds: roleStatus.roleId, roleStatus}, $inc: {roleCnt: 1}}, {new: true}).lean(lean);
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async removeRole(teamCode: string, roleIdToRm: string, lean = true) {
|
||||
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode }, {$pull: {roleIds: roleIdToRm, roleStatus: {roleId: roleIdToRm}}}, {new: true}).lean(lean);
|
||||
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode }, {$pull: {roleIds: roleIdToRm, roleStatus: {roleId: roleIdToRm}}, $inc: {roleCnt: -1}}, {new: true}).lean(lean);
|
||||
return team;
|
||||
}
|
||||
|
||||
@@ -122,7 +126,7 @@ export default class ComBattleTeam extends BaseModel {
|
||||
}
|
||||
|
||||
public static async syncTeamData(teamData: {teamCode: string, status: number, roleStatus: Array<RoleStatus>}, lean = true) {
|
||||
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode: teamData.teamCode }, {$set :{...teamData}}, {new: true}).lean(lean);
|
||||
const team = await ComBattleTeamModel.findOneAndUpdate({ teamCode: teamData.teamCode }, {$set :{...teamData, roleCnt: teamData.roleStatus.length}}, {new: true}).lean(lean);
|
||||
return team;
|
||||
}
|
||||
|
||||
@@ -168,8 +172,8 @@ export default class ComBattleTeam extends BaseModel {
|
||||
return teams;
|
||||
}
|
||||
|
||||
public static async getOneTeamByQualityAndSt(qualityArr: Array<number>, status: number, ce = 0, pub = true, lean = true) {
|
||||
const team = await ComBattleTeamModel.findOne({quality: {$in: qualityArr}, status, ceLimit: {$lte: ce}, pub}).lean(lean);
|
||||
public static async getOneTeamByQualityAndSt(qualityArr: Array<number>, status: number, ce = 0, pub = true, cntLmt = 2, lean = true) {
|
||||
const team = await ComBattleTeamModel.findOne({quality: {$in: qualityArr}, status, ceLimit: {$lte: ce}, pub, roleCnt: {$lte: cntLmt}}).lean(lean);
|
||||
return team;
|
||||
}
|
||||
|
||||
|
||||
@@ -251,13 +251,15 @@ export function getRandEelm(source: Array<any> = [], cnt = 1): Array<any> {
|
||||
if (cnt > source.length) return [];
|
||||
if (cnt === source.length) return source;
|
||||
let idxs = new Set();
|
||||
for (let i = 0; i < cnt; ++i) {
|
||||
|
||||
while(1) {
|
||||
let rand = Math.floor(Math.random() * source.length);
|
||||
idxs.add(rand);
|
||||
if (idxs.size == cnt) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return source.filter((_item, idx) => idxs.has(idx));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user