diff --git a/src/api_s2c/xstask/ApiOnekeyReceive.ts b/src/api_s2c/xstask/ApiOnekeyReceive.ts index 933665e..7f4a8f8 100644 --- a/src/api_s2c/xstask/ApiOnekeyReceive.ts +++ b/src/api_s2c/xstask/ApiOnekeyReceive.ts @@ -13,6 +13,9 @@ export default async function (call: ApiCall if (args.length < 1 || _ids.isDuplication() || heroIds.isDuplication()) return call.error(globalThis.lng.kbzz_1); + let event = await G.mongodb.cEvent('xstask').findOne({uid: call.uid, type: 'xstask'}); + if (event.receiveNum >= 8) return call.error(globalThis.lng.xstask_11); + //所有的任务 let taskList = await XstaskFun.getAllTask(call.uid); //所有的任务id diff --git a/src/api_s2c/xstask/ApiOpen.ts b/src/api_s2c/xstask/ApiOpen.ts index 3a65a5d..30e17ef 100644 --- a/src/api_s2c/xstask/ApiOpen.ts +++ b/src/api_s2c/xstask/ApiOpen.ts @@ -1,9 +1,9 @@ -import { ApiCall } from "tsrpc"; -import { playerInfoType } from '../../module/collection_palyerInfo'; -import { TeQuanFun } from '../../public/tequan'; -import { XstaskFun } from '../../public/xstask'; -import { ReqOpen, ResOpen } from "../../shared/protocols/xstask/PtlOpen"; -import { PublicShared } from '../../shared/public/public'; +import {ApiCall} from "tsrpc"; +import {playerInfoType} from '../../module/collection_palyerInfo'; +import {TeQuanFun} from '../../public/tequan'; +import {XstaskFun} from '../../public/xstask'; +import {ReqOpen, ResOpen} from "../../shared/protocols/xstask/PtlOpen"; +import {PublicShared} from '../../shared/public/public'; export default async function (call: ApiCall) { let needAddTask: number; @@ -19,7 +19,7 @@ export default async function (call: ApiCall) { useFreeRefreshNum: 0 }; needAddTask = G.gc.xstaskcom.lv[changeInfo.lv].maxTaskNum; - XstaskFun.changeInfo(call.uid, { $set: { ...changeInfo } }); + XstaskFun.changeInfo(call.uid, {$set: {...changeInfo}}); } else if (PublicShared.getToDayZeroTime() > taskInfo.lastRefreshTime) { changeInfo = { lastRefreshTime: G.time, @@ -32,14 +32,15 @@ export default async function (call: ApiCall) { needAddTask = G.gc.xstaskcom.lv[taskInfo.lv].maxTaskNum - retainTask.length; - XstaskFun.changeInfo(call.uid, { $set: { ...changeInfo } }); + XstaskFun.changeInfo(call.uid, {$set: {...changeInfo}}); XstaskFun.delTasks(call.uid, delTask.map(task => task._id)); + XstaskFun.receiveNum(call.uid, true) } // needAddTask += await TeQuanFun.getXsTaskNum(call); needAddTask && await XstaskFun.addTasks(call.uid, XstaskFun.randomTasks(taskInfo?.lv || changeInfo.lv, needAddTask)); - let { _id, uid, type, ...info } = taskInfo || changeInfo as typeof taskInfo; + let {_id, uid, type, ...info} = taskInfo || changeInfo as typeof taskInfo; call.succ({ ...info, taskList: await XstaskFun.getAllTask(call.uid), diff --git a/src/api_s2c/xstask/ApiReceive.ts b/src/api_s2c/xstask/ApiReceive.ts index c0c2e97..8f252c7 100644 --- a/src/api_s2c/xstask/ApiReceive.ts +++ b/src/api_s2c/xstask/ApiReceive.ts @@ -1,13 +1,16 @@ -import { ApiCall } from "tsrpc"; -import { HeroFun } from '../../public/hero'; -import { XstaskFun } from '../../public/xstask'; -import { ReqReceive, ResReceive } from "../../shared/protocols/xstask/PtlReceive"; -import { HongDianChange } from "../hongdian/fun"; +import {ApiCall} from "tsrpc"; +import {HeroFun} from '../../public/hero'; +import {XstaskFun} from '../../public/xstask'; +import {ReqReceive, ResReceive} from "../../shared/protocols/xstask/PtlReceive"; +import {HongDianChange} from "../hongdian/fun"; export default async function (call: ApiCall) { if (call.req.heroIds.length < 1) return call.error(globalThis.lng.xstask_9); if (call.req.heroIds.isDuplication()) return call.error(globalThis.lng.xstask_10); + let event = await G.mongodb.cEvent('xstask').findOne({uid: call.uid, type: 'xstask'}); + if (event.receiveNum >= 8) return call.error(globalThis.lng.xstask_11); + let task = await XstaskFun.getTask(call.uid, call.req._id); let taskConf = G.gc.xstask[task?.taskId]; if (!task) return call.error(globalThis.lng.xstask_1); @@ -28,6 +31,7 @@ export default async function (call: ApiCall) { heros: call.req.heroIds }; + XstaskFun.receiveNum(call.uid) XstaskFun.receiveTask(call.uid, call.req._id, change); HongDianChange.sendChangeKey(call.uid, ['xstaskhd', 'huodonghd']); diff --git a/src/api_s2c/xstask/ApiRefresh.ts b/src/api_s2c/xstask/ApiRefresh.ts index e48fee9..371270c 100644 --- a/src/api_s2c/xstask/ApiRefresh.ts +++ b/src/api_s2c/xstask/ApiRefresh.ts @@ -12,6 +12,9 @@ export default async function (call: ApiCall) { if (delNum < 1) return call.error(globalThis.lng.xstask_11); + let event = await G.mongodb.cEvent('xstask').findOne({uid: call.uid, type: 'xstask'}); + if (event.receiveNum >= 8) return call.error(globalThis.lng.xstask_11); + let change: ResRefresh = {}; let needDel = taskList.filter(task => task.receiveData == undefined || task.receiveData.rec == true); diff --git a/src/fix_patch/patch_2024.1.02.ts b/src/fix_patch/patch_2024.1.02.ts new file mode 100644 index 0000000..9428b5c --- /dev/null +++ b/src/fix_patch/patch_2024.1.02.ts @@ -0,0 +1,68 @@ +import {patchInit} from "../patch"; +// import {addGameLog, connGameLogDB} from "../gameLog"; +import {MongoClient} from "mongodb"; + +class Path { + + async fun1(a: any) { + + let logDB = await connGameLogDB(); + + console.log(11111,'开始查询') + + let ab = await logDB.collection('gameLog').aggregate([ + {$match: {"type": "kuangdong/YanShi", "req.hdid": {$lte: 21}}}, + {$group: {_id: "$uid", total: {$sum: 1}}} + ]).toArray() + + let auids = ab.map(i => ({ + uid: i._id, + type: 'yanshiNum', + time: G.time, + num: i.total, + data: { + ...i + } + })) + + console.log(auids) + // @ts-ignore + G.crossmongodb.collection('fupanLog').insertMany(auids) + + return auids + } + + + async run() { + await this.fun1(1); + } +} + +async function connGameLogDB() { + console.log('connect gamelog mongodb ......'); + let logDBUrl:string; + if(G.config.isG123){ + logDBUrl = "mongodb://root:lffu2bD%5eGn2%5eE%2bE7@blacklagoon-mongo-log-primary.pro.g123-cpp.com:3717,blacklagoon-mongo-log-secondary.pro.g123-cpp.com:3717?replicaSet=mgset-351742307"; + }else{ + logDBUrl = "mongodb://root:lyMaple525458@10.0.1.20:27017/heijiao_gamelog?authSource=admin"; + } + let client = await MongoClient.connect(logDBUrl,{ + maxPoolSize:10, + maxIdleTimeMS: 5*60*1000 + }); + return client.db(`gameLog${G.config.serverId}`); +} + + +async function main() { + await patchInit() + let patch = new Path(); + await patch.run(); + console.log("逻辑执行完成,等待退出"); + setTimeout(function () { + console.log('结束程序'); + process.exit(); + }, 3000); +} + +main(); diff --git a/src/fix_patch/patch_2024.1.2.ts b/src/fix_patch/patch_2024.1.2.ts new file mode 100644 index 0000000..c2298a5 --- /dev/null +++ b/src/fix_patch/patch_2024.1.2.ts @@ -0,0 +1,59 @@ +import {log} from "console"; +import {patchFun, patchInit} from "../patch"; +import {TanXianFun} from "../public/tanxian"; +import {PublicShared} from "../shared/public/public"; +import {addGameLog} from "../gameLog"; + +class Path { + + async fun1(a: any) { + + // 查询今天登录的用户 + let today_login_users = await G.mongodb.collection("actionLog").find( + {"log.use_attr_rmbmoney": {$gte: 100000}}, + {projection: {uid: 1, "log.use_attr_rmbmoney": 1}} + ).toArray(); + + let uids = today_login_users.map(i => i.uid) + + let users = await G.mongodb.collection("user").find({ + uid: {$in: uids}, + vip: {$lte: 6} + }, {projection: {uid: 1, vip: 1, lv: 1}}).toArray() + + let auids = users.map(i => ({ + uid: i.uid, + type: 'shuazuanshi', + time: G.time, + data: { + vip: i.vip, + lv: i.lv, + rmbmoney: today_login_users.find(v => v.uid == i.uid)?.log?.use_attr_rmbmoney + } + })) + + console.log(auids) + // @ts-ignore + G.crossmongodb.collection('fupanLog').insertMany(auids) + + return auids + } + + + async run() { + await this.fun1(1); + } +} + +async function main() { + await patchInit() + let patch = new Path(); + await patch.run(); + console.log("逻辑执行完成,等待退出"); + setTimeout(function () { + console.log('结束程序'); + process.exit(); + }, 3000); +} + +main(); diff --git a/src/module/collection_event.ts b/src/module/collection_event.ts index 7908bf4..d09d6eb 100644 --- a/src/module/collection_event.ts +++ b/src/module/collection_event.ts @@ -58,6 +58,10 @@ export type eventType = { payForDiamond: { [time: number]: number } + xstask: { + refreshTime: number, + receiveNum: number + } } & { [k: `${number}jijin`]: ResOpenYuedujijin; diff --git a/src/public/player.ts b/src/public/player.ts index 4b48e40..9237363 100644 --- a/src/public/player.ts +++ b/src/public/player.ts @@ -401,7 +401,6 @@ export class PlayerFun { */ static async cutEquip(call: call, _idArr: string[]) { for (let _id of _idArr) { - G.redis.del('equip', call.uid, _id); G.mongodb.collection('equip').deleteOne({uid: call.uid, _id: new ObjectId(_id)}); call.addEventMsg('msg_s2c/EquipChange', _id, {num: 0}); @@ -472,7 +471,6 @@ export class PlayerFun { static async cutHero(call: call, _idArr: string[]) { for (let _id of _idArr) { await HeroFun.delHero(call, _id); - G.redis.del('hero', call.uid, _id); G.mongodb.collection('hero').deleteOne({uid: call.uid, _id: new ObjectId(_id)}); call.addEventMsg('msg_s2c/HeroChange', _id, {num: 0}); addGameLog(call.uid, "_cutHero", {}, {_id: _id}) diff --git a/src/public/xstask.ts b/src/public/xstask.ts index b25c1c5..ef277a9 100644 --- a/src/public/xstask.ts +++ b/src/public/xstask.ts @@ -1,25 +1,30 @@ -import { OptionalId, UpdateFilter } from 'mongodb'; -import { ApiCall } from 'tsrpc'; -import { playerInfoType } from '../module/collection_palyerInfo'; -import { CollectionXstask } from '../module/collection_xstask'; -import { PublicShared } from '../shared/public/public'; - +import {OptionalId, UpdateFilter} from 'mongodb'; +import {ApiCall} from 'tsrpc'; +import {playerInfoType} from '../module/collection_palyerInfo'; +import {CollectionXstask} from '../module/collection_xstask'; +import {PublicShared} from '../shared/public/public'; export class XstaskFun { /**所有玩家的悬赏任务缓存 */ static uidTask: k_v = {}; + /**获取单个悬赏任务 */ static async getTask(uid: string, _id: string) { - return this.uidTask[uid]?.find(task => task._id == _id) || await G.mongodb.collection('xstask').findOne({ uid: uid, _id: G.mongodb.conversionId(_id) }); + return this.uidTask[uid]?.find(task => task._id == _id) || await G.mongodb.collection('xstask').findOne({ + uid: uid, + _id: G.mongodb.conversionId(_id) + }); } + /**获取所有悬赏任务 */ static async getAllTask(uid: string) { let taskList = this.uidTask[uid]; if (!taskList) { - taskList = this.uidTask[uid] = (await G.mongodb.collection('xstask').find({ uid: uid }).toArray()).map(task => G.mongodb.conversionIdObj(task)); - }; + taskList = this.uidTask[uid] = (await G.mongodb.collection('xstask').find({uid: uid}).toArray()).map(task => G.mongodb.conversionIdObj(task)); + } + ; return taskList; } @@ -27,16 +32,22 @@ export class XstaskFun { /**完成任务标记 */ static async finishTask(uid: string, _id: string) { // 修改数据库 - G.mongodb.collection('xstask').updateOne({ uid: uid, _id: G.mongodb.conversionId(_id) }, { $set: { 'receiveData.rec': true } }); + G.mongodb.collection('xstask').updateOne({ + uid: uid, + _id: G.mongodb.conversionId(_id) + }, {$set: {'receiveData.rec': true}}); // 修改缓存 let index = this.uidTask[uid]?.findIndex(task => task._id == _id); this.uidTask[uid][index].receiveData.rec = true - return + return } /**更新任务单个 */ static async updateTask(uid: string, _id: string, taskId: string) { - G.mongodb.collection('xstask').updateOne({ uid: uid, _id: G.mongodb.conversionId(_id) }, { $unset: { receiveData: 1 }, $set: {taskId: taskId} }); + G.mongodb.collection('xstask').updateOne({ + uid: uid, + _id: G.mongodb.conversionId(_id) + }, {$unset: {receiveData: 1}, $set: {taskId: taskId}}); let index = this.uidTask[uid]?.findIndex(task => task._id == _id); delete this.uidTask[uid][index].receiveData; this.uidTask[uid][index].taskId = taskId; @@ -48,13 +59,15 @@ export class XstaskFun { let task = this.uidTask[uid]?.find(task => task._id == _id); task && this.uidTask[uid].removeOne(task); - G.mongodb.collection('xstask').deleteOne({ uid: uid, _id: G.mongodb.conversionId(_id) }); + G.mongodb.collection('xstask').deleteOne({uid: uid, _id: G.mongodb.conversionId(_id)}); } + /**删除多个悬赏任务 */ static async delTasks(uid: string, _id: string[]) { for (let id of _id) await this.delTask(uid, id); } + /**添加多个悬赏任务 */ static async addTasks(uid: string, taskArr: { taskId: string; }[]) { @@ -76,12 +89,17 @@ export class XstaskFun { return this.uidTask[uid]; } + /**派遣任务任务 */ static async receiveTask(uid: string, _id: string, d: CollectionXstask['receiveData']) { let cache = this.uidTask[uid]?.find(task => task._id == _id); if (cache) cache.receiveData = d; - G.mongodb.collection('xstask').updateOne({ uid: uid, _id: G.mongodb.conversionId(_id) }, { $set: { receiveData: d } }); + G.mongodb.collection('xstask').updateOne({ + uid: uid, + _id: G.mongodb.conversionId(_id) + }, {$set: {receiveData: d}}); } + /**获取所有已被派遣的英雄 */ static async getAllReceiveHero(uid: string) { let heroIds: string[] = []; @@ -91,19 +109,22 @@ export class XstaskFun { return heroIds; } + /**获取悬赏任务记录信息 */ static async getInfo(uid: string) { - return await G.mongodb.collection('playerInfo', 'xstask').findOne({ uid: uid, type: 'xstask' }); + return await G.mongodb.collection('playerInfo', 'xstask').findOne({uid: uid, type: 'xstask'}); } + /**修改悬赏任务记录信息 */ static async changeInfo(uid: string, change: Pick>, '$inc' | '$set'>) { G.mongodb.collection('playerInfo', 'xstask').updateOne( - { uid: uid, type: 'xstask' }, + {uid: uid, type: 'xstask'}, change, - { upsert: true } + {upsert: true} ); } + /**随机任务 */ static randomTasks(lv: number, num: number) { let tasks = Object.values(G.gc.xstask).filter(task => G.gc.xstaskcom.lv[lv].taskColor.includes(task.colour)).sort(function () { @@ -136,4 +157,18 @@ export class XstaskFun { } return _res; } + + /** + * 刷新每天派遣次数,每天上限8次 + */ + static async receiveNum(uid: string, refresh = false) { + if (refresh) { + G.mongodb.cEvent('xstask').updateOne({uid: uid, type: 'xstask'}, + {$set: {refreshTime: G.time, receiveNum: 0}}, {upsert: true}); + } else { + G.mongodb.cEvent('xstask').updateOne({uid: uid, type: 'xstask'}, + {$inc: {receiveNum: 1}}, {upsert: true}); + } + + } } \ No newline at end of file