🐞 fix(gvg): 修复gvg守城会出现一个联军3个城
This commit is contained in:
@@ -561,7 +561,7 @@ export async function calCityGuard(configId: number) {
|
||||
for(let [groupKey, cities] of sortCities) {
|
||||
let cityResult: number[] = [];
|
||||
let index = 0; // 防死循环,万一出什么事cityResult.length一直不等于cities.length
|
||||
|
||||
let guardLeagueCnt = new Map<string, number>();
|
||||
while(cityResult.length != cities.length && (++index < 1000)) {
|
||||
let sorted = cities
|
||||
.filter(city => cityResult.indexOf(city.cityId) == -1)
|
||||
@@ -571,8 +571,8 @@ export async function calCityGuard(configId: number) {
|
||||
return b.cityId - a.cityId;
|
||||
});
|
||||
|
||||
let guardLeagueCnt = new Map<string, number>();
|
||||
for(let { league: leagueCode, cityId } of sorted) {
|
||||
if(!leagueCode) continue;
|
||||
let cnt = guardLeagueCnt.get(leagueCode)||0;
|
||||
if(cnt < GVG.GVG_CITY_OCCUPIED_NUMBER) {
|
||||
await addGuardCity(configId, groupKey, cityId, leagueCode);
|
||||
@@ -619,11 +619,12 @@ async function generateData(configId: number, sortCities: Map<string, SortCities
|
||||
|
||||
let r = new Rank(REDIS_KEY.GVG_BATTLE_LEAGUE_RANK_BY_CITY, { configId, groupKey, cityId });
|
||||
let ranks = <LeagueRankInfo[]>await r.getRankByRange();
|
||||
let guardCity = lastCities.find(city => city.cityId == cityId && city.groupKey == groupKey);
|
||||
if(ranks.length <= 0) continue;
|
||||
if(!sortCities.has(groupKey)) sortCities.set(groupKey, []);
|
||||
sortCities.get(groupKey).push({ cityType: dicCity.cityType, cityId, index: 0, league: ranks.length > 0? ranks[0].code: (guardCity?.guardLeague), score: ranks.length > 0? ranks[0].num: 0 });
|
||||
sortCities.get(groupKey).push({ cityType: dicCity.cityType, cityId, index: 0, league: ranks[0].code, score: ranks[0].num });
|
||||
|
||||
if(!rankByCity.has(groupKey)) rankByCity.set(groupKey, new Map());
|
||||
let guardCity = lastCities.find(city => city.cityId == cityId && city.groupKey == groupKey);
|
||||
if(!rankByCity.get(groupKey).has(cityId)) rankByCity.get(groupKey).set(cityId, { ranks, lastLeague: guardCity?.guardLeague??'' })
|
||||
}
|
||||
for(let { groupKey, cityId, guardLeague } of lastCities) {
|
||||
@@ -641,9 +642,11 @@ async function generateData(configId: number, sortCities: Map<string, SortCities
|
||||
}
|
||||
|
||||
async function addGuardCity(configId: number, groupKey: string, cityId: number, leagueCode: string) {
|
||||
console.log('####### addGuardCity', configId, groupKey, cityId, leagueCode)
|
||||
let dicCity = gameData.gvgCity.get(cityId);
|
||||
let dicCityAdd = gameData.gvgCityAdd.get(dicCity.cityType);
|
||||
let league = await GVGLeagueModel.findByCodeWithoutPopulate(leagueCode);
|
||||
if(!league) return;
|
||||
await GVGCityModel.guardCity(configId, groupKey, cityId, league);
|
||||
await sendMailToLeagueByContent(MAIL_TYPE.GVG_GUARD_CITY_REWARD, leagueCode, { params: [dicCity.cityName], goods: dicCityAdd.occupyReward }, league);
|
||||
await addCityGuardMessage(league, cityId);
|
||||
|
||||
Reference in New Issue
Block a user