任务:提取创建武将方法
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
import { HeroModel, HeroUpdate, HeroType } from '../db/Hero';
|
||||
import { HeroModel, HeroUpdate } from '../db/Hero';
|
||||
import { ItemModel } from '../db/Item';
|
||||
import { EquipModel, RandSe, Holes } from './../db/Equip';
|
||||
import { BagInter, EquipInter } from './interface';
|
||||
@@ -11,8 +11,8 @@ import { getRandValueByMinMax, getRandEelm } from './util';
|
||||
import { findWhere } from 'underscore';
|
||||
import { RoleModel, RoleType } from '../db/Role';
|
||||
import { Figure } from '../domain/dbGeneral';
|
||||
import { getBeforeDaySeconds } from './timeUtil';
|
||||
import { calPlayerCeAndSave } from './playerCe';
|
||||
import { getBeforeDaySeconds, nowSeconds } from './timeUtil';
|
||||
import { calPlayerCeAndSave, reCalAllHeroCe } from './playerCe';
|
||||
|
||||
export async function addSkins(roleId: string, id: number) {
|
||||
let skinInfo = gameData.fashion.get(id);
|
||||
@@ -98,7 +98,7 @@ export async function unlockFigure(roleId: string, conditions: { type: number, p
|
||||
role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
}
|
||||
let { heads, frames, spines } = role;
|
||||
let figureInfo = { heads: [], frames: [], spines: [] };
|
||||
let figureInfo = { heads: new Array<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
|
||||
for(let {type, paramHid, paramFavourLv, paramSkinId } of conditions) {
|
||||
let canUnLockList = gameData.figureCondition.get(type);
|
||||
if(canUnLockList) {
|
||||
@@ -214,4 +214,34 @@ function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = fals
|
||||
}
|
||||
|
||||
return figure
|
||||
}
|
||||
|
||||
export async function createHero(roleId: string, heroInfo: HeroUpdate) {
|
||||
let { role, figureInfo, heroes, calHeroResults, calAllHeroResults } = await createHeroes(roleId, [heroInfo])
|
||||
return { hero: heroes[0], role, figureInfo, calHeroResult: calHeroResults[0], calAllHeroResult: calAllHeroResults[0] }
|
||||
}
|
||||
|
||||
export async function createHeroes(roleId: string, heroInfos: HeroUpdate[]) {
|
||||
|
||||
let heroNum = 0;
|
||||
let skinIds = new Array<number>();
|
||||
let conditions = new Array<{type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
|
||||
let heroes = [], calHeroResults = [], calAllHeroResults = [];
|
||||
|
||||
for(let heroInfo of heroInfos) {
|
||||
let curHero = await HeroModel.createHero(heroInfo); heroes.push(curHero);
|
||||
let calHeroResult = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, curHero, {}); calHeroResults.push(calHeroResult);
|
||||
let calAllHeroResult = await reCalAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, {}, skinIds); calAllHeroResults.push(calAllHeroResult);
|
||||
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
|
||||
heroInfo.skins.forEach(cur => {
|
||||
skinIds.push(cur.id);
|
||||
conditions.push({type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: cur.id});
|
||||
});
|
||||
heroNum ++;
|
||||
}
|
||||
let figureInfo = await unlockFigure(roleId, conditions); // 解锁头像
|
||||
|
||||
let role = await RoleModel.incRoleInfo(roleId, { heroNum }, { heroNumUpdatedAt: nowSeconds() });
|
||||
return { role, figureInfo, heroes, calHeroResults, calAllHeroResults }
|
||||
}
|
||||
Reference in New Issue
Block a user