战力:替换新方法
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import { ABI_STAGE, ABI_STAGE_TO_TYPE, ABI_TYPE_MAIN, SEID_TYPE } from "../../consts";
|
||||
import { HeroUpdate } from "../../db/Hero";
|
||||
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 { TopHero } from "../../domain/dbGeneral";
|
||||
import { AttributeCal } from "../../domain/roleField/attribute";
|
||||
import { gameData, getHeroStarByQuality, getHeroWakeByQuality, getTeraph } from "../../pubUtils/data";
|
||||
import { DicRandomEffectPool } from "../../pubUtils/dictionary/DicRandomEffectPool";
|
||||
import { DicSe } from "../../pubUtils/dictionary/DicSe";
|
||||
import { addToMap, deepCopy } from "../../pubUtils/util";
|
||||
|
||||
class RoleCe {
|
||||
export class CalCe {
|
||||
roleId: string;
|
||||
globalAttrs: Map<number, GlobalMainAttr|GlobalSubAttr> = new Map(); // attrId => GlobalAttr
|
||||
heroAttrs: Map<string, HeroMainAttr|HeroSubAttr> = new Map(); // hid+attrId => HeroAttr
|
||||
@@ -17,31 +18,13 @@ class RoleCe {
|
||||
equipAttrsByHid: Map<number, string[]> = new Map(); // hid => [hid+eplaceId+attrId]
|
||||
equipAttrsByHidAndEplace: Map<string, { hid: number, eplaceId: number, keys: string[]}> = new Map(); // hid+eplaceId =>+eplaceId+attrId]
|
||||
heroLv: Map<number, number> = new Map();
|
||||
heroHistoryCe: Map<number, number> = new Map();
|
||||
heroObjectId: Map<number, string> = new Map();
|
||||
equipLv: Map<string, number> = new Map(); // hid+eplaceId => lv
|
||||
|
||||
setRoleCe(roleCe: RoleCeType) {
|
||||
this.roleId = roleCe.roleId;
|
||||
for(let globalAttr of roleCe.globalAttrs) {
|
||||
let obj = this.getGlobalAttrById(globalAttr.attrId);
|
||||
obj.setByRoleCe(globalAttr);
|
||||
}
|
||||
for(let {hid, lv, attrs} of roleCe.heroAttrs) {
|
||||
this.heroLv.set(hid, lv);
|
||||
for(let cell of attrs) {
|
||||
let obj = this.getHeroAttrByHidAndId(hid, cell.attrId);
|
||||
obj.setByRoleCe(cell);
|
||||
}
|
||||
}
|
||||
for(let { hid, eplaceId, lv, attrs } of roleCe.equipAttrs) {
|
||||
this.equipLv.set(`${hid}_${eplaceId}`, lv);
|
||||
for(let cell of attrs) {
|
||||
let obj = this.getEquipAttrByHidAndId(hid, eplaceId, cell.attrId);
|
||||
obj.setByRoleCe(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
originCes: Map<number, number> = new Map(); // hid => ce
|
||||
resultCes: Map<number, number> = new Map(); // hid => ce
|
||||
|
||||
public getGlobalAttrById(attrId: number) {
|
||||
private getGlobalAttrById(attrId: number) {
|
||||
if(!this.globalAttrs.has(attrId)) {
|
||||
if(ABI_TYPE_MAIN.indexOf(attrId) != -1) {
|
||||
let obj = new GlobalMainAttr(attrId);
|
||||
@@ -54,7 +37,7 @@ class RoleCe {
|
||||
return this.globalAttrs.get(attrId);
|
||||
}
|
||||
|
||||
public getHeroAttrByHidAndId(hid: number, attrId: number) {
|
||||
private getHeroAttrByHidAndId(hid: number, attrId: number) {
|
||||
let key = `${hid}_${attrId}`;
|
||||
if(!this.heroAttrs.has(key)) {
|
||||
if(ABI_TYPE_MAIN.indexOf(attrId) != -1) {
|
||||
@@ -73,7 +56,7 @@ class RoleCe {
|
||||
return this.heroAttrs.get(key);
|
||||
}
|
||||
|
||||
public getEquipAttrByHidAndId(hid: number, eplaceId: number, attrId: number) {
|
||||
private getEquipAttrByHidAndId(hid: number, eplaceId: number, attrId: number) {
|
||||
let key = `${hid}_${eplaceId}_${attrId}`;
|
||||
if(!this.equipAttrs.has(key)) {
|
||||
if(ABI_TYPE_MAIN.indexOf(attrId) != -1) {
|
||||
@@ -115,13 +98,35 @@ class RoleCe {
|
||||
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);
|
||||
result.set(hid, obj.calCe());
|
||||
let ce = obj.calCe();
|
||||
this.resultCes.set(hid, ce);
|
||||
}
|
||||
return this.resultCes;
|
||||
}
|
||||
|
||||
public getCeInc() {
|
||||
let ceResult = this.calHeroCe();
|
||||
let heroCe = new Map<number, { inc: number, origin: number, ce: number }>();
|
||||
let roleInc = 0;
|
||||
for(let [hid, ce] of ceResult) {
|
||||
let originCe = this.originCes.get(hid)||0;
|
||||
if(ce != originCe) {
|
||||
heroCe.set(hid, { inc: ce - originCe, origin: originCe, ce });
|
||||
roleInc += ce - originCe;
|
||||
this.setHistoryCe(hid, ce);
|
||||
}
|
||||
}
|
||||
return { heroCe, roleInc }
|
||||
}
|
||||
|
||||
private setHistoryCe(hid: number, ce: number) {
|
||||
let historyCe = this.heroHistoryCe.get(hid)||0;
|
||||
if(ce > historyCe) {
|
||||
this.heroHistoryCe.set(hid, ce);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public getRoleCeTable() {
|
||||
@@ -132,13 +137,15 @@ class RoleCe {
|
||||
let heroAttrs: HeroAttr[] = [];
|
||||
for(let [hid, keys] of this.heroAttrsByHid) {
|
||||
let lv = this.heroLv.get(hid);
|
||||
let historyCe = this.heroHistoryCe.get(hid);
|
||||
let objectId = this.heroObjectId.get(hid);
|
||||
let attrs: AttrCell[] = [];
|
||||
for(let key of keys) {
|
||||
let heroAttr = this.heroAttrs.get(key);
|
||||
attrs.push(heroAttr.getHeroAttrCell());
|
||||
}
|
||||
heroAttrs.push({
|
||||
hid, lv, attrs
|
||||
hid, lv, attrs, historyCe, objectId
|
||||
});
|
||||
}
|
||||
let equipAttrs: EquipAttr[] = [];
|
||||
@@ -157,10 +164,34 @@ class RoleCe {
|
||||
roleId: this.roleId, globalAttrs, heroAttrs, equipAttrs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计算函数
|
||||
export class CalCe extends RoleCe {
|
||||
public setRoleCe(roleCe: RoleCeType) {
|
||||
this.roleId = roleCe.roleId;
|
||||
if(roleCe) {
|
||||
for(let globalAttr of roleCe.globalAttrs) {
|
||||
let obj = this.getGlobalAttrById(globalAttr.attrId);
|
||||
obj.setByRoleCe(globalAttr);
|
||||
}
|
||||
for(let {hid, lv, attrs, historyCe, objectId } of roleCe.heroAttrs) {
|
||||
this.heroLv.set(hid, lv);
|
||||
this.heroHistoryCe.set(hid, historyCe);
|
||||
this.heroObjectId.set(hid, objectId);
|
||||
for(let cell of attrs) {
|
||||
let obj = this.getHeroAttrByHidAndId(hid, cell.attrId);
|
||||
obj.setByRoleCe(cell);
|
||||
}
|
||||
}
|
||||
for(let { hid, eplaceId, lv, attrs } of roleCe.equipAttrs) {
|
||||
this.equipLv.set(`${hid}_${eplaceId}`, lv);
|
||||
for(let cell of attrs) {
|
||||
let obj = this.getEquipAttrByHidAndId(hid, eplaceId, cell.attrId);
|
||||
obj.setByRoleCe(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.originCes = this.calHeroCe();
|
||||
}
|
||||
|
||||
public setInitHero(role: RoleUpdate, heroes: HeroUpdate[]) {
|
||||
this.roleId = role.roleId;
|
||||
for(let { hid, skinId, lv, quality, star, starStage, colorStar, colorStarStage, job, jobStage, } of heroes) {
|
||||
@@ -173,6 +204,35 @@ export class CalCe extends RoleCe {
|
||||
this.setTeraph(role.teraphs);
|
||||
}
|
||||
|
||||
|
||||
public setResultHero(hero: HeroType) {
|
||||
this.heroObjectId.set(hero.hid, hero._id);
|
||||
}
|
||||
|
||||
public getResultCeArr() {
|
||||
let arr: { hid: number, ce: number }[] = [];
|
||||
for(let [ hid, ce ] of this.resultCes) {
|
||||
arr.push({ hid, ce });
|
||||
}
|
||||
arr.sort((a, b) => b.ce - a.ce);
|
||||
return arr;
|
||||
}
|
||||
|
||||
public getTopLineup() {
|
||||
let topLineup: TopHero[] = [], topLineupCe = 0;
|
||||
let arr = this.getResultCeArr();
|
||||
for(let i = 0; i < LINEUP_NUM; i++) {
|
||||
if(arr[i]) {
|
||||
let { hid, ce } = arr[i];
|
||||
topLineup.push({
|
||||
hid, ce, hero: this.heroObjectId.get(hid)
|
||||
});
|
||||
topLineupCe += ce;
|
||||
}
|
||||
}
|
||||
return { topLineup, topLineupCe };
|
||||
}
|
||||
|
||||
// 武将基础&成长
|
||||
public setHeroBase(hid: number, skinId: number) {
|
||||
let dicHero = gameData.hero.get(skinId);
|
||||
|
||||
@@ -83,7 +83,6 @@ export class CreateHeroes {
|
||||
let ces = calCe.calHeroCe(); // 战力
|
||||
for(let hero of this.heroes) {
|
||||
hero.ce = ces.get(hero.hid)||0;
|
||||
hero.historyCe = hero.ce;
|
||||
this.incRoleCe += hero.ce;
|
||||
}
|
||||
this.roleCe = calCe.getRoleCeTable();
|
||||
|
||||
@@ -2,7 +2,6 @@ import { ITID, CONSUME_TYPE, ITEM_TABLE, CURRENCY, CURRENCY_TYPE, MAIL_TYPE, HAN
|
||||
import { getDecimalCnt, getRandEelm, getRandEelmWithWeight, getRandSingleEelm, getRandValueByMinMax, resResult } from '../../pubUtils/util';
|
||||
import { RoleModel, RoleType } from '../../db/Role';
|
||||
import { setAp } from '../actionPointService';
|
||||
import { pushCalAllHeroCe, calPlayerCeAndSave, calAllHeroCe } from '../playerCeService';
|
||||
import { ItemModel, ItemType } from '../../db/Item';
|
||||
import { STATUS } from '../../consts/statusCode';
|
||||
import { pinus } from 'pinus';
|
||||
@@ -27,6 +26,7 @@ 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';
|
||||
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ export async function handleCost(roleId: string, sid: string, goods: Array<ItemI
|
||||
}
|
||||
}
|
||||
let { newEplace } = updateEplaces(hero.ePlace, update);
|
||||
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP_STRENGTH, sid, roleId, hero, { ePlace: newEplace }, [...update.keys()]);
|
||||
await calculateCe(HERO_SYSTEM_TYPE.EQUIP_STRENGTH, roleId, role.serverId, sid, { ePlace: newEplace }, {}, { ePlaceIds: [...update.keys()] });
|
||||
}
|
||||
|
||||
|
||||
@@ -216,8 +216,6 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
|
||||
pushHeroSkinMsg(heroskins, skinInfos, uids); // 推送onHeroSkinChange
|
||||
saveItemChangeLog(roleId, skinInfos, reason);
|
||||
}
|
||||
// 推送全局加成信息
|
||||
if(calAllHeroResult) await pushCalAllHeroCe(roleId, sid, calAllHeroResult);
|
||||
}
|
||||
|
||||
// 5. 获得头像和相框等
|
||||
@@ -362,7 +360,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 calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, [skinId]); // 全局加成
|
||||
await calculateCe(HERO_SYSTEM_TYPE.ADD_SKIN, roleId, hero.serverId, sid, {}, {}, { skinId }); // 全局加成
|
||||
|
||||
if (hero) { // 有武将的,将皮肤链接到武将上
|
||||
let curSkin = hero.skins.find(cur => cur.id == skinId);
|
||||
|
||||
Reference in New Issue
Block a user