战力:修复战力

This commit is contained in:
luying
2021-08-13 19:34:08 +08:00
parent dadd548ffd
commit 6444f91c61
5 changed files with 52 additions and 43 deletions

View File

@@ -3,7 +3,6 @@ import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, Ref, mongoose } from '@typegoose/typegoose';
import User from './User';
import { shouldRefresh, reduceCe } from '../pubUtils/util';
import { initRoleAtrr } from '../pubUtils/playerCe';
import { nowSeconds, getTimeFunD } from '../pubUtils/timeUtil';
import { Figure } from '../domain/dbGeneral';
import { BAG, EXTERIOR } from '../pubUtils/dicParam';
@@ -330,7 +329,6 @@ export default class Role extends BaseModel {
const doc = new RoleModel();
const update = Object.assign(doc.toJSON(), roleInfo, { userInfo: user, serverType: user.serverType, serverId });
const role: RoleType = await RoleModel.findOneAndUpdate({ 'userInfo.uid': uid, serverId }, update, { upsert: true, new: true }).lean(lean);
initRoleAtrr(role);
return role;
}

View File

@@ -63,7 +63,7 @@ function parseCeAttr(maxStage: number, str: string) {
if (!str) return result;
let decodeArr = decodeArrayListStr(str);
for (let i = 1; i <= maxStage; i++) {
let [id, attr] = decodeArr[i]||[i.toString(), "0"];
let [id, attr] = decodeArr[i - 1]||[i.toString(), "0"];
if (isNaN(parseInt(id)) || isNaN(parseInt(attr))) {
throw new Error('data table format wrong');
}

View File

@@ -62,7 +62,7 @@ export async function reCalAllHeroCe(type: number, roleId: string, update: RoleU
let heros = await HeroModel.findByRole(roleId);
let roleAttrs = await reCalRoleAttr(type, heros, role, update, args);
if(!roleAttrs) return {role, pushHeros: [], ce: role.ce, topLineupCe: role.topLineupCe, serverId: role.serverId}; // 无加成
if(!roleAttrs) return {role, pushHeros: [], ce: role.ce, topLineupCe: role.topLineupCe, serverId: role.serverId, heros }; // 无加成
let pushHeros = new Array<{ hid: number, ce: number, incHeroCe: number }>();
@@ -92,7 +92,7 @@ export async function reCalAllHeroCe(type: number, roleId: string, update: RoleU
role = await RoleModel.updateRoleInfo(roleId, update);
let guild = await GuildModel.updateCe(roleId, allIncCe); // 公会更新战力
return { role, pushHeros, ce: role.ce, topLineupCe: role.topLineupCe, guild, serverId: role.serverId }
return { role, pushHeros, ce: role.ce, topLineupCe: role.topLineupCe, guild, serverId: role.serverId, heros }
}
@@ -100,6 +100,9 @@ export async function reCalAllHeroCe(type: number, roleId: string, update: RoleU
async function reCalRoleAttr(type: number, heros: Array<HeroType>, role: RoleType, update: RoleUpdate, args: Array<number>) {
let { attr: roleAttrs } = role;
switch (type) {
case HERO_SYSTEM_TYPE.INIT:
roleAttrs = calRoleInit(role);
break;
case HERO_SYSTEM_TYPE.ADD_SKIN:
roleAttrs = calHeroAddSkin(role, args);
break;
@@ -253,6 +256,22 @@ export function calHeroInitIncAttr(hero: HeroType, addSeidList: Array<number>, r
// }
}
/**
* 初始全局加成
* @param args
* @param ceAttr
*/
function calRoleInit(role: RoleType) {
let { attr: roleAttrs, teraphs } = role;
delete role._id;
roleAttrs = calTitle({...role, title: 0}, role); // 计算初始爵位带来的全局
for(let {id} of teraphs) {
roleAttrs = calTeraphMainAttr({ ...role, teraphs: [] }, role, id);
}
role.attr = roleAttrs;
return roleAttrs;
}
/**
* 添加皮肤全局加成
* @param args
@@ -617,6 +636,7 @@ export function calHeroFavourUpIncAttr(originHero: HeroType, update: HeroUpdate)
let { favourLv: oldFavourLv, attr: heroAttrs } = originHero;
let { favourLv = oldFavourLv } = update;
let currentFiendShipLevel = gameData.friendShipLevelMap.get(favourLv);
let difAdd = currentFiendShipLevel.add;
if (oldFavourLv && oldFavourLv > 0) { // 减上一级好感
@@ -627,7 +647,7 @@ export function calHeroFavourUpIncAttr(originHero: HeroType, update: HeroUpdate)
for (let {shipId, level} of originHero.connections) {
let dicHeroFriendShip = getFriendShipById(shipId, level);
for (let attr of dicHeroFriendShip.attributes) {
let fixUp = attr.number * (HERO_CE_RATIO + difAdd);
let fixUp = (attr.number + difAdd ) * HERO_CE_RATIO;
updateHeroAttr(heroAttrs, attr.id, { inc: { fixUp } });
}
}
@@ -1050,22 +1070,21 @@ function calTitle(role: RoleType, update: RoleUpdate) {
let { title: oldTitle, attr: roleAttrs } = role;
let { title: newTitle = oldTitle } = update;
for(let title = oldTitle; title <= newTitle; title++) {
let dicTitle = gameData.title.get(title);
if(!dicTitle) break;
for (let i = ABI_TYPE.ABI_HP; i < ABI_TYPE.ABI_MAX; i++) {
if(dicTitle.mainAttrValue.has(i)) {
let fixUp = dicTitle.mainAttrValue.get(i) * HERO_CE_RATIO;
updateRoleAttr(roleAttrs, i, { inc: { fixUp }});
}
if(dicTitle.assiAttrValue.has(i)) {
let fixUp = dicTitle.assiAttrValue.get(i) * HERO_CE_RATIO;
updateRoleAttr(roleAttrs, i, { inc: { fixUp }});
}
let dicOldTitle = gameData.title.get(oldTitle)||{ mainAttrValue: new Map(), assiAttrValue: new Map() };
let dicNewTitle = gameData.title.get(newTitle);
console.log('***** oldTitle, newTitle', oldTitle, newTitle);
for (let i = ABI_TYPE.ABI_HP; i < ABI_TYPE.ABI_MAX; i++) {
if (dicNewTitle.mainAttrValue.has(i) || dicOldTitle.mainAttrValue.has(i)) {
console.log()
let fixUp = ((dicNewTitle.mainAttrValue.get(i) || 0) - (dicOldTitle.mainAttrValue.get(i) || 0)) * HERO_CE_RATIO;
updateRoleAttr(roleAttrs, i, { inc: { fixUp } });
}
if (dicNewTitle.assiAttrValue.has(i) || dicOldTitle.mainAttrValue.has(i)) {
let fixUp = ((dicNewTitle.assiAttrValue.get(i) || 0) - (dicOldTitle.assiAttrValue.get(i) || 0)) * HERO_CE_RATIO;
updateRoleAttr(roleAttrs, i, { inc: { fixUp } });
}
}
return roleAttrs;
}
@@ -1124,13 +1143,4 @@ function calTeraphAssistAttr(role: RoleType, update: RoleUpdate, id: number) {
updateRoleAttr(roleAttrs, attrId, { inc: { ratioUp } });
});
return roleAttrs;
}
/**
* 全局加成初始化
* @param role
*/
export function initRoleAtrr(role: RoleType) {
delete role._id;
calTitle({...role, title: 0}, role); // 计算初始爵位带来的全局
}
}