战力:修复创建武将bug
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新排行榜数据
|
||||
|
||||
Reference in New Issue
Block a user