import { DEFAULT_HEROES, DEFAULT_HERO_LV, FIGURE_UNLOCK_CONDITION, HERO_SYSTEM_TYPE, LINEUP_NUM } from "../../consts"; import { HeroModel, HeroSkin, HeroUpdate } from "../../db/Hero"; import { RoleModel, RoleUpdate } from "../../db/Role"; import { SkinModel, SkinUpdate } from "../../db/Skin"; import { TopHero } from "../../domain/dbGeneral"; import { CalHeroCe, CalRoleCe } from "../../domain/roleField/calCe"; import { gameData, getHeroExpByLv } from "../../pubUtils/data"; import { unlockFigureWithoutSave } from "./rewardService"; // 储存在内存中的初始数据 export function getInitRoleInfo() { let topLineup: TopHero[] = [], topLineupCe = 0, allCe = 0, heroes: HeroUpdate[] = [], initHeroes: HeroUpdate[] = [], initSkins: SkinUpdate[] = [], heroNum = 0, conditions: {type: FIGURE_UNLOCK_CONDITION, paramHid: number }[] = []; let role = new RoleModel(); let calRoleCe = new CalRoleCe(role); let roleAttr = calRoleCe.cal(HERO_SYSTEM_TYPE.INIT); for(let { actorId: hid } of gameData.recruit) { let { quality, initialStars: star, jobid: job, name: hName, initialSkin } = gameData.hero.get(hid); // 皮肤 let skin = new SkinModel(); let dicFashion = gameData.fashion.get(initialSkin); if(!dicFashion) { console.log(`not found skin: ${initialSkin} of ${hid}`); continue; } let skinInfo = { ...skin.toJSON(), id: initialSkin, hid, skinName: dicFashion.name, skinId: dicFashion.heroId }; initSkins.push(skinInfo); // 武将 let hero = new HeroModel(); let heroInfo = {...hero.toJSON(), hid, star, quality, hName, job, skins: [new HeroSkin(initialSkin, skinInfo.skinId, skinInfo._id, true)], skinId: skinInfo.skinId, 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); heroes.push({ ...heroInfo, attr: heroAttr, ce, historyCe: ce }); // 更新role表 if(DEFAULT_HEROES.includes(hid)) { // 头像 conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: hid }); allCe += ce; heroNum++; initHeroes.push({ ...heroInfo, attr: heroAttr, ce, historyCe: ce }); } } let { figureInfo, heads, frames, spines } = unlockFigureWithoutSave(conditions, role); // 最强阵容 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, heroNum, heroNumUpdatedAt: Date.now(), heads, frames, spines }; return { role: initRole, heroes, skins: initSkins, figureInfo } }