满足条件开启功能推送,详细功能校验暂缺

This commit is contained in:
luying
2020-11-26 19:29:28 +08:00
parent f2e288f25d
commit 1f05043b4b
14 changed files with 158 additions and 44 deletions
+23 -16
View File
@@ -3,7 +3,7 @@ import { getGamedata } from '../pubUtils/gamedata';
import EventRecord, { EventRecordModel } from '../db/EventRecord';
import { RoleModel } from '../db/Role';
import { genCode, decodeStrSingle, decodeStr, getRandomWithWeight, resResult, setLocalHours } from '../pubUtils/util';
import { EVENT_STATUS, EVENT_RECORD_STATUS, EVENT_TYPE, EVENT_RANDOM_TYPE_ONE_OPEN, EVENT_QUIZ_NUM, EVENT_ANSWER_STATUS } from '../consts/consts';
import { EVENT_STATUS, EVENT_RECORD_STATUS, EVENT_TYPE, EVENT_RANDOM_TYPE_ONE_OPEN, EVENT_QUIZ_NUM, EVENT_ANSWER_STATUS, FUNCS_ID } from '../consts/consts';
import { EVENT_REFRESH_NUM } from '../consts/consts';
import { STATUS } from '../consts/statusCode';
@@ -87,7 +87,8 @@ export async function startEvent(app: Application, session: FrontendOrBackendSes
// console.log('*******setEventStatus')
let roleId = session.get('roleId');
let roleName = session.get('roleName');
let channelName = roleId;
let serverId = session.get('serverId');
let channelName = `server-${serverId}`;
let event = await refreshEvent(1, roleId, roleName, 0, []); // 刷新初始的一件
await RoleModel.setEventStatus(roleId, EVENT_STATUS.STARTING);
session.set('eventStatus', EVENT_STATUS.STARTING);
@@ -108,25 +109,31 @@ export async function checkEvent(app: Application, session: FrontendOrBackendSes
try {
let roleId = session.get('roleId');
let serverId = session.get('serverId');
let funcs = session.get('funcs');
if(roleId) {
let roleName = session.get('roleName');
let channelName = roleId;
let channelName = `server-${serverId}`;
let eventStatus = session.get('eventStatus')||EVENT_STATUS.WAITING;
let eventTime = session.get('getEventTime')||0;
let now = new Date();
let t = getEventTime(now);
let channel = app.get('channelService').getChannel(channelName, false);
if(!!channel && (eventTime < t || isForce)) { // 第一次登陆后可以刷新了
let event = await getEvent(eventStatus, roleId, roleName);
if (eventStatus == EVENT_STATUS.STARTING || eventStatus == EVENT_STATUS.OPEN) {
pushEventMsg(app, roleId, channelName, { event }); // 推送
session.set('getEventTime', t);
session.push('getEventTime', () => {});
if(funcs && funcs.includes(FUNCS_ID.EVENT) && eventStatus == EVENT_STATUS.WAITING) {
await startEvent(app, session);
} else {
let eventTime = session.get('getEventTime')||0;
let now = new Date();
let t = getEventTime(now);
let channel = app.get('channelService').getChannel(channelName, false);
if(!!channel && (eventTime < t || isForce)) { // 第一次登陆后可以刷新了
let event = await getEvent(eventStatus, roleId, roleName);
if (eventStatus == EVENT_STATUS.STARTING || eventStatus == EVENT_STATUS.OPEN) {
pushEventMsg(app, roleId, channelName, { event }); // 推送
session.set('getEventTime', t);
session.push('getEventTime', () => {});
}
}
}
}
@@ -0,0 +1,35 @@
import { Application, BackendSession, FrontendSession } from "pinus";
import { getGamedata } from "../pubUtils/gamedata";
import Role, { RoleModel } from "../db/Role";
import { FUNC_OPT_TYPE } from "../consts/consts";
// 开启功能
export async function switchOnFunc(roleId: string, type: number, param: number, app: Application, session: (BackendSession|FrontendSession)) {
const serverId = session.get('serverId');
const dataFuncs = session.get('funcs');
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 channelService = app.get('channelService');
let channel = channelService.getChannel(`server-${serverId}`, false);
if(!!channel && funcs.length > 0) {
let tsid = channel.getMember(roleId)['sid'];
channelService.pushMessageByUids('onFuncSwitchOn', {funcs}, [{
uid: roleId,
sid: tsid
}]);
}
const recs = await RoleModel.pushFuncs(roleId, addFuncs);
session.set('funcs', recs.funcs||[]);
session.push('funcs', () => {});
return recs
}
@@ -3,8 +3,11 @@ import { HeroModel } from '../db/Hero';
import Role, { RoleModel } from '../db/Role'
import { getLvByExp, getExpByLv } from '../pubUtils/gamedata';
import { redisUserInfoUpdate } from './redisService';
import { switchOnFunc } from './funcSwitchService';
import { FUNC_OPT_TYPE } from '../consts/consts';
import { Application, BackendSession } from 'pinus';
export async function roleLevelup(roleId: string, kingExp: number) {
export async function roleLevelup(roleId: string, kingExp: number, app: Application, session: BackendSession) {
let role = await RoleModel.findByRoleId(roleId);
let {lv = 1, exp = 0} = role;
let newExp = exp + kingExp;
@@ -15,8 +18,9 @@ export async function roleLevelup(roleId: string, kingExp: number) {
newExp = curExpObj.sum;
}
await RoleModel.levelup(roleId, newLv, newExp);
role = await RoleModel.levelup(roleId, newLv, newExp);
if(newLv > lv) { // 升级
await switchOnFunc(roleId, FUNC_OPT_TYPE.LEVEL_UP, newLv, app, session);
await redisUserInfoUpdate(roleId, [{field: 'lv', value: newLv}])
}
let actordata = [];
+1 -1
View File
@@ -32,7 +32,7 @@ export async function initAllRank() {
}
export async function initRank(serverId: number) {
console.log('*****', 'initRank')
// console.log('*****', 'initRank')
await redisExpire(getKeyName(REDIS_KEY.TOWER_RANK, serverId), 30 * 24 * 60 * 60);
await redisExpire(REDIS_KEY.USER_INFO, 30 * 24 * 60 * 60);