初始连接添加军团信息

This commit is contained in:
luying
2021-02-04 15:20:44 +08:00
parent aaeaf87324
commit 86c8cbc2f1
5 changed files with 40 additions and 13 deletions

View File

@@ -7,13 +7,16 @@ import { Application } from 'pinus';
import {FrontendSession} from 'pinus';
import { HeroModel } from './../../../db/Hero';
import { resResult, returnHeroCeRatio, reduceCe } from '../../../pubUtils/util';
import { COM_BTL_QUALITY } from '../../../consts';
import { COM_BTL_QUALITY, ROLE_SELECT, HERO_SELECT, GUILD_SELECT, USER_GUILD_SELECT } from '../../../consts';
import { getAp } from '../../../services/actionPointService';
import { ItemModel } from '../../../db/Item';
import { chackFunOpenWhenLogin } from '../../../services/funcSwitchService';
import { loginRefresh } from '../../../services/playerEventService';
import { nowSeconds } from '../../../pubUtils/timeUtil';
import { getRedis, setRedis, delRedis, rmRoleFromQueue } from '../../../services/redisService';
import { UserGuildModel } from '../../../db/UserGuild';
import { GuildModel } from '../../../db/Guild';
import { gameData } from '../../../pubUtils/data';
export default function (app: Application) {
return new EntryHandler(app);
@@ -39,7 +42,7 @@ export class EntryHandler {
return resResult(STATUS.TOKEN_ERR);
}
let role = await RoleModel.findByUid(user.uid, serverId);
let role = await RoleModel.findByUid(user.uid, serverId, ROLE_SELECT.ENTRY, true);
if (!role) {
return resResult(STATUS.ROLE_NOT_FOUND);
}
@@ -83,21 +86,35 @@ export class EntryHandler {
await self.app.rpc.chat.chatRemote.addWorldChannel.route(session)(role.roleId, serverId, self.app.get('serverId'));
await self.app.rpc.chat.guildRemote.enterMyChannel.route(session)(role.roleId, self.app.get('serverId'));
let heros = await HeroModel.findByRole(role.roleId);
let heros = await HeroModel.findByRole(role.roleId, [], HERO_SELECT.ENTRY, true);
let equips = await EquipModel.findbyRole(role.roleId);
let items = await ItemModel.findbyRole(role.roleId);
await chackFunOpenWhenLogin(role, session);
await loginRefresh(role.roleId);
role['heros'] = heros.map(cur => returnHeroCeRatio(cur));
role['heros'] = heros;
role['equips'] = equips;
role['consumeGoods'] = items;
let apJson = await getAp(Date.now(), role.roleId);
role['apJson'] = apJson;
role['ce'] = reduceCe(role.ce);
role['topFiveCe'] = reduceCe(role.topFiveCe);
if(role.hasGuild) {
let userGuild = await UserGuildModel.getMyGuild(role.roleId, USER_GUILD_SELECT.ENTRY );
if(userGuild) {
let guild = await GuildModel.findGuild(userGuild.guildCode, role.serverId, GUILD_SELECT.ENTRY);
if(guild) {
role['guildAuth'] = userGuild.auth;
let {lv: guildLv, memberCnt} = guild;
let dicGuild = gameData.centerBase.get(guildLv);
if(dicGuild && memberCnt >= dicGuild.peopleNum) {
role['guildMemberMax'] = true;
} else {
role['guildMemberMax'] = false;
}
}
}
}
return resResult(STATUS.SUCCESS, { role });
}

View File

@@ -1,16 +1,18 @@
export enum ROLE_SELECT {
// 初始登录数据
ENTRY = 'serverId userInfo.uid userInfo.tel ce topFiveCe teraphs roleId roleName tili lv exp gold coin vLv title hasGuild',
// 玩家列表显示基础数据
SHOW_SIMPLE = 'roleId roleName ce headHid sHid lv title job quitTime vLv guildName',
SHOW_FRIEND_APPLY_LIST = 'roleId roleName ce headHid sHid lv title job quitTime vLv guildName friendCnt recFrdApplyCnt',
HANDLE_APPLY = 'roleId friendCnt lv',
ATTR = 'globalCeAttr',
GET_LV = 'lv',
GET_ROLE_ID = 'roleId'
};
export enum HERO_SELECT {
ENTRY = '-ceAttr',
HERO_DETAIL = 'roleId roleName hid hName ce lv star colorStar quality job skins ceAttr'
}
@@ -20,4 +22,12 @@ export enum EQUIP_SELECT {
export enum FRIEND {
SEND_PRESENT = 'friendValue friendLv'
}
export enum USER_GUILD_SELECT {
ENTRY = 'guildCode auth'
}
export enum GUILD_SELECT {
ENTRY = 'guildCode lv memberCnt'
}

View File

@@ -145,12 +145,12 @@ export default class Hero extends BaseModel {
@prop({ required: true, type: EPlace, default: getInitialEplace(), _id: false })
ePlace: EPlace[]; // 武将装备引用数组
public static async findByRole(roleId: string, sort: { field: string, sortBy: number }[] = []) {
public static async findByRole(roleId: string, sort: { field: string, sortBy: number }[] = [], select?: string, getters = false) {
let sortParam = {};
for(let {field, sortBy} of sort) {
sortParam[field] = sortBy;
}
const heros: HeroType[] = await HeroModel.find({ roleId }).sort(sortParam).lean();
const heros: HeroType[] = await HeroModel.find({ roleId }).sort(sortParam).select(select).lean({ getters });
return heros;
}

View File

@@ -116,7 +116,7 @@ export default class Role extends BaseModel {
ce: number; // 总战力
@prop({ required: true, default: new CeAttrRole(), _id: false })
globalCeAttr: CeAttrRole; // 总战力
@prop({ required: true, default: 0 })
@prop({ required: true, default: 0, set: (val: number) => val, get: (val: number) => reduceCe(val) })
topFiveCe: number; // 最强5人战力
@prop({ required: true, type: TopHero, default: [], _id: false })
topFive: Array<TopHero>; // 总战力
@@ -230,8 +230,8 @@ export default class Role extends BaseModel {
return role;
}
public static async findByUid(uid: number, serverId: number, lean = true) {
const role: RoleType = await RoleModel.findOneAndUpdate({ 'userInfo.uid': uid, serverId }, { loginTime: nowSeconds() }, { new: true }).lean(lean);
public static async findByUid(uid: number, serverId: number, select?: string, getters = false) {
const role: RoleType = await RoleModel.findOneAndUpdate({ 'userInfo.uid': uid, serverId }, { loginTime: nowSeconds() }, { new: true }).select(select).lean({ getters });
return role;
}

View File

@@ -105,7 +105,7 @@ export class GuildListInfo extends GuildMainInfo {
constructor(guild: GuildType) {
super(guild);
let leader = <RoleType>guild.leader;
this.leader = leader.roleName;
if(leader) this.leader = leader.roleName;
}
setApply(hasApply: boolean) {