🐞 fix(gvg): 添加确认队伍

This commit is contained in:
luying
2023-03-15 16:11:54 +08:00
parent e488e1f4db
commit 899cb3162e
4 changed files with 33 additions and 10 deletions
@@ -44,9 +44,10 @@ export class GVGBattleHandler {
// 获取我的编队信息 // 获取我的编队信息
async getTeams(msg: {}, session: BackendSession) { async getTeams(msg: {}, session: BackendSession) {
const roleId = session.get('roleId'); const roleId = session.get('roleId');
const teams = await GVGTeamModel.findByRole(roleId, '-_id teamCode index head frame spine lineup') let { configId } = getGVGConfig();
const teams = await GVGTeamModel.findByRole(roleId, '-_id teamCode index head frame spine lineup confirmConfigId')
return resResult(STATUS.SUCCESS, { teams: teams.map(team => new MyTeamSimpleInfo(team)) }); return resResult(STATUS.SUCCESS, { teams: teams.map(team => new MyTeamSimpleInfo(team, configId)) });
} }
// 保存队伍 // 保存队伍
@@ -96,7 +97,23 @@ export class GVGBattleHandler {
let teamObj = getGVGBattleData(groupKey); let teamObj = getGVGBattleData(groupKey);
teamObj.enterCity(team); teamObj.enterCity(team);
} }
return resResult(STATUS.SUCCESS, { curTeam: new MyTeamSimpleInfo(team) }); return resResult(STATUS.SUCCESS, { curTeam: new MyTeamSimpleInfo(team, configId) });
}
// 确认我的编队信息
async confirmTeam(msg: {}, session: BackendSession) {
const roleId = session.get('roleId');
const guildCode = session.get('guildCode');
const serverId = session.get('serverId');
let { configId, period } = getGVGPeriodData();
if (period != GVG_PERIOD.BATTLE) return resResult(STATUS.GVG_NOT_BATTLE_PERIOD);
let groupKey = await getGroupKey(serverId);
let myLeague = await GVGLeagueModel.findLeagueByGuild(guildCode);
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
let teams = await refreshTeams(configId, groupKey, roleId, myLeague, true);
return resResult(STATUS.SUCCESS, { teams: teams.map(team => new MyTeamSimpleInfo(team, configId)) });
} }
// 获取城池信息 // 获取城池信息
@@ -146,7 +163,7 @@ export class GVGBattleHandler {
if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST); if(!myLeague) return resResult(STATUS.GVG_LEAGUE_NOT_EXIST);
let groupKey = await getGroupKey(serverId); let groupKey = await getGroupKey(serverId);
let teams = await refreshTeams(configId, groupKey, roleId, myLeague); let teams = await refreshTeams(configId, groupKey, roleId, myLeague, false);
// 玩家队伍信息中城池id不一致,说明玩家已经进入了其他城池 // 玩家队伍信息中城池id不一致,说明玩家已经进入了其他城池
for(let { cityId: teamCityId } of teams) { for(let { cityId: teamCityId } of teams) {
if(teamCityId > 0 && teamCityId != cityId) { if(teamCityId > 0 && teamCityId != cityId) {
@@ -180,7 +197,7 @@ export class GVGBattleHandler {
// 初始化本城池的守擂机器人 // 初始化本城池的守擂机器人
await initRobots(configId, groupKey, city||{ cityId, guardLeague: '' }); await initRobots(configId, groupKey, city||{ cityId, guardLeague: '' });
// 每赛季初自己的几支队伍恢复耐久、城市、顺便更新一下自己的玩家名、联军 // 每赛季初自己的几支队伍恢复耐久、城市、顺便更新一下自己的玩家名、联军
let teams = await refreshTeams(configId, groupKey, roleId, myLeague); let teams = await refreshTeams(configId, groupKey, roleId, myLeague, true);
if(await GVGTeamModel.checkLockTeam(roleId, cityId)) return resResult(STATUS.GVG_BATTLE_TEAM_LOCK_ENTERY_CITY); if(await GVGTeamModel.checkLockTeam(roleId, cityId)) return resResult(STATUS.GVG_BATTLE_TEAM_LOCK_ENTERY_CITY);
let gvgUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId); let gvgUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
@@ -166,16 +166,17 @@ export function calBattleScoreByCe(isSuccess: boolean, lineupCe: number) {
return isSuccess? winScore: 0; return isSuccess? winScore: 0;
} }
export async function refreshTeams(configId: number, groupKey: string, roleId: string, myLeague: GVGLeagueType) { export async function refreshTeams(configId: number, groupKey: string, roleId: string, myLeague: GVGLeagueType, hasConfirm: boolean) {
let oldTeams = await GVGTeamModel.findByRole(roleId, '-_id'); let oldTeams = await GVGTeamModel.findByRole(roleId, '-_id');
let teams: GVGTeamType[] = []; let teams: GVGTeamType[] = [];
for(let team of oldTeams) { for(let team of oldTeams) {
if(team.configId != configId) { if(team.configId != configId || (hasConfirm && team.confirmConfigId != configId)) {
let { teamCode, maxDurability, lineup } = team; let { teamCode, maxDurability, lineup } = team;
let { lv, roleName, guildCode } = await RoleModel.findByRoleId(roleId, 'lv roleName guildCode'); let { lv, roleName, guildCode } = await RoleModel.findByRoleId(roleId, 'lv roleName guildCode');
let heroes = await HeroModel.findByHidRange(lineup.map(hero => hero.actorId), roleId); let heroes = await HeroModel.findByHidRange(lineup.map(hero => hero.actorId), roleId);
let { newLineup, newLineupCe } = await generNewLineup(roleId, heroes, lineup.map(({ actorId, dataId, outIndex }) => ({ actorId, dataId, order: outIndex }))); let { newLineup, newLineupCe } = await generNewLineup(roleId, heroes, lineup.map(({ actorId, dataId, outIndex }) => ({ actorId, dataId, order: outIndex })));
let newTeam = await GVGTeamModel.refreshByConfig(teamCode, { configId, lv, durability: maxDurability, cityId: 0, areaId: 0, pointId: 0, roleName, guildCode, leagueCode: myLeague.leagueCode, leagueName: myLeague.name, groupKey, lineup: newLineup, lineupCe: newLineupCe }); let addUpdate = hasConfirm? { confirmConfigId: configId }: {};
let newTeam = await GVGTeamModel.refreshByConfig(teamCode, { configId, lv, durability: maxDurability, cityId: 0, areaId: 0, pointId: 0, roleName, guildCode, leagueCode: myLeague.leagueCode, leagueName: myLeague.name, groupKey, lineup: newLineup, lineupCe: newLineupCe, ...addUpdate });
teams.push(newTeam); teams.push(newTeam);
} else { } else {
teams.push(team); teams.push(team);
+3
View File
@@ -17,6 +17,9 @@ export default class GVGTeam extends BaseModel {
@prop({ required: true }) @prop({ required: true })
configId: number; // 赛季,每赛季在enterCity的时候检测,如果不一样就更新durability那些东西 configId: number; // 赛季,每赛季在enterCity的时候检测,如果不一样就更新durability那些东西
@prop({ required: true })
confirmConfigId: number; // 是否确认过
@prop({ required: true }) @prop({ required: true })
roleId: string; // 玩家id roleId: string; // 玩家id
+3 -1
View File
@@ -770,14 +770,16 @@ export class MyTeamSimpleInfo {
dataId: number; // 出兵表上的位置 dataId: number; // 出兵表上的位置
order: number; // 行动 order: number; // 行动
}[]; }[];
hasConfirm: boolean;
constructor(team: GVGTeamType) { constructor(team: GVGTeamType, configId: number) {
this.teamCode = team.teamCode; this.teamCode = team.teamCode;
this.index = team.index; this.index = team.index;
this.head = team.head; this.head = team.head;
this.frame = team.frame; this.frame = team.frame;
this.spine = team.spine; this.spine = team.spine;
this.lineup = team.lineup.map(({ actorId, dataId, outIndex }) => ({ actorId, dataId, order: outIndex })); this.lineup = team.lineup.map(({ actorId, dataId, outIndex }) => ({ actorId, dataId, order: outIndex }));
this.hasConfirm = team.confirmConfigId == configId;
} }
} }