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

View File

@@ -10,7 +10,7 @@ import { getAtrrNameById } from '../../../consts/constModules/abilityConst'
import { findIndex } from 'underscore';
import { SclResultInter, SclPosInter } from '../../../pubUtils/interface';
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 { 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';
@@ -48,7 +48,7 @@ export class RoleHandler {
console.log('****** createHeroes before', Date.now())
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});
let createHero = new CreateHeroes(roleId, roleName, serverId);
@@ -531,8 +531,7 @@ export class RoleHandler {
return resResult(STATUS.SUCCESS);
}
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)
}
}

View File

@@ -8,6 +8,7 @@ import { RankFirstModel, RankFirstType } from '../../../db/RankFirst';
import { getInitRoleInfo } from '../../../pubUtils/roleUtil';
import { DEFAULT_HEROES } from '../../../consts';
import { Figure } from '../../../domain/dbGeneral';
import { getDefaultRoleInfo } from '../../../services/roleService';
export default function (app: Application) {
new HandlerService(app, {});
return new RoleRemote(app);
@@ -60,21 +61,18 @@ export class RoleRemote {
}
this.initRole = role;
this.figureInfo = figureInfo;
const initRoleInfos = getDefaultRoleInfo(this.initHeroes, this.initSkins, this.initRole, this.figureInfo);
this.app.set('initRoleInfos', initRoleInfos);
}
public getInitRoleInfos() {
let initInfos = [];
for(let hid of DEFAULT_HEROES) {
initInfos.push({
heroInfo: this.initHeroes.get(hid),
skinInfo: this.initSkins.get(hid)
});
let initRoleInfos = this.app.get('initRoleInfos');
if (!initRoleInfos) {
initRoleInfos = getDefaultRoleInfo(this.initHeroes, this.initSkins, this.initRole, this.figureInfo);
this.app.set('initRoleInfos', initRoleInfos);
}
return {
initInfos,
role: this.initRole,
figureInfo: this.figureInfo
};
return initRoleInfos;
}
public getInitHeroes() {

View File

@@ -1,7 +1,7 @@
import { ChannelUser } from './../domain/ChannelUser';
import { Channel, pinus } from 'pinus';
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 { Teraph, RoleModel, RoleType } from '../db/Role';
import { ROLE_SELECT } from '../consts';
@@ -10,6 +10,8 @@ import { gameData } from '../pubUtils/data';
import { SchoolModel } from '../db/School';
import { SclResultInter, SclPosInter } from '../pubUtils/interface';
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) {
let criAttr: number[] = [], times = 0;
@@ -124,4 +126,20 @@ export async function getSchoolList(roleId: string) {
});
});
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 };
}