🐞 fix(gvg): 完善队伍的刷新
This commit is contained in:
@@ -25,6 +25,9 @@ import { GVGUserDataModel } from "../../db/GVGUserData";
|
||||
import { RoleModel } from "../../db/Role";
|
||||
import { getFightTimeByPeriod } from "./gvgFightService";
|
||||
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;
|
||||
}
|
||||
|
||||
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 teams: GVGTeamType[] = [];
|
||||
for(let team of oldTeams) {
|
||||
if(team.configId != configId) {
|
||||
let { teamCode, maxDurability } = team;
|
||||
let { lv } = await RoleModel.findByRoleId(roleId, 'lv');
|
||||
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 { teamCode, maxDurability, lineup } = team;
|
||||
let { lv, roleName, guildCode } = await RoleModel.findByRoleId(roleId, 'lv roleName guildCode');
|
||||
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);
|
||||
} else {
|
||||
teams.push(team);
|
||||
@@ -168,6 +173,29 @@ export async function refreshTeams(configId: number, groupKey: string, roleId: s
|
||||
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);
|
||||
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;
|
||||
let areaId = getRandSingleEelm(battleAreaIds);
|
||||
let teamCodes = teamObj.findCatapultAttackTeam(areaId, catapult.leagueCode);
|
||||
console.log('##### targetAreaId', catapult.teamCode, areaId);
|
||||
|
||||
let teams = await GVGTeamModel.attackByCatapult(teamCodes, catapult.captapultAtk, dicGVGCity.attackBirth);
|
||||
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) {
|
||||
await sendMessageToGVGAreaByTeamWithSuc(team.groupKey, team.fromAreaId, PUSH_ROUTE.GVG_PLAYER_LEAVE_AREA, {
|
||||
cityId: team.cityId, areaId: team.fromAreaId, teamCode: team.teamCode
|
||||
@@ -571,7 +607,7 @@ export async function pushTeamMoveMessage(team: GVGTeamType) {
|
||||
}
|
||||
if(team.areaId > 0) {
|
||||
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)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user