import { Application, BackendSession, FrontendSession } from "pinus"; import { getGamedata } from "../pubUtils/gamedata"; import Role, { RoleModel } from "../db/Role"; import { FUNC_OPT_TYPE } from "../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(); 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 }