feat(gvg): 复活队伍

This commit is contained in:
luying
2023-02-17 16:45:24 +08:00
parent 40cffb7cc3
commit 8595c8d4ae
9 changed files with 114 additions and 33 deletions

View File

@@ -150,8 +150,14 @@ export default class GVGTeam extends BaseModel {
return teams;
}
// 获取的编队
public static async findByTeamCode(roleId: string, teamCode: string, select = '') {
// 获取某个玩家的某个的编队
public static async findMyTeamByCode(roleId: string, teamCode: string, select = '') {
const res: GVGTeamType = await GVGTeamModel.findOne({ roleId, teamCode }).select(select).lean();
return res;
}
// 获取编队
public static async findByCode(roleId: string, teamCode: string, select = '') {
const res: GVGTeamType = await GVGTeamModel.findOne({ roleId, teamCode }).select(select).lean();
return res;
}
@@ -256,31 +262,31 @@ export default class GVGTeam extends BaseModel {
}
// 结算挑战方
public static async battleEndAttack(teamCode: string, hpInc: number, playerScoreInc: number, rebirthAreaId: number) {
public static async battleEndAttack(teamCode: string, hpInc: number, playerScoreInc: number, rebirthAreaId: number, reviveCd: number) {
let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $inc: { durability: hpInc, score: playerScoreInc } }, { new: true }).lean();
if(team.durability <= 0) {
let originPointId = team.pointId;
team = await GVGTeamModel.teamBreak(teamCode, team.isRobot, team.maxDurability, rebirthAreaId);
team = await GVGTeamModel.teamBreak(teamCode, team.isRobot, team.maxDurability, rebirthAreaId, reviveCd);
team.originPointId = originPointId;
}
return team;
}
// 结算防守方
public static async battleEndDefense(teamCode: string, hpInc: number, playerScoreInc: number, rebirthAreaId: number) {
public static async battleEndDefense(teamCode: string, hpInc: number, playerScoreInc: number, rebirthAreaId: number, reviveCd: number) {
let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { defenseTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD, lockTime: 0, lockTeamCode: '' }, $inc: { durability: hpInc, score: playerScoreInc } }, { new: true }).lean();
if(team.durability <= 0) {
let originPointId = team.pointId;
team = await GVGTeamModel.teamBreak(teamCode, team.isRobot, team.maxDurability, rebirthAreaId);
team = await GVGTeamModel.teamBreak(teamCode, team.isRobot, team.maxDurability, rebirthAreaId, reviveCd);
team.originPointId = originPointId;
}
return team;
}
// 队伍进入修整器
public static async teamBreak(teamCode: string, isRobot: boolean, maxDurability: number, areaId: number) {
public static async teamBreak(teamCode: string, isRobot: boolean, maxDurability: number, areaId: number, reviveCd: number) {
if(!isRobot) {
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { restartTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD, stopMoveTime: nowSeconds(), areaId, durability: maxDurability } }, { new: true }).lean();
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { restartTime: nowSeconds() - reviveCd, stopMoveTime: nowSeconds(), areaId, durability: maxDurability } }, { new: true }).lean();
team.curTeamBreak = true;
return team;
} else {
@@ -332,6 +338,11 @@ export default class GVGTeam extends BaseModel {
return team;
}
// 复活
public static async reviveTeam(teamCode: string) {
let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { restartTime: 0 } }, { new: true }).lean();
return team;
}
}
export const GVGTeamModel = getModelForClass(GVGTeam);

View File

@@ -79,6 +79,9 @@ export default class GVGUserData extends BaseModel {
@prop({ required: false })
cityId: number; // 城池id
@prop({ required: false })
reviveCnt: number; // 城池id
public static async findByRole(configId: number, leagueCode: string, roleId: string) {
const result: GVGUserDataType = await GVGUserDataModel.findOneAndUpdate({ configId, leagueCode, roleId }, {}, { new: true, upsert: true}).lean();
return result;
@@ -130,6 +133,11 @@ export default class GVGUserData extends BaseModel {
return result;
}
public static async addReviveCnt(configId: number, leagueCode: string, roleId: string, cnt: number) {
const result: GVGUserDataType = await GVGUserDataModel.findOneAndUpdate({ configId, leagueCode, roleId }, { $inc: { reviveCnt: cnt } }, { new: true, upsert: true}).lean();
return result;
}
}
export const GVGUserDataModel = getModelForClass(GVGUserData);