role:同进程数据共享不再用 rpc

This commit is contained in:
liangtongchuan
2021-09-10 18:04:40 +08:00
parent 2de9cf0c14
commit 5fc63705d3
3 changed files with 31 additions and 16 deletions
@@ -10,7 +10,7 @@ import { getAtrrNameById } from '../../../consts/constModules/abilityConst'
import { findIndex } from 'underscore'; import { findIndex } from 'underscore';
import { SclResultInter, SclPosInter } from '../../../pubUtils/interface'; import { SclResultInter, SclPosInter } from '../../../pubUtils/interface';
import { SchoolModel } from '../../../db/School'; import { SchoolModel } from '../../../db/School';
import { getTeraphStrengthenResult, getSchoolList } from '../../../services/roleService' import { getTeraphStrengthenResult, getSchoolList, getDefaultRoleInfo } from '../../../services/roleService'
import { calPlayerCeAndSave, calAllHeroCe } from '../../../services/playerCeService'; import { calPlayerCeAndSave, calAllHeroCe } from '../../../services/playerCeService';
import { HERO_SYSTEM_TYPE, LINEUP_NUM, ROLE_SELECT, REDIS_KEY, TASK_TYPE, DEFAULT_HEROES, DEFAULT_HERO_LV, DEFAULT_ITEMS, DEFAULT_EQUIPS, DEFAULT_GOLD, DEFAULT_COIN } from '../../../consts'; import { HERO_SYSTEM_TYPE, LINEUP_NUM, ROLE_SELECT, REDIS_KEY, TASK_TYPE, DEFAULT_HEROES, DEFAULT_HERO_LV, DEFAULT_ITEMS, DEFAULT_EQUIPS, DEFAULT_GOLD, DEFAULT_COIN } from '../../../consts';
import { checkBattleHeroesByHid } from '../../../services/normalBattleService'; import { checkBattleHeroesByHid } from '../../../services/normalBattleService';
@@ -48,7 +48,7 @@ export class RoleHandler {
console.log('****** createHeroes before', Date.now()) console.log('****** createHeroes before', Date.now())
let initInfos: { role: RoleUpdate, initInfos: {heroInfo: HeroUpdate, skinInfo: SkinUpdate}[], figureInfo: { heads: Figure[], frames: Figure[], spines: Figure[] }} let initInfos: { role: RoleUpdate, initInfos: {heroInfo: HeroUpdate, skinInfo: SkinUpdate}[], figureInfo: { heads: Figure[], frames: Figure[], spines: Figure[] }}
= await this.app.rpc.role.roleRemote.getInitRoleInfos.toServer(this.app.getServerId()); = this.app.get('initRoleInfos');
role = await RoleModel.updateRoleInfo(roleId, {...initInfos.role, roleName, hasInit: true}); role = await RoleModel.updateRoleInfo(roleId, {...initInfos.role, roleName, hasInit: true});
let createHero = new CreateHeroes(roleId, roleName, serverId); let createHero = new CreateHeroes(roleId, roleName, serverId);
@@ -531,8 +531,7 @@ export class RoleHandler {
return resResult(STATUS.SUCCESS); return resResult(STATUS.SUCCESS);
} }
async getInitRole() { async getInitRole() {
let initRoleInfo = await this.app.rpc.role.roleRemote.getInitRoleInfos.toServer(this.app.getServerId()); const initRoleInfo = this.app.get('initRoleInfos');
return resResult(STATUS.SUCCESS, initRoleInfo) return resResult(STATUS.SUCCESS, initRoleInfo)
} }
} }
@@ -8,6 +8,7 @@ import { RankFirstModel, RankFirstType } from '../../../db/RankFirst';
import { getInitRoleInfo } from '../../../pubUtils/roleUtil'; import { getInitRoleInfo } from '../../../pubUtils/roleUtil';
import { DEFAULT_HEROES } from '../../../consts'; import { DEFAULT_HEROES } from '../../../consts';
import { Figure } from '../../../domain/dbGeneral'; import { Figure } from '../../../domain/dbGeneral';
import { getDefaultRoleInfo } from '../../../services/roleService';
export default function (app: Application) { export default function (app: Application) {
new HandlerService(app, {}); new HandlerService(app, {});
return new RoleRemote(app); return new RoleRemote(app);
@@ -60,21 +61,18 @@ export class RoleRemote {
} }
this.initRole = role; this.initRole = role;
this.figureInfo = figureInfo; this.figureInfo = figureInfo;
const initRoleInfos = getDefaultRoleInfo(this.initHeroes, this.initSkins, this.initRole, this.figureInfo);
this.app.set('initRoleInfos', initRoleInfos);
} }
public getInitRoleInfos() { public getInitRoleInfos() {
let initInfos = []; let initRoleInfos = this.app.get('initRoleInfos');
for(let hid of DEFAULT_HEROES) { if (!initRoleInfos) {
initInfos.push({ initRoleInfos = getDefaultRoleInfo(this.initHeroes, this.initSkins, this.initRole, this.figureInfo);
heroInfo: this.initHeroes.get(hid), this.app.set('initRoleInfos', initRoleInfos);
skinInfo: this.initSkins.get(hid)
});
} }
return { return initRoleInfos;
initInfos,
role: this.initRole,
figureInfo: this.figureInfo
};
} }
public getInitHeroes() { public getInitHeroes() {
+19 -1
View File
@@ -1,7 +1,7 @@
import { ChannelUser } from './../domain/ChannelUser'; import { ChannelUser } from './../domain/ChannelUser';
import { Channel, pinus } from 'pinus'; import { Channel, pinus } from 'pinus';
import { getRandValueByMinMax, getRandEelm, decodeIdCntArrayStr } from '../pubUtils/util'; import { getRandValueByMinMax, getRandEelm, decodeIdCntArrayStr } from '../pubUtils/util';
import { TERAPH_RANDOM } from "../consts"; import { DEFAULT_HEROES, TERAPH_RANDOM } from "../consts";
import { DicTeraph } from '../pubUtils/dictionary/DicTeraph'; import { DicTeraph } from '../pubUtils/dictionary/DicTeraph';
import { Teraph, RoleModel, RoleType } from '../db/Role'; import { Teraph, RoleModel, RoleType } from '../db/Role';
import { ROLE_SELECT } from '../consts'; import { ROLE_SELECT } from '../consts';
@@ -10,6 +10,8 @@ import { gameData } from '../pubUtils/data';
import { SchoolModel } from '../db/School'; import { SchoolModel } from '../db/School';
import { SclResultInter, SclPosInter } from '../pubUtils/interface'; import { SclResultInter, SclPosInter } from '../pubUtils/interface';
import { CheckMeterial } from './rewardService'; import { CheckMeterial } from './rewardService';
import { HeroUpdate } from '../db/Hero';
import { SkinUpdate } from '../db/Skin';
export async function getTeraphStrengthenResult(role: RoleType, count: number, dicTeraph: DicTeraph, teraph: Teraph) { export async function getTeraphStrengthenResult(role: RoleType, count: number, dicTeraph: DicTeraph, teraph: Teraph) {
let criAttr: number[] = [], times = 0; let criAttr: number[] = [], times = 0;
@@ -125,3 +127,19 @@ export async function getSchoolList(roleId: string) {
}); });
return school; return school;
} }
function getDefaultHeroInfos(heroes: Map<number, HeroUpdate>, skins: Map<number, SkinUpdate>) {
const initInfos = [];
for(let hid of DEFAULT_HEROES) {
initInfos.push({
heroInfo: heroes.get(hid),
skinInfo: skins.get(hid)
});
}
return initInfos;
}
export function getDefaultRoleInfo(heroes: Map<number, HeroUpdate>, skins: Map<number, SkinUpdate>, role, figureInfo) {
const initInfos = getDefaultHeroInfos(heroes, skins);
return { initInfos, role, figureInfo };
}