Files
ZYZ/game-server/app/services/playerCeService.ts
2020-12-11 15:50:43 +08:00

48 lines
1.4 KiB
TypeScript

/**
* 体力系统
*/
import { ActionPointModel } from '../db/ActionPoint';
import { ACTION_POIN } 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';
//战力计算TODO
export function calPlayerCe(hero:any, type: number, args: Array<{id: number}>) {
let ce = 0;
let incAttr;
if (type == 1) {
incAttr = calHeroStarIncAttr(hero, args);
}
return ce;
}
//修改并下发战力
export async function calPlayerCeAndSave(sid: string, roleId: string, heros:Array<any>, type?: number, args?: Array<{id: number}>) {
let playerCe = 0;
let pushHeros = [];
for (let hero of heros) {
hero.ce = calPlayerCe(hero, type, args);
playerCe = playerCe + hero.ce;
await hero.save();
pushHeros.push({
hid: hero.hid,
ce: hero.ce
});
}
let role = await RoleModel.findOne({roleId});
role.ce = playerCe;
await role.save();
//下发战力
let uids = [{uid: roleId, sid}];
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, {ce: playerCe, heros:pushHeros, topFiveCe:0}), uids);
return heros;
}
export function calHeroStarIncAttr (hero:any, args: Array<{id: number}>) {
let incHp = 0;
return {incHp};//属性增量可以是多个
}