feat(共鸣系统): 添加下发鸣主数据

This commit is contained in:
zhangxk
2023-10-10 20:47:58 +08:00
parent c23dc63bd5
commit 6470bfd5d8
5 changed files with 36 additions and 18 deletions

View File

@@ -8,7 +8,7 @@ import { HeroParam } from "../../domain/roleField/hero";
import { gameData, getEquipByJobClassAndEPlace } from "../../pubUtils/data";
import { ReturnResonanceParam } from "../../pubUtils/interface";
import { calculateCeWithHeroes } from "../playerCeService";
import { initSkinTalent } from "../roleService";
import { getNewJob, initSkinTalent } from "../roleService";
import { pick } from 'underscore';
import * as util from 'util';
@@ -19,22 +19,24 @@ import * as util from 'util';
// }
export async function refreshResonanceData(roleId: string, serverId: number, sid: string) {
let resonances: ReturnResonanceParam[] = [];
let resonanceDatas: ReturnResonanceParam[] = [];
let resonanceLv = {}, resonanceJob = {}, resonanceCon = [], resonanceEquip = [];
let dbHeroes: HeroType[] = await HeroModel.findByRole(roleId, [{ field: 'ce', sortBy: -1 }]);
if (dbHeroes.length < LINEUP_NUM) return resonances;
if (dbHeroes.length < LINEUP_NUM) return { resonanceDatas };
let { dbResonanceMap, newPositionArr } = await getResonanceDataMap(roleId);
for (let position of newPositionArr) {
resonances.push({ position });
resonanceDatas.push({ position });
}
if (dbResonanceMap.size == 0) return resonances;
if (dbResonanceMap.size == 0) return { resonanceDatas };
let dbJewelMap = await getJewelDataMap(dbHeroes);
// 武将等级
let topLineHero: HeroType = sortData(dbResonanceMap, dbHeroes, RESONANCE_SORT_TYPE.LV);
resonanceLv = { hid: topLineHero.hid, lv: topLineHero.lv };
for (let [hid] of dbResonanceMap) {
let hero = dbHeroes.find(cur => cur.hid == hid);
hero.lv = topLineHero.lv;
@@ -43,10 +45,12 @@ export async function refreshResonanceData(roleId: string, serverId: number, sid
// 职业(职阶、天赋)
topLineHero = sortData(dbResonanceMap, dbHeroes, RESONANCE_SORT_TYPE.JOBSTAGE);
resonanceJob = { hid: topLineHero.hid, job: topLineHero.job, jobStage: topLineHero.jobStage };
for (let [hid] of dbResonanceMap) {
let hero = dbHeroes.find(cur => cur.hid == hid);
let preJobStage = hero.jobStage;
hero.jobStage = topLineHero.jobStage;
hero.job = getNewJob(hero, topLineHero.job);
if (preJobStage != hero.jobStage) {
//天赋树置空
@@ -57,6 +61,7 @@ export async function refreshResonanceData(roleId: string, serverId: number, sid
// 羁绊1, 2, 3
for (let index = 1; index <= FRIENDSHIP_INDEX.THREE; index++) {
topLineHero = sortData(dbResonanceMap, dbHeroes, RESONANCE_SORT_TYPE.CONNECT, index);
resonanceCon.push({ hid: topLineHero.hid, index, level: topLineHero.connections[index]?.level || 0 });
for (let [hid] of dbResonanceMap) {
let hero = dbHeroes.find(cur => cur.hid == hid);
const topDicShipId = gameData.friendShipByIndex.get(`${topLineHero.hid}_${index}`);
@@ -70,6 +75,8 @@ export async function refreshResonanceData(roleId: string, serverId: number, sid
shipData.exp = topShipData.exp;
shipData.level = topShipData.level;
}
let tempCon = resonanceCon.find(cur => cur.index == index);
tempCon.level = topShipData.level;
}
}
@@ -78,6 +85,7 @@ export async function refreshResonanceData(roleId: string, serverId: number, sid
//装备强化
topLineHero = sortData(dbResonanceMap, dbHeroes, RESONANCE_SORT_TYPE.EQUIP_LV, id);
resonanceEquip.push({ hid: topLineHero.hid, id, lv: topLineHero.ePlace.find(cur => cur.id == id)?.lv || 0 });
for (let [hid] of dbResonanceMap) {
let hero = dbHeroes.find(cur => cur.hid == hid);
const topLineHeroEplace = topLineHero.ePlace.find(cur => cur.id == id);
@@ -169,7 +177,7 @@ export async function refreshResonanceData(roleId: string, serverId: number, sid
for (let [hid] of dbResonanceMap) {
let hero = dbHeroes.find(cur => cur.hid == hid);
// console.log('-x-x--x-x-x-x-x-x-x-x-x-55 hero', util.inspect(hero, { depth: null }));
updateHeroes.push({ ...pick(hero, ['roleId', 'hid', 'lv', 'exp', 'jobStage', 'connections', 'skins', 'jobStage', 'ePlace']) })
updateHeroes.push({ ...pick(hero, ['roleId', 'hid', 'lv', 'exp', 'job', 'jobStage', 'connections', 'skins', 'jobStage', 'ePlace']) })
newHeroes.push(hero);
newHeroIds.push(hid);
}
@@ -183,10 +191,10 @@ export async function refreshResonanceData(roleId: string, serverId: number, sid
const { hid } = hero;
const heroResult = new HeroParam(hero);
if (!dbResonanceMap.has(hid)) continue;
resonances.push({ position: dbResonanceMap.get(hid).position, ...pick(heroResult, ['hid', 'seqId', 'lv', 'exp', 'jobStage', 'talent', 'usedTalentPoint', 'totalTalentPoint', 'connections', 'ePlace', 'ce']) });
resonanceDatas.push({ position: dbResonanceMap.get(hid).position, ...pick(heroResult, ['hid', 'seqId', 'lv', 'exp', 'job', 'jobStage', 'talent', 'usedTalentPoint', 'totalTalentPoint', 'connections', 'ePlace', 'ce']) });
}
return resonances;
return { resonanceDatas, resonanceLv, resonanceJob, resonanceCon, resonanceEquip };
}
@@ -206,7 +214,10 @@ export function sortData(dbResonanceMap: Map<number, ResonanceType>, heroes: Her
case RESONANCE_SORT_TYPE.JOBSTAGE:
{
heroes.sort((a, b) => {
if (a.jobStage !== b.jobStage) {
if (a.job != b.job) {
return b.job - a.job;
}
else if (a.jobStage !== b.jobStage) {
return b.jobStage - a.jobStage;
} else {
return b.ce - a.ce;