战力计算

This commit is contained in:
mamengke01
2020-12-11 21:03:14 +08:00
parent 4d649f46a8
commit b411c5efe0
18 changed files with 2741 additions and 1566 deletions
+51 -23
View File
@@ -6,43 +6,71 @@ import { ActionPointModel } from '../db/ActionPoint';
import { HERO_SYSTEM_TYPE } from '../consts/consts';
import { pinus } from 'pinus';
import { STATUS } from '../consts/statusCode';
import {resResult } from '../pubUtils/util';
import {HeroModel} from '../db/Hero';
import {RoleModel} from '../db/Role';
import { resResult } from '../pubUtils/util';
import { HeroModel } from '../db/Hero';
import { RoleModel } from '../db/Role';
import { getJobInfoById, getJobByGradeAndClass, getHeroInfoById } from '../pubUtils/gamedata';
import { HEROTARIN, CE_RATIO} from '../consts/abilityConst';
const HERO_CE_RATIO = 100;
//战力计算TODO
export function calPlayerCe(hero:any, type: number, args: Array<number>) {
let ce = 0;
let incAttr;
if (HERO_SYSTEM_TYPE.STAR == 1) {
incAttr = calHeroStarIncAttr(hero, args);
}
return ce;
export function calPlayerCe(hero: any, type: number, args: Array<number>) {
let incCe = 0;
let incArr = {};
let reIncAttr;
if (type == HERO_SYSTEM_TYPE.STAR) {
reIncAttr = calHeroStarIncAttr(hero, args);
} else if (type == HERO_SYSTEM_TYPE.TRAIN) {
reIncAttr = calHeroTrainIncAttr(hero);
}
for (let attrName in reIncAttr) {
for (let attrKey in reIncAttr[attrName]) {
hero.CeAttr[attrName][attrKey] += parseInt(reIncAttr[attrName][attrKey]);
}
incArr[attrName] = reIncAttr[attrName].fixUp * HERO_CE_RATIO + reIncAttr[attrName].base *(HERO_CE_RATIO + reIncAttr[attrName].ratioUp); //计算属性
incCe += incArr[attrName] * CE_RATIO[attrName];
}
hero.ce += incCe;
return incCe;
}
//修改并下发战力
export async function calPlayerCeAndSave(sid: string, roleId: string, heros:Array<any>, type?: number, args?: Array<number>) {
let playerCe = 0;
export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Array<any>, type?: number, args?: Array<number>) {
let incPlayerCe = 0;
let pushHeros = [];
for (let hero of heros) {
hero.ce = calPlayerCe(hero, type, args);
playerCe = playerCe + hero.ce;
let incHeroCe = calPlayerCe(hero, type, args);
incPlayerCe += incHeroCe;
await hero.save();
pushHeros.push({
hid: hero.hid,
ce: hero.ce
ce: hero.ce,
incHeroCe : incHeroCe,
});
}
let role = await RoleModel.findOne({roleId});
role.ce = playerCe;
let role = await RoleModel.findOne({ roleId });
role.ce += incPlayerCe;
await role.save();
//下发战力
let uids = [{uid: roleId, sid}];
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, {ce: playerCe, heros:pushHeros, topFiveCe:0}), uids);
let uids = [{ uid: roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: role.ce, heros: pushHeros, topFiveCe: 0 }), uids);
return heros;
}
export function calHeroStarIncAttr (hero:any, args: Array<number>) {
let incHp = 0;
return {incHp};//属性增量可以是多个
export function calHeroStarIncAttr(hero: any, args: Array<number>) {
return {};//属性增量可以是多个
}
export function calHeroTrainIncAttr(hero: any) {
let res = {};
let attrName: string = HEROTARIN[hero.jobStage];
res[attrName] = {};
let currentJob = getJobInfoById(hero.job);
if (currentJob.grade > 1) {
let jobGradeAndClass = getJobByGradeAndClass(currentJob.job_class, currentJob.grade - 1);
let lastJob = getJobInfoById(jobGradeAndClass.jobid);
res[attrName].fixUp = (currentJob[attrName] - lastJob[attrName]) * HERO_CE_RATIO;
} else {
res[attrName].fixUp = currentJob[attrName] * HERO_CE_RATIO;
}
return res;
}