战力计算

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
@@ -5,7 +5,7 @@ import { resResult, getItems, decodeStr } from '../../../pubUtils/util';
import { STATUS } from '../../../consts/statusCode';
import {HeroModel} from '../../../db/Hero';
import {CURRENCY_BY_TYPE, CURRENCY_TYPE, ITID, CONSUME_TYPE, HERO_GROW_MAX} from '../../../consts/consts';
import {getJobInfoById, getMaxGradeByjobClass, getHeroInfoById, getGoodById, getHeroExpByLv, getGamedata, getJobByGradeAndClass, getFriendShipById, getFriendShipLevels, getFashionsById} from '../../../pubUtils/gamedata';
import {getJobInfoById, getMaxGradeByjobClass, getHidAndLevelByShipId, getHeroInfoById, getGoodById, getHeroExpByLv, getGamedata, getJobByGradeAndClass, getFriendShipById, getFriendShipLevels, getFashionsById} from '../../../pubUtils/gamedata';
import { ABI_STAGE } from '../../../consts/abilityConst';
import { RoleModel } from '../../../db/Role';
@@ -280,7 +280,7 @@ export class HeroHandler {
let roleId: string = session.get('roleId');
let sid: string = session.get('sid');
let { hid } = msg;
let hero = await HeroModel.findByHidAndRole(hid, roleId);
let hero = await HeroModel.findByHidAndRole(hid, roleId, false);
if (!hero)
return resResult(STATUS.HERO_NOT_FIND);
let heroJob = getJobInfoById(hero.job);
@@ -307,7 +307,7 @@ export class HeroHandler {
let roleId: string = session.get('roleId');
let sid: string = session.get('sid');
let { hid } = msg;
let hero = await HeroModel.findByHidAndRole(hid, roleId);
let hero = await HeroModel.findByHidAndRole(hid, roleId, false);
if (!hero)
return resResult(STATUS.HERO_NOT_FIND);
let heroJob = getJobInfoById(hero.job);
@@ -329,26 +329,41 @@ export class HeroHandler {
}
//激活羁绊
async heroConectionActivate(msg: {hid:number, id:number}, session: BackendSession) {
async heroConectionActivate(msg: {shipId: number}, session: BackendSession) {
let roleId: string = session.get('roleId');
let sid: string = session.get('sid');
let { hid, id } = msg;
let friendShip = getFriendShipById(id);
if (!friendShip)
return resResult(STATUS.HERO_CONECTION_IS_EXIT);
if (friendShip.actorId != hid)
return resResult(STATUS.WRONG_PARMS);
let hero = await HeroModel.findByHidAndRole(hid, roleId);
let { shipId } = msg;
let shipHidAndLevel = getHidAndLevelByShipId(shipId);
if (!shipHidAndLevel)
return resResult(STATUS.HERO_CONECTION_IS_NOT_EXIT);
let hero = await HeroModel.findByHidAndRole(shipHidAndLevel.actorId, roleId, false);
if (!hero)
return resResult(STATUS.HERO_NOT_FIND);
if (!!_.findWhere(hero.conections, {id:id}))
return resResult(STATUS.HERO_CONECTION_IS_EXIT);
let flag = true;
let level = 1;
for (let conection of hero.conections) {
if (conection.shipId == shipId ) {
if (conection.level >= shipHidAndLevel.level) {
return resResult(STATUS.HERO_CONECTION_IS_MAX_LEVEL);
} else {
flag = false;
conection.level++;
level = conection.level;
}
}
}
if (!!flag) {
hero.conections.push({shipId,level});
}
let friendShip = getFriendShipById(shipId, level);
if (hero.star < friendShip.level)
return resResult(STATUS.NOT_REACH_UNLOCK_LEVEL);
let heroIds = friendShip.memberId.split('|');
for (let heroId of heroIds) {
let member = await HeroModel.findByHidAndRole(heroId, roleId);
if(!member)
let hids = friendShip.hids;
for (let hid of hids) {
if (hid == shipHidAndLevel.actorId)
continue;
let member = await HeroModel.findByHidAndRole(hid, roleId, false);
if (!member)
return resResult(STATUS.HERO_NOT_FIND);
if (member.star < friendShip.level)
return resResult(STATUS.NOT_REACH_UNLOCK_LEVEL);
@@ -357,9 +372,6 @@ export class HeroHandler {
if(!result) {
return resResult(STATUS.BATTLE_CONSUMES_NOT_ENOUGH);
}
hero.conections.push({
id : id
});
//重算战力并下发
let heros = await calPlayerCeAndSave(sid, roleId, [hero]);
return resResult(STATUS.SUCCESS, { hid : heros[0].hid, conections : heros[0].conections});
@@ -370,7 +382,7 @@ export class HeroHandler {
let roleId: string = session.get('roleId');
let sid: string = session.get('sid');
let { hid, items } = msg;
let hero = await HeroModel.findByHidAndRole(hid, roleId);
let hero = await HeroModel.findByHidAndRole(hid, roleId, false);
if (!hero)
return resResult(STATUS.HERO_NOT_FIND);
let friendShipLevels = getFriendShipLevels();
@@ -412,7 +424,7 @@ export class HeroHandler {
let skinInfo = getFashionsById(id);
if (!skinInfo)
return resResult(STATUS.HERO_SKIN_NOT_FIND);
let hero = await HeroModel.findByHidAndRole(skinInfo.actorId, roleId);
let hero = await HeroModel.findByHidAndRole(skinInfo.actorId, roleId, false);
if (!hero)
return resResult(STATUS.HERO_NOT_FIND);
let result = false;
+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;
}