Merge branch 'ce'
# Conflicts: # game-server/app.ts
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
import { HeroModel, HeroType } from '../db/Hero';
|
||||
import { HeroModel, HeroType, } 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,13 @@ 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 { getTimeFun } from './timeUtil';
|
||||
import { reCalAllHeroCe } from './playerCe';
|
||||
import { checkTaskWithEquip } from './taskUtil';
|
||||
// import { checkTask, checkTaskWithHeroes, checkTaskWithEquip, accomplishTask } from './taskUtil';
|
||||
import { CreateHeroParam } from '../domain/roleField/hero';
|
||||
import { SkinModel } from '../db/Skin';
|
||||
import { SkinModel, } from '../db/Skin';
|
||||
import { TaskListReturn } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
@@ -185,16 +184,14 @@ export function getFriendPointObject(count: number) {
|
||||
export function getHonourObject(count: number) {
|
||||
return { id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.HONOUR), count };
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁头像/相框
|
||||
* @param roleId 玩家id
|
||||
* 返回 解锁头像/相框
|
||||
* @param conditions 解锁条件
|
||||
* @param role 如果已查询过role表就直接可以使用
|
||||
*/
|
||||
export async function unlockFigure(roleId: string, conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }[], role?: RoleType) {
|
||||
if (!role || !role.heads || !role.frames) {
|
||||
role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
}
|
||||
export function unlockFigureWithoutSave(conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }[], role: RoleType) {
|
||||
|
||||
let { heads, frames, spines } = role;
|
||||
let figureInfo = { heads: new Array<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
|
||||
for (let { type, paramHid, paramFavourLv, paramSkinId } of conditions) {
|
||||
@@ -235,6 +232,20 @@ export async function unlockFigure(roleId: string, conditions: { type: number, p
|
||||
|
||||
}
|
||||
}
|
||||
return { figureInfo, heads, frames, spines };
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁头像/相框
|
||||
* @param roleId 玩家id
|
||||
* @param conditions 解锁条件
|
||||
* @param role 如果已查询过role表就直接可以使用
|
||||
*/
|
||||
export async function unlockFigure(roleId: string, conditions: { type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }[], role?: RoleType) {
|
||||
if (!role || !role.heads || !role.frames) {
|
||||
role = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_HEADS);
|
||||
}
|
||||
let { figureInfo, heads, frames, spines } = unlockFigureWithoutSave(conditions, role);
|
||||
role = await RoleModel.updateRoleInfo(roleId, { heads, frames, spines });
|
||||
return figureInfo;
|
||||
}
|
||||
@@ -314,75 +325,17 @@ 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);
|
||||
let skin = await increaseSkin(roleId, roleName, initialSkin);
|
||||
if(skin) allSkins.push(skin);
|
||||
let skins = [];
|
||||
for(let skin of allSkins) {
|
||||
skins.push({ id: skin.id, skin: skin._id, enable: skin.id == initialSkin });
|
||||
}
|
||||
// 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: { id: number, skin: string, enable: boolean }[] = [];
|
||||
// for(let skin of allSkins) {
|
||||
// skins.push({ id: skin.id, skin: skin._id, enable: skin.id == initialSkin });
|
||||
// }
|
||||
|
||||
return skins
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建武将
|
||||
* @param roleId 玩家id
|
||||
* @param roleName 玩家名
|
||||
* @param serverId 服务器id
|
||||
* @param {CreateHeroParam} heroInfo 创建武将所需信息
|
||||
* @param funcs 玩家开启了的功能,主要用于任务
|
||||
*/
|
||||
export async function createHero(roleId: string, roleName: string, serverId: number, heroInfo: CreateHeroParam, funcs?: number[]) {
|
||||
let { role, figureInfo, heroes, calHeroResults, calAllHeroResult, taskPushMessage, activityTaskPushMessage } = await createHeroes(roleId, roleName, serverId, [heroInfo], funcs)
|
||||
return { hero: heroes[0], role, figureInfo, calHeroResult: calHeroResults[0], calAllHeroResult, taskPushMessage, activityTaskPushMessage }
|
||||
}
|
||||
|
||||
export async function createHeroes(roleId: string, roleName: string, serverId: number, heroInfos: CreateHeroParam[], funcs?: number[]) {
|
||||
|
||||
let heroNum = 0;
|
||||
let conditions = new Array<{ type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
|
||||
let heroes: HeroType[] = [], calHeroResults = [], calAllHeroResult = undefined;
|
||||
let figureInfos:{ heads: Figure[], frames: Figure[], spines: Figure[] }[] = [];
|
||||
|
||||
for (let heroInfo of heroInfos) {
|
||||
let dicHero = gameData.hero.get(heroInfo.hid);
|
||||
let { quality, initialStars: star, jobid: job, name: hName, initialSkin } = dicHero;
|
||||
|
||||
let info = { roleId, roleName, serverId, quality, star, job, hName };
|
||||
|
||||
let skins = await getSkinsOfThisHero(roleId, roleName, heroInfo.hid, initialSkin);
|
||||
|
||||
let curHero = await HeroModel.createHero(Object.assign(info, heroInfo, { skins }));
|
||||
|
||||
// 计算初始战力
|
||||
let calHeroResult = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, curHero, {});
|
||||
calHeroResults.push(calHeroResult);
|
||||
heroes.push(calHeroResult.hero);
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
|
||||
heroNum++;
|
||||
}
|
||||
figureInfos.push(await unlockFigure(roleId, conditions)); // 解锁头像
|
||||
|
||||
let role = await RoleModel.incRoleInfo(roleId, { heroNum }, { heroNumUpdatedAt: nowSeconds() });
|
||||
// 任务
|
||||
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 { role, figureInfo: combineFigureInfo(figureInfos), heroes, calHeroResults, calAllHeroResult, taskPushMessage, activityTaskPushMessage }
|
||||
}
|
||||
// return skins
|
||||
// }
|
||||
|
||||
export function combineFigureInfo(figureInfos: { heads: Figure[], frames: Figure[], spines: Figure[] }[]) {
|
||||
let figureInfo = { heads: new Array<Figure>(), frames: new Array<Figure>(), spines: new Array<Figure>() };
|
||||
@@ -404,4 +357,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';
|
||||
|
||||
281
shared/pubUtils/roleUtil.ts
Normal file
281
shared/pubUtils/roleUtil.ts
Normal file
@@ -0,0 +1,281 @@
|
||||
import { DEFAULT_HERO_LV, FIGURE_UNLOCK_CONDITION, LINEUP_NUM, REDIS_KEY, STATUS, TASK_TYPE } from "../consts";
|
||||
import { SkinModel } from "../db/Skin";
|
||||
import { DEFAULT_HEROES, DEFAULT_LV, HERO_SYSTEM_TYPE } from "../consts";
|
||||
import { HeroModel, HeroType, HeroUpdate } from "../db/Hero";
|
||||
import { RoleModel, RoleType, RoleUpdate } from "../db/Role";
|
||||
import { SkinUpdate } from "../db/Skin";
|
||||
import { Figure, TopHero } from "../domain/dbGeneral";
|
||||
import { CalHeroCe, CalRoleCe } from "../domain/roleField/calCe";
|
||||
import { gameData, getHeroExpByLv } from "../pubUtils/data";
|
||||
import { accomplishTask, checkTask, checkTaskWithHeroes } from './taskUtil';
|
||||
import { combineFigureInfo, unlockFigure, unlockFigureWithoutSave } from './itemUtils';
|
||||
import { TaskListReturn } from "../domain/roleField/task";
|
||||
import { nowSeconds } from "./timeUtil";
|
||||
import { reduceCe, resResult } from "./util";
|
||||
import { calculatetopLineup, calPlayerCeAndSave } from "./playerCe";
|
||||
import { GuildModel, GuildType } from "../db/Guild";
|
||||
import { PvpDefenseModel } from "../db/PvpDefense";
|
||||
import { CreateHeroParam } from "../domain/roleField/hero";
|
||||
|
||||
// 储存在内存中的初始数据
|
||||
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);
|
||||
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);
|
||||
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, lv: DEFAULT_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0, heroNum, heroNumUpdatedAt: Date.now(), heads, frames, spines };
|
||||
return {
|
||||
role: initRole, heroes, skins: initSkins, figureInfo
|
||||
}
|
||||
}
|
||||
|
||||
export class UpdateHeroes {
|
||||
roleId: string;
|
||||
roleName: string;
|
||||
serverId: number;
|
||||
funcs: number[] = [];
|
||||
incHeroNum: number = 0;
|
||||
incRoleCe: number = 0;
|
||||
pushHeroes: {hid: number, incHeroCe: number, ce: number}[] = [];
|
||||
roleUpdate: RoleUpdate;
|
||||
role: RoleType;
|
||||
guild: GuildType;
|
||||
|
||||
constructor(roleId: string, roleName: string, serverId: number, funcs?: number[]) {
|
||||
this.roleId = roleId;
|
||||
this.roleName = roleName;
|
||||
this.serverId = serverId;
|
||||
if(funcs) this.funcs = funcs;
|
||||
}
|
||||
|
||||
public setRole(role: RoleType) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public async getRole() {
|
||||
if(!this.role) {
|
||||
this.role = await RoleModel.findByRoleId(this.roleId);
|
||||
}
|
||||
return this.role;
|
||||
}
|
||||
|
||||
public addRoleUpdateParam(param: RoleUpdate) {
|
||||
this.roleUpdate = {...this.roleUpdate, ...param};
|
||||
}
|
||||
|
||||
public async updateDbCe(isCreate: boolean, heroInfo: HeroUpdate, originCe = 0) {
|
||||
let role = await this.getRole();
|
||||
if(isCreate) this.incHeroNum ++;
|
||||
if(heroInfo != originCe) this.incRoleCe += heroInfo.ce - originCe;
|
||||
this.addRoleUpdateParam(await calculatetopLineup(role, heroInfo.hid, heroInfo.ce, heroInfo._id ));
|
||||
this.pushHeroes.push({ hid: heroInfo.hid, incHeroCe: heroInfo.ce - originCe, ce: heroInfo.ce });
|
||||
}
|
||||
|
||||
// 更新战力相关的各个表
|
||||
public async saveCeToDb() {
|
||||
let role = await this.getRole();
|
||||
// 更新role表
|
||||
this.role = await RoleModel.updateRoleInfo(this.roleId, {
|
||||
heroNum: this.incHeroNum + role.heroNum, ce: this.incRoleCe + role.ce, heroNumUpdatedAt: nowSeconds(), ...this.roleUpdate
|
||||
});
|
||||
|
||||
// 更新guild表
|
||||
if(role.hasGuild) {
|
||||
this.guild = await GuildModel.updateCe(this.roleId, this.incRoleCe); // 公会更新战力
|
||||
}
|
||||
for(let { hid, incHeroCe } of this.pushHeroes) {
|
||||
await PvpDefenseModel.updateCe(this.roleId, hid, incHeroCe); // 更新pvp防守阵战力
|
||||
}
|
||||
}
|
||||
|
||||
public async updateRedisRank(Rank: any) {
|
||||
let role = await this.getRole();
|
||||
let { serverId, roleId, pushHeroes } = this;
|
||||
// 更新军团信息
|
||||
if(this.guild) {
|
||||
let r = new Rank(REDIS_KEY.GUILD_INFO, { code: this.guild.code });
|
||||
await r.generParamAndSet(REDIS_KEY.GUILD_INFO, { roleId }, { role });
|
||||
}
|
||||
// 武将数量
|
||||
if(this.incHeroNum > 0) {
|
||||
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
|
||||
await r.setRankWithRoleInfo(roleId, role.heroNum, role.heroNumUpdatedAt, role);
|
||||
}
|
||||
|
||||
// 最强阵容
|
||||
let r = new Rank(REDIS_KEY.TOP_LINEUP_RANK, { serverId });
|
||||
await r.setRankWithRoleInfo(roleId, reduceCe(role.topLineupCe), 0, role);
|
||||
|
||||
// 最强武将
|
||||
for(let { hid, ce } of pushHeroes) {
|
||||
let r2 = new Rank(REDIS_KEY.TOP_HERO_RANK, { serverId });
|
||||
await r2.setRankWithHeroInfo(roleId, hid, ce, 0);
|
||||
|
||||
let r4 = new Rank(REDIS_KEY.HERO_RANK, { serverId, hid });
|
||||
await r4.setRankWithHeroInfo(roleId, hid, ce, 0);
|
||||
}
|
||||
|
||||
// 总战力
|
||||
let r3 = new Rank(REDIS_KEY.SUM_CE_RANK, { serverId });
|
||||
await r3.setRankWithRoleInfo(roleId, reduceCe(role.ce), 0, role);
|
||||
|
||||
// 更新最强五人阵容信息
|
||||
let r5 = new Rank(REDIS_KEY.TOP_LINEUP_INFO, { serverId });
|
||||
await r5.generParamAndSet(REDIS_KEY.TOP_LINEUP_INFO, { roleId }, { role });
|
||||
}
|
||||
|
||||
public async pushMessage(pinus: any, sid: string) {
|
||||
let role = await this.getRole();
|
||||
let uids = [{ uid: this.roleId, sid }];
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce) , heros: this.pushHeroes.map(cur => { return {...cur, ce: reduceCe(cur.ce), incHeroCe: reduceCe(cur.incHeroCe) }}), topLineupCe: reduceCe(role.topLineupCe) }), uids);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class CreateHeroes extends UpdateHeroes {
|
||||
private resultHeroes: HeroType[] = [];
|
||||
private heroNum = 0;
|
||||
// 推送信息
|
||||
private taskPushMessage: TaskListReturn[] = [];
|
||||
private activityTaskPushMessage = [];
|
||||
private figureInfos: { heads: Figure[], frames: Figure[], spines: Figure[] }[] = [];
|
||||
|
||||
// web-server和gm-server里面创建
|
||||
public async calWithParam(heroInfos: CreateHeroParam[]) {
|
||||
let heroNum = 0;
|
||||
let conditions = new Array<{ type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>();
|
||||
|
||||
for (let heroInfo of heroInfos) {
|
||||
let dicHero = gameData.hero.get(heroInfo.hid);
|
||||
let { quality, initialStars: star, jobid: job, name: hName, initialSkin } = dicHero;
|
||||
let info = { roleId: this.roleId, roleName: this.roleName, serverId: this.serverId, quality, star, job, hName };
|
||||
let skin = new SkinModel();
|
||||
let dicFashion = gameData.fashion.get(initialSkin);
|
||||
let skins = await this.getSkinsOfThisHero(heroInfo.hid, { ...skin.toJSON(), id: initialSkin, hid: heroInfo.hid, skinName: dicFashion.name });
|
||||
let curHero = await HeroModel.createHero(Object.assign(info, heroInfo, { skins }));
|
||||
|
||||
// 计算初始战力
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, this.roleId, curHero, {});
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
|
||||
heroNum++;
|
||||
}
|
||||
this.figureInfos.push(await unlockFigure(this.roleId, conditions)); // 解锁头像
|
||||
|
||||
await RoleModel.incRoleInfo(this.roleId, { heroNum }, { heroNumUpdatedAt: nowSeconds() });
|
||||
await this.clearTask();
|
||||
}
|
||||
|
||||
private async getSkinsOfThisHero(hid: number, initSkinInfo: SkinUpdate) {
|
||||
let allSkins = await SkinModel.findbyRoleAndHid(this.roleId, hid);
|
||||
let skin = await SkinModel.insertSkins(this.roleId, this.roleName, [initSkinInfo]);
|
||||
if(skin) allSkins.push(...skin);
|
||||
let skins: { id: number, skin: string, enable: boolean }[] = [];
|
||||
for(let skin of allSkins) {
|
||||
skins.push({ id: skin.id, skin: skin._id, enable: skin.id == initSkinInfo.id });
|
||||
}
|
||||
return skins
|
||||
}
|
||||
|
||||
// game-server里面创建武将
|
||||
public async createWithHeroInfo(infos: Map<number, { heroInfo: HeroUpdate, skinInfo: SkinUpdate }>) {
|
||||
let role = await this.getRole();
|
||||
// 数据处理
|
||||
let conditions = new Array<{ type: number, paramHid?: number, paramFavourLv?: number, paramSkinId?: number }>(); // 解锁头像条件
|
||||
let initHeroInfos: HeroUpdate[] = [];
|
||||
for (let [ hid, { heroInfo, skinInfo }] of infos) {
|
||||
conditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: heroInfo.hid });
|
||||
this.updateDbCe(true, heroInfo);
|
||||
// 皮肤使用初始加载进内存的数据
|
||||
let skins = await this.getSkinsOfThisHero(hid, skinInfo);
|
||||
initHeroInfos.push({ ...heroInfo, skins });
|
||||
}
|
||||
// 武将使用初始加载数据插入
|
||||
this.resultHeroes = await HeroModel.insertHeroes(this.roleId, this.roleName, this.serverId, initHeroInfos);
|
||||
// 头像解锁
|
||||
let { figureInfo, frames, heads, spines } = unlockFigureWithoutSave(conditions, role);
|
||||
this.figureInfos.push(figureInfo);
|
||||
this.addRoleUpdateParam({ frames, heads, spines });
|
||||
// 更新战力
|
||||
await this.saveCeToDb();
|
||||
await this.clearTask();
|
||||
}
|
||||
|
||||
// 创建初始账号时候的初始
|
||||
public async createWithInitInfo(heroeInfos: HeroUpdate[], skinInfos: SkinUpdate[], figureInfo: { heads: Figure[], frames: Figure[], spines: Figure[] }) {
|
||||
this.figureInfos.push(figureInfo);
|
||||
for(let heroInfo of heroeInfos) this.updateDbCe(true, heroInfo);
|
||||
this.resultHeroes = await HeroModel.insertHeroes(this.roleId, this.roleName, this.serverId, heroeInfos);
|
||||
await SkinModel.insertSkins(this.roleId, this.roleName, skinInfos);
|
||||
await this.clearTask();
|
||||
}
|
||||
|
||||
private async clearTask() {
|
||||
// 任务
|
||||
console.log('****** checkTask before', Date.now())
|
||||
let m1 = await checkTask(this.roleId, TASK_TYPE.HERO_NUM, this.heroNum, true, {}, this.funcs);
|
||||
let m2 = await checkTaskWithHeroes(this.roleId, TASK_TYPE.HERO_QUALITY, this.resultHeroes, this.funcs);
|
||||
let m3 = await checkTaskWithHeroes(this.roleId, TASK_TYPE.HERO_QUALITY_STAR_UP, this.resultHeroes, this.funcs);
|
||||
let m4 = await checkTaskWithHeroes(this.roleId, TASK_TYPE.HERO_LV, this.resultHeroes, this.funcs);
|
||||
this.taskPushMessage.push(...m1, ...m2, ...m3, ...m4);
|
||||
console.log('****** checkTask after', Date.now())
|
||||
//成长任务
|
||||
console.log('****** accomplishTask before', Date.now())
|
||||
let mm1 = await accomplishTask(this.serverId, this.roleId, TASK_TYPE.HERO_NUM, this.heroNum)
|
||||
let mm2 = await accomplishTask(this.serverId, this.roleId, TASK_TYPE.HERO_QUALITY, this.heroNum, { heroes: this.resultHeroes })
|
||||
console.log('****** accomplishTask after', Date.now())
|
||||
this.activityTaskPushMessage.push(...mm1, ...mm2);
|
||||
}
|
||||
|
||||
public async pushMessage(pinus: any, sid: string) {
|
||||
let role = await this.getRole();
|
||||
let uids = [{ uid: this.roleId, sid }];
|
||||
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce) , heros: this.pushHeroes.map(cur => { return {...cur, ce: reduceCe(cur.ce), incHeroCe: reduceCe(cur.incHeroCe) }}), topLineupCe: reduceCe(role.topLineupCe) }), uids);
|
||||
pinus.app.get('channelService').pushMessageByUids('onTaskUpdate', resResult(STATUS.SUCCESS, this.taskPushMessage), uids);
|
||||
pinus.app.get('channelService').pushMessageByUids('onActivityUpdate', resResult(STATUS.SUCCESS, this.activityTaskPushMessage), uids);
|
||||
let figureInfo = combineFigureInfo(this.figureInfos);
|
||||
if (!!figureInfo && (figureInfo.heads.length > 0 || figureInfo.frames.length > 0 || figureInfo.spines.length > 0)) {
|
||||
pinus.app.get('channelService').pushMessageByUids('onHeadChange', resResult(STATUS.SUCCESS, { ...figureInfo }), uids);
|
||||
}
|
||||
}
|
||||
|
||||
public getResultHeroes() {
|
||||
return this.resultHeroes;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user