军团活动:修复bug
This commit is contained in:
@@ -25,7 +25,8 @@ export class GuildRemote {
|
||||
private DEMOTION = 'onDemotion';
|
||||
private PROMOTION = 'onPromotion';
|
||||
private GUILD_REC_ADD = 'onGuildRecAdd';
|
||||
private GUILD_ACT_RANK = 'onGuildGateRankUpdate'; // 军团活动排行榜
|
||||
private GATE_ACT_RANK = 'onGuildGateRankUpdate'; // 军团活动排行榜
|
||||
private CITY_ACT_RANK = 'onGuildCityRankUpdate'; // 军团活动排行榜
|
||||
private GUILD_GATE_ACT_HP = 'onGuildGateHpUpdate'; // 军团活动蛮夷入侵排行榜
|
||||
private GUILD_ACTIVITY_END = 'onGuildActivityEnd'; // 军团活动结束
|
||||
private GUILD_CITY_DECLARE = 'onGuildCityDeclare'; // 有军团对这个城池进行宣战了
|
||||
@@ -199,7 +200,15 @@ export class GuildRemote {
|
||||
* @param guildCode
|
||||
*/
|
||||
public pushRank(guildCode: string, msg: GuildGateRankParam) {
|
||||
this.pushMessage(guildCode, this.GUILD_ACT_RANK, msg);
|
||||
this.pushMessage(guildCode, this.GATE_ACT_RANK, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向军团推送排行榜名次
|
||||
* @param guildCode
|
||||
*/
|
||||
public pushCityActRank(guildCode: string, msg: GuildGateRankParam) {
|
||||
this.pushMessage(guildCode, this.CITY_ACT_RANK, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Application, ChannelService, BackendSession, pinus } from "pinus";
|
||||
import { GUILD_ACTIVITY_TYPE, STATUS, REDIS_KEY, GUILD_POINT_WAYS } from "../../../consts";
|
||||
import { GUILD_ACTIVITY_TYPE, STATUS, REDIS_KEY, GUILD_POINT_WAYS, CITY_STATUS } from "../../../consts";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { getGuildActivityStatus, getCityActivityObj, getCityStatus as pubGetCityStatus, getCities, getCityActivityRank } from "../../../services/guildActivityService";
|
||||
import { getGuildActivityStatus, getCityActivityObj, getCityStatus as pubGetCityStatus, getCities, getCityActivityRank, sendSingleCityActEndMsg } from "../../../services/guildActivityService";
|
||||
import { GuildActivityCityModel } from "../../../db/GuildActivityCity";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { UserGuildActivityRecModel } from "../../../db/UserGuildActivityRec";
|
||||
@@ -77,6 +77,9 @@ export class CityActivityHandler {
|
||||
|
||||
const dbCities = await GuildActivityCityModel.getAllCities(serverId);
|
||||
let cityStatus = pubGetCityStatus(guildCode, cityId, dicCity.preCity, dbCities);
|
||||
if(cityStatus == CITY_STATUS.DECLARED) {
|
||||
obj.pushGuild(guildCode, serverId, cityId);
|
||||
}
|
||||
|
||||
let historyCity = obj.getHistoryCity(roleId);
|
||||
if(historyCity) {
|
||||
@@ -219,9 +222,10 @@ export class CityActivityHandler {
|
||||
let pushResult = await UserGuildActivityRecModel.pushCityRecord(code, { round, hid, damage });
|
||||
if(!pushResult) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
gateHp = obj.getGateHpAndInc(serverId, cityId, -1 * damage);
|
||||
gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp, -1 * damage);
|
||||
if(gateHp <= 0) {
|
||||
// TODO 推送 停止活动并结算奖励
|
||||
// 推送 停止活动并结算奖励
|
||||
await sendSingleCityActEndMsg(cityId, serverId);
|
||||
}
|
||||
// 推送 城门血量
|
||||
let chatSid = await getCityChannelSid(cityId);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Application, BackendSession, ChannelService, pinus } from "pinus";
|
||||
import { getMedianCe, getGuildActivityStatus, getRecordScore, getGateActivityObj, sendSingleGateActEndMsg, sendGuildActEndMsg, participants, getGateActivityRank } from "../../../services/guildActivityService";
|
||||
import { getMedianCe, getGuildActivityStatus, getRecordScore, getGateActivityObj, sendSingleGateActEndMsg, participants, getGateActivityRank, getCityActivityObj } from "../../../services/guildActivityService";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { STATUS, GUILD_ACTIVITY_TYPE, GUILD_POINT_WAYS, ENEMIES_TYPE, GET_POINT_WAYS } from "../../../consts";
|
||||
import { GameModel } from "../../../db/Game";
|
||||
@@ -15,8 +15,9 @@ import { REDIS_KEY } from "../../../consts";
|
||||
import { addActive } from "../../../services/guildService";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { getGuildChannelSid } from "../../../services/chatService";
|
||||
import { guildActivityStart } from "../../../services/timeTaskService";
|
||||
import { guildActivityStart, gateActivityEnd, cityActivityEnd } from "../../../services/timeTaskService";
|
||||
import { UserGuildModel } from "../../../db/UserGuild";
|
||||
import { GuildActivityCityModel } from "../../../db/GuildActivityCity";
|
||||
|
||||
export default function (app: Application) {
|
||||
return new GateActivityHandler(app);
|
||||
@@ -311,7 +312,7 @@ export class GateActivityHandler {
|
||||
map.set(serverId, [code]);
|
||||
}
|
||||
}
|
||||
await delGuildActivityRank(map);
|
||||
await delGuildActivityRank(aid, map);
|
||||
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
@@ -319,7 +320,11 @@ export class GateActivityHandler {
|
||||
// ! 测试接口
|
||||
async debugEndActivity(msg: { aid: number }, session: BackendSession) {
|
||||
let { aid } = msg;
|
||||
await sendGuildActEndMsg(aid);
|
||||
if(aid == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
||||
await gateActivityEnd();
|
||||
} else if (aid == GUILD_ACTIVITY_TYPE.CITY_ACTIVITY) {
|
||||
await cityActivityEnd();
|
||||
}
|
||||
return resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@@ -216,6 +216,17 @@ export async function sendAllGuildRanks(aid: number) {
|
||||
pinus.app.rpc.chat.guildRemote.pushRank.toServer(chatSid, guildCode, ranks);
|
||||
}
|
||||
}
|
||||
} else if (aid == GUILD_ACTIVITY_TYPE.CITY_ACTIVITY) {
|
||||
let obj = getCityActivityObj();
|
||||
let { cities } = obj.getAllCities();
|
||||
console.log(JSON.stringify(cities));
|
||||
for(let { serverId, cityId, guildCodes } of cities) {
|
||||
for(let guildCode of guildCodes) {
|
||||
let ranks = await getCityActivityRank(guildCode, serverId, cityId);
|
||||
let chatSid = await getGuildChannelSid(guildCode);
|
||||
pinus.app.rpc.chat.guildRemote.pushCityActRank.toServer(chatSid, guildCode, ranks);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,6 +384,8 @@ export async function cityActivitySettleReward(cityId: number, serverId: number)
|
||||
await updateUserRecAndSendHonour(honour, 0, 0, roleId, members);
|
||||
}
|
||||
}
|
||||
|
||||
obj.delCityRecord(cityId, serverId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -414,9 +427,9 @@ export function getCities(guildCode: string, dbCities: GuildActivityCityType[])
|
||||
let curCity = dbCities.find(cur => cur.cityId == cityId);
|
||||
|
||||
if(curCity) {
|
||||
param.guardGuildCode = curCity.guardGuildCode;
|
||||
param.guardGuildName = curCity.guardGuildName;
|
||||
param.declareCount = curCity.declareCount;
|
||||
param.guardGuildCode = curCity.guardGuildCode||"";
|
||||
param.guardGuildName = curCity.guardGuildName||"";
|
||||
param.declareCount = curCity.declareCount||0;
|
||||
}
|
||||
|
||||
param.status = getCityStatus(guildCode, cityId, dic.preCity, dbCities);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GOOD_QUALITY, REDIS_RANK_TO_INFO, COM_BTL_QUALITY } from './../consts';
|
||||
import { GOOD_QUALITY, REDIS_RANK_TO_INFO, COM_BTL_QUALITY, GUILD_ACTIVITY_TYPE, GUILD_ACTIVITY_STATUS } from './../consts';
|
||||
import { RoleModel, RoleType } from "../db/Role";
|
||||
import * as Redis from 'redis';
|
||||
import {REDIS_KEY} from '../consts'
|
||||
@@ -11,6 +11,7 @@ import { GuildRankParam, GuildLeader, RankParam } from '../domain/rank';
|
||||
import { GuildModel } from '../db/Guild';
|
||||
import { comBtlRanges } from '../pubUtils/gamedata';
|
||||
import { getNextHourPoint } from '../pubUtils/timeUtil';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
/**
|
||||
* 在服务重新启动时,将信息存入redis
|
||||
*/
|
||||
@@ -183,7 +184,6 @@ export async function getRank(key: string, serverId: number, roleId: string, lim
|
||||
const rankFromDb = await redisClient().zrevrangebyscoreAsync(getKeyName(key, serverId), '+inf', '-inf', "WITHSCORES", "LIMIT", 0, limit);
|
||||
|
||||
let _key = key.split(':')[0];
|
||||
console.log('****', _key)
|
||||
let infoKey = REDIS_RANK_TO_INFO.get(_key)||REDIS_KEY.USER_INFO;
|
||||
|
||||
for(let ii = 0; ii < rankFromDb.length; ii+=2) {
|
||||
@@ -674,14 +674,29 @@ export function getCityKeyName(key: string, cityId: number) {
|
||||
* debug接口使用,直接删除排行榜数据
|
||||
* @param params serverId => guildCodes
|
||||
*/
|
||||
export async function delGuildActivityRank(params: Map<number, string[]>) {
|
||||
for(let [serverId, guildCodes] of params) {
|
||||
await redisClient().delAsync(getKeyName(REDIS_KEY.GATE_ACTIVITY, serverId));
|
||||
await redisClient().delAsync(getKeyName(REDIS_KEY.GATE_ACTIVITY, serverId, 'time'));
|
||||
await redisClient().delAsync(getKeyName(REDIS_KEY.GATE_ACTIVITY, serverId, 'union'));
|
||||
|
||||
for(let guildCode of guildCodes) {
|
||||
await redisClient().delAsync(getKeyName(getGuildKeyName(REDIS_KEY.USER_GATE_ACTIVITY, guildCode), serverId));
|
||||
export async function delGuildActivityRank(aid: number, params: Map<number, string[]>) {
|
||||
if(aid == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
||||
for(let [serverId, guildCodes] of params) {
|
||||
await redisClient().delAsync(getKeyName(REDIS_KEY.GATE_ACTIVITY, serverId));
|
||||
await redisClient().delAsync(getKeyName(REDIS_KEY.GATE_ACTIVITY, serverId, 'time'));
|
||||
await redisClient().delAsync(getKeyName(REDIS_KEY.GATE_ACTIVITY, serverId, 'union'));
|
||||
|
||||
for(let guildCode of guildCodes) {
|
||||
await redisClient().delAsync(getKeyName(getGuildKeyName(REDIS_KEY.USER_GATE_ACTIVITY, guildCode), serverId));
|
||||
}
|
||||
}
|
||||
} else if (aid == GUILD_ACTIVITY_TYPE.CITY_ACTIVITY) {
|
||||
let dicCity = gameData.cityActivity;
|
||||
for(let [cityId] of dicCity) {
|
||||
for(let [serverId, guildCodes] of params) {
|
||||
await redisClient().delAsync(getKeyName(getCityKeyName(REDIS_KEY.CITY_ACTIVITY, cityId) , serverId));
|
||||
await redisClient().delAsync(getKeyName(getCityKeyName(REDIS_KEY.CITY_ACTIVITY, cityId), serverId, 'time'));
|
||||
await redisClient().delAsync(getKeyName(getCityKeyName(REDIS_KEY.CITY_ACTIVITY, cityId), serverId, 'union'));
|
||||
|
||||
for(let guildCode of guildCodes) {
|
||||
await redisClient().delAsync(getKeyName(getGuildKeyName(REDIS_KEY.USER_CITY_ACTIVITY, guildCode), serverId));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,7 +379,9 @@ export async function guildActivityStart(dicGuildActivity?: DicGuildActivity) {
|
||||
// 结束时间
|
||||
guildActEndJobId = scheduleJob('guildActivityEnd', dicGuildActivity.duringTime, gateActivityEnd);
|
||||
} else if (dicGuildActivity.id == GUILD_ACTIVITY_TYPE.CITY_ACTIVITY) {
|
||||
|
||||
guildActSecondsJobId = scheduleJob('guildActivitySeconds', '*/10 * * * * *', cityActivitySeconds);
|
||||
// 结束时间
|
||||
guildActEndJobId = scheduleJob('guildActivityEnd', dicGuildActivity.duringTime, cityActivityEnd);
|
||||
} else if (dicGuildActivity.id == GUILD_ACTIVITY_TYPE.RACE_ACTIVITY) {
|
||||
|
||||
}
|
||||
@@ -406,6 +408,27 @@ export async function gateActivitySeconds() {
|
||||
}
|
||||
}
|
||||
|
||||
// 诸侯混战
|
||||
// 结束军团活动
|
||||
export async function cityActivityEnd() {
|
||||
|
||||
let servers = pinus.app.getServersByType('guild');
|
||||
for(let { id } of servers) {
|
||||
await pinus.app.rpc.guild.guildActivityRemote.guildActivityEnd.toServer(id, GUILD_ACTIVITY_TYPE.CITY_ACTIVITY);
|
||||
}
|
||||
|
||||
if(guildActSecondsJobId) guildActSecondsJobId.cancel();
|
||||
if(guildActEndJobId) guildActEndJobId.cancel();
|
||||
}
|
||||
|
||||
// 每10秒下发一次的任务
|
||||
export async function cityActivitySeconds() {
|
||||
let servers = pinus.app.getServersByType('guild');
|
||||
for(let { id } of servers) {
|
||||
await pinus.app.rpc.guild.guildActivityRemote.sendRankToGuilds.toServer(id, GUILD_ACTIVITY_TYPE.CITY_ACTIVITY);
|
||||
}
|
||||
}
|
||||
|
||||
function auctionSchedule() {
|
||||
scheduleJob('startGuildAuction', '0 0 20 20 * ?', startGuildAuction);
|
||||
scheduleJob('startWorldAuction', '0 0 20 30 * ?', startWorldAuction);
|
||||
|
||||
@@ -66,7 +66,11 @@ export function guild(session: Session, msg: any, app: Application, cb: (err: Er
|
||||
'guild.gateActivityHandler.debugEndActivity'
|
||||
].indexOf(arg.route) !== -1) {
|
||||
rid = session.get('guildCode');
|
||||
} else if (['guild.cityActivityHandler.getCityStatus'
|
||||
} else if (['guild.cityActivityHandler.getCityStatus',
|
||||
'guild.cityActivityHandler.declareCity',
|
||||
'guild.cityActivityHandler.checkBattle',
|
||||
'guild.cityActivityHandler.hitGate',
|
||||
'guild.cityActivityHandler.battleEnd'
|
||||
].indexOf(arg.route) !== -1) {
|
||||
if (arg.body.cityId) {
|
||||
rid = arg.body.cityId.toString();
|
||||
|
||||
@@ -17,10 +17,10 @@ export default class GuildActivityCity extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
declareCount: number; // 宣战数量
|
||||
|
||||
@prop({ required: true })
|
||||
@prop({ required: true, default: "" })
|
||||
guardGuildCode: string; // 占领的军团的code
|
||||
|
||||
@prop({ required: true })
|
||||
@prop({ required: true, default: "" })
|
||||
guardGuildName: string; // 占领的军团名
|
||||
|
||||
@prop({ required: true })
|
||||
|
||||
@@ -123,7 +123,6 @@ export class CityActivityObject {
|
||||
}
|
||||
|
||||
public getAllCities() {
|
||||
|
||||
let allCities = new Array<{ serverId: number, cityId: number, guildCodes: string[]}>();
|
||||
let serverlists = new Array<number>();
|
||||
for(let [key, guildCodes] of this.cities) {
|
||||
@@ -185,10 +184,24 @@ export class CityActivityObject {
|
||||
if(!this.cities.has(key)) {
|
||||
this.cities.set(key, [guildCode]);
|
||||
} else {
|
||||
this.cities.get(key).push(guildCode);
|
||||
let arr = this.cities.get(key);
|
||||
if(!arr.includes(guildCode)) {
|
||||
arr.push(guildCode);
|
||||
}
|
||||
}
|
||||
this.guilds.set(guildCode, cityId);
|
||||
}
|
||||
|
||||
public delCityRecord(cityId: number, serverId: number) {
|
||||
let key = this.getKey(serverId, cityId);
|
||||
let guildCodes = this.cities.get(key)||[];
|
||||
for(let guildCode of guildCodes) {
|
||||
this.members.delete(guildCode);
|
||||
this.guilds.delete(guildCode);
|
||||
}
|
||||
this.gateHp.delete(key);
|
||||
this.cities.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
export interface GuildGateRankParam {
|
||||
|
||||
Reference in New Issue
Block a user