优化:初始账号皮肤优化
This commit is contained in:
@@ -51,14 +51,19 @@ export class RoleHandler {
|
||||
hid, lv: DEFAULT_HERO_LV, exp: getHeroExpByLv(DEFAULT_HERO_LV - 1) || 0
|
||||
});
|
||||
}
|
||||
|
||||
console.log('****** createHeroes before', Date.now())
|
||||
await createHeroes(roleId, roleName, sid, serverId, funcs, heroInfos);
|
||||
console.log('****** createHeroes after', Date.now())
|
||||
session.set('roleName', roleName);
|
||||
session.push('roleName', () => { });
|
||||
|
||||
let items = [].concat(DEFAULT_ITEMS, DEFAULT_EQUIPS, [getGoldObject(DEFAULT_GOLD)], [getCoinObject(DEFAULT_COIN)]);
|
||||
await addItems(roleId, roleName, sid, items);
|
||||
|
||||
console.log('****** calAllHeroCe before', Date.now())
|
||||
let calResult = await calAllHeroCe(HERO_SYSTEM_TYPE.INIT, sid, roleId, { hasInit: true, roleName });
|
||||
console.log('****** calAllHeroCe after', Date.now())
|
||||
|
||||
let battleId = SCRIPT.SCRIPT_BATTLE_ID;
|
||||
let warInfo = gameData.war.get(battleId);
|
||||
|
||||
@@ -459,8 +459,10 @@ export async function createHeroes(roleId: string, roleName: string, sid: string
|
||||
let resultHeroes: HeroType[] = [], resultItems: RewardInter[] = [];
|
||||
if (newHeroInfo.length > 0) {
|
||||
|
||||
console.log('****** pubCreateHeroes before', Date.now())
|
||||
let { heroes, role, figureInfo, calHeroResults, calAllHeroResult, taskPushMessage, activityTaskPushMessage } = await pubCreateHeroes(roleId, roleName, serverId, newHeroInfo, funcs);
|
||||
|
||||
console.log('****** pubCreateHeroes after', Date.now())
|
||||
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
|
||||
await r.setRankWithRoleInfo(roleId, role.heroNum, role.heroNumUpdatedAt, role);
|
||||
|
||||
|
||||
@@ -17,6 +17,22 @@ import { CreateHeroParam } from '../domain/roleField/hero';
|
||||
import { SkinModel } from '../db/Skin';
|
||||
import { TaskListReturn } from '../domain/roleField/task';
|
||||
|
||||
/**
|
||||
* 只插入皮肤,不管那么多的
|
||||
* @param roleId
|
||||
* @param roleName
|
||||
* @param skinId
|
||||
* @returns
|
||||
*/
|
||||
export async function increaseSkin(roleId:string, roleName: string, skinId: number) {
|
||||
let dicSkin = gameData.fashion.get(skinId);
|
||||
if (!dicSkin) return false;
|
||||
|
||||
let skin = await SkinModel.increaseSkin(roleId, skinId, { roleId, roleName, id: skinId, skinName: dicSkin.name, hid: dicSkin.actorId });
|
||||
if(!skin) return false; // 插入失败
|
||||
return skin
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加皮肤
|
||||
* @param roleId 玩家id
|
||||
@@ -26,13 +42,10 @@ import { TaskListReturn } from '../domain/roleField/task';
|
||||
* @returns {{ hero, figureInfo, calAllHeroResult }} hero:添加皮肤后的武将 figureInfo: 触发头像添加信息 calAllHeroResult:全局战力加成后结果
|
||||
*/
|
||||
export async function addSkin(roleId: string, roleName: string, skinId: number, enable: boolean, hero?: HeroType) {
|
||||
let dicSkin = gameData.fashion.get(skinId);
|
||||
if (!dicSkin) return false;
|
||||
let skin = await increaseSkin(roleId, roleName, skinId);
|
||||
if(!skin) return false;
|
||||
|
||||
let skin = await SkinModel.increaseSkin(roleId, skinId, { roleId, roleName, id: skinId, skinName: dicSkin.name, hid: dicSkin.actorId });
|
||||
if(!skin) return false; // 插入失败
|
||||
|
||||
if(dicSkin.actorId && !hero) hero = await HeroModel.findByHidAndRole(dicSkin.actorId, roleId);
|
||||
if(skin.hid && !hero) hero = await HeroModel.findByHidAndRole(skin.hid, roleId);
|
||||
let condition = { type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: skinId };
|
||||
let figureInfo = await unlockFigure(roleId, [condition]); // 解锁头像
|
||||
let calAllHeroResult = await reCalAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, {}, [skinId]); // 全局加成
|
||||
@@ -300,16 +313,16 @@ function unlockSingleFigure(dbFigures: Figure[], id: number, unlockDirect = fals
|
||||
return figure
|
||||
}
|
||||
|
||||
async function linkOldSkins(roleId: string, hero: HeroType) {
|
||||
let allSkins = await SkinModel.findbyRoleAndHid(roleId, hero.hid);
|
||||
let skins = hero.skins||[];
|
||||
async function getSkinsOfThisHero(roleId: string, hid: number) {
|
||||
let allSkins = await SkinModel.findbyRoleAndHid(roleId, hid);
|
||||
let skins = [];
|
||||
for(let skin of allSkins) {
|
||||
let index = skins.findIndex(cur => cur.id == skin.id);
|
||||
if(index == -1) {
|
||||
skins.push({ id: skin.id, skin: skin._id, enable: false });
|
||||
}
|
||||
}
|
||||
return await HeroModel.updateHeroInfo(roleId, hero.hid, { skins })
|
||||
return skins
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -338,15 +351,11 @@ export async function createHeroes(roleId: string, roleName: string, serverId: n
|
||||
|
||||
let info = { roleId, roleName, serverId, quality, star, job, hName };
|
||||
|
||||
let curHero = await HeroModel.createHero(Object.assign(info, heroInfo));
|
||||
let addSkinResult = await addSkin(roleId, roleName, initialSkin, true, curHero); // 添加皮肤
|
||||
curHero = await linkOldSkins(roleId, curHero);
|
||||
await increaseSkin(roleId, roleName, initialSkin);
|
||||
let skins = await getSkinsOfThisHero(roleId, heroInfo.hid);
|
||||
|
||||
let curHero = await HeroModel.createHero(Object.assign(info, heroInfo, skins));
|
||||
|
||||
if(addSkinResult) { // 处理添加皮肤结果
|
||||
curHero = addSkinResult.hero;
|
||||
figureInfos.push(addSkinResult.figureInfo);
|
||||
calAllHeroResult = addSkinResult.calAllHeroResult; // 全局加成,所以同一个人的处理都是累加
|
||||
}
|
||||
// 计算初始战力
|
||||
let calHeroResult = await calPlayerCeAndSave(HERO_SYSTEM_TYPE.INIT, roleId, curHero, {});
|
||||
calHeroResults.push(calHeroResult);
|
||||
@@ -358,16 +367,20 @@ 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())
|
||||
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);
|
||||
return { role, figureInfo: combineFigureInfo(figureInfos), heroes, calHeroResults, calAllHeroResult, taskPushMessage, activityTaskPushMessage }
|
||||
return { role, figureInfo: combineFigureInfo(figureInfos), heroes, calHeroResults, calAllHeroResult, taskPushMessage:[], activityTaskPushMessage:[] }
|
||||
}
|
||||
|
||||
export function combineFigureInfo(figureInfos: { heads: Figure[], frames: Figure[], spines: Figure[] }[]) {
|
||||
|
||||
@@ -73,13 +73,14 @@ export async function reCalAllHeroCe(type: number, roleId: string, update: RoleU
|
||||
let newAttr = new AttributeCal();
|
||||
newAttr.setByDbData(roleAttrs, heroAttrs);
|
||||
let heroCe = newAttr.calCe(); // 计算最终战力
|
||||
|
||||
let incHeroCe = heroCe - hero.ce;
|
||||
allIncCe += incHeroCe;
|
||||
roleCe += heroCe;
|
||||
pushHeros.push({ hid: hero.hid, ce: reduceCe(hero.ce), incHeroCe: reduceCe(incHeroCe) });
|
||||
await HeroModel.updateHeroInfo(roleId, hero.hid, { ce: heroCe });
|
||||
await PvpDefenseModel.updateCe(roleId, hero.hid, incHeroCe); // 更新pvp防守阵战力
|
||||
if(heroCe != hero.ce) {
|
||||
let incHeroCe = heroCe - hero.ce;
|
||||
allIncCe += incHeroCe;
|
||||
roleCe += heroCe;
|
||||
pushHeros.push({ hid: hero.hid, ce: reduceCe(hero.ce + heroCe), incHeroCe: reduceCe(incHeroCe) });
|
||||
await HeroModel.updateHeroInfo(roleId, hero.hid, { ce: heroCe });
|
||||
await PvpDefenseModel.updateCe(roleId, hero.hid, incHeroCe); // 更新pvp防守阵战力
|
||||
}
|
||||
|
||||
}
|
||||
let { topLineup, topLineupCe } = await calculatetopLineup(role); // 计算更新最强五人战力
|
||||
|
||||
@@ -303,7 +303,7 @@ export async function checkTaskWithGoods(roleId: string, taskType: number, goods
|
||||
|
||||
// 根据taskType判断有哪些任务需要check的
|
||||
export async function checkTask(roleId: string, taskType: number, count: number, isInc: boolean, param: TaskParam, funcs?: number[]) {
|
||||
console.log('******checkTask', roleId, taskType, count, isInc, param, funcs)
|
||||
// console.log('******checkTask', roleId, taskType, count, isInc, param, funcs)
|
||||
let tasks = gameData.taskType.get(taskType) || [];
|
||||
let pushMessage = new Array<TaskListReturn>();
|
||||
let groups = new Map<string, { task0: DicTask, tasks: DicTask[] }>();
|
||||
@@ -438,7 +438,7 @@ export async function checkTaskRec(roleId: string, type: number, group: number,
|
||||
isMatch = taskParam[0] == 0 || param.quality == taskParam[0];
|
||||
break;
|
||||
}
|
||||
console.log('****isMatch', isMatch, checkHistory, type, taskType, group, count)
|
||||
// console.log('****isMatch', isMatch, checkHistory, type, taskType, group, count)
|
||||
if (param.isDebug) {
|
||||
isMatch = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user