diff --git a/game-server/app/servers/role/handler/heroHandler.ts b/game-server/app/servers/role/handler/heroHandler.ts index 72be0f42b..299392cc1 100644 --- a/game-server/app/servers/role/handler/heroHandler.ts +++ b/game-server/app/servers/role/handler/heroHandler.ts @@ -1,6 +1,6 @@ import {Application, BackendSession, createTcpMailBox, ChannelService} from 'pinus'; import { handleCost, addItems } from '../../../services/rewardService'; -import { calPlayerCeAndSave, getAllAttrStage } from '../../../pubUtils/playerCe'; +import { calPlayerCeAndSave, getAllAttrStage } from '../../../services/playerCeService'; import { resResult } from '../../../pubUtils/util'; import { STATUS } from '../../../consts/statusCode'; import {HeroModel} from '../../../db/Hero'; diff --git a/game-server/app/services/playerCeService.ts b/game-server/app/services/playerCeService.ts new file mode 100644 index 000000000..8bb5e7b92 --- /dev/null +++ b/game-server/app/services/playerCeService.ts @@ -0,0 +1,22 @@ +/** + * 体力系统 + */ + +import { pinus } from 'pinus'; +import { STATUS } from '../consts/statusCode'; + +import { resResult } from '../pubUtils/util'; +import { calPlayerCeAndSave as pubCalPlayerCeAndSave } from '../pubUtils/playerCe'; +import { HeroType } from '../db/Hero'; +const _ = require('underscore'); + + +//修改并下发战力 +export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Array, type?: number, args?: Array) { + let {role, pushHeros} = await pubCalPlayerCeAndSave(roleId, heros, type, args); + + //下发战力 + let uids = [{ uid: roleId, sid }]; + pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: role.ce, heros: pushHeros, topFiveCe: 0 }), uids); + return heros; +} diff --git a/gm-server/app/service/Utils.ts b/gm-server/app/service/Utils.ts index 64aabbe1b..245c14134 100644 --- a/gm-server/app/service/Utils.ts +++ b/gm-server/app/service/Utils.ts @@ -1,6 +1,8 @@ import { Service } from 'egg'; import * as pubUtils from '../pubUtils/util'; import * as pubGamedata from '../pubUtils/gamedata' +import { HeroType } from '@db/Hero'; +import { calPlayerCeAndSave } from '@pubUtils/playerCe'; const csprng = require('csprng'); /** @@ -46,4 +48,8 @@ export default class Utils extends Service { public resResult(status: {code: number, simStr: string}, data?, customMsg?: string) { return pubUtils.resResult(status, data, customMsg); } + + public calPlayerCeAndSave(roleId: string, heros: HeroType[], type: number, args: number[]) { + return calPlayerCeAndSave(roleId, heros, type, args) + } } diff --git a/shared/pubUtils/playerCe.ts b/shared/pubUtils/playerCe.ts index b406e7fef..881e9e865 100644 --- a/shared/pubUtils/playerCe.ts +++ b/shared/pubUtils/playerCe.ts @@ -3,10 +3,8 @@ */ import { HERO_SYSTEM_TYPE } from '../consts'; -import { pinus } from 'pinus'; -import { STATUS } from '../consts/statusCode'; -import { resResult, deepCopy } from '../pubUtils/util'; +import { deepCopy } from '../pubUtils/util'; import { HeroModel, HeroType } from '../db/Hero'; import { RoleModel } from '../db/Role'; import { CeAttrData, CeAttr } from '../db/generalField'; @@ -26,7 +24,7 @@ export function calPlayerCe(hero: HeroType, type: number, args: Array) { let removeSeidList = new Array(); if (type == HERO_SYSTEM_TYPE.STAR) { - reIncAttr = calHeroStarIncAttr(hero, args, addSeidList, removeSeidList); // args: 升的星盘 + reIncAttr = calHeroStarIncAttr(hero, args, addSeidList); // args: 升的星盘 } else if (type == HERO_SYSTEM_TYPE.TRAIN) { reIncAttr = calHeroTrainIncAttr(hero); } else if (type == HERO_SYSTEM_TYPE.STAGEUP) { @@ -56,7 +54,7 @@ export function calPlayerCe(hero: HeroType, type: number, args: Array) { } //修改并下发战力 -export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Array, type?: number, args?: Array) { +export async function calPlayerCeAndSave(roleId: string, heros: Array, type?: number, args?: Array) { let incPlayerCe = 0; let pushHeros = new Array<{hid: number, ce: number, incHeroCe: number}>(); @@ -74,13 +72,10 @@ export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Arr let role = await RoleModel.findByRoleId(roleId); role.ce += incPlayerCe; await RoleModel.updateRoleInfo(roleId, role); - //下发战力 - let uids = [{ uid: roleId, sid }]; - pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: role.ce, heros: pushHeros, topFiveCe: 0 }), uids); - return heros; + return {pushHeros, role} } -export function calHeroStarIncAttr (hero: HeroType, args: Array, addSeidList: Array, removeSeidList: Array) { +export function calHeroStarIncAttr (hero: HeroType, args: Array, addSeidList: Array) { let {star, starStage, quality, colorStar, colorStarStage, ceAttr} = hero; let res: CeAttr = {}; const dicHero = gameData.hero.get(hero.hid); diff --git a/shared/pubUtils/util.ts b/shared/pubUtils/util.ts index 5c5ce76cc..a72e5515b 100644 --- a/shared/pubUtils/util.ts +++ b/shared/pubUtils/util.ts @@ -456,8 +456,9 @@ export function readJsonFile(fileName: string) { export function readWarJsonFileList() { const folder = 'warJsons'; return fs.readdirSync(__dirname + `/../resource/${folder}`) + .filter(cur => {return cur.indexOf('.') != 0}) .map(file => { - return fs.readFileSync(path.resolve(__dirname, `../resource/${folder}/${file}`)).toString('utf8').replace(/^\uFEFF/, ''); + return fs.readFileSync(path.resolve(__dirname, `../resource/${folder}/${file}`)).toString('utf8'); }); } diff --git a/web-server/app/service/Utils.ts b/web-server/app/service/Utils.ts index e92e44377..357143a28 100644 --- a/web-server/app/service/Utils.ts +++ b/web-server/app/service/Utils.ts @@ -1,5 +1,7 @@ import { Service } from 'egg'; import { resResult as pubResult } from '../pubUtils/util'; +import { calPlayerCeAndSave } from 'app/pubUtils/playerCe'; +import { HeroType } from '@db/Hero'; const csprng = require('csprng'); /** * Utils Service @@ -39,4 +41,9 @@ export default class Utils extends Service { public resResult(status: {code: number, simStr: string}, data?, customMsg?: string) { return pubResult(status, data, customMsg); } + + public calPlayerCeAndSave(roleId: string, heros: HeroType[], type: number, args: number[]) { + return calPlayerCeAndSave(roleId, heros, type, args) + } + }