战力:修复创建武将bug

This commit is contained in:
luying
2022-03-28 17:44:14 +08:00
parent f35af70adc
commit 14b28921af
13 changed files with 379 additions and 393 deletions
@@ -20,9 +20,8 @@ import { GuildLeader } from '../../../domain/rank';
import { HeroModel } from '../../../db/Hero';
import { SkinModel } from '../../../db/Skin';
import { PvpDefenseModel } from '../../../db/PvpDefense';
import { calculatetopLineup } from '../../../pubUtils/util';
import { createHeroes } from '../../../services/role/createHero';
import { calculateCe } from '../../../services/playerCeService';
import { calculateCeWithHero } from '../../../services/playerCeService';
let timer: NodeJS.Timer;
export default function (app: Application) {
@@ -95,7 +94,7 @@ export class GmRoleHandler {
param.lv = newLv;
param['exp'] = exp;
}
await calculateCe(HERO_SYSTEM_TYPE.INIT, roleId, hero.serverId, sid, param, {}, { hid });
await calculateCeWithHero(HERO_SYSTEM_TYPE.INIT, roleId, hero.serverId, sid, hid, param);
// if(param.job > 0) {
// await calculateCe(HERO_SYSTEM_TYPE.STAGEUP, roleId, hero.serverId, sid, param, {}, { hid });
@@ -118,9 +117,8 @@ export class GmRoleHandler {
await HeroModel.deleteHero(roleId, hid);
await SkinModel.deleteByHero(roleId, hid);
let role = await RoleModel.findByRoleId(roleId);
let { topLineup, topLineupCe } = await calculatetopLineup(role, hid, 0, null);
await PvpDefenseModel.deleteHero(roleId, hid);
await RoleModel.updateRoleInfo(roleId, { topLineup, topLineupCe, ce: role.ce - hero.ce });
await RoleModel.updateRoleInfo(roleId, { topLineup: role.topLineup.filter(cur => cur.hid != hid), topLineupCe: role.topLineupCe - hero.ce, ce: role.ce - hero.ce });
return resResult(STATUS.SUCCESS);
}
@@ -16,7 +16,7 @@ import { pushEquipQualityMax, pushEquipStarMax } from "../../../services/sysChat
import { addConsumeToHero } from "../../../services/roleService";
import { CheckMeterial } from "../../../services/role/checkMaterial";
import { combineItems } from "../../../services/role/util";
import { calculateCe } from "../../../services/playerCeService";
import { calculateCeWithHero } from "../../../services/playerCeService";
export default function (app: Application) {
new HandlerService(app, {});
@@ -58,7 +58,7 @@ export class EquipHandler {
consumes: addConsumeToHero(hero.consumes, dicEquip.composeMaterial),
}
await calculateCe(HERO_SYSTEM_TYPE.COMPOSE_EQUIP, roleId, serverId, sid, update, {}, { hid, ePlaceId });
await calculateCeWithHero(HERO_SYSTEM_TYPE.COMPOSE_EQUIP, roleId, serverId, sid, hid, update, { ePlaceId });
await checkTaskInComposeEquip(serverId, roleId, sid, oldEplace, newEplace);
let curHero = {
@@ -105,7 +105,7 @@ export class EquipHandler {
ePlace: newEplace,
consumes: addConsumeToHero(hero.consumes, consumes)
}
await calculateCe(HERO_SYSTEM_TYPE.EQUIP_STRENGTH, roleId, serverId, sid, update, {}, { hid, ePlaceId });
await calculateCeWithHero(HERO_SYSTEM_TYPE.EQUIP_STRENGTH, roleId, serverId, sid, hid, update, { ePlaceId });
await checkTaskInEquipLvUp(serverId, roleId, sid, oldEplace, newEplace, [ePlaceId]);
const curHero = {
@@ -156,7 +156,7 @@ export class EquipHandler {
ePlace: newEplace,
consumes: addConsumeToHero(hero.consumes, consumes),
}
await calculateCe(HERO_SYSTEM_TYPE.EQUIP_STRENGTH, roleId, serverId, sid, update, {}, { hid, ePlaceIds: [...eplaceIds.keys()] });
await calculateCeWithHero(HERO_SYSTEM_TYPE.EQUIP_STRENGTH, roleId, serverId, sid, hid, update, { ePlaceIds: [...eplaceIds.keys()] });
await checkTaskInEquipLvUp(serverId, roleId, sid, ePlace, newEplace, [...eplaceIds.keys()]);
const curHero = {
@@ -223,7 +223,7 @@ export class EquipHandler {
ePlace: newEplace,
consumes: addConsumeToHero(hero.consumes, consumes),
}
await calculateCe(HERO_SYSTEM_TYPE.EQUIP_QUALITY, roleId, serverId, sid, update, {}, { hid, ePlaceId });
await calculateCeWithHero(HERO_SYSTEM_TYPE.EQUIP_QUALITY, roleId, serverId, sid, hid, update, { ePlaceId });
await checkTaskInEquipQualityUp(serverId, roleId, sid, oldEplace, newEplace, ePlaceId, hid, isUpQuality);
pushEquipQualityMax(roleId, roleName, serverId, hid, newEquip, isUpQuality);
@@ -298,7 +298,7 @@ export class EquipHandler {
ePlace: newEplace,
consumes: addConsumeToHero(hero.consumes, consumes)
}
await calculateCe(HERO_SYSTEM_TYPE.EQUIP_STAR, roleId, serverId, sid, update, {}, { hid, ePlaceId });
await calculateCeWithHero(HERO_SYSTEM_TYPE.EQUIP_STAR, roleId, serverId, sid, hid, update, { ePlaceId });
await checkTaskInEquipStarUp(serverId, roleId, sid, oldEplace, newEplace, ePlaceId, hid, isUpStar);
pushEquipStarMax(roleId, roleName, serverId, hid, newEquip, isUpStar);
@@ -343,7 +343,7 @@ export class EquipHandler {
let canChange = originJewel && checkJewelCanPutOnEquip(originEquip, originJewel);
if(canChange) canSentMineToOrigin = true;
let { newEplace, updatedEplace } = updateEplace(originEplace, ePlaceId, { jewel: canChange? originJewel.seqId: 0 });
await calculateCe(HERO_SYSTEM_TYPE.EQUIP_JEWEL, roleId, serverId, sid, { ePlace: newEplace }, {}, { hid, ePlaceId, oldJewel: jewel, newJewel: canChange? originJewel:null });
await calculateCeWithHero(HERO_SYSTEM_TYPE.EQUIP_JEWEL, roleId, serverId, sid, hid, { ePlace: newEplace }, { ePlaceId, oldJewel: jewel, newJewel: canChange? originJewel:null });
await checkTaskInPutJewel(serverId, roleId, sid, originEplace, newEplace, ePlaceId, jewel, canChange? originJewel:null);
originHeroResult = { hid: originHero.hid, ePlace: updatedEplace };
@@ -356,7 +356,7 @@ export class EquipHandler {
// 目标镶嵌上
let curJewel = await JewelModel.putOnOrOff(seqId, hid, ePlaceId);
let { newEplace, updatedEplace } = updateEplace(oldEplace, ePlaceId, { jewel: seqId });
await calculateCe(HERO_SYSTEM_TYPE.EQUIP_JEWEL, roleId, serverId, sid, { ePlace: newEplace }, {}, { hid, ePlaceId, oldJewel: originJewel, newJewel: curJewel });
await calculateCeWithHero(HERO_SYSTEM_TYPE.EQUIP_JEWEL, roleId, serverId, sid, hid, { ePlace: newEplace }, { ePlaceId, oldJewel: originJewel, newJewel: curJewel });
await checkTaskInPutJewel(serverId, roleId, sid, oldEplace, newEplace, ePlaceId, originJewel, curJewel);
let curHero = {
@@ -384,7 +384,7 @@ export class EquipHandler {
let curJewel = await JewelModel.putOnOrOff(curEquip.jewel, 0, 0);
let { newEplace, updatedEplace } = updateEplace(oldEplace, ePlaceId, { jewel: 0 });
await calculateCe(HERO_SYSTEM_TYPE.EQUIP_JEWEL, roleId, serverId, sid, { ePlace: newEplace }, {}, { hid, ePlaceId, oldJewel: curJewel });
await calculateCeWithHero(HERO_SYSTEM_TYPE.EQUIP_JEWEL, roleId, serverId, sid, hid, { ePlace: newEplace }, { ePlaceId, oldJewel: curJewel });
await checkTaskInPutJewel(serverId, roleId, sid, oldEplace, newEplace, ePlaceId, null, curJewel);
let curHero = {
@@ -437,7 +437,7 @@ export class EquipHandler {
ePlace: newEplace,
consumes: updateConsumes,
}
await calculateCe(HERO_SYSTEM_TYPE.EQUIP_STONE, roleId, serverId, sid, update, {}, { hid, ePlaceId, jewel });
await calculateCeWithHero(HERO_SYSTEM_TYPE.EQUIP_STONE, roleId, serverId, sid, hid, update, { ePlaceId, jewel });
await checkTaskInPutStone(serverId, roleId, sid, oldEplace, newEplace, ePlaceId, jewel);
let curHero = {
@@ -557,7 +557,7 @@ export class EquipHandler {
// 更新战力
if(hid > 0) {
const hero = await HeroModel.findByHidAndRole(hid, roleId);
await calculateCe(HERO_SYSTEM_TYPE.JEWEL_RESET_RANDSE, roleId, serverId, sid, {}, {}, { hid, ePlaceId, oldJewel: jewel, newJewel, hero });
await calculateCeWithHero(HERO_SYSTEM_TYPE.JEWEL_RESET_RANDSE, roleId, serverId, sid, hid, {}, { ePlaceId, oldJewel: jewel, newJewel, hero });
}
await checkTaskInEquipReset(serverId, roleId, sid);
@@ -639,7 +639,7 @@ export class EquipHandler {
// 更新战力
if(isSuccess && hid > 0) {
const hero = await HeroModel.findByHidAndRole(hid, roleId);
await calculateCe(HERO_SYSTEM_TYPE.JEWEL_QUENCH, roleId, serverId, sid, {}, {}, { hid, ePlaceId, oldJewel: jewel, newJewel, hero });
await calculateCeWithHero(HERO_SYSTEM_TYPE.JEWEL_QUENCH, roleId, serverId, sid, hid, {}, { ePlaceId, oldJewel: jewel, newJewel, hero });
}
await checkTaskInEquipQuench(serverId, roleId, sid, isSuccess);
@@ -759,7 +759,7 @@ export class EquipHandler {
// 更新战力
if(targetJewel.hid > 0) {
const hero = await HeroModel.findByHidAndRole(targetJewel.hid, roleId);
await calculateCe(HERO_SYSTEM_TYPE.JEWEL_RESET_RANDSE, roleId, serverId, sid, {}, {}, { hid: targetJewel.ePlaceId, ePlaceId: targetJewel.ePlaceId, oldJewel: originJewel, newJewel, hero });
await calculateCeWithHero(HERO_SYSTEM_TYPE.JEWEL_RESET_RANDSE, roleId, serverId, sid, targetJewel.hid, {}, { hid: targetJewel.ePlaceId, ePlaceId: targetJewel.ePlaceId, oldJewel: originJewel, newJewel, hero });
}
@@ -10,7 +10,6 @@ import { gameData, getHeroExpByLv, getHeroStarByQuality, getHeroWakeByQuality, g
import { ItemInter, RewardInter } from '../../../pubUtils/interface';
import { getDropItems, FIGURE_UNLOCK_CONDITION } from '../../../consts/constModules/itemConst'
import { pushComposeOrangeHero, pushHeroQualityUpMsg, pushHeroStarMax, pushHeroWakeUp } from '../../../services/chatService';
import { calculatetopLineup } from '../../../pubUtils/util';
import { PvpDefenseModel } from '../../../db/PvpDefense';
import { checkTask, checkTaskInHeroQUalityUp, checkTaskInHeroStarUp, checkTaskInHeroTrain, checkTaskInHeroWakeUp } from '../../../services/task/taskService';
import { isNumber, pick } from 'underscore';
@@ -22,7 +21,7 @@ import { HERO, REBORN } from '../../../pubUtils/dicParam';
import { createHero, createHeroes } from '../../../services/role/createHero';
import { CheckMeterial } from '../../../services/role/checkMaterial';
import { HeroParam } from '../../../domain/roleField/hero';
import { calculateCe } from '../../../services/playerCeService';
import { calculateCeWithHero } from '../../../services/playerCeService';
export default function (app: Application) {
new HandlerService(app, {});
@@ -85,7 +84,6 @@ export class HeroHandler {
let { lv: oldLv, exp: oldExp } = hero;
if (oldLv >= playerLv) return resResult(STATUS.ROLE_HERO_LV_OVER);
if (oldLv + addLv > playerLv) addLv = playerLv - oldLv;
console.log('******* addLv', addLv, oldLv, playerLv);
let nextExp = getHeroExpByLv(oldLv + addLv - 1);
console.log('nextExp', nextExp, oldLv + addLv - 1, oldExp)
@@ -127,7 +125,7 @@ export class HeroHandler {
consumes: addConsumeToHero(hero.consumes, material)
}
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.LVUP, roleId, serverId, sid, update, {}, { hid });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.LVUP, roleId, serverId, sid, hid, update);
// 任务
await checkTask(serverId, roleId, sid, TASK_TYPE.HERO_LV, { oldLv, hero: curHero });
@@ -188,7 +186,7 @@ export class HeroHandler {
}
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.STAR, roleId, serverId, sid, update, {}, { hid, hero, isUpStar });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.STAR, roleId, serverId, sid, hid, update, { hid, hero, isUpStar });
if (isUpStar) {
await checkTaskInHeroStarUp(serverId, roleId, sid, curHero, oldStar); // 任务
}
@@ -236,7 +234,7 @@ export class HeroHandler {
consumes: addConsumeToHero(hero.consumes, material)
}
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.QUALITY, roleId, serverId, sid, update, {}, { hid, hero });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.QUALITY, roleId, serverId, sid, hid, update, { hero });
await checkTaskInHeroQUalityUp(serverId, roleId, sid, curHero);
pushHeroQualityUpMsg(roleId, roleName, serverId, curHero);
return resResult(STATUS.SUCCESS, { curHero: pick(curHero, ['hid', 'quality']) });
@@ -301,7 +299,7 @@ export class HeroHandler {
consumes: addConsumeToHero(hero.consumes, consumes)
}
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.COLORSTAR, roleId, serverId, sid, update, {}, { hid, hero, isUpStar });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.COLORSTAR, roleId, serverId, sid, hid, update, { hero, isUpStar });
if (isUpStar) {
await checkTaskInHeroWakeUp(serverId, roleId, sid, curHero, oldColorStar); // 任务
}
@@ -353,7 +351,7 @@ export class HeroHandler {
jobStage: newJobStage,
consumes: addConsumeToHero(hero.consumes, consumes)
}
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.TRAIN, roleId, serverId, sid, update, {}, { hid, hero });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.TRAIN, roleId, serverId, sid, hid, update, { hero });
await checkTaskInHeroTrain(serverId, roleId, sid, curHero, trainCount); // 任务
return resResult(STATUS.SUCCESS, { curHero: pick(curHero, ['hid', 'job', 'jobStage'])});
}
@@ -389,7 +387,7 @@ export class HeroHandler {
consumes: addConsumeToHero(hero.consumes, consumes)
}
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.STAGEUP, roleId, serverId, sid, update, {}, { hid, hero });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.STAGEUP, roleId, serverId, sid, hid, update, { hid, hero });
await checkTask(serverId, roleId, sid, TASK_TYPE.HERO_STAGE_UP, { hero: curHero, stageUpCnt: 1 }); // 任务
const heroResult = new HeroParam(curHero);
return resResult(STATUS.SUCCESS, { curHero: {...pick(heroResult, ['hid', 'job', 'jobStage', 'totalTalentPoint']) }});
@@ -444,7 +442,7 @@ export class HeroHandler {
consumes: addConsumeToHero(hero.consumes, consumes)
}
//重算战力并下发
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.CONNECT, roleId, serverId, sid, update, {}, { hid: hero.hid, shipId });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.CONNECT, roleId, serverId, sid, hero.hid, update, { shipId });
// 任务
await checkTask(serverId, roleId, sid, TASK_TYPE.HERO_CONNECT, { connectLv: level })
return resResult(STATUS.SUCCESS, { curHero: pick(curHero, ['hid', 'connections']) });
@@ -531,7 +529,7 @@ export class HeroHandler {
// } else {
// hero = await HeroModel.updateHeroInfo(roleId, hero.hid, update);
// }
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.FAVOUR, roleId, serverId, sid, update, {}, { hid: hero.hid, isFavourLvUp });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.FAVOUR, roleId, serverId, sid, hero.hid, update, { isFavourLvUp });
if(isFavourLvUp) {
await unlockFigure(sid, roleId, [{ type: FIGURE_UNLOCK_CONDITION.HERO_FAVOR, paramHid: curHero.hid, paramFavourLv: curHero.favourLv }]);
await checkTask(serverId, roleId, sid, TASK_TYPE.HERO_FAVOUR_LV, { hero: curHero, oldFavourLv: oldLv }); // 任务
@@ -591,7 +589,7 @@ export class HeroHandler {
job: dicNewJob.jobid,
ePlace: newEplace
}
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.SKIN, roleId, serverId, sid, update, {}, { hid: hero.hid });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.SKIN, roleId, serverId, sid, hero.hid, update);
let resultHero = new HeroParam(curHero);
return resResult(STATUS.SUCCESS, { curHero: {...pick(resultHero, ['hid', 'skins', 'skinId', 'job', 'talent', 'usedTalentPoint']), ePlace: newEplace }});
}
@@ -658,7 +656,7 @@ export class HeroHandler {
}
}
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.REBIRTH, roleId, serverId, sid, {...initInfo, attr: heroAttr}, {}, { hid });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.REBIRTH, roleId, serverId, sid, hid, {...initInfo, attr: heroAttr});
let goods = await addItems(roleId, roleName, sid, consumes, ITEM_CHANGE_REASON.REBIRTH);
const heroResult = new HeroParam(curHero);
@@ -698,7 +696,7 @@ export class HeroHandler {
let { newSkins } = updateSkinTalent(skins, new Talent(id), usedTalentPoint + needTalentPoint);
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.TALENT, roleId, serverId, sid, { skins: newSkins }, {}, { hid });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.TALENT, roleId, serverId, sid, hid, { skins: newSkins });
const heroResult = new HeroParam(curHero);
return resResult(STATUS.SUCCESS, { curHero: {...pick(heroResult, ['hid', 'talent', 'usedTalentPoint', 'totalTalentPoint']) }});
@@ -735,7 +733,7 @@ export class HeroHandler {
let { newSkins } = updateSkinTalent(skins, new Talent(id, talent.level + 1), usedTalentPoint + needTalentPoint);
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.TALENT, roleId, serverId, sid, { skins: newSkins }, {}, { hid });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.TALENT, roleId, serverId, sid, hid, { skins: newSkins });
const heroResult = new HeroParam(curHero);
return resResult(STATUS.SUCCESS, { curHero: {...pick(heroResult, ['hid', 'talent', 'usedTalentPoint', 'totalTalentPoint']) }});
}
@@ -760,7 +758,7 @@ export class HeroHandler {
let newSkins = initSkinTalent(skins);
let { curHero } = await calculateCe(HERO_SYSTEM_TYPE.TALENT, roleId, serverId, sid, { skins: newSkins }, {}, { hid });
let { curHero } = await calculateCeWithHero(HERO_SYSTEM_TYPE.TALENT, roleId, serverId, sid, hid, { skins: newSkins });
const heroResult = new HeroParam(curHero);
return resResult(STATUS.SUCCESS, { curHero: {...pick(heroResult, ['hid', 'talent', 'usedTalentPoint', 'totalTalentPoint']) }});
@@ -820,7 +818,6 @@ export class HeroHandler {
await HeroModel.deleteHero(roleId, hid);
let role = await RoleModel.findByRoleId(roleId);
await calculatetopLineup(role, hid, 0, null);
await PvpDefenseModel.deleteHero(roleId, hid);
await RoleModel.updateRoleInfo(roleId, { topLineup: role.topLineup, topLineupCe: role.topLineupCe, ce: role.ce - hero.ce });
return resResult(STATUS.SUCCESS);
@@ -1,6 +1,6 @@
import { STATUS } from '../../../consts/statusCode';
import { RoleModel, RoleUpdate } from './../../../db/Role';
import { HeroModel, HeroUpdate } from '../../../db/Hero';
import { HeroModel, HeroType, HeroUpdate } from '../../../db/Hero';
import { resResult, decodeIdCntArrayStr, parseGoodStr, genCode } from '../../../pubUtils/util';
import { Application, BackendSession, pinus, HandlerService, } from 'pinus';
import { handleCost, addItems, getGoldObject, getCoinObject } from '../../../services/role/rewardService';
@@ -24,8 +24,8 @@ import * as dicParam from '../../../pubUtils/dicParam';
import Counter from '../../../db/Counter';
import { UserModel } from '../../../db/User';
import { checkFilterWords, reportTAEvent, treatRoleName } from '../../../services/sdkService';
import { createHeroes, CreateHeroes } from '../../../services/role/createHero';
import { calculateCe } from '../../../services/playerCeService';
import { createHeroes } from '../../../services/role/createHero';
import { calculateCeWithHero, calculateWithRole } from '../../../services/playerCeService';
export default function (app: Application) {
new HandlerService(app, {});
@@ -44,14 +44,14 @@ export class RoleHandler {
let { roleName } = msg;
let role = await RoleModel.findByRoleId(roleId, 'roleName hasInit', true);
let role = await RoleModel.findByRoleId(roleId, 'roleName hasInit title teraphs', true);
if (role.hasInit) return resResult(STATUS.ROLE_HAS_INIT);
let checkName = await RoleModel.checkName(roleName, serverId);
if (checkName) return resResult(STATUS.NAME_HAS_USED);
let { resultHeroes: heroes } = await createHeroes(roleId, roleName, sid, serverId, DEFAULT_HEROES.map(hid => ({hid, count: 1})));
role = await RoleModel.updateRoleInfo(roleId, { roleName, hasInit: true });
let { resultHeroes: heroes } = await createHeroes(roleId, roleName, sid, serverId, DEFAULT_HEROES.map(hid => ({hid, count: 1})), { roleName, hasInit: true, title: role.title, teraphs: role.teraphs });
// role = await RoleModel.updateRoleInfo(roleId, { roleName, hasInit: true }); // 在算战力的时候一起更新
session.set('roleName', roleName);
session.push('roleName', () => { });
@@ -95,7 +95,7 @@ export class RoleHandler {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
let update = { title: title + 1 }
let { curRole } = await calculateCe(HERO_SYSTEM_TYPE.TITLE, roleId, serverId, sid, {}, update, {});
let { curRole } = await calculateWithRole(HERO_SYSTEM_TYPE.TITLE, roleId, serverId, sid, update);
// 任务
await checkTask(serverId, roleId, sid, TASK_TYPE.ROLE_TITLE, { oldTitle: title, title: update.title });
@@ -128,7 +128,7 @@ export class RoleHandler {
if (!result)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
let { curRole } = await calculateCe(HERO_SYSTEM_TYPE.TERAPH, roleId, serverId, sid, {}, { teraphs }, { teraphId: id });
let { curRole } = await calculateWithRole(HERO_SYSTEM_TYPE.TERAPH, roleId, serverId, sid, { teraphs }, { teraphId: id });
// 任务
await checkTask(serverId, roleId, sid, TASK_TYPE.ROLE_TERAPH_STRENGTHEN, { count });
@@ -171,7 +171,7 @@ export class RoleHandler {
let result = await handleCost(roleId, sid, consumes, ITEM_CHANGE_REASON.TERAPH_QUALITY_UP);
if (!result)
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
let { curRole } = await calculateCe(HERO_SYSTEM_TYPE.TERAPH_UP, roleId, serverId, sid, {}, { teraphs }, { teraphId: id });
let { curRole } = await calculateWithRole(HERO_SYSTEM_TYPE.TERAPH_UP, roleId, serverId, sid, { teraphs }, { teraphId: id });
// 神像进阶,进阶一次就触发一次礼包弹框
await checkTask(serverId, roleId, sid, TASK_TYPE.ROLE_TERAPH_STAGE_UP);
@@ -204,14 +204,14 @@ export class RoleHandler {
return resResult(STATUS.DIC_DATA_NOT_FOUND);
}
let isOpen = !!dicPosition.get(positionId.toString()); // 该位置是否解锁
let curHero: HeroType = null;
if (hid > 0) {
let findHero = await SchoolModel.findByHid(roleId, hid);
if (!!findHero) {
return resResult(STATUS.ROLE_SCHOOL_HERO_USED);
}
let curHero = await HeroModel.findByHidAndRole(hid, roleId);
curHero = await HeroModel.findByHidAndRole(hid, roleId);
if (!curHero) return resResult(STATUS.HERO_NOT_FIND);
}
@@ -228,7 +228,7 @@ export class RoleHandler {
}
await SchoolModel.updateBySclAndPos(roleId, schoolId, positionId, { hid, isOpen })
await calculateCe(HERO_SYSTEM_TYPE.SCHOOL, roleId, serverId, sid, {}, {}, { schoolId, schoolHid: hid, preSchoolHid: preHid });
await calculateWithRole(HERO_SYSTEM_TYPE.SCHOOL, roleId, serverId, sid, {}, { schoolId, hero: curHero, schoolHid: hid, preSchoolHid: preHid });
// 任务
await checkTask(serverId, roleId, sid, TASK_TYPE.ROLE_SCHOOL_PUT_HERO, { hid, preHid });
@@ -319,7 +319,7 @@ export class RoleHandler {
update.scrollId = dicHeroScroll ? dicHeroScroll.id : 0;
let hero = await HeroModel.updateHeroInfo(roleId, hid, update);
await calculateCe(HERO_SYSTEM_TYPE.SCROLL, roleId, serverId, sid, update, {}, { hid });
await calculateCeWithHero(HERO_SYSTEM_TYPE.SCROLL, roleId, serverId, sid, hid, update);
// 任务
await checkTaskInActiveScroll(serverId, roleId, sid, scrollActive, hero);
+107 -25
View File
@@ -5,7 +5,7 @@
import { pinus } from 'pinus';
import { STATUS } from '../consts/statusCode';
import { resResult, reduceCe, calculatetopLineup } from '../pubUtils/util';
import { resResult, reduceCe } from '../pubUtils/util';
import { HeroModel, HeroType, HeroUpdate } from '../db/Hero';
import { RoleUpdate, RoleType, RoleModel } from '../db/Role';
@@ -18,8 +18,11 @@ import { RoleCeModel } from '../db/RoleCe';
import { PvpDefenseModel } from '../db/PvpDefense';
import { saveCeChangeLog } from '../pubUtils/logUtil';
import { JewelType } from '../db/Jewel';
import { SchoolModel } from '../db/School';
import { HasJustId } from 'mongoose';
interface Param {
isInitRole?: boolean,
hid?: number,
hero?: HeroType,
isUpStar?: boolean,
@@ -37,56 +40,135 @@ interface Param {
skinId?: number,
}
export async function calculateCe(type: HERO_SYSTEM_TYPE, roleId: string, serverId: number, sid: string, heroUpdate: HeroUpdate, roleUpdate: RoleUpdate, param: Param) {
export async function calculateCeWithHero(type: HERO_SYSTEM_TYPE, roleId: string, serverId: number, sid: string, hid: number, heroUpdate: HeroUpdate, param: Param = {}) {
let heroUpdates = new Map<number, HeroUpdate>();
heroUpdates.set(hid, heroUpdate);
let { heroes, curRole } = await calculateCes(type, roleId, serverId, sid, heroUpdates, {}, {}, param);
let curHero = heroes.find(cur => cur.hid == hid);
return { heroes, curHero, curRole }
}
export async function calculateWithRole(type: HERO_SYSTEM_TYPE, roleId: string, serverId: number, sid: string, roleUpdate: RoleUpdate, param: Param = {}) {
let { heroes, curRole } = await calculateCes(type, roleId, serverId, sid, new Map(), roleUpdate, {}, param);
return { heroes, curRole };
}
export async function calculateCes(type: HERO_SYSTEM_TYPE, roleId: string, serverId: number, sid: string, heroUpdates: Map<number, HeroUpdate>, roleUpdate: RoleUpdate, roleIncUpdate: RoleUpdate, param: Param = {}) {
let calCe = new CalCe();
let roleCe = await RoleCeModel.findByRoleId(roleId);
calCe.setRoleCe(roleCe);
switch (type) {
case HERO_SYSTEM_TYPE.LVUP: // 升级
case HERO_SYSTEM_TYPE.INIT:
{
calCe.setHeroLv(param.hid, heroUpdate.lv);
for(let [hid, { skinId, lv, quality, star, starStage, colorStar, colorStarStage, job, jobStage, }] of heroUpdates) {
calCe.setHeroBase(hid, skinId);
calCe.setHeroLv(hid, lv);
calCe.setHeroStar(hid, job, quality, star, starStage, colorStar, colorStarStage);
calCe.setJob(hid, job, jobStage);
}
if(param.isInitRole) {
let { title, teraphs } = roleUpdate;
calCe.setTitle(title);
calCe.setTeraph(teraphs);
}
break;
}
case HERO_SYSTEM_TYPE.STAR: // 升星
case HERO_SYSTEM_TYPE.LVUP: // 1. 升级
{
let { star, starStage, colorStar, colorStarStage } = heroUpdate;
let { hid, hero: { quality, job } } = param;
calCe.setHeroStar(hid, job, quality, star, starStage, colorStar, colorStarStage);
for(let [hid, { lv }] of heroUpdates) {
calCe.setHeroLv(hid, lv);
}
break;
}
case HERO_SYSTEM_TYPE.STAR: // 2. 升星
{
for(let [hid, { star, starStage }] of heroUpdates) {
let { hero: { quality, job, colorStar, colorStarStage }, isUpStar } = param;
await treatHeroStar(calCe, roleId, hid, star, starStage, quality, colorStar, colorStarStage, job, isUpStar);
}
break;
}
case HERO_SYSTEM_TYPE.QUALITY: // 3. 升品
{
for(let [hid, { quality }] of heroUpdates) {
let { hero: { star, starStage, colorStar, colorStarStage, job } } = param;
await treatHeroStar(calCe, roleId, hid, star, starStage, quality, colorStar, colorStarStage, job, true);
}
break;
}
case HERO_SYSTEM_TYPE.COLORSTAR: // 4. 觉醒
{
for(let [hid, { colorStar, colorStarStage }] of heroUpdates) {
let { hero: { star, starStage, quality, job }, isUpStar } = param;
await treatHeroStar(calCe, roleId, hid, star, starStage, quality, colorStar, colorStarStage, job, isUpStar);
}
break;
}
case HERO_SYSTEM_TYPE.SCHOOL: // 放百家学宫
{
let { schoolId, schoolHid, preSchoolHid, hero } = param;
if(preSchoolHid) {
calCe.setSchool(false, preSchoolHid, schoolId, 0, 0, 0);
}
if(schoolHid) {
let { star, colorStar, quality } = hero;
calCe.setSchool(true, schoolHid, schoolId, star, colorStar, quality);
}
break;
}
}
let { heroCe, roleInc } = calCe.getCeInc(); // 计算战力,获得有变化的武将战力
let changeHids: number[] = [];
let pushHeros = new Array<{ hid: number, ce: number, incHeroCe: number }>();
let heroes: HeroType[] = [], curHero: HeroType;
for(let [ hid, { ce, inc } ] of heroCe) {
let hero: HeroType;
if(hid == param.hid) { // 更新的那一个武将
hero = await HeroModel.updateHeroInfo(roleId, hid, { ...heroUpdate, ce });
curHero = hero;
} else { // 由于百家学宫等问题牵扯到的其他武将
hero = await HeroModel.updateHeroInfo(roleId, hid, { ce });
let heroes: HeroType[] = [];
for(let [hid, heroUpdate] of heroUpdates) {
if(heroCe.has(hid)) {
let { ce, inc } = heroCe.get(hid);
let heroUpdate = heroUpdates.get(hid)||{};
let hero = await HeroModel.updateHeroInfo(roleId, hid, { ...heroUpdate, ce });
calCe.setResultHero(hero);
heroes.push(hero);
await PvpDefenseModel.updateCe(roleId, hid, inc); // 更新pvp防守阵战力
pushHeros.push({ hid, ce, incHeroCe: inc });
changeHids.push(hid);
} else {
let hero = await HeroModel.updateHeroInfo(roleId, param.hid, heroUpdate);
heroes.push(hero);
}
calCe.setResultHero(hero);
heroes.push(hero);
await PvpDefenseModel.updateCe(roleId, hid, inc); // 更新pvp防守阵战力
pushHeros.push({ hid, ce, incHeroCe: inc })
}
if(!heroCe.has(param.hid)) {
curHero = await HeroModel.updateHeroInfo(roleId, param.hid, heroUpdate);
for(let [hid, { ce, inc }] of heroCe) {
if(changeHids.indexOf(hid) == -1) {
let hero = await HeroModel.updateHeroInfo(roleId, hid, { ce });
pushHeros.push({ hid, ce: hero.ce, incHeroCe: inc });
changeHids.push(hid);
}
}
let { topLineup, topLineupCe } = calCe.getTopLineup();
let role = await RoleModel.incRoleInfo(roleId, { ce: roleInc }, { ...roleUpdate, topLineup, topLineupCe });
let roleCeUpdate = calCe.getRoleCeTable();
roleCe = await RoleCeModel.updateRoleCe(roleId, roleCeUpdate);
let role = await RoleModel.incRoleInfo(roleId, { ...roleIncUpdate, ce: roleInc }, { ...roleUpdate, topLineup, topLineupCe });
let guild = await GuildModel.updateCe(roleId, roleInc); // 公会更新战力
saveCeChangeLog(role, roleInc, role.ce, type, [...heroCe.keys()]);
saveCeChangeLog(role, roleInc, role.ce, type, changeHids);
updateRank(roleId, serverId, topLineupCe, role, pushHeros, guild);
let uids = [{ uid: roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: role.ce, heros: pushHeros, topLineupCe }), uids);
if(guild) {
await updateUserInfo(REDIS_KEY.GUILD_INFO, guild.code, [{ field: 'guildCe', value: guild.guildCe }]);
}
return { heroes, curHero, curRole: role }
return { heroes, curRole: role }
}
async function treatHeroStar(calCe: CalCe, roleId: string, hid: number, star: number, starStage: number, quality: number, colorStar: number, colorStarStage: number, job: number, isUpStar: boolean) {
calCe.setHeroStar(hid, job, quality, star, starStage, colorStar, colorStarStage);
if(isUpStar) {
let school = await SchoolModel.findByHid(roleId, hid);
if(school) calCe.setSchool(true, hid, school.schoolId, star, colorStar, quality);
}
}
// 更新排行榜数据
+95 -50
View File
@@ -1,10 +1,10 @@
import { ABI_STAGE, ABI_STAGE_TO_TYPE, ABI_TYPE_MAIN, LINEUP_NUM, SEID_TYPE } from "../../consts";
import { HeroType, HeroUpdate } from "../../db/Hero";
import { RoleUpdate, Teraph } from "../../db/Role";
import { AttrCell, EquipAttr, HeroAttr, RoleCeType } from "../../db/RoleCe";
import { AttrCell, EquipAttr, HeroAttr, RoleCeType, SchoolAttr } from "../../db/RoleCe";
import { TopHero } from "../../domain/dbGeneral";
import { AttributeCal } from "../../domain/roleField/attribute";
import { gameData, getHeroStarByQuality, getHeroWakeByQuality, getTeraph } from "../../pubUtils/data";
import { gameData, getHeroStarByQuality, getHeroWakeByQuality, getSchoolRateByStar, getTeraph } from "../../pubUtils/data";
import { DicRandomEffectPool } from "../../pubUtils/dictionary/DicRandomEffectPool";
import { DicSe } from "../../pubUtils/dictionary/DicSe";
import { addToMap, deepCopy } from "../../pubUtils/util";
@@ -23,6 +23,8 @@ export class CalCe {
equipLv: Map<string, number> = new Map(); // hid+eplaceId => lv
originCes: Map<number, number> = new Map(); // hid => ce
resultCes: Map<number, number> = new Map(); // hid => ce
schoolAttrs: Map<string, { hid: number, attrId: number, ce: number }> = new Map(); // hid + attr => ratio
schoolAttrsByAttrId: Map<number, string[]> = new Map(); // attrId => hid + attr
private getGlobalAttrById(attrId: number) {
if(!this.globalAttrs.has(attrId)) {
@@ -39,6 +41,7 @@ export class CalCe {
private getHeroAttrByHidAndId(hid: number, attrId: number) {
let key = `${hid}_${attrId}`;
console.log('$$$$$$$$ getHeroAttrByHidAndId', hid, attrId)
if(!this.heroAttrs.has(key)) {
if(ABI_TYPE_MAIN.indexOf(attrId) != -1) {
let obj = new HeroMainAttr(hid, attrId);
@@ -53,6 +56,7 @@ export class CalCe {
}
this.heroAttrsByHid.get(hid).push(key);
}
console.log('$$$$$$$$ heroAttrsByHid', this.heroAttrsByHid)
return this.heroAttrs.get(key);
}
@@ -80,6 +84,30 @@ export class CalCe {
return this.equipAttrs.get(key);
}
private setSchoolRate(hid: number, attrId: number, value: number) {
let key = `${hid}_${attrId}`;
if(!this.schoolAttrs.has(key)) {
this.schoolAttrs.set(key, { hid, attrId, ce: value });
if(!this.schoolAttrsByAttrId.has(attrId)) {
this.schoolAttrsByAttrId.set(attrId, []);
}
this.schoolAttrsByAttrId.get(attrId).push(key);
} else {
this.schoolAttrs.get(key).ce = value;
}
}
private calSchoolAttrsToGlobal(attrId: number) {
let keys = this.schoolAttrsByAttrId.get(attrId)||[];
let schoolResult = 0;
for(let key of keys) {
let { ce } = this.schoolAttrs.get(key);
schoolResult += ce;
}
let globalAttr = this.getGlobalAttrById(attrId);
globalAttr.school = schoolResult;
}
public calHeroCe() {
let ces = new Map<number, { id: number, val: number }[]>(); // hid => [{attrId, val}]
for(let [hid, keys] of this.heroAttrsByHid) {
@@ -98,17 +126,20 @@ export class CalCe {
ces.get(hid).push({ id: attrId, val });
}
}
let result = new Map<number, number>();
for(let [hid, arr] of ces) {
let obj = new AttributeCal();
obj.setByWarJson(arr);
let ce = obj.calCe();
this.resultCes.set(hid, ce);
result.set(hid, ce);
}
return this.resultCes;
return result;
}
public getCeInc() {
let ceResult = this.calHeroCe();
console.log('##### ceResult', ceResult, 'originCes', this.originCes)
let heroCe = new Map<number, { inc: number, origin: number, ce: number }>();
let roleInc = 0;
for(let [hid, ce] of ceResult) {
@@ -137,7 +168,7 @@ export class CalCe {
let heroAttrs: HeroAttr[] = [];
for(let [hid, keys] of this.heroAttrsByHid) {
let lv = this.heroLv.get(hid);
let historyCe = this.heroHistoryCe.get(hid);
let historyCe = this.heroHistoryCe.get(hid)||0;
let objectId = this.heroObjectId.get(hid);
let attrs: AttrCell[] = [];
for(let key of keys) {
@@ -160,12 +191,18 @@ export class CalCe {
hid, eplaceId, lv, attrs
});
}
let schoolAttrs: SchoolAttr[] = [];
for(let [_, { hid, attrId, ce }] of this.schoolAttrs) {
schoolAttrs.push({ hid, attrId, value: ce });
}
return {
roleId: this.roleId, globalAttrs, heroAttrs, equipAttrs
roleId: this.roleId, globalAttrs, heroAttrs, equipAttrs, schoolAttrs
}
}
public setRoleCe(roleCe: RoleCeType) {
console.log('&&&&&&&& setRoleCe', roleCe)
this.roleId = roleCe.roleId;
if(roleCe) {
for(let globalAttr of roleCe.globalAttrs) {
@@ -188,23 +225,14 @@ export class CalCe {
obj.setByRoleCe(cell);
}
}
for(let { hid, attrId, value } of roleCe.schoolAttrs) {
this.setSchoolRate(hid, attrId, value);
}
}
this.originCes = this.calHeroCe();
console.log('############ setRoleCe', this.originCes)
}
public setInitHero(role: RoleUpdate, heroes: HeroUpdate[]) {
this.roleId = role.roleId;
for(let { hid, skinId, lv, quality, star, starStage, colorStar, colorStarStage, job, jobStage, } of heroes) {
this.setHeroBase(hid, skinId);
this.setHeroLv(hid, lv);
this.setHeroStar(hid, job, quality, star, starStage, colorStar, colorStarStage);
this.setJob(hid, job, jobStage);
}
this.setTitle(role.title);
this.setTeraph(role.teraphs);
}
public setResultHero(hero: HeroType) {
this.heroObjectId.set(hero.hid, hero._id);
}
@@ -267,7 +295,6 @@ export class CalCe {
let heroAttr = this.getHeroAttrByHidAndId(hid, attrId);
heroAttr.starUp = value;
};
}
// 职业基础
@@ -313,6 +340,23 @@ export class CalCe {
}
}
// 百家学宫
public setSchool(isPutOn: boolean, hid: number, schoolId: number, star: number, colorStar: number, quality: number) {
let dicSchool = gameData.school.get(schoolId);
let dicSchoolRate = getSchoolRateByStar(star, colorStar, quality);
console.log('#### setSchool', star, colorStar, quality, dicSchoolRate)
for (let attrId of dicSchool.upAttribute) {
if(ABI_TYPE_MAIN.includes(attrId)) { // 主属性
this.setSchoolRate(hid, attrId, isPutOn?dicSchoolRate.mainAttrAPerent: 0);
} else {
this.setSchoolRate(hid, attrId, isPutOn?dicSchoolRate.assiAttrAddValue: 0);
}
this.calSchoolAttrsToGlobal(attrId);
}
}
// 添加技能增加的被动属性
private addSeidEffect(seidList: number[]) {
let fixUp = new Map<number, number>(), ratioUp = new Map<number, number>();
@@ -383,9 +427,10 @@ abstract class GlobalAllAttr {
abstract getValues(): number[];
public getGlobalAttr() {
let values = this.getValues().map(cur => (cur||0));
return {
attrId: this.attrId,
values: this.getValues()
values
}
}
}
@@ -417,19 +462,19 @@ class GlobalMainAttr extends GlobalAllAttr {
for(let i = GLOBAL_MAIN_ATTR_INDEX.START; i < GLOBAL_MAIN_ATTR_INDEX.END; i++) {
switch(i) {
case GLOBAL_MAIN_ATTR_INDEX.SCHOOL:
if(this.school) values[i] = this.school;
values.push(this.school);
break;
case GLOBAL_MAIN_ATTR_INDEX.TERAPH:
if(this.teraph) values[i] = this.teraph;
values.push(this.teraph);
break;
case GLOBAL_MAIN_ATTR_INDEX.TITLE:
if(this.title) values[i] = this.title;
values.push(this.title);
break;
case GLOBAL_MAIN_ATTR_INDEX.SCROLL:
if(this.scroll) values[i] = this.scroll;
values.push(this.scroll);
break;
case GLOBAL_MAIN_ATTR_INDEX.SKIN:
if(this.skin) values[i] = this.skin;
values.push(this.skin);
break;
}
}
@@ -462,16 +507,16 @@ class GlobalSubAttr extends GlobalAllAttr {
for(let i = GLOBAL_MAIN_ATTR_INDEX.START; i < GLOBAL_MAIN_ATTR_INDEX.END; i++) {
switch(i) {
case GLOBAL_MAIN_ATTR_INDEX.SCHOOL:
if(this.school) values[i] = this.school;
values.push(this.school);
break;
case GLOBAL_MAIN_ATTR_INDEX.TERAPH:
if(this.teraph) values[i] = this.teraph;
values.push(this.teraph);
break;
case GLOBAL_MAIN_ATTR_INDEX.TITLE:
if(this.title) values[i] = this.title;
values.push(this.title);
break;
case GLOBAL_MAIN_ATTR_INDEX.SKIN:
if(this.skin) values[i] = this.skin;
values.push(this.skin);
break;
}
}
@@ -543,31 +588,31 @@ class HeroMainAttr extends HeroAllAttr {
for(let i = HERO_MAIN_ATTR_INDEX.START; i < HERO_MAIN_ATTR_INDEX.END; i++) {
switch(i) {
case HERO_MAIN_ATTR_INDEX.BASE:
if(this.base) values[i] = this.base;
values.push(this.base);
break;
case HERO_MAIN_ATTR_INDEX.JOB:
if(this.job) values[i] = this.job;
values.push(this.job);
break;
case HERO_MAIN_ATTR_INDEX.STAR_UP:
if(this.starUp) values[i] = this.starUp;
values.push(this.starUp);
break;
case HERO_MAIN_ATTR_INDEX.CONNECT:
if(this.connect) values[i] = this.connect;
values.push(this.connect);
break;
case HERO_MAIN_ATTR_INDEX.FAVOUR:
if(this.favour) values[i] = this.favour;
values.push(this.favour);
break;
case HERO_MAIN_ATTR_INDEX.TALENT:
if(this.talent) values[i] = this.talent;
values.push(this.talent);
break;
case HERO_MAIN_ATTR_INDEX.EQUIP:
if(this.equip) values[i] = this.equip;
values.push(this.equip);
break;
case HERO_MAIN_ATTR_INDEX.EQUIP_UP:
if(this.equipUp) values[i] = this.equipUp;
values.push(this.equipUp);
break;
case HERO_MAIN_ATTR_INDEX.EQUIP_STONE:
if(this.equipStone) values[i] = this.equipStone;
values.push(this.equipStone);
break;
}
}
@@ -599,16 +644,16 @@ class HeroSubAttr extends HeroAllAttr {
for(let i = HERO_SUB_ATTR_INDEX.START; i < HERO_SUB_ATTR_INDEX.END; i++) {
switch(i) {
case HERO_SUB_ATTR_INDEX.BASE:
if(this.base) values[i] = this.base;
values.push(this.base);
break;
case HERO_SUB_ATTR_INDEX.JOB:
if(this.job) values[i] = this.job;
values.push(this.job);
break;
case HERO_SUB_ATTR_INDEX.TALENT:
if(this.talent) values[i] = this.talent;
values.push(this.talent);
break;
case HERO_SUB_ATTR_INDEX.EQUIP:
if(this.equip) values[i] = this.equip;
values.push(this.equip);
break;
}
}
@@ -672,22 +717,22 @@ class EquipMainAttr extends EquipAllAttr {
for(let i = EQUIP_MAIN_ATTR_INDEX.START; i < EQUIP_MAIN_ATTR_INDEX.END; i++) {
switch(i) {
case EQUIP_MAIN_ATTR_INDEX.EQUIP_QUALITY:
if(this.equipQuality) values[i] = this.equipQuality;
values.push(this.equipQuality);
break;
case EQUIP_MAIN_ATTR_INDEX.EQUIP_STRENGTH:
if(this.equipStrengthen) values[i] = this.equipStrengthen;
values.push(this.equipStrengthen);
break;
case EQUIP_MAIN_ATTR_INDEX.EQUIP_STAR:
if(this.equipStar) values[i] = this.equipStar;
values.push(this.equipStar);
break;
case EQUIP_MAIN_ATTR_INDEX.EQUIP_SUIT:
if(this.equipSuit) values[i] = this.equipSuit;
values.push(this.equipSuit);
break;
case EQUIP_MAIN_ATTR_INDEX.JEWEL:
if(this.jewel) values[i] = this.jewel;
values.push(this.jewel);
break;
case EQUIP_MAIN_ATTR_INDEX.STONE:
if(this.stone) values[i] = this.stone;
values.push(this.stone);
break;
}
}
@@ -715,10 +760,10 @@ class EquipSubAttr extends EquipAllAttr {
for(let i = EQUIP_SUB_ATTR_INDEX.START; i < EQUIP_SUB_ATTR_INDEX.END; i++) {
switch(i) {
case EQUIP_SUB_ATTR_INDEX.EQUIP_STAR:
if(this.equipStar) values[i] = this.equipStar;
values.push(this.equipStar);
break;
case EQUIP_SUB_ATTR_INDEX.JEWEL:
if(this.jewel) values[i] = this.jewel;
values.push(this.jewel);
break;
}
}
+50 -183
View File
@@ -1,188 +1,19 @@
import { FIGURE_UNLOCK_CONDITION, ITEM_CHANGE_REASON, REDIS_KEY, STATUS, TASK_TYPE, HERO_SYSTEM_TYPE, LINEUP_NUM } from "../../consts";
import { FIGURE_UNLOCK_CONDITION, ITEM_CHANGE_REASON, REDIS_KEY, STATUS, TASK_TYPE, HERO_SYSTEM_TYPE, LINEUP_NUM, COUNTER } from "../../consts";
import { SkinModel } from "../../db/Skin";
import { HeroModel, HeroSkin, HeroType, HeroUpdate } from "../../db/Hero";
import { RoleModel, RoleType, RoleUpdate } from "../../db/Role";
import { SkinUpdate } from "../../db/Skin";
import { Figure, TopHero } from "../../domain/dbGeneral";
import { TaskListReturn } from "../../domain/roleField/task";
import { GuildModel, GuildType } from "../../db/Guild";
import { PvpDefenseModel } from "../../db/PvpDefense";
import { pick } from "underscore";
import { calculatetopLineup } from "../../pubUtils/util";
import { nowSeconds } from "../../pubUtils/timeUtil";
import { saveCeChangeLog } from "../../pubUtils/logUtil";
import { getRandSingleEelm, reduceCe, resResult } from "../../pubUtils/util";
import { AttributeCal } from "../../domain/roleField/attribute";
import { CreateHeroParam, HeroParam, HeroShowParam } from "../../domain/roleField/hero";
import { pinus } from "pinus";
import { Rank } from "../rankService";
import { checkTaskInCreateHero } from "../task/taskService";
import { ItemInter, RewardInter } from "../../pubUtils/interface";
import { transPiece } from "./util";
import { getInitHeroById } from "../roleService";
import { addItems, combineFigureInfo, unlockFigure, unlockFigureWithoutSave } from "./rewardService";
import { gameData } from "../../pubUtils/data";
import { CalCe } from "./calCe";
import RoleCe, { RoleCeModel, RoleCeUpdate } from "../../db/RoleCe";
export class CreateHeroes {
private roleId: string;
private roleName: string;
private serverId: number;
private incHeroNum: number = 0;
private incRoleCe: number = 0;
private role: RoleType;
private guild: GuildType;
// 推送信息
private figureConditions: { type: FIGURE_UNLOCK_CONDITION, paramHid: number }[] = [];
private skins: SkinUpdate[] = [];
private heroes: HeroUpdate[] = [];
private roleCe: RoleCeUpdate = {};
private resultHeroes: HeroType[] = [];
private topLineup: TopHero[] = [];
private topLineupCe: number = 0;
constructor(roleId: string, roleName: string, serverId: number) {
this.roleId = roleId;
this.roleName = roleName;
this.serverId = serverId;
}
public setRole(role: RoleType) {
this.role = role;
}
public async getRole() {
if(!this.role) {
this.role = await RoleModel.findByRoleId(this.roleId);
this.topLineup = this.role.topLineup;
this.topLineupCe = this.role.topLineupCe;
}
return this.role;
}
public async createHeroes(hids: number[]) {
let { roleId, roleName } = this;
for(let hid of hids) {
let initSkin = SkinModel.getInitInfo(hid);
let initHero = HeroModel.getInitInfo(hid, { roleId, roleName, skins: [new HeroSkin(initSkin)] });
this.heroes.push(initHero);
this.skins.push(initSkin);
this.figureConditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: hid });
this.incHeroNum ++;
}
await this.calCe(); // 计算战力
await this.saveCeToDb();
}
private async calCe() {
let role = await this.getRole();
let calCe = new CalCe();
calCe.setInitHero(role, this.heroes); // 设置武将初始信息
let ces = calCe.calHeroCe(); // 战力
for(let hero of this.heroes) {
hero.ce = ces.get(hero.hid)||0;
this.incRoleCe += hero.ce;
}
this.roleCe = calCe.getRoleCeTable();
}
// 更新战力相关的各个表
private async saveCeToDb() {
let role = await this.getRole();
// 更新武将表
for(let hero of this.heroes) {
let resultHero = await HeroModel.createHero(hero);
this.resultHeroes.push(resultHero);
await calculatetopLineup(role, resultHero.hid, resultHero.ce, resultHero._id);
}
this.heroes = [];
// 更新role表
role = await RoleModel.incRoleInfo(this.roleId, { heroNum: this.incHeroNum, ce: this.incRoleCe }, { heroNumUpdatedAt: nowSeconds(), });
this.setRole(role);
// 更新roleCe表
await RoleCeModel.updateRoleCe(this.roleId, this.roleCe);
// 更新皮肤表
await SkinModel.insertSkins(this.roleId, this.roleName, this.skins)
// 更新guild表
if(role.hasGuild) {
this.guild = await GuildModel.updateCe(this.roleId, this.incRoleCe, true); // 公会更新战力
}
for(let { hid, ce } of this.resultHeroes) {
await PvpDefenseModel.updateCe(this.roleId, hid, ce); // 更新pvp防守阵战力
}
saveCeChangeLog(role, this.incRoleCe, role.ce, HERO_SYSTEM_TYPE.INIT, this.resultHeroes.map(cur => cur.hid));
}
public async updateRedisRank() {
let { serverId, roleId, resultHeroes, role } = this;
// 更新军团信息
if(this.guild) {
let r = new Rank(REDIS_KEY.GUILD_INFO, { guildCode: this.guild.code });
await r.generParamAndSet(REDIS_KEY.GUILD_INFO, { guildCode: this.guild.code }, { guild: this.guild });
}
// 武将数量
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 hero of resultHeroes) {
let r2 = new Rank(REDIS_KEY.TOP_HERO_RANK, { serverId });
await r2.setRankWithHeroInfo(roleId, hero.hid, hero.ce, 0, hero);
let r4 = new Rank(REDIS_KEY.HERO_RANK, { serverId, hid: hero.hid });
await r4.setRankWithHeroInfo(roleId, hero.hid, hero.ce, 0, hero);
}
// 总战力
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(sid: string) {
let role = await this.getRole();
let uids = [{ uid: this.roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: role.ce, heros: this.resultHeroes.map(({ hid, ce }) => ({ hid, ce, incHeroCe: ce})), topLineupCe: role.topLineupCe}), uids);
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, this.getSkinPushMsg()), uids);
pinus.app.get('channelService').pushMessageByUids('onHeroUpdate', resResult(STATUS.SUCCESS, { heroes: this.getResultHeroes() }), uids);
checkTaskInCreateHero(this.serverId, this.roleId, sid, this.incHeroNum, this.resultHeroes);
await unlockFigure(sid, this.roleId, this.figureConditions);
}
private getSkinPushMsg() {
let skinPushMessages: {heros: {skins: HeroSkin[], hid: number}[], skins: {id: number, hid: number, inc: number, reason: number }[]} = { heros: [], skins:[] }; // 皮肤推送信息
for(let { hid, skins } of this.resultHeroes) {
skinPushMessages.heros.push({ hid, skins });
}
for(let { id, hid } of this.skins) {
skinPushMessages.skins.push({ id, hid, inc: 1, reason: ITEM_CHANGE_REASON.GET_HERO_UNLOCK_SKIN })
}
return skinPushMessages;
}
public getResultHeroes() {
return this.resultHeroes;
}
public getShowHeroes() {
return this.resultHeroes.map(cur => {
let hero = new HeroShowParam(cur);
return { ...hero, ce: reduceCe(cur.ce)}
});
}
}
import { addItems, combineFigureInfo, unlockFigure, } from "./rewardService";
import { CounterModel } from "../../db/Counter";
import { calculateCes } from "../playerCeService";
import { RoleUpdate } from "../../db/Role";
/**
* 创建多个武将
@@ -191,7 +22,7 @@ export class CreateHeroes {
* @param serverId
* @param heroInfo
*/
export async function createHeroes(roleId: string, roleName: string, sid: string, serverId: number, heroInfo: CreateHeroParam[]) {
export async function createHeroes(roleId: string, roleName: string, sid: string, serverId: number, heroInfo: CreateHeroParam[], initRoleInfos?: RoleUpdate) {
let hids = heroInfo.map(cur => cur.hid);
let userHeroesMap = await HeroModel.findMapByHidRange(hids, roleId);
@@ -211,24 +42,60 @@ export class CreateHeroes {
}
}
let resultHeroes: HeroType[] = [], resultItems: RewardInter[] = [], heroes: HeroShowParam[] = [];
let resultHeroes: HeroType[] = [], resultItems: RewardInter[] = [], showHeroes: HeroShowParam[] = [];
let figureConditions: { type: FIGURE_UNLOCK_CONDITION, paramHid: number }[] = [];
let incHeroNum = 0;
let skins: SkinUpdate[] = [];
if (createHids.length > 0) {
let createHero = new CreateHeroes(roleId, roleName, serverId);
await createHero.createHeroes(createHids);
await createHero.pushMessage(sid);
await createHero.updateRedisRank();
heroes = createHero.getShowHeroes();
resultHeroes = createHero.getResultHeroes();
let heroInfos = new Map<number, HeroUpdate>();
for(let hid of createHids) {
let initSkin = SkinModel.getInitInfo(hid);
skins.push(initSkin); // 初始皮肤
let seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
let initHero = HeroModel.getInitInfo(hid, { seqId, roleId, roleName, skins: [new HeroSkin(initSkin)] });
heroInfos.set(hid, initHero);
figureConditions.push({ type: FIGURE_UNLOCK_CONDITION.GET_HERO, paramHid: hid });
incHeroNum ++;
}
await unlockFigure(sid, roleId, figureConditions);
let roleUpdata: RoleUpdate = { heroNumUpdatedAt: nowSeconds() };
if(initRoleInfos) {
roleUpdata = { ...initRoleInfos, ...roleUpdata }
}
let { heroes } = await calculateCes(HERO_SYSTEM_TYPE.INIT, roleId, serverId, sid, heroInfos, roleUpdata, { heroNum: incHeroNum });
for(let hero of heroes) {
showHeroes.push(new HeroShowParam(hero));
resultHeroes.push(hero);
}
let uids = [{ uid: roleId, sid }];
await SkinModel.insertSkins(roleId, roleName, skins);
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, getSkinPushMsg(resultHeroes, skins)), uids);
pinus.app.get('channelService').pushMessageByUids('onHeroUpdate', resResult(STATUS.SUCCESS, { heroes }), uids);
}
if (pieces.length > 0) {
let goods = await addItems(roleId, roleName, sid, pieces, ITEM_CHANGE_REASON.HERO_TRANSFER_PIECE);
resultItems = goods;
}
return { heroes, resultHeroes, goods: resultItems }
return { heroes: showHeroes, resultHeroes, goods: resultItems }
}
export async function createHero(roleId: string, roleName: string, sid: string, serverId: number, heroInfo: CreateHeroParam) {
let result = await createHeroes(roleId, roleName, sid, serverId, [heroInfo]);
return result;
}
function getSkinPushMsg(resultHeroes: HeroType[], skins: SkinUpdate[]) {
let skinPushMessages: {heros: {skins: HeroSkin[], hid: number}[], skins: {id: number, hid: number, inc: number, reason: number }[]} = { heros: [], skins:[] }; // 皮肤推送信息
for(let { hid, skins } of resultHeroes) {
skinPushMessages.heros.push({ hid, skins });
}
for(let { id, hid } of skins) {
skinPushMessages.skins.push({ id, hid, inc: 1, reason: ITEM_CHANGE_REASON.GET_HERO_UNLOCK_SKIN })
}
return skinPushMessages;
}
@@ -22,11 +22,9 @@ import { reportTAEvent, reportTAUserSet } from '../sdkService';
import { saveCoinChangeLog, saveFigureInfoLog, saveGoldChangeLog, saveItemChangeLog } from '../../pubUtils/logUtil';
import { JewelModel, JewelType, jewelUpdate, RandSe } from '../../db/Jewel';
import { updateEplaces } from '../equipService';
import { checkPopUpConditionInCreateHero } from '../activity/popUpShopService';
import { CreateHeroes } from './createHero';
import { combineItems, getCoinEventProperties, getGoldEventProperties, sortItems } from './util';
import { nowSeconds } from '../../pubUtils/timeUtil';
import { calculateCe } from '../playerCeService';
import { calculateCeWithHero } from '../playerCeService';
@@ -71,7 +69,7 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
heroMap.get(jewel.hid).jewels.push(jewel);
}
}
for(let [_hid, {hero, jewels} ] of heroMap) {
for(let [hid, {hero, jewels} ] of heroMap) {
// 脱下天晶石
let update = new Map<number, Partial<EPlace>>();
for(let jewel of jewels) {
@@ -82,7 +80,7 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
}
}
let { newEplace } = updateEplaces(hero.ePlace, update);
await calculateCe(HERO_SYSTEM_TYPE.EQUIP_STRENGTH, roleId, role.serverId, sid, { ePlace: newEplace }, {}, { ePlaceIds: [...update.keys()] });
await calculateCeWithHero(HERO_SYSTEM_TYPE.EQUIP_STRENGTH, roleId, role.serverId, sid, hid, { ePlace: newEplace }, { ePlaceIds: [...update.keys()] });
}
@@ -360,7 +358,7 @@ export async function addSkin(roleId: string, roleName: string, sid: string, ski
if(skin.hid && !hero) hero = await HeroModel.findByHidAndRole(skin.hid, roleId);
let condition = { type: FIGURE_UNLOCK_CONDITION.GET_SKIN, paramSkinId: skinId };
await unlockFigure(sid, roleId, [condition]); // 解锁头像
await calculateCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, hero.serverId, sid, {}, {}, { skinId }); // 全局加成
await calculateCeWithHero(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, hero.serverId, sid, skin.hid, {}, { skinId }); // 全局加成
if (hero) { // 有武将的,将皮肤链接到武将上
let curSkin = hero.skins.find(cur => cur.id == skinId);
+15 -15
View File
@@ -64,21 +64,21 @@ module.exports = {
'required uInt32 code': 2,
'required Data data': 3
},
'onPlayerCeUpdate': {
'message Data': {
"message Hero": {
'required uInt32 hid': 1,
'required uInt32 ce': 2,
'required sInt32 incHeroCe': 3,
},
'required sInt32 ce': 1,
'repeated Hero heros': 2,
'required uInt32 topLineupCe': 3
},
'required string msg': 1,
'required uInt32 code': 2,
'required Data data': 3
},
// 'onPlayerCeUpdate': {
// 'message Data': {
// "message Hero": {
// 'required uInt32 hid': 1,
// 'required uInt32 ce': 2,
// 'required sInt32 incHeroCe': 3,
// },
// 'required sInt32 ce': 1,
// 'repeated Hero heros': 2,
// 'required uInt32 topLineupCe': 3
// },
// 'required string msg': 1,
// 'required uInt32 code': 2,
// 'required Data data': 3
// },
'onPlayerDataChange': {
'message Data': {
'optional uInt32 coin': 1,
+16 -16
View File
@@ -281,22 +281,22 @@ export default class Hero extends BaseModel {
return update
}
public static async createHero(heroInfo: HeroUpdate, lean = true) {
const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
const update = this.getInitInfo(heroInfo.hid, { ...heroInfo, seqId });
const hero: HeroType = await HeroModel.findOneAndUpdate({ roleId: heroInfo.roleId, hid: heroInfo.hid }, update, { upsert: true, new: true }).lean(lean);
return hero;
}
// public static async createHero(heroInfo: HeroUpdate, lean = true) {
// const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
// const update = this.getInitInfo(heroInfo.hid, { ...heroInfo, seqId });
// const hero: HeroType = await HeroModel.findOneAndUpdate({ roleId: heroInfo.roleId, hid: heroInfo.hid }, update, { upsert: true, new: true }).lean(lean);
// return hero;
// }
public static async insertHeroes(roleId: string, roleName: string, serverId: number, heroInfos: HeroUpdate[]) {
let insertInfos: HeroUpdate[] = [];
for(let hero of heroInfos) {
const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
insertInfos.push({ ...hero, seqId, roleId, roleName, serverId })
}
await HeroModel.insertMany(insertInfos);
return <HeroType[]>insertInfos;
}
// public static async insertHeroes(roleId: string, roleName: string, serverId: number, heroInfos: HeroUpdate[]) {
// let insertInfos: HeroUpdate[] = [];
// for(let hero of heroInfos) {
// const seqId = await CounterModel.getNewCounter(COUNTER.HID) || -1;
// insertInfos.push({ ...hero, seqId, roleId, roleName, serverId })
// }
// await HeroModel.insertMany(insertInfos);
// return <HeroType[]>insertInfos;
// }
public static async sumHeroCe(roleId: string) {
let ce: Array<{ ce: number }> = await HeroModel.aggregate([
@@ -323,7 +323,7 @@ export default class Hero extends BaseModel {
public static async updateHeroInfo(roleId: string, hid: number, heroUpdate: HeroUpdate, select?: string, getters = false) {
delete heroUpdate._id;
let result: HeroType = await HeroModel.findOneAndUpdate({ roleId, hid }, { $set: heroUpdate }, { new: true }).select(select).lean({ getters });
let result: HeroType = await HeroModel.findOneAndUpdate({ roleId, hid }, { $set: heroUpdate }, { new: true, upsert: true }).select(select).lean({ getters });
return result;
}
+4 -4
View File
@@ -5,7 +5,7 @@ import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoos
export class AttrCell {
@prop({ required: true })
attrId: number; // 属性id
@prop({ required: true })
@prop({ required: true, type: Number })
values: number[]; // 战力公式中的全局加成的数据,查表后的结果
}
@@ -35,7 +35,7 @@ export class EquipAttr {
}
// 百家学宫加成
class SchoolAttr {
export class SchoolAttr {
@prop({ required: true })
hid: number; // 武将id
@prop({ required: true })
@@ -76,13 +76,13 @@ export default class RoleCe extends BaseModel {
equipAttrs: EquipAttr[]
@prop({ required: true, type: SchoolAttr, _id: false })
schoolAttr: SchoolAttr[];
schoolAttrs: SchoolAttr[];
@prop({ required: true, type: ScrollAttr, _id: false })
scrollAttrs: ScrollAttr[];
public static async findByRoleId(roleId: string) {
let result: RoleCeType = await RoleCeModel.findOneAndUpdate({ roleId }).lean();
let result: RoleCeType = await RoleCeModel.findOne({ roleId }).lean();
return result;
}
-1
View File
@@ -4,7 +4,6 @@
import { HERO_SYSTEM_TYPE, ABI_TYPE, HERO_CE_RATIO, LINEUP_NUM, TALENT_RELATION_TYPE } from '../consts';
import { cal, calculatetopLineup, deepCopy, getAllAttrStage, reduceCe } from './util';
import { HeroModel, HeroType, HeroUpdate, CeAttrData, EPlace, Stone, Talent } from '../db/Hero';
import { RoleModel, RoleType, RoleUpdate, CeAttrDataRole } from '../db/Role';
import { AttributeCal } from '../domain/roleField/attribute';
+45 -45
View File
@@ -788,50 +788,50 @@ export function addToMap<T>(map: Map<T, number>, id: T, value: number) {
}
}
/**
* 计算最强阵容战力
* @param role
* @param hid
* @param ce
* @param heroId
*/
export async function calculatetopLineup(role: RoleType, hid?: number, ce?: number, heroId?: string) {
let topLineup = role?.topLineup || new Array();
if(!hid) { // 直接重新排
let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
} else {
topLineup.sort((a, b) => { return b.ce - a.ce }); // 0-6,最大-最小
let index = topLineup.findIndex(cur => cur.hid == hid);
if(index != -1 && !heroId) {
let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
} else {
if (index == -1) { // 不在最强列表
if (topLineup.length < LINEUP_NUM) { // 不满6人
topLineup.push({ hid, ce, hero: heroId });
} else if (topLineup.length == LINEUP_NUM) {
if (ce > topLineup[topLineup.length - 1].ce) { // 跻身最强6人
topLineup.pop();
topLineup.push({ hid, ce, hero: heroId });
}
} else {
topLineup.splice(LINEUP_NUM, topLineup.length - LINEUP_NUM);
}
} else { // 原来就是最强6人
if (ce < topLineup[topLineup.length - 1].ce) { // 滑出最强
let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
} else {
topLineup[index].ce = ce;
}
}
}
}
// /**
// * 计算最强阵容战力
// * @param role
// * @param hid
// * @param ce
// * @param heroId
// */
// export async function calculatetopLineup(role: RoleType, hid?: number, ce?: number, heroId?: string) {
// let topLineup = role?.topLineup || new Array();
// if(!hid) { // 直接重新排
// let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
// topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
// } else {
// topLineup.sort((a, b) => { return b.ce - a.ce }); // 0-6,最大-最小
// let index = topLineup.findIndex(cur => cur.hid == hid);
// if(index != -1 && !heroId) {
// let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
// topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
// } else {
// if (index == -1) { // 不在最强列表
// if (topLineup.length < LINEUP_NUM) { // 不满6人
// topLineup.push({ hid, ce, hero: heroId });
// } else if (topLineup.length == LINEUP_NUM) {
// if (ce > topLineup[topLineup.length - 1].ce) { // 跻身最强6人
// topLineup.pop();
// topLineup.push({ hid, ce, hero: heroId });
// }
// } else {
// topLineup.splice(LINEUP_NUM, topLineup.length - LINEUP_NUM);
// }
// } else { // 原来就是最强6人
// if (ce < topLineup[topLineup.length - 1].ce) { // 滑出最强
// let heroes = await HeroModel.getTopHero(role.roleId, LINEUP_NUM);
// topLineup = heroes.map(cur => { return { hid: cur.hid, ce: cur.ce, hero: cur._id } });
// } else {
// topLineup[index].ce = ce;
// }
// }
// }
// }
let topLineupCe = topLineup.reduce((pre, cur) => {
return pre + cur.ce
}, 0);
// let topLineupCe = topLineup.reduce((pre, cur) => {
// return pre + cur.ce
// }, 0);
return { topLineup, topLineupCe };
}
// return { topLineup, topLineupCe };
// }