排行榜: 获取排行榜

This commit is contained in:
luying
2021-04-12 09:47:15 +08:00
parent 34e02dea89
commit 5dca7b304d
32 changed files with 1077 additions and 290 deletions
+6 -4
View File
@@ -1,7 +1,7 @@
export enum ROLE_SELECT {
// 初始登录数据
ENTRY = 'serverId userInfo.uid userInfo.tel userInfo.serverType ce topLineup topLineupCe teraphs roleId roleName tili lv exp gold coin vLv title hasGuild funcs eventStatus heads head frames frame spines spine guildCode frdCnt showLineup',
ENTRY = 'serverId userInfo.uid userInfo.tel userInfo.serverType ce topLineup topLineupCe teraphs roleId roleName tili lv exp gold coin vLv title hasGuild funcs eventStatus heads head frames frame spines spine guildCode frdCnt showLineup updatedAt',
// 玩家列表显示基础数据
SHOW_SIMPLE = 'roleId roleName ce head frame spine lv title job quitTime loginTime vLv guildName serverId userInfo.serverType',
// 显示申请需要的信息
@@ -14,12 +14,14 @@ export enum ROLE_SELECT {
COM_BATTLE = 'lv head frame spine topLineupCe',
GET_HEADS = 'heads head frames frame spines spine',
// 排行榜基础数据
RANK = 'roleId roleName lv vLv head frame spine title guildName ce'
RANK = 'roleId roleName lv vLv head frame spine title guildName ce isReducedCe topLineup towerLv towerUpTime topLineupCe heroNum updatedAt heroNumUpdatedAt dungeonWarId dungeonUpdatedAt dungeonHeroes mainWarId mainUpdatedAt mainEliteWarId mainEliteUpdatedAt showLineup',
};
export enum HERO_SELECT {
ENTRY = '-attr',
HERO_DETAIL = 'roleId roleName hid hName ce lv star colorStar quality job skins attr'
HERO_DETAIL = 'roleId roleName hid hName ce isReducedCe lv star colorStar quality job skins attr',
// 排行榜中lineup字段
RANK_LINEUP = 'seqId roleId hid star colorStar lv quality job ce isReducedCe updatedAt'
}
export enum EQUIP_SELECT {
@@ -40,7 +42,7 @@ export enum GUILD_SELECT {
// 获得邀请列表
INVITED_MEMBER = '_id code isMemberMax +invitedMembers +inviteTime',
// 排行榜字段
RANK = 'code name icon lv memberCnt leader'
RANK = 'code name icon lv memberCnt leader leader activeWeekly activeUpdateTime'
}
export enum FRIEND_SHIP_SELECT {
+113 -15
View File
@@ -226,20 +226,34 @@ export const DEFAULT_HERO_LV = 1;
export const FIX_SMS_CODE_TELS = ['18855953630', '13911134885', '15167549151', '15618654010', '15167549151', '18342915387', '15000250967'];
export const REDIS_KEY = {
USER_INFO: "userInfo", // 玩家缓存信息
TOWER_RANK: "towerRank", // 天梯排行榜
COM_TEAM_SEARCH_PRE: 'comTeamSerQ', // 匹配中的玩家,按品质分
PVP_RANK: "pvpRank", // pvp排行榜
GUILD_INFO: "guildInfo", // 公会信息
GUILD_ACTIVE_RANK: "guildActiveRank", // 公会周活跃排行榜
DB_GAME: 'db_game', // 服务器列表
ONLINE_USERS: 'onlineUsers', // 在线用户情况
CHANNEL_SERVERS: 'chat:channelServers', // 渠道对应的 chat 服务器 Id,
USER_GATE_ACTIVITY: 'usrGateAct', // 蛮夷入侵玩家排行
GATE_ACTIVITY: 'gateAct', // 蛮夷入侵军团排行
USER_CITY_ACTIVITY: 'usrCityAct', // 诸侯混战玩家排行
CITY_ACTIVITY: 'cityAct', // 诸侯混战军团排行
RACE_ACTIVITY: 'raceAct', // 粮草先行军团排行
USER_INFO: "userInfo", // 玩家缓存信息
TOWER_RANK: "towerRank", // 天梯排行榜
COM_TEAM_SEARCH_PRE: 'comTeamSerQ', // 匹配中的玩家,按品质分
PVP_RANK: "pvpRank", // pvp排行榜
GUILD_INFO: "guildInfo", // 公会信息
GUILD_ACTIVE_RANK: "guildActiveRank", // 公会周活跃排行榜
DB_GAME: 'dbGame', // 服务器列表
ONLINE_USERS: 'onlineUsers', // 在线用户情况
CHANNEL_SERVERS: 'chat:channelServers', // 渠道对应的 chat 服务器 Id,
USER_GATE_ACTIVITY: 'usrGateAct', // 蛮夷入侵玩家排行
GATE_ACTIVITY: 'gateAct', // 蛮夷入侵军团排行
USER_CITY_ACTIVITY: 'usrCityAct', // 诸侯混战玩家排行
CITY_ACTIVITY: 'cityAct', // 诸侯混战军团排行
RACE_ACTIVITY: 'raceAct', // 粮草先行军团排行
TOP_LINEUP_INFO: 'topLineInfo', // 最强阵容数据
TOP_LINEUP_RANK: 'topLineRank', // 最强阵容排行
TOP_HERO_RANK: 'topHeroRank', // 最强武将排行
HERO_INFO: 'heroInfo', // 最强武将信息
HERO_NUM_RANK: 'heroNum', // 武将数量排行
USER_LV: 'usrLv', // 主公等级排行榜
SUM_CE_RANK: 'sumCeRank', // 总战力排名
DUNGEON_RANK: 'dungeonRank', // 秘境排名
DUNGEON_LINEUP: 'dungeonLineup', // 秘境通关阵容
MAIN_RANK: 'mainRank', // 主线通关排名
MAIN_ELITE_RANK: 'mainEliteRank', // 精英通关排名
GUILD_LV_RANK: "guildLvRank", // 公会等级排行榜
HERO_RANK: "heroRank", // 武将排行榜
SHOW_LINEUP: "showLineup", // 展示阵容
}
// 各排行榜对应hash的key
@@ -247,13 +261,97 @@ export const REDIS_RANK_TO_INFO = new Map([
[REDIS_KEY.TOWER_RANK, REDIS_KEY.USER_INFO],
[REDIS_KEY.PVP_RANK, REDIS_KEY.USER_INFO],
[REDIS_KEY.GUILD_ACTIVE_RANK, REDIS_KEY.GUILD_INFO],
[REDIS_KEY.GUILD_LV_RANK, REDIS_KEY.GUILD_INFO],
[REDIS_KEY.GATE_ACTIVITY, REDIS_KEY.GUILD_INFO],
[REDIS_KEY.USER_GATE_ACTIVITY, REDIS_KEY.USER_INFO],
[REDIS_KEY.CITY_ACTIVITY, REDIS_KEY.GUILD_INFO],
[REDIS_KEY.USER_CITY_ACTIVITY, REDIS_KEY.USER_INFO],
[REDIS_KEY.RACE_ACTIVITY, REDIS_KEY.GUILD_INFO]
[REDIS_KEY.RACE_ACTIVITY, REDIS_KEY.GUILD_INFO],
[REDIS_KEY.TOP_LINEUP_RANK, REDIS_KEY.USER_INFO],
[REDIS_KEY.TOP_HERO_RANK, REDIS_KEY.USER_INFO],
[REDIS_KEY.HERO_NUM_RANK, REDIS_KEY.USER_INFO],
[REDIS_KEY.USER_LV, REDIS_KEY.USER_INFO],
[REDIS_KEY.SUM_CE_RANK, REDIS_KEY.USER_INFO],
[REDIS_KEY.DUNGEON_RANK, REDIS_KEY.USER_INFO],
[REDIS_KEY.MAIN_RANK, REDIS_KEY.USER_INFO],
[REDIS_KEY.MAIN_ELITE_RANK, REDIS_KEY.USER_INFO],
[REDIS_KEY.HERO_RANK, REDIS_KEY.USER_INFO]
]);
export const REDIS_RANK_TO_EXTRA = new Map([
[REDIS_KEY.TOP_LINEUP_RANK, [REDIS_KEY.TOP_LINEUP_INFO]],
[REDIS_KEY.TOP_HERO_RANK, [REDIS_KEY.HERO_INFO]],
[REDIS_KEY.DUNGEON_RANK, [REDIS_KEY.DUNGEON_LINEUP]],
[REDIS_KEY.HERO_RANK, [REDIS_KEY.HERO_INFO, REDIS_KEY.SHOW_LINEUP]]
]);
// 排行榜类型
export enum RANK_TYPE {
TOP_LINTUP = 1, // 最强阵容战力
TOP_HERO = 2, // 最强武将
HERO_NUM = 3, // 武将数量
USER_LV = 4, // 主公等级
SUM_CE = 5, // 总战力
TOWER = 6, // 镇念塔
DUNGEON = 7, // 秘境
MAIN = 8, // 主线
MAIN_ELITE = 9, // 精英
GUILD_LV = 10, // 军团按等级排序
GUILD_ACTIVE = 11, // 军团活跃度排序
HERO = 12, // 武将排行
}
// 接口中的排行榜类型对应的redis中的key
export const RANK_TYPE_TO_KEY = new Map([
[RANK_TYPE.TOP_LINTUP, REDIS_KEY.TOP_LINEUP_RANK],
[RANK_TYPE.TOP_HERO, REDIS_KEY.TOP_HERO_RANK],
[RANK_TYPE.HERO_NUM, REDIS_KEY.HERO_NUM_RANK],
[RANK_TYPE.USER_LV, REDIS_KEY.USER_LV],
[RANK_TYPE.SUM_CE, REDIS_KEY.SUM_CE_RANK],
[RANK_TYPE.TOWER, REDIS_KEY.TOWER_RANK],
[RANK_TYPE.DUNGEON, REDIS_KEY.DUNGEON_RANK],
[RANK_TYPE.MAIN, REDIS_KEY.MAIN_RANK],
[RANK_TYPE.MAIN_ELITE, REDIS_KEY.MAIN_ELITE_RANK],
[RANK_TYPE.GUILD_LV, REDIS_KEY.GUILD_LV_RANK],
[RANK_TYPE.GUILD_ACTIVE, REDIS_KEY.GUILD_ACTIVE_RANK],
[RANK_TYPE.HERO, REDIS_KEY.HERO_RANK]
]);
// field处理方法
export enum COMPOSE_FIELD_TYPE {
ROLE = 1,
GUILD = 2,
ROLE_HERO = 3
}
// 各个key的field如何处理
export const KEY_TO_COMPOSE_FIELD = new Map([
[REDIS_KEY.USER_INFO, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.TOWER_RANK, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.PVP_RANK, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.GUILD_INFO, COMPOSE_FIELD_TYPE.GUILD],
[REDIS_KEY.GUILD_ACTIVE_RANK, COMPOSE_FIELD_TYPE.GUILD],
[REDIS_KEY.GUILD_LV_RANK, COMPOSE_FIELD_TYPE.GUILD],
[REDIS_KEY.USER_GATE_ACTIVITY, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.GATE_ACTIVITY, COMPOSE_FIELD_TYPE.GUILD],
[REDIS_KEY.USER_CITY_ACTIVITY, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.CITY_ACTIVITY, COMPOSE_FIELD_TYPE.GUILD],
[REDIS_KEY.RACE_ACTIVITY, COMPOSE_FIELD_TYPE.GUILD],
[REDIS_KEY.TOP_LINEUP_INFO, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.TOP_LINEUP_RANK, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.TOP_HERO_RANK, COMPOSE_FIELD_TYPE.ROLE_HERO],
[REDIS_KEY.HERO_INFO, COMPOSE_FIELD_TYPE.ROLE_HERO],
[REDIS_KEY.HERO_NUM_RANK, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.USER_LV, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.DUNGEON_RANK, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.DUNGEON_LINEUP, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.MAIN_RANK, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.MAIN_ELITE_RANK, COMPOSE_FIELD_TYPE.ROLE],
[REDIS_KEY.HERO_RANK, COMPOSE_FIELD_TYPE.ROLE_HERO],
[REDIS_KEY.SHOW_LINEUP, COMPOSE_FIELD_TYPE.ROLE],
]);
export const FUNC_OPT_TYPE = {
LEVEL_UP: 1,
BATTLE_END: 2
+17 -7
View File
@@ -2,7 +2,7 @@ import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
import Role, { RoleType } from './Role';
import { genCode } from '../pubUtils/util';
import { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE, GUILD_SELECT } from '../consts';
import { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE, GUILD_SELECT, RANK_TYPE, REDIS_KEY } from '../consts';
import { getCurWeekTime, nowSeconds } from '../pubUtils/timeUtil';
import { reduceCe } from '../pubUtils/util';
@@ -28,6 +28,9 @@ export default class Guild extends BaseModel {
@prop({ required: true, default: 1 })
lv: number;
@prop({ required: true, default: 1 })
lvUpdateTime: number;
@prop({ required: true, default: 1 })
memberCnt: number;
@@ -98,7 +101,7 @@ export default class Guild extends BaseModel {
public static async createGuild(params: { name: string, icon: number, notice: string }, role: RoleType, serverId: number) {
const doc = new GuildModel();
const update = Object.assign(doc.toJSON(), params, { leader: role._id, members: [role.roleId], guildCe: role.ce, serverId });
const update = Object.assign(doc.toJSON(), params, { leader: role._id, members: [role.roleId], guildCe: role.ce, serverId, lvUpdateTime: nowSeconds() });
delete update._id;
const code = genCode(6);
const result: GuildType = await GuildModel.findOneAndUpdate({ code }, update, { upsert: true, new: true })
@@ -132,12 +135,19 @@ export default class Guild extends BaseModel {
}
public static async getRank(serverId: number, page: number = 1) {
public static async getRank(type: string, serverId: number, page: number = 1) {
let sort = {}, condition = {};
switch(type) {
case REDIS_KEY.GUILD_LV_RANK:
sort = { lv: -1, lvUpdateTime: 1 }; break;
case REDIS_KEY.GUILD_ACTIVE_RANK:
sort = { activeWeekly: -1, activeUpdateTime: 1 }; condition = { activeWeekly: { $gt: 0 } }; break;
}
const guildList: GuildType[] = await GuildModel.find({ status: GUILD_STATUS.RUNNING, serverId }, {_id: 0})
.sort({ activeWeekly: -1, activeUpdateTime: -1 })
const guildList: GuildType[] = await GuildModel.find({ status: GUILD_STATUS.RUNNING, serverId, ...condition }, {_id: 0})
.sort(sort)
.limit(100).skip((page - 1) * 100)
.select('code icon name lv leader activeWeekly activeUpdateTime')
.select(GUILD_SELECT.RANK)
.populate('leader', {roleName: 1, title: 1, frame: 1, head: 1, spine: 1, lv: 1, _id: 0}, 'Role')
.lean({ virtuals: true });
return guildList;
@@ -189,7 +199,7 @@ export default class Guild extends BaseModel {
public static async upStructure(code: string, id: number, cost: number, select?: string) {
if (id == GUILD_STRUCTURE.ARMY_CENTER) {
const result: GuildType = await GuildModel.findOneAndUpdate({ code, 'structure.id': id, fund: { $gte: cost } }, { $inc: { 'structure.$.lv': 1, lv: 1, fund: -1 * cost }, $set: { isMemberMax: false } }, { new: true }).select(select).lean();
const result: GuildType = await GuildModel.findOneAndUpdate({ code, 'structure.id': id, fund: { $gte: cost } }, { $inc: { 'structure.$.lv': 1, lv: 1, fund: -1 * cost }, $set: { isMemberMax: false, lvUpdateTime: nowSeconds() } }, { new: true }).select(select).lean();
return result;
} else {
const result: GuildType = await GuildModel.findOneAndUpdate({ code, 'structure.id': id, fund: { $gte: cost } }, { $inc: { 'structure.$.lv': 1, fund: -1 * cost } }, { new: true }).select(select).lean();
+15 -2
View File
@@ -4,6 +4,7 @@ import Equip, { } from './Equip';
import { CounterModel } from './Counter';
import { COUNTER, EQUIP_TYPE } from '../consts';
import { reduceCe } from '../pubUtils/util';
import { nowSeconds } from '../pubUtils/timeUtil';
class CeAttrData {
@prop({ required: true })
@@ -90,6 +91,8 @@ export default class Hero extends BaseModel {
lv: number; // 武将等级
@prop({ required: true, default: 0, set: (val: number) => val, get: (val: number) => reduceCe(val) })
ce: number; // 武将战力
@prop({ required: false, set: (val: boolean) => val, get: () => true })
isReducedCe: boolean; // 如果战力没有缩过就会返回false,缩过了就会返回true
@prop({ required: true, default: 0 })
historyCe: number; // 武将历史最高战力
@prop({required: true, type: CeAttrData, default: [], _id: false })
@@ -190,7 +193,7 @@ export default class Hero extends BaseModel {
return hero;
}
public static async createHero(heroInfo: {roleId: string, serverId: number, roleName: string, hid: number, hName: string, star: number, quality: number, job: number, lv?: number, exp?: number, skins:Skin[]}, lean = true) {
public static async createHero(heroInfo: HeroUpdate, lean = true) {
const doc = new HeroModel();
const seqId = await CounterModel.getNewCounter(COUNTER.HID)||-1;
const update = Object.assign(doc.toJSON(), heroInfo, {seqId});
@@ -267,7 +270,17 @@ export default class Hero extends BaseModel {
return user;
}
public static async getRank(hid: number, serverId: number, select?: string, limit = 100) {
public static async getAllRank(serverId: number, select?: string, limit = 200) {
let result: HeroType[] = await HeroModel.find({serverId}, { _id: false} ).select(select).limit(limit).sort({ ce: -1, updatedAt: 1 }).lean({ getters: true });
return result;
}
public static async getMyTopHero(roleId: string, select?: string) {
let result: HeroType = await HeroModel.findOne({ roleId }, { _id: false} ).select(select).sort({ ce: -1, updatedAt: 1 }).lean({ getters: true });
return result;
}
public static async getRank(hid: number, serverId: number, select?: string, limit = 200) {
let result: HeroType[] = await HeroModel.find({serverId, hid}, { _id: false} ).select(select).limit(limit).lean({ getters: true });
return result;
}
+63 -6
View File
@@ -160,6 +160,8 @@ export default class Role extends BaseModel {
topLineup: Array<TopHero>; // 总战力
@prop({ required: true, default: 100 })
tili: number; // 体力值
@prop({ required: false, set: (val: boolean) => val, get: () => true })
isReducedCe: boolean; // 如果战力没有缩过就会返回false,缩过了就会返回true
@prop({ required: true, default: 0 })
vLv: number; // VIP 等级
@@ -264,6 +266,26 @@ export default class Role extends BaseModel {
recFrdApplyCnt: number; // 玩家收取好友申请数量
@prop({ required: true, default: 0 })
updatedMailAt: number;
// 排行相关
@prop({ required: true, default: 0 })
heroNum: number; // 武将数量
@prop({ required: true, default: 0 })
heroNumUpdatedAt: number; // 武将数量更新时间
@prop({ required: true, default: 0 })
dungeonWarId: number; // 秘境通关关卡
@prop({ required: true, default: 0 })
dungeonUpdatedAt: number; // 秘境通关时间
@prop({ required: true, default: 0 })
mainWarId: number; // 主线通关关卡
@prop({ required: true, default: 0 })
mainUpdatedAt: number; // 秘境通关时间
@prop({ required: true, default: 0 })
mainEliteWarId: number; // 精英通关关卡
@prop({ required: true, default: 0 })
mainEliteUpdatedAt: number; // 精英通关时间
public static async findAllByUid(uid: number, getters = false, virtuals = true) {
const role: RoleType[] = await RoleModel.find({ 'userInfo.uid': uid }).select('roleId roleName serverId head frame spine lv updatedAt').lean({ getters, virtuals});
return role;
@@ -436,13 +458,31 @@ export default class Role extends BaseModel {
}
// 获取排行榜
public static async getRank(type: string, serverId: number, fields: string[], page = 1, limit = 100) {
public static async getRank(type: string, serverId: number, select?: string, page = 1, limit = 200) {
let sortBy = {};
if(type == 'tower') {
sortBy['towerLv'] = -1;
sortBy['towerUpTime'] = 1;
let condition = {};
switch(type) {
case 'tower':
sortBy = { towerLv: -1, towerUpTime: 1 }; condition = { towerLv: { $gt: 0 } }; break;
case 'topLineup':
sortBy = { topLineupCe: -1, updatedAt: 1 }; condition = { topLineupCe: { $gt: 0 } }; break;
case 'heroNum':
sortBy = { heroNum: -1, heroNumUpdatedAt: 1 }; condition = { heroNum: { $gt: 0 } }; break;
case 'lv':
sortBy = { lv: -1, updatedAt: 1 }; condition = { lv: { $gt: 0 } }; break;
case 'ce':
sortBy = { ce: -1, updatedAt: 1 }; condition = { ce: { $gt: 0 } }; break;
case 'dungeon':
sortBy = { dungeonWarId: -1, dungeonUpdatedAt: 1 }; condition = { dungeonWarId: { $gt: 0 } }; break;
case 'main':
sortBy = { mainWarId: -1, mainUpdatedAt: 1 }; condition = { mainWarId: { $gt: 0 } }; break;
case 'mainElite':
sortBy = { mainEliteWarId: -1, mainEliteUpdatedAt: 1 }; condition = { mainEliteWarId: { $gt: 0 } }; break;
default:
sortBy = {}; break;
}
const ranks: RoleType[] = await RoleModel.find({serverId}).select(fields.join(' ')).sort(sortBy).limit(limit).skip((page - 1) * limit).lean({ virtuals: true });
const ranks: RoleType[] = await RoleModel.find({serverId, ...condition}).select(select).sort(sortBy).limit(limit).skip((page - 1) * limit).lean({ virtuals: true, getters: true });
return ranks;
}
@@ -453,7 +493,7 @@ export default class Role extends BaseModel {
let dungeonHeroes = role && role.dungeonHeroes;
let hasHero = dungeonHeroes&&dungeonHeroes.find(cur => cur.battleId == battleId);
if(!dungeonHeroes || !hasHero) {
role = await RoleModel.findOneAndUpdate({roleId}, {$push:{dungeonHeroes: {battleId, heroes}}})
role = await RoleModel.findOneAndUpdate({roleId}, {$push:{dungeonHeroes: {battleId, heroes}}, $set: { dungeonWarId: battleId, dungeonUpdatedAt: nowSeconds() }});
}
return role;
}
@@ -471,6 +511,22 @@ export default class Role extends BaseModel {
return result;
}
public static async incRoleInfo(roleId: string, inc: RoleInc, set: RoleUpdate, getters = false, virtuals = true) {
delete set._id;
let result: RoleType = await RoleModel.findOneAndUpdate({roleId}, {$inc: inc, $set: set}, {new: true}).lean({ getters, virtuals });
return result;
}
public static async updateMainWarId(roleId: string, mainWarId: number, mainUpdatedAt: number, getters = false, virtuals = true) {
let result: RoleType = await RoleModel.findOneAndUpdate({roleId, mainWarId: { $lt: mainWarId }}, {$set:{mainWarId, mainUpdatedAt}}, {new: true}).lean({ getters, virtuals });
return result;
}
public static async updateMainEliteWarId(roleId: string, mailEliteWarId: number, mainEliteUpdatedAt: number, getters = false, virtuals = true) {
let result: RoleType = await RoleModel.findOneAndUpdate({roleId, mailEliteWarId: { $lt: mailEliteWarId }}, {$set:{mailEliteWarId, mainEliteUpdatedAt}}, {new: true}).lean({ getters, virtuals });
return result;
}
// 记录加入公会
public static async joinGuild(roleId: string, guildCode: string, guildName: string) {
const result = await RoleModel.findOneAndUpdate({ roleId, hasGuild: false }, { hasGuild: true, guildCode, guildName }, { new: true }).lean();
@@ -576,6 +632,7 @@ export const RoleModel = getModelForClass(Role);
export interface RoleType extends Pick<DocumentType<Role>, keyof Role>{};
export type RoleUpdate = Partial<RoleType>; // 将所有字段变成可选项
export type RoleInc = Partial<Pick<DocumentType<Role>, 'heroNum'|'blockCnt'|'friendCnt'|'gold'|'coin'>>;
// 初始化
function getInitialTeraph() {
+54 -14
View File
@@ -4,6 +4,7 @@ import { RoleUpdate, RoleType } from "../db/Role";
import { reduceCe } from "../pubUtils/util";
import { GuildUpdateParam } from "../db/Guild";
import { currentId } from "async_hooks";
import { HeroType } from "../db/Hero";
// 排行榜返回玩家值
export class RankParam {
@@ -17,7 +18,7 @@ export class RankParam {
title: number;
ce: number;
constructor(role: RoleUpdate, needReduceCe = false) {
constructor(role: RoleUpdate) {
this.roleName = role.roleName;
this.lv = role.lv;
this.vLv = role.vLv;
@@ -25,11 +26,11 @@ export class RankParam {
this.frame = role.frame;
this.spine = role.spine;
this.title = role.title;
this.guildName = role.guildName;
if(needReduceCe) {
this.ce = reduceCe(role.ce);
} else {
this.guildName = role.guildName||"";
if(role.isReducedCe) {
this.ce = role.ce;
} else {
this.ce = reduceCe(role.ce);
}
}
}
@@ -39,16 +40,26 @@ export class RoleRankInfo extends RankParam {
roleId: string;
num: number;
time: number;
hero: LineupParam[];
lineup: LineupParam[];
setInfo(rank: number, roleId: string, num: number, time: number) {
setInfo(rank: number, myId: myIdInter, num: number, time: number) {
this.rank = rank;
this.roleId = roleId;
this.roleId = myId.roleId;
this.num = num;
this.time = time;
}
isMyInfo(myId: string) {
return this.roleId == myId;
isMyInfo(myId: myIdInter) {
return this.roleId == myId.roleId;
}
setTopLine(lineup: LineupParam[]){
this.lineup = lineup;
}
setSingleHero(hero: LineupParam[]){
this.hero = hero;
}
}
@@ -85,15 +96,15 @@ export class GuildRankInfo extends GuildRankParam {
num: number;
time: number;
setInfo(rank: number, code: string, num: number, time: number) {
setInfo(rank: number, myId: myIdInter, num: number, time: number) {
this.rank = rank;
this.code = code;
this.code = myId.guildCode;
this.num = num;
this.time = time;
}
isMyInfo(myId: string) {
return this.code == myId;
isMyInfo(myId: myIdInter) {
return this.code == myId.guildCode;
}
}
@@ -115,6 +126,25 @@ export class GuildLeader {
}
}
// 排行榜返回玩家值
export class LineupParam {
hid: number;
star: number;
colorStar: number;
lv: number;
quality: number;
job: number;
constructor(hero: HeroType) {
this.hid = hero.hid;
this.star = hero.star;
this.colorStar = hero.colorStar;
this.lv = hero.lv;
this.quality = hero.quality;
this.job = hero.job;
}
}
export class SimpleGuildRankParam {
rank: number = 0;
code: string = "";
@@ -163,12 +193,14 @@ export class KeyName {
serverId?: number;
guildCode?: string;
cityId?: number;
hid?: number;
constructor(key: string, param: KeyNameParam) {
this.key = key;
if(param.serverId) this.serverId = param.serverId;
if(param.guildCode) this.guildCode = param.guildCode;
if(param.cityId) this.cityId = param.cityId;
if(param.hid) this.hid = param.hid;
}
public getName() {
@@ -176,6 +208,7 @@ export class KeyName {
if(this.serverId) res += `:${this.serverId}`;
if(this.guildCode) res += `:${this.guildCode}`;
if(this.cityId) res += `:${this.cityId}`;
if(this.hid) res += `:${this.hid}`;
return res;
}
@@ -196,4 +229,11 @@ export class KeyName {
}
}
export type KeyNameParam = Partial<KeyName>;
export type KeyNameParam = Partial<KeyName>;
export interface myIdInter {
roleId?: string;
guildCode?: string;
hid?: number;
}
+3 -2
View File
@@ -1,4 +1,4 @@
import { dicHero } from "./dictionary/DicHero";
import { dicHero, dicMyHeroes } from "./dictionary/DicHero";
import { dicGoods, blueprt, dicJewel, figureCondition } from "./dictionary/DicGoods";
import { dicBlueprtCompose } from "./dictionary/DicBlueprtCompose";
import { dicBlueprtPossibility } from "./dictionary/DicBlueprtPossibility";
@@ -166,7 +166,8 @@ export const gameData = {
raceEventItems: decodeRaceEventItems(),
shop: dicShop,
shopItem: dicShopItem,
shopList: dicShopList
shopList: dicShopList,
dicMyHeroes: dicMyHeroes
};
// 在此提供一些原先在gamedata中提供的方法,以便更方便获取gameData数据
+4
View File
@@ -34,8 +34,12 @@ let arr = JSON.parse(str);
type KeysEnum<T> = { [P in keyof Required<T>]: true };
const DicHeroKeys: KeysEnum<DicHero> = {heroId: true, name: true, quality: true, camp: true, jobid: true, skill: true, pieceId: true, initialStars: true, pieceCount: true, baseAbilityArr: true, baseAbilityUpArr: true, initialSkin: true};
export const dicMyHeroes = new Array<number>();
export const dicHero = new Map<number, DicHero>();
arr.forEach(o => {
if(o.heroId > 0 && o.heroId <= 300) {
dicMyHeroes.push(o.heroId);
}
o.baseAbilityArr = parseBaseAbilityArr(o);
o.baseAbilityUpArr = parseBaseAbilityUpArr(o);
+4 -3
View File
@@ -1,17 +1,18 @@
import { HeroModel } from '../db/Hero';
import { HeroModel, HeroUpdate, HeroType } from '../db/Hero';
import { ItemModel } from '../db/Item';
import { EquipModel, RandSe, Holes } from './../db/Equip';
import { BagInter, EquipInter } from './interface';
import { gameData } from './data';
import { RANDOM_SE_COUNT, FIX_ATTRIBUTES_RAN, ITID, CURRENCY_BY_TYPE, CURRENCY_TYPE, ROLE_SELECT, FIGURE_UNLOCK_CONDITION, CONSUME_TYPE } from '../consts';
import { RANDOM_SE_COUNT, FIX_ATTRIBUTES_RAN, ITID, CURRENCY_BY_TYPE, CURRENCY_TYPE, ROLE_SELECT, FIGURE_UNLOCK_CONDITION, CONSUME_TYPE, HERO_SYSTEM_TYPE } from '../consts';
import { getRandValueByMinMax, getRandEelm } from './util';
import { findWhere } from 'underscore';
import { RoleModel, RoleType } from '../db/Role';
import { Figure } from '../domain/dbGeneral';
import { getBeforeDaySeconds } from './timeUtil';
import { calPlayerCeAndSave } from './playerCe';
export async function addSkins(roleId: string, id: number) {
let skinInfo = gameData.fashion.get(id);
@@ -213,4 +214,4 @@ function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = fals
}
return figure
}
}
+5 -3
View File
@@ -24,7 +24,7 @@ import { DicJob } from './dictionary/DicJob';
export async function calPlayerCeAndSave(type: number, roleId: string, originHero: HeroType, update: HeroUpdate, args?: Array<number>) {
let role = await RoleModel.findByRoleId(roleId);
let { attr: roleAttrs = [] } = role;
let { attr: roleAttrs = [], serverId } = role;
let heroAttrs = calPlayerCe(originHero, update, type, args); // 根据操作计算attr的增加
@@ -52,7 +52,7 @@ export async function calPlayerCeAndSave(type: number, roleId: string, originHer
ce: reduceCe(heroCe),
incHeroCe: reduceCe(incCe),
});
return { pushHeros, role, topLineupCe, hero, guild }
return { pushHeros, role, topLineupCe, hero, guild, serverId }
}
//全局属性加成
@@ -89,8 +89,10 @@ export async function reCalAllHeroCe(type: number, roleId: string, update: RoleU
update.topLineupCe = topLineupCe;
role = await RoleModel.updateRoleInfo(roleId, update);
let guild = await GuildModel.updateCe(roleId, allIncCe); // 公会更新战力
return { role, pushHeros, ce: role.ce, topLineupCe: role.topLineupCe, guild }
return { role, pushHeros, ce: role.ce, topLineupCe: role.topLineupCe, guild, serverId: role.serverId }
}
// 计算武将全局战力