✨ feat(gvg): 定时器
This commit is contained in:
@@ -259,6 +259,8 @@ export enum REDIS_KEY {
|
||||
GVG_VESTIGE_MEMBER_ALL = 'vestigeUsrAll', // 玩家所有遗迹积分
|
||||
GVG_VESTIGE_LEAGUE = 'vestigeLeague', // 联军所有遗迹积分
|
||||
LEAGUE_INFO ="leagueInfo", // 联军信息
|
||||
GVG_BATTLE_RANK ="gvgBattleUsr", // 激战期个人排行榜
|
||||
GVG_BATTLE_LEAGUE_RANK = "gvgBattleLeague", // 激战期联军排行榜
|
||||
}
|
||||
|
||||
// 各排行榜对应hash的key
|
||||
@@ -314,7 +316,11 @@ export function getInfoKeyByRedisKey(redisKey: REDIS_KEY) {
|
||||
case REDIS_KEY.GVG_VESTIGE_MEMBER_ALL: // 全遗迹玩家排行榜
|
||||
return { infoKey: REDIS_KEY.USER_INFO, extraKey: [] };
|
||||
case REDIS_KEY.GVG_VESTIGE_LEAGUE: // 遗迹联军排行榜
|
||||
return { infoKey: REDIS_KEY.LEAGUE_INFO, extraKey: [] }
|
||||
return { infoKey: REDIS_KEY.LEAGUE_INFO, extraKey: [] };
|
||||
case REDIS_KEY.GVG_BATTLE_RANK: // 激战期玩家排行榜
|
||||
return { infoKey: REDIS_KEY.USER_INFO, extraKey: [] };
|
||||
case REDIS_KEY.GVG_BATTLE_LEAGUE_RANK: // 激战期联军排行榜
|
||||
return { infoKey: REDIS_KEY.LEAGUE_INFO, extraKey: [] };
|
||||
default:
|
||||
return { infoKey: REDIS_KEY.USER_INFO, extraKey: [] };
|
||||
}
|
||||
@@ -414,6 +420,8 @@ export const KEY_TO_COMPOSE_FIELD = new Map([
|
||||
[REDIS_KEY.GVG_VESTIGE_MEMBER_ALL, COMPOSE_FIELD_TYPE.ROLE],
|
||||
[REDIS_KEY.GVG_VESTIGE_LEAGUE, COMPOSE_FIELD_TYPE.LEAGUE],
|
||||
[REDIS_KEY.LEAGUE_INFO, COMPOSE_FIELD_TYPE.LEAGUE],
|
||||
[REDIS_KEY.GVG_BATTLE_RANK, COMPOSE_FIELD_TYPE.ROLE],
|
||||
[REDIS_KEY.GVG_BATTLE_LEAGUE_RANK, COMPOSE_FIELD_TYPE.LEAGUE],
|
||||
]);
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import BaseModel from "./BaseModel";
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { LeagueRankInfo } from "../domain/rank";
|
||||
|
||||
class Player {
|
||||
@prop({ required: true })
|
||||
@@ -44,14 +45,6 @@ export default class GVGCity extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
userCnt: number; // 城池人数
|
||||
|
||||
// 创建城市
|
||||
public static async createCity(configId: number, groupId: number, serverType: number, cityId: number) {
|
||||
let doc = new GVGCityModel();
|
||||
let update = Object.assign(doc.toJSON(), { configId, cityId, groupId, serverType});
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId, cityId, groupId, serverType }, { $setOnInsert: update }, { upsert: true, new: true }).lean();
|
||||
return city;
|
||||
}
|
||||
|
||||
// 通过 cityId 获取城市
|
||||
public static async findByCityId(configId: number, groupId: number, serverType: number, cityId: number) {
|
||||
const city: GVGCityType = await GVGCityModel.findOne({ configId, groupId, serverType, cityId }).lean();
|
||||
@@ -81,6 +74,15 @@ export default class GVGCity extends BaseModel {
|
||||
const cities: GVGCityType[] = await GVGCityModel.find({ configId, hasGuard: true }).lean();
|
||||
return cities
|
||||
}
|
||||
|
||||
// 占领城池
|
||||
public static async guardCity(configId: number, groupId: number, serverType: number, cityId: number, league: LeagueRankInfo) {
|
||||
console.log('##### guardCity', configId, groupId, serverType, cityId)
|
||||
const city: GVGCityType = await GVGCityModel.findOneAndUpdate({ configId: configId + 1, cityId, groupId, serverType }, { $set: {
|
||||
hasGuard: true, guardLeague: league.code, guardLeagueName: league.name, guardLeagueIcon: league.icon
|
||||
} }, { upsert: true, new: true }).lean();
|
||||
return city;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -253,30 +253,42 @@ export default class GVGTeam extends BaseModel {
|
||||
}
|
||||
|
||||
// 结算挑战方
|
||||
public static async battleEndAttack(teamCode: string, hpInc: number, playerScoreInc: number) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $inc: { durability: hpInc, playerScore: playerScoreInc } }, { new: true }).lean();
|
||||
public static async battleEndAttack(teamCode: string, hpInc: number, playerScoreInc: number, rebirthAreaId: number) {
|
||||
let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $inc: { durability: hpInc, score: playerScoreInc } }, { new: true }).lean();
|
||||
if(team.durability <= 0) {
|
||||
team = await GVGTeamModel.teamBreak(teamCode, team.isRobot, team.maxDurability, rebirthAreaId);
|
||||
}
|
||||
return team;
|
||||
}
|
||||
|
||||
originPointId: number;
|
||||
// 结算防守方
|
||||
public static async battleEndDefense(teamCode: string, hpInc: number, playerScoreInc: number) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { defenseTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD, lockTime: 0, lockTeamCode: '' }, $inc: { durability: hpInc, playerScore: playerScoreInc } }, { new: true }).lean();
|
||||
public static async battleEndDefense(teamCode: string, hpInc: number, playerScoreInc: number, rebirthAreaId: number) {
|
||||
let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { defenseTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD, lockTime: 0, lockTeamCode: '' }, $inc: { durability: hpInc, score: playerScoreInc } }, { new: true }).lean();
|
||||
if(team.durability <= 0) {
|
||||
let originPointId = team.pointId;
|
||||
team = await GVGTeamModel.teamBreak(teamCode, team.isRobot, team.maxDurability, rebirthAreaId);
|
||||
team.originPointId = originPointId;
|
||||
}
|
||||
return team;
|
||||
}
|
||||
|
||||
curTeamBreak: boolean;
|
||||
// 队伍进入修整器
|
||||
public static async teamBreak(teamCode: string, isRobot: boolean, maxDurability: number, areaId: number) {
|
||||
if(!isRobot) {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { restartTime: nowSeconds() + GVG.GVG_DEFAULT_DEFENSE_CD, stopMoveTime: nowSeconds(), areaId, durability: maxDurability } }, { new: true }).lean();
|
||||
team.curTeamBreak = true;
|
||||
return team;
|
||||
} else {
|
||||
const team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $set: { durability: 0, isBroken: true } }, { new: true }).lean();
|
||||
team.curTeamBreak = true;
|
||||
return team;
|
||||
}
|
||||
}
|
||||
|
||||
public static async findByAreaId(groupId: number, serverType: number, cityId: number, areaId: number) {
|
||||
const team: GVGTeamType[] = await GVGTeamModel.find({ groupId, serverType, cityId, areaId, stopMoveTime: { $lte: nowSeconds() } }).lean();
|
||||
const team: GVGTeamType[] = await GVGTeamModel.find({ groupId, serverType, cityId, areaId, stopMoveTime: { $lte: nowSeconds() }, isBroken: false }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
@@ -287,7 +299,7 @@ export default class GVGTeam extends BaseModel {
|
||||
|
||||
// 这个编队上是否已经有队伍了
|
||||
public static async checkPoint(configId: number, groupId: number, serverType: number, pointId: number) {
|
||||
return await GVGTeamModel.exists({ configId, groupId, serverType, pointId });
|
||||
return await GVGTeamModel.exists({ configId, groupId, serverType, pointId, isBroken: false });
|
||||
}
|
||||
|
||||
// 投石车伤害
|
||||
@@ -303,6 +315,12 @@ export default class GVGTeam extends BaseModel {
|
||||
let teams: GVGTeamType[] = await GVGTeamModel.find({ batchCode }).lean();
|
||||
return teams
|
||||
}
|
||||
|
||||
// 加积分
|
||||
public static async addScore(teamCode: string, incScore: number) {
|
||||
let team: GVGTeamType = await GVGTeamModel.findOneAndUpdate({ teamCode }, { $inc: { score: incScore } }, { new: true }).lean();
|
||||
return team;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -366,6 +366,7 @@ export class KeyName {
|
||||
groupId?: number;
|
||||
serverType?: number;
|
||||
day?: string;
|
||||
configId?: number;
|
||||
|
||||
constructor(key: string, param: KeyNameParam) {
|
||||
this.key = key;
|
||||
@@ -380,6 +381,7 @@ export class KeyName {
|
||||
if(param.groupId) this.groupId = param.groupId;
|
||||
if(param.serverType) this.serverType = param.serverType;
|
||||
if(param.day) this.day = param.day;
|
||||
if(param.configId) this.configId = param.configId;
|
||||
}
|
||||
|
||||
public getName() {
|
||||
@@ -418,6 +420,10 @@ export class KeyName {
|
||||
return `${this.key}:${this.day}:${this.groupId}:${this.serverType}`;
|
||||
case REDIS_KEY.GVG_VESTIGE_LEAGUE:
|
||||
return `${this.key}:${this.day}:${this.groupId}:${this.serverType}`;
|
||||
case REDIS_KEY.GVG_BATTLE_RANK:
|
||||
return `${this.key}:${this.configId}:${this.groupId}:${this.serverType}:${this.cityId}`;
|
||||
case REDIS_KEY.GVG_BATTLE_LEAGUE_RANK:
|
||||
return `${this.key}:${this.configId}:${this.groupId}:${this.serverType}:${this.cityId}`;
|
||||
default:
|
||||
return this.key;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user