🐞 fix(gvg): 完善队伍的刷新
This commit is contained in:
@@ -7,7 +7,7 @@ import { Application, BackendSession, ChannelService, HandlerService, pinus } fr
|
|||||||
import { resResult, genCode } from "../../../pubUtils/util";
|
import { resResult, genCode } from "../../../pubUtils/util";
|
||||||
import { GVGLeagueModel } from '../../../db/GVGLeague';
|
import { GVGLeagueModel } from '../../../db/GVGLeague';
|
||||||
import { getGroupKey, getGVGConfig, getGVGPeriodData, getGVGServerType } from '../../../services/gvg/gvgService';
|
import { getGroupKey, getGVGConfig, getGVGPeriodData, getGVGServerType } from '../../../services/gvg/gvgService';
|
||||||
import { redisAddBattleScore, battleEndSendMessage, calBattleScoreByCe, checkAreaIsInCity, checkGVGBattleStart, checkMoveStatus, getBattleRanksByCity, getBirthAreaOfCity, getGVGWarId, getOppHeroes, getTechKnifeHurt, getTechReviveMinus, initRobots, pushTeamMoveMessage, getGVGCitiesInfo, leaveCity, refreshTeams, checkEnterCityTime } from '../../../services/gvg/gvgBattleService';
|
import { redisAddBattleScore, battleEndSendMessage, calBattleScoreByCe, checkAreaIsInCity, checkGVGBattleStart, checkMoveStatus, getBattleRanksByCity, getBirthAreaOfCity, getGVGWarId, getOppHeroes, getTechKnifeHurt, getTechReviveMinus, initRobots, pushTeamMoveMessage, getGVGCitiesInfo, leaveCity, refreshTeams, checkEnterCityTime, generNewLineup } from '../../../services/gvg/gvgBattleService';
|
||||||
import { getGVGBattleData } from '../../../services/gvg/gvgBattleMemory';
|
import { getGVGBattleData } from '../../../services/gvg/gvgBattleMemory';
|
||||||
import { GVGBattleRecModel } from '../../../db/GVGBattleRec';
|
import { GVGBattleRecModel } from '../../../db/GVGBattleRec';
|
||||||
import { getFightTimeByPeriod } from '../../../services/gvg/gvgFightService';
|
import { getFightTimeByPeriod } from '../../../services/gvg/gvgFightService';
|
||||||
@@ -77,30 +77,11 @@ export class GVGBattleHandler {
|
|||||||
let groupKey = await getGroupKey(serverId);
|
let groupKey = await getGroupKey(serverId);
|
||||||
let updateParam: SaveTeamUpdateParam = { index, head, spine, frame, configId, groupKey }
|
let updateParam: SaveTeamUpdateParam = { index, head, spine, frame, configId, groupKey }
|
||||||
if(lineup) {
|
if(lineup) {
|
||||||
let attrByHid = await getHeroesAttributes(roleId);
|
|
||||||
let { isOK, heroes } = await checkBattleHeroesByHid(roleId, lineup.map(cur => cur.actorId));
|
let { isOK, heroes } = await checkBattleHeroesByHid(roleId, lineup.map(cur => cur.actorId));
|
||||||
if(!isOK) return resResult(STATUS.BATTLE_HERO_NOT_FOUND);
|
if(!isOK) return resResult(STATUS.BATTLE_HERO_NOT_FOUND);
|
||||||
let newLineup: GVGHeroInfo[] = [];
|
let { newLineup, newLineupCe } = await generNewLineup(roleId, heroes, lineup);
|
||||||
for(let { actorId, dataId, order } of lineup) {
|
|
||||||
let hero = heroes.find(cur => cur.hid == actorId);
|
|
||||||
if(hero) {
|
|
||||||
let artifact = hero.artifact? await ArtifactModel.findbySeqId(roleId, hero.artifact): null;
|
|
||||||
let heroInfo = new GVGHeroInfo();
|
|
||||||
heroInfo.setHeroInfo(hero, artifact);
|
|
||||||
heroInfo.setDataId(dataId, order);
|
|
||||||
|
|
||||||
let attr = attrByHid.get(actorId);
|
|
||||||
if(!attr) continue;
|
|
||||||
let attribute = attr.getAttributesToString();
|
|
||||||
heroInfo.setAttribute(attribute);
|
|
||||||
|
|
||||||
newLineup.push(heroInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let lineupCe = heroes.reduce((pre, cur) => pre + cur.ce, 0);
|
|
||||||
updateParam.lineup = newLineup;
|
updateParam.lineup = newLineup;
|
||||||
updateParam.lineupCe = lineupCe;
|
updateParam.lineupCe = newLineupCe;
|
||||||
}
|
}
|
||||||
let originTeam = await GVGTeamModel.findByRoleAndIndex(roleId, index, 'cityId');
|
let originTeam = await GVGTeamModel.findByRoleAndIndex(roleId, index, 'cityId');
|
||||||
if(!originTeam && cityId > 0) {
|
if(!originTeam && cityId > 0) {
|
||||||
@@ -113,6 +94,7 @@ export class GVGBattleHandler {
|
|||||||
if (!team) {
|
if (!team) {
|
||||||
return resResult(STATUS.GVG_SAVE_TEAM_FAILED);
|
return resResult(STATUS.GVG_SAVE_TEAM_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cityId > 0) {
|
if(cityId > 0) {
|
||||||
let teamObj = getGVGBattleData(groupKey);
|
let teamObj = getGVGBattleData(groupKey);
|
||||||
teamObj.enterCity(team);
|
teamObj.enterCity(team);
|
||||||
@@ -192,7 +174,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, roleName, guildCode, myLeague);
|
let teams = await refreshTeams(configId, groupKey, roleId, myLeague);
|
||||||
|
|
||||||
let gvgUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
|
let gvgUserData = await GVGUserDataModel.findByRole(configId, myLeague.leagueCode, roleId);
|
||||||
let originCityId = gvgUserData?.cityId||0;
|
let originCityId = gvgUserData?.cityId||0;
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ class GVGBattleData {
|
|||||||
|
|
||||||
if(!this.teams.has(team.teamCode)) {
|
if(!this.teams.has(team.teamCode)) {
|
||||||
this.teams.set(team.teamCode, new GVGTeamMem(team))
|
this.teams.set(team.teamCode, new GVGTeamMem(team))
|
||||||
|
} else {
|
||||||
|
this.teams.get(team.teamCode).updateTeam(team);
|
||||||
}
|
}
|
||||||
this.teams.get(team.teamCode).setCity(team.cityId, team.areaId, team.pointId);
|
this.teams.get(team.teamCode).setCity(team.cityId, team.areaId, team.pointId);
|
||||||
if(team.pointId > 0 && !team.isRobot) {
|
if(team.pointId > 0 && !team.isRobot) {
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ import { GVGUserDataModel } from "../../db/GVGUserData";
|
|||||||
import { RoleModel } from "../../db/Role";
|
import { RoleModel } from "../../db/Role";
|
||||||
import { getFightTimeByPeriod } from "./gvgFightService";
|
import { getFightTimeByPeriod } from "./gvgFightService";
|
||||||
import { getRandSingleEelm } from "../../pubUtils/util";
|
import { getRandSingleEelm } from "../../pubUtils/util";
|
||||||
|
import { HeroModel, HeroType } from "../../db/Hero";
|
||||||
|
import { ArtifactModel } from "../../db/Artifact";
|
||||||
|
import { getHeroesAttributes } from "../playerCeService";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取本联军上周占领的城池
|
* 获取本联军上周占领的城池
|
||||||
@@ -152,14 +155,16 @@ 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, roleName: string, guildCode: string, myLeague: GVGLeagueType) {
|
export async function refreshTeams(configId: number, groupKey: string, roleId: string, myLeague: GVGLeagueType) {
|
||||||
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) {
|
||||||
let { teamCode, maxDurability } = team;
|
let { teamCode, maxDurability, lineup } = team;
|
||||||
let { lv } = await RoleModel.findByRoleId(roleId, 'lv');
|
let { lv, roleName, guildCode } = await RoleModel.findByRoleId(roleId, 'lv roleName guildCode');
|
||||||
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 });
|
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 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 });
|
||||||
teams.push(newTeam);
|
teams.push(newTeam);
|
||||||
} else {
|
} else {
|
||||||
teams.push(team);
|
teams.push(team);
|
||||||
@@ -168,6 +173,29 @@ export async function refreshTeams(configId: number, groupKey: string, roleId: s
|
|||||||
return teams
|
return teams
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function generNewLineup(roleId: string, heroes: HeroType[], lineup: { actorId: number, dataId: number, order: number }[]) {
|
||||||
|
let attrByHid = await getHeroesAttributes(roleId);
|
||||||
|
let newLineup: GVGHeroInfo[] = [], newLineupCe = 0;
|
||||||
|
for(let { actorId, dataId, order } of lineup) {
|
||||||
|
let hero = heroes.find(cur => cur.hid == actorId);
|
||||||
|
if(hero) {
|
||||||
|
let artifact = hero.artifact? await ArtifactModel.findbySeqId(roleId, hero.artifact): null;
|
||||||
|
let heroInfo = new GVGHeroInfo();
|
||||||
|
heroInfo.setHeroInfo(hero, artifact);
|
||||||
|
heroInfo.setDataId(dataId, order);
|
||||||
|
|
||||||
|
let attr = attrByHid.get(actorId);
|
||||||
|
if(!attr) continue;
|
||||||
|
let attribute = attr.getAttributesToString();
|
||||||
|
heroInfo.setAttribute(attribute);
|
||||||
|
|
||||||
|
newLineup.push(heroInfo);
|
||||||
|
newLineupCe += hero.ce;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { newLineup, newLineupCe };
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 离开城池
|
* 离开城池
|
||||||
* 当玩家占领据点的时候,可以保留据点;不占领的时候,不保留;退出游戏的时候,全不保留
|
* 当玩家占领据点的时候,可以保留据点;不占领的时候,不保留;退出游戏的时候,全不保留
|
||||||
@@ -194,6 +222,13 @@ export async function leaveCity(isForce: boolean, roleId: string, serverId: numb
|
|||||||
// 处理内存数据
|
// 处理内存数据
|
||||||
let teamObj = getGVGBattleData(groupKey);
|
let teamObj = getGVGBattleData(groupKey);
|
||||||
teamObj.leaveCity(roleId);
|
teamObj.leaveCity(roleId);
|
||||||
|
for(let team of teams) {
|
||||||
|
if(team.cityId > 0 && team.areaId > 0) {
|
||||||
|
await sendMessageToGVGAreaByTeamWithSuc(groupKey, team.areaId, PUSH_ROUTE.GVG_PLAYER_LEAVE_AREA, {
|
||||||
|
cityId: team.cityId, areaId: team.areaId, teamCode: team.teamCode
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,7 +367,6 @@ export async function catapultHurt() {
|
|||||||
if(!catapult || catapult.isBroken || !dicGVGCity || battleAreaIds.length <= 0) continue;
|
if(!catapult || catapult.isBroken || !dicGVGCity || battleAreaIds.length <= 0) continue;
|
||||||
let areaId = getRandSingleEelm(battleAreaIds);
|
let areaId = getRandSingleEelm(battleAreaIds);
|
||||||
let teamCodes = teamObj.findCatapultAttackTeam(areaId, catapult.leagueCode);
|
let teamCodes = teamObj.findCatapultAttackTeam(areaId, catapult.leagueCode);
|
||||||
console.log('##### targetAreaId', catapult.teamCode, areaId);
|
|
||||||
|
|
||||||
let teams = await GVGTeamModel.attackByCatapult(teamCodes, catapult.captapultAtk, dicGVGCity.attackBirth);
|
let teams = await GVGTeamModel.attackByCatapult(teamCodes, catapult.captapultAtk, dicGVGCity.attackBirth);
|
||||||
teamObj.battleEnd(teams);
|
teamObj.battleEnd(teams);
|
||||||
@@ -554,7 +588,9 @@ export async function pushTeamBeHurtMessage(team: GVGTeamType, replaceTeam?: GVG
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await pushTeamMoveMessage(team);
|
if(team.curTeamBreak) {
|
||||||
|
await pushTeamMoveMessage(team);
|
||||||
|
}
|
||||||
if(team.isRobot && team.isBroken) {
|
if(team.isRobot && team.isBroken) {
|
||||||
await sendMessageToGVGAreaByTeamWithSuc(team.groupKey, team.fromAreaId, PUSH_ROUTE.GVG_PLAYER_LEAVE_AREA, {
|
await sendMessageToGVGAreaByTeamWithSuc(team.groupKey, team.fromAreaId, PUSH_ROUTE.GVG_PLAYER_LEAVE_AREA, {
|
||||||
cityId: team.cityId, areaId: team.fromAreaId, teamCode: team.teamCode
|
cityId: team.cityId, areaId: team.fromAreaId, teamCode: team.teamCode
|
||||||
@@ -571,7 +607,7 @@ export async function pushTeamMoveMessage(team: GVGTeamType) {
|
|||||||
}
|
}
|
||||||
if(team.areaId > 0) {
|
if(team.areaId > 0) {
|
||||||
await sendMessageToGVGAreaByTeamWithSuc(team.groupKey, team.areaId, PUSH_ROUTE.GVG_PLAYER_AREA_ADD, {
|
await sendMessageToGVGAreaByTeamWithSuc(team.groupKey, team.areaId, PUSH_ROUTE.GVG_PLAYER_AREA_ADD, {
|
||||||
cityId: team.cityId, areaId: team.fromAreaId, player: new GVGTeamInList(team)
|
cityId: team.cityId, areaId: team.areaId, fromAreaId: team.fromAreaId, player: new GVGTeamInList(team)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export class GVGTeamMem extends GVGTeam {
|
|||||||
|
|
||||||
public updateTeam(team: GVGTeamType) {
|
public updateTeam(team: GVGTeamType) {
|
||||||
for(let key in team) {
|
for(let key in team) {
|
||||||
|
if(key == 'lineup' || key == '_id' || key == 'createdAt' || key == 'updatedAt') continue;
|
||||||
this[key] = team[key];
|
this[key] = team[key];
|
||||||
}
|
}
|
||||||
this.isMoving = this.stopMoveTime > nowSeconds();
|
this.isMoving = this.stopMoveTime > nowSeconds();
|
||||||
|
|||||||
Reference in New Issue
Block a user