优化:武将初始加载

This commit is contained in:
luying
2021-09-01 19:56:19 +08:00
parent 9d25fafbde
commit e572cb2fa5
15 changed files with 507 additions and 86 deletions
+49
View File
@@ -0,0 +1,49 @@
import { DEFAULT_HERO_LV, LINEUP_NUM } from "../consts";
import { SkinModel } from "../db/Skin";
import { DEFAULT_COIN, DEFAULT_GOLD, DEFAULT_HEROES, DEFAULT_LV, HERO_SYSTEM_TYPE } from "../consts";
import { HeroModel, HeroUpdate } from "../db/Hero";
import { RoleModel, RoleUpdate } from "../db/Role";
import { SkinUpdate } from "../db/Skin";
import { TopHero } from "../domain/dbGeneral";
import { CalHeroCe, CalRoleCe } from "../domain/roleField/calCe";
import { gameData, getHeroExpByLv } from "../pubUtils/data";
// 储存在内存中的初始数据
export function getInitRoleInfo() {
let topLineup: TopHero[] = [], topLineupCe = 0, allCe = 0, initHeroes: HeroUpdate[] = [], initSkins: SkinUpdate[] = [], heroNum = 0;
let role = new RoleModel();
let calRoleCe = new CalRoleCe(role);
let roleAttr = calRoleCe.cal(HERO_SYSTEM_TYPE.INIT);
for(let hid of DEFAULT_HEROES) {
let { quality, initialStars: star, jobid: job, name: hName, initialSkin } = gameData.hero.get(hid);
// 皮肤
let skin = new SkinModel();
let dicFashion = gameData.fashion.get(initialSkin);
let skinInfo = { ...skin.toJSON(), id: initialSkin, hid, skinName: dicFashion.name };
initSkins.push(skinInfo);
// 武将
let hero = new HeroModel();
let heroInfo = {...hero.toJSON(), hid, star, quality, hName, job, skins: [{ id: initialSkin, skin: skinInfo._id, enable: true }], lv: DEFAULT_HERO_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0 };
let calHeroCe = new CalHeroCe(hid, heroInfo);
let heroAttr = calHeroCe.cal(HERO_SYSTEM_TYPE.INIT);
let ce = calHeroCe.getCalculatedCe(roleAttr);
allCe += ce;
initHeroes.push({ ...heroInfo, attr: heroAttr, ce, historyCe: ce });
heroNum++;
}
// 最强阵容
initHeroes.sort((a, b) => { return b.ce - a.ce });
for(let i = 0; i < LINEUP_NUM; i++) {
if(initHeroes[i]) {
let { hid, ce, _id } = initHeroes[i];
topLineup.push({ hid, ce, hero: _id });
topLineupCe += ce;
}
}
let initRole: RoleUpdate = { topLineupCe, topLineup, attr: roleAttr, ce: allCe, lv: DEFAULT_LV, gold: DEFAULT_GOLD, coin: DEFAULT_COIN, heroNum, heroNumUpdatedAt: Date.now() };
return {
role: initRole, heroes: initHeroes, skins: initSkins
}
}