优化:武将初始加载
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
import { HeroModel, HeroType } from '../db/Hero';
|
||||
import { HeroModel, HeroType, HeroUpdate } from '../db/Hero';
|
||||
import { ItemModel } from '../db/Item';
|
||||
import { EquipModel, RandSe, Holes, RandMain, equipUpdate } from './../db/Equip';
|
||||
import { gameData, getQuenchByQualityAndGrade, getQuenchGradeByValue } from './data';
|
||||
@@ -8,14 +8,14 @@ import { RANDOM_SE_COUNT, ITID, CURRENCY_BY_TYPE, CURRENCY_TYPE, ROLE_SELECT, FI
|
||||
import { getRandValueByMinMax, getRandEelm } from './util';
|
||||
|
||||
import { findWhere } from 'underscore';
|
||||
import { RoleModel, RoleType } from '../db/Role';
|
||||
import { RoleModel, RoleType, } from '../db/Role';
|
||||
import { Figure } from '../domain/dbGeneral';
|
||||
import { getTimeFun, nowSeconds } from './timeUtil';
|
||||
import { calPlayerCeAndSave, reCalAllHeroCe } from './playerCe';
|
||||
import { accomplishTask, checkTask, checkTaskWithEquip, checkTaskWithHeroes } from './taskUtil';
|
||||
// import { checkTask, checkTaskWithHeroes, checkTaskWithEquip, accomplishTask } from './taskUtil';
|
||||
import { CreateHeroParam } from '../domain/roleField/hero';
|
||||
import { SkinModel } from '../db/Skin';
|
||||
import { SkinModel, SkinType, SkinUpdate, } from '../db/Skin';
|
||||
import { TaskListReturn } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
@@ -314,11 +314,11 @@ function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = fals
|
||||
return figure
|
||||
}
|
||||
|
||||
async function getSkinsOfThisHero(roleId: string, roleName: string, hid: number, initialSkin: number) {
|
||||
let allSkins = await SkinModel.findbyRoleAndHid(roleId, hid);
|
||||
async function getSkinsOfThisHero(roleId: string, roleName: string, hid: number, initialSkin: number, allSkins?: SkinType[]) {
|
||||
if(!allSkins) allSkins = await SkinModel.findbyRoleAndHid(roleId, hid);
|
||||
let skin = await increaseSkin(roleId, roleName, initialSkin);
|
||||
if(skin) allSkins.push(skin);
|
||||
let skins = [];
|
||||
let skins: { id: number, skin: string, enable: boolean }[] = [];
|
||||
for(let skin of allSkins) {
|
||||
skins.push({ id: skin.id, skin: skin._id, enable: skin.id == initialSkin });
|
||||
}
|
||||
@@ -367,7 +367,7 @@ export async function createHeroes(roleId: string, roleName: string, serverId: n
|
||||
|
||||
let role = await RoleModel.incRoleInfo(roleId, { heroNum }, { heroNumUpdatedAt: nowSeconds() });
|
||||
// 任务
|
||||
console.log('****** checkTask before', Date.now())
|
||||
console.log('****** checkTask before', Date.now())
|
||||
let m1 = await checkTask(roleId, TASK_TYPE.HERO_NUM, heroNum, true, {}, funcs);
|
||||
let m2 = await checkTaskWithHeroes(roleId, TASK_TYPE.HERO_QUALITY, heroes, funcs);
|
||||
let m3 = await checkTaskWithHeroes(roleId, TASK_TYPE.HERO_QUALITY_STAR_UP, heroes, funcs);
|
||||
@@ -375,7 +375,7 @@ export async function createHeroes(roleId: string, roleName: string, serverId: n
|
||||
let taskPushMessage = m1.concat(m2, m3, m4);
|
||||
console.log('****** checkTask after', Date.now())
|
||||
//成长任务
|
||||
console.log('****** accomplishTask before', Date.now())
|
||||
console.log('****** accomplishTask before', Date.now())
|
||||
let mm1 = await accomplishTask(serverId, roleId, TASK_TYPE.HERO_NUM, heroNum)
|
||||
let mm2 = await accomplishTask(serverId, roleId, TASK_TYPE.HERO_QUALITY, heroNum, { heroes })
|
||||
console.log('****** accomplishTask after', Date.now())
|
||||
@@ -384,6 +384,39 @@ export async function createHeroes(roleId: string, roleName: string, serverId: n
|
||||
return { role, figureInfo: combineFigureInfo(figureInfos), heroes, calHeroResults, calAllHeroResult, taskPushMessage, activityTaskPushMessage }
|
||||
}
|
||||
|
||||
|
||||
export async function createHeroesWhenInit(roleId: string, roleName: string, serverId: number, heroInfos: HeroUpdate[], skinInfos: SkinUpdate[], funcs?: number[]) {
|
||||
|
||||
let heroNum = 0;
|
||||
let conditions = new Array<{ type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
|
||||
let figureInfos:{ heads: Figure[], frames: Figure[], spines: Figure[] }[] = [];
|
||||
|
||||
for (let heroInfo of heroInfos) {
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
|
||||
heroNum++;
|
||||
}
|
||||
figureInfos.push(await unlockFigure(roleId, conditions)); // 解锁头像
|
||||
let heroes = await HeroModel.insertHeroes(roleId, roleName, serverId, heroInfos);
|
||||
await SkinModel.insertSkins(roleId, roleName, skinInfos);
|
||||
|
||||
// 任务
|
||||
console.log('****** checkTask before', Date.now())
|
||||
let m1 = await checkTask(roleId, TASK_TYPE.HERO_NUM, heroNum, true, {}, funcs);
|
||||
let m2 = await checkTaskWithHeroes(roleId, TASK_TYPE.HERO_QUALITY, heroes, funcs);
|
||||
let m3 = await checkTaskWithHeroes(roleId, TASK_TYPE.HERO_QUALITY_STAR_UP, heroes, funcs);
|
||||
let m4 = await checkTaskWithHeroes(roleId, TASK_TYPE.HERO_LV, heroes, funcs);
|
||||
let taskPushMessage = m1.concat(m2, m3, m4);
|
||||
console.log('****** checkTask after', Date.now())
|
||||
//成长任务
|
||||
console.log('****** accomplishTask before', Date.now())
|
||||
let mm1 = await accomplishTask(serverId, roleId, TASK_TYPE.HERO_NUM, heroNum)
|
||||
let mm2 = await accomplishTask(serverId, roleId, TASK_TYPE.HERO_QUALITY, heroNum, { heroes })
|
||||
console.log('****** accomplishTask after', Date.now())
|
||||
let activityTaskPushMessage = mm1.concat(mm2);
|
||||
console.log(funcs);
|
||||
return { figureInfo: combineFigureInfo(figureInfos), heroes, taskPushMessage, activityTaskPushMessage }
|
||||
}
|
||||
|
||||
export function combineFigureInfo(figureInfos: { heads: Figure[], frames: Figure[], spines: Figure[] }[]) {
|
||||
let figureInfo = { heads: new Array<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
|
||||
for(let {heads, frames, spines} of figureInfos) {
|
||||
@@ -404,4 +437,14 @@ export function transPiece(hid: number) {
|
||||
let dicHero = gameData.hero.get(hid);
|
||||
let count = gameData.heroTransPiece.get(dicHero.quality);
|
||||
return { pieceId: dicHero.pieceId, count }
|
||||
}
|
||||
}
|
||||
|
||||
// export class CreateHero {
|
||||
// roleId: string;
|
||||
// roleName: string;
|
||||
// serverId: number;
|
||||
|
||||
// constructor(roleId: string, roleName: string, serverId: number) {
|
||||
|
||||
// }
|
||||
// }
|
||||
@@ -5,9 +5,9 @@
|
||||
import { HERO_SYSTEM_TYPE, ABI_TYPE, HERO_CE_RATIO, HERO_SUB_ATTR_RATIO, LINEUP_NUM } from '../consts';
|
||||
|
||||
import { cal, deepCopy, getAllAttrStage, reduceCe } from './util';
|
||||
import { HeroModel, HeroType, HeroUpdate } from '../db/Hero';
|
||||
import { RoleModel, RoleType, RoleUpdate } from '../db/Role';
|
||||
import { CeAttrData, CeAttrDataRole, AttributeCal } from '../domain/roleField/attribute';
|
||||
import { HeroModel, HeroType, HeroUpdate, CeAttrData } from '../db/Hero';
|
||||
import { RoleModel, RoleType, RoleUpdate, CeAttrDataRole } from '../db/Role';
|
||||
import { AttributeCal } from '../domain/roleField/attribute';
|
||||
import { ABI_STAGE, SEID_TYPE } from '../consts';
|
||||
import { gameData, getJobByGradeAndClass, getHeroWakeByQuality, getHeroStarByQuality, getFriendShipById, getSchoolRateByStar, getScollByStar, getTeraph, getDicSuitByTypeAndLv } from './data';
|
||||
import { DicSe } from './dictionary/DicSe';
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user