pvp创建获取

This commit is contained in:
mamengke01
2021-01-06 16:06:31 +08:00
parent d2f76c9198
commit a785a4733a
17 changed files with 189 additions and 71 deletions
@@ -1,6 +1,13 @@
import {Application, BackendSession} from 'pinus';
const _ = require('underscore');
import { gameData } from '../../../pubUtils/data';
import { checkPvp } from '../../../pubUtils/pvpUtil';
import { RoleModel } from '../../../db/Role';
import { STATUS } from '../../../consts/statusCode';
import { resResult } from '../../../pubUtils/util';
import { SystemConfigModel } from '../../../db/SystemConfig'
import { PvpDefenseModel } from '../../../db/PvpDefense';
export default function(app: Application) {
return new PvpHandler(app);
}
@@ -9,5 +16,14 @@ export class PvpHandler {
constructor(private app: Application) {
}
async getData (msg: {}, session: BackendSession) {
let roleId = session.get('roleId');
let roleName = session.get('roleName');
let sid = session.get('sid');
let serverId = session.get('serverId');
let result = await PvpDefenseModel.findByRoleIdIncludeAll(roleId);
let system = await SystemConfigModel.findSystemConfig();
return resResult(STATUS.SUCCESS, { data: result });
}
}
@@ -10,8 +10,8 @@ import { resResult, returnHeroCeRatio, reduceCe } from '../../../pubUtils/util';
import { FUNC_OPT_TYPE } from '../../../consts';
import { getAp } from '../../../services/actionPointService';
import { ItemModel } from '../../../db/Item';
import { switchOnFunc } from '../../../services/funcSwitchService';
import { chackFunOpenWhenLogin } from '../../../services/funcSwitchService';
import { eventOnPlayerLvUp } from '../../../services/playerEventService';
export default function (app: Application) {
return new EntryHandler(app);
}
@@ -78,7 +78,7 @@ export class EntryHandler {
let equips = await EquipModel.findbyRole(role.roleId);
let items = await ItemModel.findbyRole(role.roleId);
await chackFunOpenWhenLogin(role, session.get('funcs'));
role['heros'] = heros.map(cur => returnHeroCeRatio(cur));
role['equips'] = equips;
role['consumeGoods'] = items;
@@ -86,7 +86,6 @@ export class EntryHandler {
role['apJson'] = apJson;
role['ce'] = reduceCe(role.ce);
await switchOnFunc(role.roleId, FUNC_OPT_TYPE.LEVEL_UP, role.lv, session);
return resResult(STATUS.SUCCESS, { role });
}
+20 -17
View File
@@ -2,32 +2,35 @@ import { BackendSession, FrontendSession, pinus } from "pinus";
import { getGamedata } from "../pubUtils/gamedata";
import { RoleModel } from "../db/Role";
import { resResult } from "../pubUtils/util";
import { STATUS } from "../consts";
import { STATUS, FUNC_OPT_TYPE } from "../consts";
import { eventOnPlayerLvUp } from '../services/playerEventService';
// 开启功能
export async function switchOnFunc(roleId: string, type: number, param: number, session: (BackendSession|FrontendSession)) {
const dataFuncs = session.get('funcs');
const sid = session.get('sid');
const dicFuncSwitch = getGamedata('dic_func_switch');
let funcs = new Array<{id: number, desc: string, script: string}>(), addFuncs = new Array<number>();
for(let obj of dicFuncSwitch) {
if(obj.conditionType == type && !dataFuncs.includes(obj.id) && obj.param <= param) {
funcs.push({id: obj.id, desc: obj.desc, script: obj.script});
addFuncs.push(obj.id);
}
let addFuncs = new Array<number>();
switch (type) {
case FUNC_OPT_TYPE.LEVEL_UP:
await eventOnPlayerLvUp(roleId, param, addFuncs, dataFuncs);
break;
case FUNC_OPT_TYPE.BATTLE_END:
//开启奇遇
break;
}
if(funcs.length > 0) {
pinus.app.get('channelService').pushMessageByUids('onFuncSwitchOn', resResult(STATUS.SUCCESS, {funcs}), [{
if (addFuncs.length) {
pinus.app.get('channelService').pushMessageByUids('onFuncSwitchOn', resResult(STATUS.SUCCESS, {addFuncs}), [{
uid: roleId,
sid: sid
}]);
const recs = await RoleModel.pushFuncs(roleId, addFuncs);
session.set('funcs', recs.funcs||[]);
session.push('funcs', () => {});
return recs;
}
const recs = await RoleModel.pushFuncs(roleId, addFuncs);
session.set('funcs', recs.funcs||[]);
session.push('funcs', () => {});
return recs
}
export async function chackFunOpenWhenLogin(role: any, dataFuncs:Array<number>) {
await eventOnPlayerLvUp(role.roleId, role.lv, [], dataFuncs);
}
@@ -0,0 +1,19 @@
/**
* 体力系统
*/
import { fromCallback } from 'bluebird';
import { checkPvp } from '../pubUtils/pvpUtil'
import { getFuncsSwitch } from '../pubUtils/data';
import { FUNCS_ID, FUNC_OPT_TYPE } from '../consts/constModules/sysConst';
import { RoleModel } from '../db/Role'
export async function eventOnPlayerLvUp(roleId: string, lv: number, addFuncs: Array<number>, dataFuncs: Array<number>) {
if (!dataFuncs.includes(FUNCS_ID.PVP)) {//开启pvp
let res = getFuncsSwitch(FUNCS_ID.PVP);
if (!res || lv >= res.param) {
let role = await RoleModel.findByRoleId(roleId);
await checkPvp(role);
addFuncs.push(FUNCS_ID.PVP);
}
}
}
@@ -0,0 +1,13 @@
/**
* 体力系统
*/
import { scheduleJob, cancelJob } from 'pinus-scheduler';
export async function init() {
scheduleJob("0 31 23 * * *", setPvpSeasonResult, {name:'setPvpSeasonResult'})
}
export async function setPvpSeasonResult() {
}