✨ feat(gvg): 激战期挑战相关接口整理
This commit is contained in:
@@ -13,7 +13,7 @@ class TeamInfo {
|
||||
teamCode: string; // 玩家队伍唯一标识
|
||||
|
||||
@prop({ required: true })
|
||||
teamId: number; // 队伍id,1-3,玩家的第几个队伍
|
||||
index: number; // 队伍id,1-3,玩家的第几个队伍
|
||||
|
||||
@prop({ required: true })
|
||||
leagueCode: string; // 联军
|
||||
@@ -62,7 +62,7 @@ export default class GVGBattleRec extends BaseModel {
|
||||
|
||||
public static async createRec(attackTeam: GVGTeamType, defenseTeam: GVGTeamType) {
|
||||
const battleCode = genCode(8);
|
||||
const result: GVGBattleRecType = await GVGBattleRecModel.findOneAndUpdate({ battleCode }, { $set: { attackTeam, defenseTeam, isSuccess: false } }).lean();
|
||||
const result: GVGBattleRecType = await GVGBattleRecModel.findOneAndUpdate({ battleCode }, { $set: { attackTeam, defenseTeam, isSuccess: false } }, { new: true, upsert: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+90
-57
@@ -6,12 +6,16 @@ import { LineupHero } from './../domain/roleField/hero';
|
||||
import { nowSeconds } from "../pubUtils/timeUtil";
|
||||
import { GVG } from "../pubUtils/dicParam";
|
||||
import { DicGVGAreaPoint } from "../pubUtils/dictionary/DicGVGAreaPoint";
|
||||
import { InitTeamParam, SaveTeamUpdateParam } from "../domain/gvgField/gvgDb";
|
||||
|
||||
@index({ roleId: 1, teamId: 1 })
|
||||
@index({ roleId: 1, index: 1 })
|
||||
@index({ teamCode: 1 })
|
||||
@index({ cityId: 1, leagueId: 1 })
|
||||
export default class GVGTeam extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
configId: number; // 赛季,每赛季在enterCity的时候检测,如果不一样就更新durability那些东西
|
||||
|
||||
@prop({ required: true })
|
||||
roleId: string; // 玩家id
|
||||
|
||||
@@ -25,7 +29,7 @@ export default class GVGTeam extends BaseModel {
|
||||
teamCode: string; // 玩家队伍唯一标识
|
||||
|
||||
@prop({ required: true })
|
||||
teamId: number; // 队伍id,1-3,玩家的第几个队伍
|
||||
index: number; // 队伍id,1-3,玩家的第几个队伍
|
||||
|
||||
@prop({ required: true })
|
||||
leagueCode: string; // 联军
|
||||
@@ -66,6 +70,12 @@ export default class GVGTeam extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
attackTime: number; // 进攻冷却时间
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
lockTime: number; // 正在被进攻中
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
attackTeam: string; // 正在被这支队伍进攻中
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
fromAreaId: number; // 从那个区域移动
|
||||
|
||||
@@ -79,7 +89,10 @@ export default class GVGTeam extends BaseModel {
|
||||
defenseTime: number; // 防守保护时间
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
point: number; // 积分
|
||||
playerScore: number; // 积分
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
leagueScore: number; // 积分
|
||||
|
||||
@prop({ required: true, type: () => LineupHero, _id: false })
|
||||
lineup: LineupHero[];
|
||||
@@ -96,57 +109,34 @@ export default class GVGTeam extends BaseModel {
|
||||
@prop({ required: true, default: false })
|
||||
isRobot: boolean; // 是否是机器人
|
||||
|
||||
@prop({ required: true, default: false })
|
||||
isCatapult: boolean; // 是否是投石车
|
||||
|
||||
@prop({ required: true, default: false })
|
||||
isBroken: boolean; // 机器人是否被击破,如果没有被击破,那么这个位置上就还是机器人,如果被击破了,这个位置就空出给玩家
|
||||
|
||||
// 创建队伍
|
||||
public static async createTeam(roleId: string, roleName: string, serverId: number, leagueCode: string, leagueName: string, teamId: number, head: number, spine: number, frame: number, durability: number, lineup: [LineupHero], lineupCe: number) {
|
||||
public static async saveTeam(roleId: string, index: number, updateParam: SaveTeamUpdateParam, initParam: InitTeamParam) {
|
||||
const doc = new GVGTeamModel();
|
||||
const teamCode = genCode(8);
|
||||
const update = Object.assign(doc.toJSON(), { roleId, roleName, serverId, leagueCode, leagueName, teamId, teamCode, head, spine, frame, lineup, durability, maxDurability: durability, lineupCe });
|
||||
const team: GVGTeamType | null = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $setOnInsert: update }, { upsert: true, new: true }).lean();
|
||||
const insert = Object.assign(doc.toJSON(), { ...initParam, teamCode });
|
||||
delete insert.lineup;
|
||||
const team: GVGTeamType | null = await GVGTeamModel.findOneAndUpdate({ roleId, index }, { $setOnInsert: insert, $set: updateParam }, { upsert: true, new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 保存队伍
|
||||
public static async saveTeam(roleId: string, roleName: string, serverId: number, leagueCode: string, leagueName: string, teamId: number, head: number, spine: number, frame: number, durability: number, lineup: [LineupHero], lineupCe: number) {
|
||||
let team: GVGTeamType = await GVGTeamModel.findOne({ roleId, teamId }).lean();
|
||||
if (!team) {
|
||||
team = await this.createTeam(roleId, roleName, serverId, leagueCode, leagueName, teamId, head, spine, frame, durability, lineup, lineupCe);
|
||||
return team;
|
||||
}
|
||||
|
||||
const update = { head, spine, frame };
|
||||
if (lineup && lineup.length > 0) {
|
||||
update['lineup'] = lineup;
|
||||
}
|
||||
team = await GVGTeamModel.findOneAndUpdate({ roleId, teamId }, { update }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 查找角色队伍数
|
||||
public static async getTeamCntByRole(roleId: string) {
|
||||
const teams: GVGTeamType[] = await GVGTeamModel.find({ roleId }).select('teamCode').lean();
|
||||
return teams.length;
|
||||
}
|
||||
|
||||
// 通过城池ID获取队伍数
|
||||
public static async getTeamCntByCity(cityId: number, leagueCode?: string) {
|
||||
const query = { cityId };
|
||||
if (leagueCode) {
|
||||
query['leagueCode'] = leagueCode;
|
||||
}
|
||||
const teams: GVGTeamType[] = await GVGTeamModel.find(query).select('').lean();
|
||||
return teams.length;
|
||||
}
|
||||
|
||||
public static async checkCity(roleId: string, cityId: number, groupId: number, serverType: number) {
|
||||
return await GVGTeamModel.exists({ roleId, cityId, groupId, serverType });
|
||||
}
|
||||
|
||||
// 玩家切换城池更新队伍信息
|
||||
public static async enterCity(roleId: string, cityId: number, areaId: number, groupId: number, serverType: number) {
|
||||
const res = await GVGTeamModel.updateMany({ roleId }, { cityId, areaId, pointId: 0, groupId, serverType }).lean();
|
||||
return !!res['ok'];
|
||||
}
|
||||
|
||||
// 查找角色队伍数
|
||||
public static async getTeamCntByRole(roleId: string) {
|
||||
const teams: GVGTeamType[] = await GVGTeamModel.find({ roleId }).select('teamCode').lean();
|
||||
return teams.length;
|
||||
}
|
||||
|
||||
// 获取我的编队
|
||||
public static async findByRole(roleId: string, select = '') {
|
||||
const teams: GVGTeamType[] = await GVGTeamModel.find({ roleId }).select(select).lean();
|
||||
@@ -161,12 +151,12 @@ export default class GVGTeam extends BaseModel {
|
||||
|
||||
// 移动
|
||||
public static async startMove(teamCode: string, areaId: number, fromAreaId: number) {
|
||||
const res: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { areaId, fromAreaId, stopMoveTime: nowSeconds() + GVG.GVG_DEFAULT_MOVE_CD } }).lean();
|
||||
const res: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { areaId, fromAreaId, stopMoveTime: nowSeconds() + GVG.GVG_DEFAULT_MOVE_CD } }, { new: true }).lean();
|
||||
return res;
|
||||
}
|
||||
|
||||
public static async stopMove(teamCode: string, areaId: number) {
|
||||
const res: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { areaId, fromAreaId: 0, stopMoveTime: nowSeconds() } }).lean();
|
||||
const res: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { areaId, fromAreaId: 0, stopMoveTime: nowSeconds() } }, { new: true }).lean();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -180,40 +170,83 @@ export default class GVGTeam extends BaseModel {
|
||||
}
|
||||
return { attackTeam, defenseTeam }
|
||||
}
|
||||
|
||||
public static async checkRobot(groupId: number, serverType: number, cityId: number) {
|
||||
return await GVGTeamModel.exists({ groupId, serverType, cityId, isRobot: true });
|
||||
}
|
||||
|
||||
public static async initRobots(groupId: number, serverType: number, cityId: number, dicPoints: DicGVGAreaPoint[]) {
|
||||
await GVGTeamModel.bulkWrite(dicPoints.map(dic => {
|
||||
// 每赛季初刷新自己的耐久等东西
|
||||
public static async refreshByConfig(roleId: string, updateArr: GVGTeamUpdate[]) {
|
||||
await GVGTeamModel.bulkWrite(updateArr.map(obj => {
|
||||
return {
|
||||
updateOne: {
|
||||
filter: { groupId, serverType, cityId, pointId: dic.pointId },
|
||||
update: { $setOnInsert: { teamCode: `robot${dic.pointId}`, ...dic, roleName: dic.name, isRobot: true } }, upsert: true
|
||||
filter: { roleId, teamCode: obj.teamCode },
|
||||
update: { $set: obj }
|
||||
}
|
||||
}
|
||||
}));
|
||||
return await GVGTeamModel.findByRole(roleId, '-_id');
|
||||
}
|
||||
|
||||
public static async findRobotTeams(groupId: number, serverType: number, cityId: number) {
|
||||
const team: GVGTeamType[] = await GVGTeamModel.find({ groupId, serverType, cityId, isRobot: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 每赛季初刷新机器人
|
||||
public static async initRobots(configId: number, groupId: number, serverType: number, cityId: number, dicPoints: DicGVGAreaPoint[]) {
|
||||
await GVGTeamModel.bulkWrite(dicPoints.map(({ pointId, areaId, name, head, spine, ce, durability }) => {
|
||||
return {
|
||||
updateOne: {
|
||||
filter: { groupId, serverType, cityId, areaId, pointId },
|
||||
update: { $setOnInsert: { teamCode: genCode(8), maxDurability: durability, roleName: name, head, spine, lineupCe: ce, isRobot: true, isBroken: false, startMoveTime: 0, stopMoveTime: 0 }, $set: { configId, durability } },
|
||||
upsert: true
|
||||
}
|
||||
}
|
||||
}));
|
||||
return await this.findRobotTeams(groupId, serverType, cityId);
|
||||
}
|
||||
|
||||
// 攻击方攻击cd
|
||||
public static async lockAttack(teamCode: string, groupId: number, serverType: number) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { attackTime: nowSeconds() + GVG.GVG_DEFAULT_ATTACK_CD, groupId, serverType } }, { new: true }).lean();
|
||||
public static async battleStartLockAttack(teamCode: string) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { attackTime: nowSeconds() + GVG.GVG_DEFAULT_ATTACK_CD } }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 防守方防守cd
|
||||
public static async lockDefense(teamCode: string, groupId: number, serverType: number) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { attackTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD, groupId, serverType } }, { new: true }).lean();
|
||||
// 防守方锁定cd
|
||||
public static async battleStartLockDefense(teamCode: string, attackTeam: string) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { lockTime: nowSeconds() + GVG.GVG_DEFAULT_ATTACK_CD, attackTeam } }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 结算挑战方
|
||||
public static async battleEndAttack(teamCode: string, hpInc: number, playerScoreInc: number, leagueScoreInc: number) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $inc: { durability: hpInc, playerScore: playerScoreInc, leagueScore: leagueScoreInc } }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 结算防守方
|
||||
public static async battleEndDefense(teamCode: string, hpInc: number, playerScoreInc: number) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { defenseTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD }, $inc: { durability: hpInc, playerScore: playerScoreInc } }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
// 队伍进入修整器
|
||||
public static async teamBreak(teamCode: string, isRobot: boolean, maxDurability: number, areaId: 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();
|
||||
return team;
|
||||
} else {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { durability: 0, isBroken: true } }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
}
|
||||
|
||||
public static async findByAreaId(groupId: number, serverType: number, cityId: number, areaId: number) {
|
||||
const team: GVGTeamType[] = await GVGTeamModel.find({ groupId, serverType, cityId, areaId, stopMoveTime: { $lte: nowSeconds() } }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
public static async findByConfigId(configId: number) {
|
||||
const team: GVGTeamType[] = await GVGTeamModel.find({ configId, cityId: { $gt: 0 } }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user