From 686f1fafc65cc8928120bd747f0abc5df2ea1c5d Mon Sep 17 00:00:00 2001 From: xcy Date: Sun, 31 Dec 2023 14:18:57 +0800 Subject: [PATCH 1/8] =?UTF-8?q?fix:=20=E4=B8=9B=E6=9E=97=E7=8C=8E=E6=89=8B?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_cross/clsl/ApiFindEnemy.ts | 44 ++- src/api_cross/clsl/ApiLog.ts | 2 +- src/api_cross/clsl/ApiRank.ts | 29 +- src/api_cross/clsl/ApiRankUids.ts | 9 - src/api_cross/clsl/ApiUpLoad.ts | 34 ++- src/api_s2c/conglinshoulie/ApiFind.ts | 101 +++++-- src/api_s2c/conglinshoulie/ApiOpen.ts | 16 +- src/api_s2c/rank/ApiOpen.ts | 19 +- src/cross/protocols/clsl/PtlFindEnemy.ts | 1 + src/cross/protocols/clsl/PtlRank.ts | 2 +- src/cross/protocols/clsl/PtlRankUids.ts | 9 - src/cross/protocols/serviceProto.ts | 126 ++++----- src/json/clsl_com.json5 | 33 +-- src/json/clsl_dan.json | 250 ++++++++++++++++++ src/jsonType.ts | 8 +- src/module/collection_clsl.ts | 7 +- src/module/mongodb.ts | 5 +- src/monopoly/protocols/serviceProto.ts | 6 +- src/public/fight.ts | 2 +- src/public/rank/rank.ts | 20 +- src/public/rank/rank_clsl.ts | 89 +++---- src/public/scheduler/scheduler.ts | 4 +- src/public/scheduler/scheduler_clsl.ts | 148 ++++++++--- .../protocols/conglinshoulie/PtlOpen.ts | 4 + src/shared/protocols/rank/PtlOpen.ts | 5 +- src/shared/protocols/serviceProto.ts | 23 +- 26 files changed, 715 insertions(+), 281 deletions(-) delete mode 100644 src/api_cross/clsl/ApiRankUids.ts delete mode 100644 src/cross/protocols/clsl/PtlRankUids.ts diff --git a/src/api_cross/clsl/ApiFindEnemy.ts b/src/api_cross/clsl/ApiFindEnemy.ts index e6ead85..743f42f 100644 --- a/src/api_cross/clsl/ApiFindEnemy.ts +++ b/src/api_cross/clsl/ApiFindEnemy.ts @@ -1,16 +1,48 @@ import { ApiCall } from "tsrpc"; import { ReqFindEnemy, ResFindEnemy } from "../../cross/protocols/clsl/PtlFindEnemy"; import { formatNpcData } from '../../shared/fightControl/fightFun'; +import { PublicShared } from "../../shared/public/public"; export default async function (call: ApiCall) { - let my = await G.mongodb.collection('clslCrossUser').findOne({ uid: call.req.uid }); - let starConf = getStarConf(my.allStar); - let others = await G.mongodb.collection('clslCrossUser').find({ uid: { $nin: [call.req.uid] } }).toArray(); - let enemy = others.random(); + let p = PublicShared.randomNum(1, 1000); + let starConf = getStarConf(call.req.myStasr); + + let enemy: { allStar: number, info: any }; + + // 本次随机到npc概率判断 + if (p <= starConf.pro * 1000) { + enemy = { + allStar: call.req.myStasr, + info: formatNpcData(starConf.npc) + } + } else { + // 在自定范围内随机一个对手 + let others = await G.mongodb.collection("clslCrossUser").aggregate([ + { + $match: [ + { allStar: { $gte: starConf.fighter[0], $lte: starConf.fighter[1] } } + ], + $sample: { size: 1 } + } + + ]).toArray(); + + if (others.length <= 0) { + enemy = { + allStar: call.req.myStasr, + info: formatNpcData(starConf.npc) + } + } else { + enemy = { + allStar: others[0].allStar, + info: others[0].info, + } + } + } call.succ({ - allStar: enemy?.allStar || my.allStar, - info: enemy?.info || formatNpcData(starConf.npc) + allStar: enemy.allStar, + info: enemy.info || formatNpcData(starConf.npc) }); } diff --git a/src/api_cross/clsl/ApiLog.ts b/src/api_cross/clsl/ApiLog.ts index 7b795f7..6f8b44b 100644 --- a/src/api_cross/clsl/ApiLog.ts +++ b/src/api_cross/clsl/ApiLog.ts @@ -4,7 +4,7 @@ import { FightFun } from '../../public/fight'; export default async function (call: ApiCall) { if (call.req.result) { - // FightFun.saveLog(call.req.uid, 'clsl', call.req.result); + FightFun.saveLog(call.req.uid, 'clsl', call.req.result); call.succ({}); } else { call.succ({ diff --git a/src/api_cross/clsl/ApiRank.ts b/src/api_cross/clsl/ApiRank.ts index a12970e..ada7663 100644 --- a/src/api_cross/clsl/ApiRank.ts +++ b/src/api_cross/clsl/ApiRank.ts @@ -1,10 +1,35 @@ import { ApiCall } from "tsrpc"; import { ReqRank, ResRank } from "../../cross/protocols/clsl/PtlRank"; import { Rank } from '../../public/rank/rank'; +import { PublicShared } from "../../shared/public/public"; +import { RankClslCross } from "../../public/rank/rank_clsl"; export default async function (call: ApiCall) { + let group_time = G.gc.clsl_com.divideTime; + let week_zero_time = PublicShared.getToWeekMondayZeroTime(); + + if (G.time < week_zero_time + group_time) { + call.succ({ rankList: [], myRank: { rank: -1, player: {}, valArr: [] } }) + } + + let a = await G.mongodb.collection('clslCrossUser').findOne({ + uid: call.req.uid + }); + + if (!a){ + call.succ({ rankList: [], myRank: { rank: -1, player: {}, valArr: [] } }) + } + + let rank: Rank; + if (Rank.list[`clslCross_${a.group}`]) { + rank = Rank.list[`clslCross_${a.group}`] + } + else { + rank = new RankClslCross(a.group) + } + let page = call.req.page || 0 let offset = call.req.offset || -1 // 预防未查询到的调用,按原逻辑查询全部,避免引起未知问题 - let {min, max} = Rank.pageToMin(page, offset) - call.succ(await Rank.list.clslCross.getRankList(call.req.gud.uid, { min, max })); + let { min, max } = Rank.pageToMin(page, offset) + call.succ(await rank.getRankList(call.req.uid, { min, max })); } \ No newline at end of file diff --git a/src/api_cross/clsl/ApiRankUids.ts b/src/api_cross/clsl/ApiRankUids.ts deleted file mode 100644 index 8854781..0000000 --- a/src/api_cross/clsl/ApiRankUids.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { ApiCall } from "tsrpc"; -import { ReqRankUids, ResRankUids } from "../../cross/protocols/clsl/PtlRankUids"; -import { Rank } from '../../public/rank/rank'; - -export default async function (call: ApiCall) { - // 返回排名的uids, 应用场景是定时器发送奖励,不分页。 - let uids = await Rank.list.clslCross.getRankListIdKeyAll() - call.succ({uids}); -} \ No newline at end of file diff --git a/src/api_cross/clsl/ApiUpLoad.ts b/src/api_cross/clsl/ApiUpLoad.ts index 7d40b57..57a47fd 100644 --- a/src/api_cross/clsl/ApiUpLoad.ts +++ b/src/api_cross/clsl/ApiUpLoad.ts @@ -1,23 +1,41 @@ import { ApiCall } from "tsrpc"; import { ReqUpLoad, ResUpLoad } from "../../cross/protocols/clsl/PtlUpLoad"; import { Rank } from '../../public/rank/rank'; +import { PublicShared } from "../../shared/public/public"; +import { RankClslCross } from "../../public/rank/rank_clsl"; export default async function (call: ApiCall) { let { allStar, uid, ...ops } = call.req; - let a = await G.mongodb.collection('clslCrossUser').findOneAndUpdate( + let a = (await G.mongodb.collection('clslCrossUser').findOneAndUpdate( { uid: uid }, { $inc: { allStar: allStar || 0 }, $set: ops }, - { upsert: true } - ); + { upsert: true, returnDocument: "after" } + )).value; + + let week = PublicShared.getToWeek(); + let group_time = G.gc.clsl_com.divideTime; + let week_zero_time = PublicShared.getToWeekMondayZeroTime(); - if (allStar != undefined && ops.info) { - Rank.list.clslCross.addNew({ - player: a.value.info.player, - valArr: [(await G.mongodb.collection('clslCrossUser').findOne({ uid: uid })).allStar] - }); + if (G.time > week_zero_time + group_time) { + if (!a.group){ + + } + if (allStar != undefined && ops.info) { + let rank; + if (Rank.list[`clslCross_${a.group}`]) { + rank = Rank.list[`clslCross_${a.group}`] + } + else{ + rank = new RankClslCross(a.group) + } + rank.addNew({ + player: a.info.player, + valArr: [a.allStar, a.info.player.power] + }); + } } } \ No newline at end of file diff --git a/src/api_s2c/conglinshoulie/ApiFind.ts b/src/api_s2c/conglinshoulie/ApiFind.ts index e0436cd..2309485 100644 --- a/src/api_s2c/conglinshoulie/ApiFind.ts +++ b/src/api_s2c/conglinshoulie/ApiFind.ts @@ -1,43 +1,90 @@ -import {ApiCall} from "tsrpc"; -import {FightFun} from '../../public/fight'; -import {PlayerFun} from '../../public/player'; -import {ReqFind, ResFind} from "../../shared/protocols/conglinshoulie/PtlFind"; -import {PublicShared} from '../../shared/public/public'; -import {addStar, clslDb} from './ApiOpen'; +import { ApiCall } from "tsrpc"; +import { FightFun } from '../../public/fight'; +import { PlayerFun } from '../../public/player'; +import { ReqFind, ResFind } from "../../shared/protocols/conglinshoulie/PtlFind"; +import { PublicShared } from '../../shared/public/public'; +import { addStar, clslDb } from './ApiOpen'; +import { EmailFun } from "../../public/email"; export default async function (call: ApiCall) { let weekZeroTime = PublicShared.getToWeekMondayZeroTime(); - if (G.time < weekZeroTime + G.gc.clsl_com.fightTime[0] || G.time > weekZeroTime + G.gc.clsl_com.fightTime[1]) return call.errorCode(-1); - let db = await clslDb().findOne({uid: call.uid, type: 'clsl'}); + // 未到开启时间 + if (G.time < weekZeroTime + G.gc.clsl_com.fightTime[0] || G.time > weekZeroTime + G.gc.clsl_com.fightTime[1]) { + return call.errorCode(-1) + }; + + // 获取自己的数据 + let db = await clslDb().findOne({ uid: call.uid, type: 'clsl' }); + let curStar = db?.allStar || 0; let useNum = db?.useFightNum || 0; let buyNum = db?.buyFightNum || 0; - let starConf = G.gc.clsl_dan[curStar] || Object.values(G.gc.clsl_dan).slice(-1)[0]; + let danPrize = db?.danPrize || []; + let curMaxStar = db?.curMaxStar || 0; - if (useNum >= buyNum + G.gc.clsl_com.fightNum) return call.errorCode(-2); - - let my = await call.conn.getDefaultFightData(); - let other = (await G.clientCross.callApi('clsl/FindEnemy', {uid: call.uid})).res; - let result = FightFun.fight([my, other.info]); - - if ((result.winSide != 0 && starConf.failCut) || result.winSide == 0) { - addStar(call, result.winSide == 0 ? 1 : -starConf.failCut, my); + // 战斗次数不足 + if (useNum >= buyNum + G.gc.clsl_com.fightNum) { + return call.errorCode(-2); } - result.initData[0].star = curStar - result.initData[1].star = other.allStar + // 自己战斗数据 + let my = await call.conn.getDefaultFightData(); - result.winSide == 0 && clslDb().updateOne({uid: call.uid, type: 'clsl'}, {$inc: {fightWinNum: 1}}); - clslDb().updateOne({uid: call.uid, type: 'clsl'}, {$inc: {useFightNum: 1}}); + // 获取一个对手 + let other = (await G.clientCross.callApi('clsl/FindEnemy', { uid: call.uid, myStasr: curStar })).res; + let result = FightFun.fight([my, other.info]); + + let starConf = G.gc.clsl_dan[curStar] || Object.values(G.gc.clsl_dan).slice(-1)[0]; + + let updata = { $inc: { useFightNum: 1 } }; + + // 更新战斗胜利的次数 + if (result.winSide == 0) { + updata.$inc["fightWinNum"] = 1; + + // 首次达到某个段位 + if (curStar + 1 > curMaxStar) { + curMaxStar += 1; + updata.$inc["curMaxStar"] = 1; + } + } + + // 段位奖励邮件 + let title = G.gc.clsl_com.email_dan.title; + let content = G.gc.clsl_com.email_dan.content; + G.gc.clsl_com.danPrize.forEach(conf => { + // 段位未达到 或者 奖励已经发放 + if (conf.star > curMaxStar || danPrize.includes[conf.star]) { + return + } + + // 发放邮件 + EmailFun.addEmail({ + uid: call.uid, + type: 'system', + title: title, + content: content, + prize: conf.prize, + }) + + danPrize.push(conf.star); + updata["$set"] = { danPrize: danPrize }; + }) + + // 输了掉星 或者 赢了加星 同时更新排行数据 + addStar(call, result.winSide == 0 ? 1 : -starConf.failCut, my, updata); + + result.initData[0].star = curStar; + result.initData[1].star = other.allStar; + + // 发送战斗奖励 await PlayerFun.sendPrize(call, starConf.fightPrize); - G.clientCross?.callApi('clsl/Log', {uid: call.uid, result: result}); - G.clientCross?.callApi('clsl/Log', {uid: other.info.player.uid, result: result}); + // 记录战斗日志 + G.clientCross?.callApi('clsl/Log', { uid: call.uid, result: result }); + G.clientCross?.callApi('clsl/Log', { uid: other.info.player.uid, result: result }); - call.succ({ - enemy: other, - result: result - }); + call.succ({ enemy: other, result: result }); } \ No newline at end of file diff --git a/src/api_s2c/conglinshoulie/ApiOpen.ts b/src/api_s2c/conglinshoulie/ApiOpen.ts index e50e2b8..4824215 100644 --- a/src/api_s2c/conglinshoulie/ApiOpen.ts +++ b/src/api_s2c/conglinshoulie/ApiOpen.ts @@ -9,8 +9,8 @@ export default async function (call: ApiCall) { let db = await clslDb().findOne({ uid: call.uid, type: 'clsl' }); let { _id, uid, type, ...ops } = db || {} as WithId>>; + // 刷新 挑战次数、购买挑战次数、胜利次数任务 if (!db || ops?.refreshTime < PublicShared.getToDayZeroTime()) { - let change: Partial = { refreshTime: G.time, useFightNum: 0, @@ -30,6 +30,8 @@ export default async function (call: ApiCall) { call.succ({ allStar: ops?.allStar || 0, + danPrize: ops?.danPrize || [], + curMaxStar: ops?.curMaxStar || 0, buyFightNum: ops?.buyFightNum || 0, useFightNum: ops?.useFightNum || 0, fightWinNum: ops?.fightWinNum || 0, @@ -41,7 +43,15 @@ export function clslDb() { return G.mongodb.cPlayerInfo('clsl'); } -export async function addStar(call: ApiCall, star: number, info?: joinFightData) { - clslDb().updateOne({ uid: call.uid, type: 'clsl' }, { $inc: { allStar: star } }, { upsert: true }); +export async function addStar(call: ApiCall, star: number, info?: joinFightData, update?: any) { + update = update || {}; + + if (update.$inc) { + update.$inc["allStar"] = star + } else { + update["$inc"] = { allStar: star } + } + + clslDb().updateOne({ uid: call.uid, type: 'clsl' }, update, { upsert: true }); G.clientCross.callApi('clsl/UpLoad', { uid: call.uid, allStar: star, info: info || await call.conn.getDefaultFightData() }); } \ No newline at end of file diff --git a/src/api_s2c/rank/ApiOpen.ts b/src/api_s2c/rank/ApiOpen.ts index 9605fe4..a5bd1fe 100644 --- a/src/api_s2c/rank/ApiOpen.ts +++ b/src/api_s2c/rank/ApiOpen.ts @@ -4,6 +4,7 @@ import { Rank } from '../../public/rank/rank'; import { ReqOpen, ResOpen } from "../../shared/protocols/rank/PtlOpen"; import { getToper50RankInfo } from "../hbzb/jfs/fun"; import { getZbsRankList } from "../hbzb/zbs/fun"; +import { re } from "mathjs"; export default async function (call: ApiCall) { let obj = await rankOpenfun(call, call.req) @@ -24,7 +25,7 @@ export default async function (call: ApiCall) { export async function rankOpenfun(call, req: ReqOpen): Promise { let obj: ResOpen = {}; // 数组,兼容旧的参数 - if(req instanceof Array) { + if (req instanceof Array) { var types = req var page = 0 var offset = 1 @@ -39,7 +40,7 @@ export async function rankOpenfun(call, req: ReqOpen): Promise { const { min, max } = Rank.pageToMin(page, offset) for (let type of types) { switch (type) { - case 'jjc': + case 'jjc': // 获取前50名ranklist数据 let rankList = await JJCFun.getRankList(min, max); // 获取自己的排名 @@ -68,21 +69,23 @@ export async function rankOpenfun(call, req: ReqOpen): Promise { case 'slzd4': case 'slzd5': case 'slzd6': - obj[type] = await Rank.list[type].getRankList(call.conn.gud.ghId, {min, max}); + obj[type] = await Rank.list[type].getRankList(call.conn.gud.ghId, { min, max }); break; case 'kbzz': - let resCall = await G.clientCross.callApi('kbzz/Rank', { uid: call.uid, page, offset}); + let resCall = await G.clientCross.callApi('kbzz/Rank', { uid: call.uid, page, offset }); if (!resCall.isSucc) { return call.error('', { code: -2, message: globalThis.lng.rank_kbzz }); } obj[type] = resCall.res; break; case 'clslCross': - //let resCallClsl = await G.clientCross.callApi('clsl/Rank', { gud: call.conn.gud, page, offset}); - //obj[type] = resCallClsl.res; + let res = await G.clientCross.callApi('clsl/Rank', { + uid: call.uid, page: page, offset: offset + }); + obj[type] = res.res; break; case 'wzryCross': - let resCallWzry = await G.clientCross.callApi('wzry/Rank', { gud: call.conn.gud, page, offset}); + let resCallWzry = await G.clientCross.callApi('wzry/Rank', { gud: call.conn.gud, page, offset }); obj[type] = resCallWzry.res; break; case "hbzbLocal": @@ -93,7 +96,7 @@ export async function rankOpenfun(call, req: ReqOpen): Promise { obj[type] = await getZbsRankList(call.uid) as any; break; default: - obj[type] = await Rank.list[type].getRankList(call.uid, {min, max}); + obj[type] = await Rank.list[type].getRankList(call.uid, { min, max }); break; } } diff --git a/src/cross/protocols/clsl/PtlFindEnemy.ts b/src/cross/protocols/clsl/PtlFindEnemy.ts index a3f5368..c7cb7df 100644 --- a/src/cross/protocols/clsl/PtlFindEnemy.ts +++ b/src/cross/protocols/clsl/PtlFindEnemy.ts @@ -3,6 +3,7 @@ import { joinFightData } from '../../../shared/fightControl/fightType'; export type ReqFindEnemy = { uid: string; + myStasr:number; }; export type ResFindEnemy = { diff --git a/src/cross/protocols/clsl/PtlRank.ts b/src/cross/protocols/clsl/PtlRank.ts index c240888..13a6a83 100644 --- a/src/cross/protocols/clsl/PtlRank.ts +++ b/src/cross/protocols/clsl/PtlRank.ts @@ -3,7 +3,7 @@ import { player } from '../../../shared/protocols/user/type'; export type ReqRank = { - gud: player; + uid: string; page?: number; offset?: number; }; diff --git a/src/cross/protocols/clsl/PtlRankUids.ts b/src/cross/protocols/clsl/PtlRankUids.ts deleted file mode 100644 index 9938f0d..0000000 --- a/src/cross/protocols/clsl/PtlRankUids.ts +++ /dev/null @@ -1,9 +0,0 @@ - - -export type ReqRankUids = { - -}; - -export type ResRankUids = { - uids: string[]; -}; \ No newline at end of file diff --git a/src/cross/protocols/serviceProto.ts b/src/cross/protocols/serviceProto.ts index e99cd52..f403b19 100644 --- a/src/cross/protocols/serviceProto.ts +++ b/src/cross/protocols/serviceProto.ts @@ -2,7 +2,6 @@ import { ServiceProto } from 'tsrpc-proto'; import { ReqFindEnemy, ResFindEnemy } from './clsl/PtlFindEnemy'; import { ReqLog, ResLog } from './clsl/PtlLog'; import { ReqRank, ResRank } from './clsl/PtlRank'; -import { ReqRankUids, ResRankUids } from './clsl/PtlRankUids'; import { ReqUpLoad, ResUpLoad } from './clsl/PtlUpLoad'; import { ReqDelCrossEmail, ResDelCrossEmail } from './email/PtlDelCrossEmail'; import { ReqGetCrossEmail, ResGetCrossEmail } from './email/PtlGetCrossEmail'; @@ -54,10 +53,6 @@ export interface ServiceType { req: ReqRank, res: ResRank }, - "clsl/RankUids": { - req: ReqRankUids, - res: ResRankUids - }, "clsl/UpLoad": { req: ReqUpLoad, res: ResUpLoad @@ -211,186 +206,181 @@ export const serviceProto: ServiceProto = { }, { "id": 3, - "name": "clsl/RankUids", - "type": "api" - }, - { - "id": 4, "name": "clsl/UpLoad", "type": "api" }, { - "id": 5, + "id": 4, "name": "email/DelCrossEmail", "type": "api" }, { - "id": 6, + "id": 5, "name": "email/GetCrossEmail", "type": "api" }, { - "id": 7, + "id": 6, "name": "hbzb/jfs/GetEnemy", "type": "api" }, { - "id": 8, + "id": 7, "name": "hbzb/jfs/GetLog", "type": "api" }, { - "id": 9, + "id": 8, "name": "hbzb/jfs/GetRankList", "type": "api" }, { - "id": 10, + "id": 9, "name": "hbzb/jfs/GetUser", "type": "api" }, { - "id": 11, + "id": 10, "name": "hbzb/GetUser", "type": "api" }, { - "id": 12, + "id": 11, "name": "hbzb/UpdateHbzbCrossUser", "type": "api" }, { - "id": 13, + "id": 12, "name": "hbzb/zbs/GetEnemy", "type": "api" }, { - "id": 14, + "id": 13, "name": "hbzb/zbs/GetLog", "type": "api" }, { - "id": 15, + "id": 14, "name": "hbzb/zbs/GetRankList", "type": "api" }, { - "id": 16, + "id": 15, "name": "hbzb/zbs/GetStatus", "type": "api" }, { - "id": 17, + "id": 16, "name": "hbzb/zbs/SendJjcTop", "type": "api" }, { - "id": 18, + "id": 17, "name": "kbzz/Apply", "type": "api" }, { - "id": 19, + "id": 18, "name": "kbzz/GetUser", "type": "api" }, { - "id": 20, + "id": 19, "name": "kbzz/GroupRank", "type": "api" }, { - "id": 21, + "id": 20, "name": "kbzz/Rank", "type": "api" }, { - "id": 22, + "id": 21, "name": "kbzz/Refresh", "type": "api" }, { - "id": 23, + "id": 22, "name": "kbzz/State", "type": "api" }, { - "id": 24, + "id": 23, "name": "kbzz/UpUser", "type": "api" }, { - "id": 25, + "id": 24, "name": "msg_cross/CrossChat", "type": "msg" }, { - "id": 26, + "id": 25, "name": "msg_cross/HbzbChangeRank", "type": "msg" }, { - "id": 27, + "id": 26, "name": "msg_cross/HbzbJfsLog", "type": "msg" }, { - "id": 28, + "id": 27, "name": "msg_cross/HbzbSendUser", "type": "msg" }, { - "id": 29, + "id": 28, "name": "msg_cross/HbzbZbsLog", "type": "msg" }, { - "id": 30, + "id": 29, "name": "wzry/BaoMing", "type": "api" }, { - "id": 31, + "id": 30, "name": "wzry/catFightLog", "type": "api" }, { - "id": 32, + "id": 31, "name": "wzry/DldRefre", "type": "api" }, { - "id": 33, + "id": 32, "name": "wzry/getJingCai", "type": "api" }, { - "id": 34, + "id": 33, "name": "wzry/Rank", "type": "api" }, { - "id": 35, + "id": 34, "name": "wzry/SetWzFight", "type": "api" }, { - "id": 36, + "id": 35, "name": "wzry/UpdateFight", "type": "api" }, { - "id": 37, + "id": 36, "name": "wzry/WzFightData", "type": "api" }, { - "id": 38, + "id": 37, "name": "wzry/WzFightGroup", "type": "api" }, { - "id": 39, + "id": 38, "name": "wzry/Wzzd", "type": "api" } @@ -405,6 +395,13 @@ export const serviceProto: ServiceProto = { "type": { "type": "String" } + }, + { + "id": 1, + "name": "myStasr", + "type": { + "type": "Number" + } } ] }, @@ -2753,10 +2750,9 @@ export const serviceProto: ServiceProto = { "properties": [ { "id": 0, - "name": "gud", + "name": "uid", "type": { - "type": "Reference", - "target": "../../shared/protocols/user/type/player" + "type": "String" } }, { @@ -2777,14 +2773,6 @@ export const serviceProto: ServiceProto = { } ] }, - "../../shared/protocols/user/type/player": { - "type": "IndexedAccess", - "index": "gud", - "objectType": { - "type": "Reference", - "target": "../../shared/protocols/user/PtlLogin/ResLogin" - } - }, "clsl/PtlRank/ResRank": { "type": "IndexedAccess", "index": "", @@ -2897,24 +2885,6 @@ export const serviceProto: ServiceProto = { } ] }, - "clsl/PtlRankUids/ReqRankUids": { - "type": "Interface" - }, - "clsl/PtlRankUids/ResRankUids": { - "type": "Interface", - "properties": [ - { - "id": 0, - "name": "uids", - "type": { - "type": "Array", - "elementType": { - "type": "String" - } - } - } - ] - }, "clsl/PtlUpLoad/ReqUpLoad": { "type": "Partial", "target": { @@ -3258,6 +3228,14 @@ export const serviceProto: ServiceProto = { } ] }, + "../../shared/protocols/user/type/player": { + "type": "IndexedAccess", + "index": "gud", + "objectType": { + "type": "Reference", + "target": "../../shared/protocols/user/PtlLogin/ResLogin" + } + }, "hbzb/jfs/PtlGetEnemy/ResGetEnemy": { "type": "Interface", "properties": [ diff --git a/src/json/clsl_com.json5 b/src/json/clsl_com.json5 index def4d62..1595c97 100644 --- a/src/json/clsl_com.json5 +++ b/src/json/clsl_com.json5 @@ -1,18 +1,11 @@ { - //赛区划分 - divide: [ - { day: [1, 30], group: 0 }, - { day: [31, 60], group: 1 }, - { day: [61, 120], group: 2 }, - { day: [121, 210], group: 3 }, - { day: [211, 99999999], group: 4 }, - ], - //赛区划分时间 - divideTime: 0, - //挑战时间 + //赛区划分按照周三23:50的时候王者玩家100个一组 + //赛区划分时间周三23:50 + divideTime: 258600, + //挑战时间周一08:00——周六22:00 fightTime: [28800, 511200], - //发奖时间 - prizeTime: 598200, + //发奖时间周六22:05 + prizeTime: 511500, //胜场奖励 fightWinPrize: [ { total: 5, prize: [{ a: 'attr', t: 'clsl_sd', n: 1 },{ a: 'item', t: '37', n: 1 }], star: 1 }, @@ -39,13 +32,13 @@ ], //段位奖励 danPrize: [ - { star: [49, 49], prize: [{ a: 'item', t: '605', n:3 },{ a: 'item', t: '29', n:10 },{ a: 'item', t: '631', n:3 },{ a: 'item', t: '40', n:1 }] }, - { star: [39, 48], prize: [{ a: 'item', t: '605', n:2 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '631', n:2 }] }, - { star: [29, 38], prize: [{ a: 'item', t: '606', n:3 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '631', n:1 }] }, - { star: [21, 28], prize: [{ a: 'item', t: '606', n:2 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:1000 }] }, - { star: [13, 20], prize: [{ a: 'item', t: '606', n:1 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:800 }] }, - { star: [7, 12], prize: [{ a: 'item', t: '29', n:10 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:600 }] }, - { star: [0, 6], prize: [{ a: 'item', t: '29', n:5 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:400 }] } + { star: 49, prize: [{ a: 'item', t: '605', n:3 },{ a: 'item', t: '29', n:10 },{ a: 'item', t: '631', n:3 },{ a: 'item', t: '40', n:1 }] }, + { star: 39, prize: [{ a: 'item', t: '605', n:2 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '631', n:2 }] }, + { star: 29, prize: [{ a: 'item', t: '606', n:3 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '631', n:1 }] }, + { star: 21, prize: [{ a: 'item', t: '606', n:2 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:1000 }] }, + { star: 13, prize: [{ a: 'item', t: '606', n:1 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:800 }] }, + { star: 7, prize: [{ a: 'item', t: '29', n:10 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:600 }] }, + { star: 0, prize: [{ a: 'item', t: '29', n:5 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:400 }] } ], //王者排名邮件信息 email_rank: { diff --git a/src/json/clsl_dan.json b/src/json/clsl_dan.json index cf565d0..0ed85ab 100644 --- a/src/json/clsl_dan.json +++ b/src/json/clsl_dan.json @@ -18,6 +18,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 0, + 6 + ], "npc": 60001 }, "1": { @@ -39,6 +44,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 0, + 6 + ], "npc": 60002 }, "2": { @@ -60,6 +70,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 0, + 6 + ], "npc": 60003 }, "3": { @@ -81,6 +96,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 0, + 6 + ], "npc": 60004 }, "4": { @@ -102,6 +122,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 0, + 6 + ], "npc": 60005 }, "5": { @@ -123,6 +148,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 0, + 6 + ], "npc": 60006 }, "6": { @@ -144,6 +174,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 0, + 6 + ], "npc": 60007 }, "7": { @@ -165,6 +200,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 7, + 12 + ], "npc": 60008 }, "8": { @@ -186,6 +226,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 7, + 12 + ], "npc": 60009 }, "9": { @@ -207,6 +252,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 7, + 12 + ], "npc": 60010 }, "10": { @@ -228,6 +278,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 7, + 12 + ], "npc": 60011 }, "11": { @@ -249,6 +304,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 7, + 12 + ], "npc": 60012 }, "12": { @@ -270,6 +330,11 @@ "n": 100 } ], + "pro": 0.6, + "fighter": [ + 7, + 12 + ], "npc": 60013 }, "13": { @@ -291,6 +356,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 13, + 20 + ], "npc": 60014 }, "14": { @@ -312,6 +382,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 13, + 20 + ], "npc": 60015 }, "15": { @@ -333,6 +408,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 13, + 20 + ], "npc": 60016 }, "16": { @@ -354,6 +434,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 13, + 20 + ], "npc": 60017 }, "17": { @@ -375,6 +460,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 13, + 20 + ], "npc": 60018 }, "18": { @@ -396,6 +486,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 13, + 20 + ], "npc": 60019 }, "19": { @@ -417,6 +512,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 13, + 20 + ], "npc": 60020 }, "20": { @@ -438,6 +538,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 13, + 20 + ], "npc": 60021 }, "21": { @@ -459,6 +564,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 21, + 28 + ], "npc": 60022 }, "22": { @@ -480,6 +590,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 21, + 28 + ], "npc": 60023 }, "23": { @@ -501,6 +616,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 21, + 28 + ], "npc": 60024 }, "24": { @@ -522,6 +642,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 21, + 28 + ], "npc": 60025 }, "25": { @@ -543,6 +668,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 21, + 28 + ], "npc": 60026 }, "26": { @@ -564,6 +694,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 21, + 28 + ], "npc": 60027 }, "27": { @@ -585,6 +720,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 21, + 28 + ], "npc": 60028 }, "28": { @@ -606,6 +746,11 @@ "n": 100 } ], + "pro": 0.3, + "fighter": [ + 21, + 28 + ], "npc": 60029 }, "29": { @@ -627,6 +772,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 29, + 38 + ], "npc": 60030 }, "30": { @@ -648,6 +798,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 29, + 38 + ], "npc": 60031 }, "31": { @@ -669,6 +824,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 29, + 38 + ], "npc": 60032 }, "32": { @@ -690,6 +850,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 29, + 38 + ], "npc": 60033 }, "33": { @@ -711,6 +876,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 29, + 38 + ], "npc": 60034 }, "34": { @@ -732,6 +902,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 29, + 38 + ], "npc": 60035 }, "35": { @@ -753,6 +928,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 29, + 38 + ], "npc": 60036 }, "36": { @@ -774,6 +954,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 29, + 38 + ], "npc": 60037 }, "37": { @@ -795,6 +980,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 29, + 38 + ], "npc": 60038 }, "38": { @@ -816,6 +1006,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 29, + 38 + ], "npc": 60039 }, "39": { @@ -837,6 +1032,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 39, + 48 + ], "npc": 60040 }, "40": { @@ -858,6 +1058,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 39, + 48 + ], "npc": 60041 }, "41": { @@ -879,6 +1084,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 39, + 48 + ], "npc": 60042 }, "42": { @@ -900,6 +1110,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 39, + 48 + ], "npc": 60043 }, "43": { @@ -921,6 +1136,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 39, + 48 + ], "npc": 60044 }, "44": { @@ -942,6 +1162,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 39, + 48 + ], "npc": 60045 }, "45": { @@ -963,6 +1188,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 39, + 48 + ], "npc": 60046 }, "46": { @@ -984,6 +1214,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 39, + 48 + ], "npc": 60047 }, "47": { @@ -1005,6 +1240,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 39, + 48 + ], "npc": 60048 }, "48": { @@ -1026,6 +1266,11 @@ "n": 100 } ], + "pro": 0.15, + "fighter": [ + 39, + 48 + ], "npc": 60049 }, "49": { @@ -1047,6 +1292,11 @@ "n": 100 } ], + "pro": 0, + "fighter": [ + 39, + 49 + ], "npc": 60050 } } \ No newline at end of file diff --git a/src/jsonType.ts b/src/jsonType.ts index c953d75..59a07a6 100644 --- a/src/jsonType.ts +++ b/src/jsonType.ts @@ -103,7 +103,7 @@ type gc_choujiang = { type gc_chuanshuozhilu = { "hid": string, "time": number, "task": { "idx": number, "total": number, "type": string, "prize": { "a": string, "t": string, "n": number, [x: string]: any }[], "des": string, [x: string]: any }[], "box": { "total": number, "prize": { "a": string, "t": string, "n": number, [x: string]: any }[], [x: string]: any }, [x: string]: any }[] type gc_clsl_com = { - "divide": { "day": [number, number], "group": number, [x: string]: any }[], "divideTime": number, "fightTime": [number, number], "prizeTime": number, "fightWinPrize": { "total": number, "prize": { "a": string, "t": string, "n": number, [x: string]: any }[], "star": number, [x: string]: any }[], "fightNum": number, "vipBuyFightNum": [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number], "buyFightNumNeed": { "a": string, "t": string, "n": number, [x: string]: any }[], "rankPrize": { "rank": [number, number], "prize": { "a": string, "t": string, "n": number, [x: string]: any }[], "title": string, [x: string]: any }[], "danPrize": { "star": [number, number], "prize": { "a": string, "t": string, "n": number, [x: string]: any }[], [x: string]: any }[], "email_rank": { "title": string, "content": string, [x: string]: any }, "email_dan": { "title": string, "content": string, [x: string]: any }, [x: string]: any + "divide": { "day": [number, number], "group": number, [x: string]: any }[], "divideTime": number, "fightTime": [number, number], "prizeTime": number, "fightWinPrize": { "total": number, "prize": { "a": string, "t": string, "n": number, [x: string]: any }[], "star": number, [x: string]: any }[], "fightNum": number, "vipBuyFightNum": [number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number, number], "buyFightNumNeed": { "a": string, "t": string, "n": number, [x: string]: any }[], "rankPrize": { "rank": [number, number], "prize": { "a": string, "t": string, "n": number, [x: string]: any }[], "title": string, [x: string]: any }[], "danPrize": { "star": number, "prize": { "a": string, "t": string, "n": number, [x: string]: any }[], [x: string]: any }[], "email_rank": { "title": string, "content": string, [x: string]: any }, "email_dan": { "title": string, "content": string, [x: string]: any }, [x: string]: any } type gc_clsl_dan = k_v<{ @@ -122,7 +122,11 @@ type gc_clsl_dan = k_v<{ /** 战斗奖励 */ 'fightPrize': { "a": string, "t": string, "n": number, [x: string]: any }[] /** 机器人 */ - 'npc': number + 'npc': number, + /** 随机机器人概率*/ + 'pro':number + /** 对手范围 */ + 'fighter':number[] }>; type gc_com = k_v<{ diff --git a/src/module/collection_clsl.ts b/src/module/collection_clsl.ts index 39767cd..e4de710 100644 --- a/src/module/collection_clsl.ts +++ b/src/module/collection_clsl.ts @@ -6,4 +6,9 @@ export type CollectionCllsCrossUser = { area: number; allStar: number; info: joinFightData; -}; \ No newline at end of file +}; + +export type CollectionCllsCrossGroup = { + week: string; + groups: { [group: string]: { st: number, et: number } }; +} \ No newline at end of file diff --git a/src/module/mongodb.ts b/src/module/mongodb.ts index e5c920e..8bcacc7 100644 --- a/src/module/mongodb.ts +++ b/src/module/mongodb.ts @@ -4,7 +4,7 @@ import {rankType} from '../shared/protocols/rank/PtlOpen'; import {CollectionChatLog} from './collection_chatlog'; import {CollectionActionLog} from './collection_actionLog'; import {CollectionCardlog} from './collection_cardlog'; -import {CollectionCllsCrossUser} from './collection_clsl'; +import {CollectionCllsCrossGroup, CollectionCllsCrossUser} from './collection_clsl'; import {CollectionCrosskv} from './collection_crosskv'; import {CollectionDayPay} from './collection_dayPay'; import {CollectionDxlt} from './collection_dxlt'; @@ -115,7 +115,8 @@ export type MongodbCollections = { any: { type: string, data: any[]; }; zhanling: CollectionZhanLing; - clslCrossUser: CollectionCllsCrossUser; + clslCrossGroup: CollectionCllsCrossGroup; + clslCrossUser: CollectionCllsCrossUser & { group: string }; lingzhulaixi: CollectionLingZhuLaiXi; wzry_user_cross: CollectionWzryCross; wzry_fight: CollectionWzryCrossFight; diff --git a/src/monopoly/protocols/serviceProto.ts b/src/monopoly/protocols/serviceProto.ts index 886f4d6..3d8d36f 100644 --- a/src/monopoly/protocols/serviceProto.ts +++ b/src/monopoly/protocols/serviceProto.ts @@ -709,21 +709,21 @@ export const serviceProto: ServiceProto = { "id": 13, "type": { "type": "Literal", - "literal": "kbzz" + "literal": "clslCross" } }, { "id": 14, "type": { "type": "Literal", - "literal": "xszm" + "literal": "kbzz" } }, { "id": 15, "type": { "type": "Literal", - "literal": "clslCross" + "literal": "xszm" } }, { diff --git a/src/public/fight.ts b/src/public/fight.ts index 2e99911..b2029a4 100644 --- a/src/public/fight.ts +++ b/src/public/fight.ts @@ -130,7 +130,7 @@ export class FightFun { * @param result */ static async saveLog(uid: string, type: string, result: fightResult) { - let writeList = ['ganhai', 'jjc', 'hbzbJfs', 'hbzbZbs', 'slzd'] + let writeList = ['ganhai', 'jjc', 'hbzbJfs', 'hbzbZbs', 'slzd', 'clsl'] if (uid.indexOf('npc') != -1 || !writeList.includes(type)) return; G.mongodb.collection('fightLog').insertOne({uid, type, ...result}) diff --git a/src/public/rank/rank.ts b/src/public/rank/rank.ts index 634f4a5..fe7ed27 100644 --- a/src/public/rank/rank.ts +++ b/src/public/rank/rank.ts @@ -108,8 +108,12 @@ export abstract class Rank { return this.getType(); } - constructor() { + constructor(param?: any) { + // 将param属性赋值给this + param && Object.assign(this, param); Rank.list[this.getType() as string] = this; + + // 初始化排行榜 this.cotr(); } @@ -135,7 +139,7 @@ export abstract class Rank { //将db里的数据,写入到 rank:xxx:sort里 //写入的单条数据为: {uid:score} - this.db.find({ type: this.type }, { + this.db.find({ type: this.type }, { projection: { "idKey": 1, "type": 1, @@ -263,7 +267,7 @@ export abstract class Rank { } return item; }) - if(ghid.length > 0){ + if (ghid.length > 0) { let ghinfo = await G.mongodb.collection("gonghui").find( { _id: { $in: ghid } }, { projection: { name: 1 } } ).toArray(); @@ -400,10 +404,10 @@ export abstract class Rank { // 清空相关rank数据 async clear() { - this.queue.enqueue(async () => { - // G.redis.rawDel(this.getRedisKey) - G.redis.rawDel(this.getRedisKeySort); - await this.db.deleteMany({ type: this.type }); - }); + // this.queue.enqueue(async () => { + // G.redis.rawDel(this.getRedisKey) + G.redis.rawDel(this.getRedisKeySort); + this.db.deleteMany({ type: this.type }); + // }); } } \ No newline at end of file diff --git a/src/public/rank/rank_clsl.ts b/src/public/rank/rank_clsl.ts index 551c184..3849146 100644 --- a/src/public/rank/rank_clsl.ts +++ b/src/public/rank/rank_clsl.ts @@ -1,58 +1,53 @@ import { rankType } from '../../shared/protocols/rank/PtlOpen'; import { rankInfo } from '../../shared/protocols/type'; -import { player } from '../../shared/protocols/user/type'; +import { PublicShared } from '../../shared/public/public'; import { Rank } from './rank'; export class RankClslCross extends Rank { - - countMaxNum = 99999; + group: string; minStar = Object.values(G.gc.clsl_dan)[Object.keys(G.gc.clsl_dan).length - 1].allStar; - getType(): rankType { - return 'clslCross'; - } - // compare(other: rankInfo, cur: rankInfo): boolean { - // return cur.valArr[0] > other.valArr[0]; - // } - // compareSort(a: rankInfo, b: rankInfo): number { - // return b.valArr[0] - a.valArr[0]; - // } - - // // 积分, 排名依据 - // getValArr(info: rankInfo):number|string { - // return info?.valArr[0] || 0 - // } - // async getRankList(uid: string, {gud, min, max}) { - // let rankList = await this.getRankListRange(min, max); - // let rank = await this.getRankSortByOne(uid); - // let score = await this.getRankScore(uid) - // return { - // rankList: rankList, - // myRank: { - // rank: rank, - // player: gud, - // valArr: [score] - // } - // }; - // } - + constructor(group: string = 'group0') { + super({ group }); + } + + getType(): rankType { return `clslCross_${this.group}` as rankType } + + getValArr(info: rankInfo): number | string { + // 星级 + let star = info?.valArr[0] || 0; + + // 战力 + let zhanli1 = info?.valArr[1] || 0; + + // 将星级作为整数部分,战力作为小数部分长度为10位 进行拼接 + let val = `${star}.${zhanli1.toString().padStart(10, '0')}`; + + return Number(val) + } + async addNew(info: rankInfo) { - this.queue.enqueue(async () => { - // 积分大于配置的最小参数,更新数据 - if (info.valArr[0] >= this.minStar) { - this.setRankData(info.player[this.findKey], info) - this.db.updateOne({ type: this.type, idKey: info.player[this.findKey] }, { $set: { data: info } }, { upsert: true }); - // rankList.sort(this.compareSort); - } - // 积分小于配置,且用户数据存在时,删除 - else if (info.valArr[0] < this.minStar) { - let rankInfo = await this.getRankData(info.player[this.findKey]) - if(rankInfo?.player) { - this.db.deleteOne({ type: this.type, idKey: info.player[this.findKey] }); - this.delRankData(info.player[this.findKey]) - } - } - }); + // 积分大于配置的最小参数,更新数据 + if (info.valArr[0] >= this.minStar) { + this.setRankData(info.player[this.findKey], info) + this.db.updateOne({ type: this.type, idKey: info.player[this.findKey] }, { $set: { data: info } }, { upsert: true }); + } + } +} + +/** + * 从林猎手 排行榜检测初始化 +*/ +export async function RankClslCrossInit() { + let week = PublicShared.getToWeek(); + let group_time = G.gc.clsl_com.divideTime; + let week_zero_time = PublicShared.getToWeekMondayZeroTime(); + + if (G.time > week_zero_time + group_time) { + let groups = await G.mongodb.collection('clslCrossGroup').findOne({ week: week }); + Object.keys(groups.groups).forEach(group => { + new RankClslCross(group); + }) } } \ No newline at end of file diff --git a/src/public/scheduler/scheduler.ts b/src/public/scheduler/scheduler.ts index a8b93a7..438360c 100644 --- a/src/public/scheduler/scheduler.ts +++ b/src/public/scheduler/scheduler.ts @@ -13,9 +13,9 @@ export type schedulerType = | 'hbzb_cross_reset' | 'hbzb_zbs_ready' | 'kbzz' - | 'clsl_cross_ctor' - | 'clsl_local_ctor' | 'clsl_prize' + | 'clsl_cross_ctor' + | 'clsl_cross_group' | 'wzry_autobaoming' | 'wzry_dldstart' | 'wzry_dldjinji' diff --git a/src/public/scheduler/scheduler_clsl.ts b/src/public/scheduler/scheduler_clsl.ts index dfc83b4..73936bf 100644 --- a/src/public/scheduler/scheduler_clsl.ts +++ b/src/public/scheduler/scheduler_clsl.ts @@ -1,12 +1,16 @@ +import { PublicShared } from '../../shared/public/public'; import { EmailFun } from '../email'; -import { Rank } from '../rank/rank'; +import { RankClslCross, RankClslCrossInit } from '../rank/rank_clsl'; import { Scheduler, schedulerType } from './scheduler'; - -export class SchedulerClslCrossCtor extends Scheduler { +/** + * 丛林猎手赛季重置 +*/ +export class SchedulerClslLocalCtor extends Scheduler { id: schedulerType = 'clsl_cross_ctor'; - time = G.gc.clsl_com.divideTime; - name = '丛林猎手赛季初始化'; + + time = 0; + name = '丛林猎手赛季重置'; type: 'day' | 'week' = 'week'; async read() { @@ -15,30 +19,101 @@ export class SchedulerClslCrossCtor extends Scheduler { } async start() { + let week = PublicShared.getToWeek( + PublicShared.getToWeekMondayZeroTime(G.time - 3600) + ); - G.mongodb.collection('clslCrossUser').updateMany({}, { $set: { allStar: 0 } }); - Rank.list.clslCross.clear(); + // 修改clslCrossUser表中的uid为del_uid_week 并且 设置ttltime为当前时间 + await G.mongodb.collection('clslCrossUser').updateMany( + {}, { $rename: { "uid": `del_uid_${week}` }, $set: { "ttltime": new Date() } } + ); + + // 获取分组信息 重置排行榜 + let groups = await G.mongodb.collection('clslCrossGroup').findOne({ week }); + Object.keys(groups.groups).forEach((group) => { + // 清理排行数据 + new RankClslCross(group).clear(); + }) await this.record(); } } +/** + * 丛林猎手赛季划分 + * 达到王者段位的所有玩家 按照创号时间从早到晚排序 每100个玩家划分一个区间 +*/ +export class SchedulerClslCrossCtor extends Scheduler { + id: schedulerType = 'clsl_cross_group'; + time = G.gc.clsl_com.divideTime; + name = '丛林猎手赛季区间划分 周四00:00'; + type: 'day' | 'week' = 'week'; + star = Object.values(G.gc.clsl_dan).slice(-1)[0].allStar; -export class SchedulerClslLocalCtor extends SchedulerClslCrossCtor { - id: schedulerType = 'clsl_local_ctor'; + async read() { + await this.ctorStartTime(); + this.isReady = false; + } async start() { + let week = PublicShared.getToWeek(); + let users = await G.mongodb.collection('clslCrossUser').find({}, { + projection: { + "uid": 1, + "allStar": 1, + "info.player.cTime": 1 + } + }).toArray(); - G.mongodb.cPlayerInfo('clsl').updateMany({ type: 'clsl' }, { $set: { allStar: 0 } }); + // 筛选出所有王者分段 按照建号时间排序 + let wzusers = users.filter(u => u.allStar >= this.star).sort((a, b) => a.info.player.cTime - b.info.player.cTime); + + // 每100个玩家划分一个区间 + let groups: { [group: string]: { st: number, et: number, users: string[] } } = {}; + for (let i = 0; i < wzusers.length / 100; i++) { + groups['group' + i] = { + st: wzusers[i * 100].info.player.cTime, + et: wzusers[(i + 1) * 100 - 1].info.player.cTime, + users: wzusers.slice(i * 100, (i + 1) * 100).map(u => u.uid), + } + } + + // 剩余玩家 + let remaining_users = [].concat(wzusers.slice((wzusers.length / 100) * 100)); // 王者剩余玩家 + remaining_users = remaining_users.concat(users.filter(u => u.allStar < this.star)); // 非王者剩余玩家 + for (let i = 0; i < remaining_users.length; i++) { + for (let group in groups) { + if (remaining_users[i].info.player.cTime >= groups[group].st && remaining_users[i].info.player.cTime <= groups[group].et) { + groups[group].users.push(remaining_users[i].uid); + } + } + } + + // 更新玩家分组id + for (let group in groups) { + await G.mongodb.collection('clslCrossUser').updateMany({ uid: { $in: groups[group].users } }, { $set: { group: group } }); + } + + // 记录分组 + await G.mongodb.collection("clslCrossGroup").updateOne({ week: week }, { $set: { groups: groups } }, { upsert: true }); + + // 初始化丛林猎手排行榜 + await RankClslCrossInit() await this.record(); } } + +/** + * 丛林猎手赛季发奖 +*/ export class SchedulerClslPrize extends Scheduler { id: schedulerType = 'clsl_prize'; - time = G.gc.clsl_com.prizeTime; + name = '丛林猎手赛季发奖'; type: 'day' | 'week' = 'week'; + time = G.gc.clsl_com.prizeTime; + star = Object.values(G.gc.clsl_dan).slice(-1)[0].allStar; async read() { await this.ctorStartTime(); @@ -46,41 +121,32 @@ export class SchedulerClslPrize extends Scheduler { } async start() { + // 排名奖励 + let group2users: { [group: string]: string[] } = {}; + (await G.mongodb.collection('clslCrossUser').find({ allStar: { $gte: this.star } }).toArray()).forEach(u => { + if (u.group in group2users) { + group2users[u.group].push(u.uid); + } else { + group2users[u.group] = [u.uid]; + } + }); - // 段位奖励 - let locals = await G.mongodb.cPlayerInfo('clsl').find({ type: 'clsl' }).toArray(); - G.gc.clsl_com.danPrize.forEach((conf) => { - let sends = locals.filter(l => l.allStar >= conf.star[0]).map(s => s.uid); - // locals.remove(l => sends.includes(l.uid)); - - sends.forEach(uid => { - EmailFun.addEmail({ - uid: uid, - type: 'system', - title: G.gc.clsl_com.email_dan.title, - content: G.gc.clsl_com.email_dan.content, - prize: conf.prize, - contentInsertArr: [conf.star] + Object.values(group2users).forEach((uids, index) => { + G.gc.clsl_com.rankPrize.forEach((conf) => { + let players = uids.slice(conf.rank[0] - 1, conf.rank[1]); + players.forEach((uid, index) => { + EmailFun.addEmail({ + uid: uid, + type: 'system', + title: G.gc.clsl_com.email_rank.title, + content: G.gc.clsl_com.email_rank.content, + prize: conf.prize, + contentInsertArr: [conf.rank[0] + index] + }, true); }); }); }) - // 排名奖励 - let crossUids = (await G.clientCross.callApi('clsl/RankUids', {})).res.uids; - G.gc.clsl_com.rankPrize.forEach((conf) => { - let players = crossUids.slice(conf.rank[0] - 1, conf.rank[1]); - players.forEach((uid, index) => { - EmailFun.addEmail({ - uid: uid, - type: 'system', - title: G.gc.clsl_com.email_rank.title, - content: G.gc.clsl_com.email_rank.content, - prize: conf.prize, - contentInsertArr: [conf.rank[0] + index] - }); - }); - }); - await this.record(); } } \ No newline at end of file diff --git a/src/shared/protocols/conglinshoulie/PtlOpen.ts b/src/shared/protocols/conglinshoulie/PtlOpen.ts index 356c588..d506509 100644 --- a/src/shared/protocols/conglinshoulie/PtlOpen.ts +++ b/src/shared/protocols/conglinshoulie/PtlOpen.ts @@ -17,4 +17,8 @@ export type ResOpen = { fightWinNum: number; /**已领取的胜场奖励 */ recWinPrize: number[]; + /**本期最高段位*/ + curMaxStar: number; + /**段位奖励发放记录*/ + danPrize: number[]; }; \ No newline at end of file diff --git a/src/shared/protocols/rank/PtlOpen.ts b/src/shared/protocols/rank/PtlOpen.ts index d85d8d8..f878176 100644 --- a/src/shared/protocols/rank/PtlOpen.ts +++ b/src/shared/protocols/rank/PtlOpen.ts @@ -13,9 +13,8 @@ export type ResOpen = { }; export type rankType = 'jjc' | 'tanxian' | 'zhanli' | 'qjzzd' | 'hbzbLocal' | 'hbzbCross' | 'hbzbZbsCross' - | 'slzd1' | 'slzd2' | 'slzd3' | 'slzd4' | 'slzd5' | 'slzd6' - | 'kbzz' | 'xszm' | 'clslCross' - | 'zccg' | 'gbzl' | 'tujian' | 'wzryCross'; + | 'slzd1' | 'slzd2' | 'slzd3' | 'slzd4' | 'slzd5' | 'slzd6' | "clslCross" + | 'kbzz' | 'xszm' | 'zccg' | 'gbzl' | 'tujian' | 'wzryCross'; export type rankTypeObj = { type?: rankType[], diff --git a/src/shared/protocols/serviceProto.ts b/src/shared/protocols/serviceProto.ts index 57b3262..723937c 100644 --- a/src/shared/protocols/serviceProto.ts +++ b/src/shared/protocols/serviceProto.ts @@ -7253,6 +7253,23 @@ export const serviceProto: ServiceProto = { "type": "Number" } } + }, + { + "id": 5, + "name": "curMaxStar", + "type": { + "type": "Number" + } + }, + { + "id": 6, + "name": "danPrize", + "type": { + "type": "Array", + "elementType": { + "type": "Number" + } + } } ] }, @@ -20073,21 +20090,21 @@ export const serviceProto: ServiceProto = { "id": 13, "type": { "type": "Literal", - "literal": "kbzz" + "literal": "clslCross" } }, { "id": 14, "type": { "type": "Literal", - "literal": "xszm" + "literal": "kbzz" } }, { "id": 15, "type": { "type": "Literal", - "literal": "clslCross" + "literal": "xszm" } }, { From e00e9c4dfc2120168c90e0de9f11086a6711135a Mon Sep 17 00:00:00 2001 From: xcy Date: Wed, 27 Dec 2023 16:42:46 +0800 Subject: [PATCH 2/8] =?UTF-8?q?fix:=20=E4=B8=9B=E6=9E=97=E7=8B=A9=E7=8C=8E?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_cross/clsl/ApiFindEnemy.ts | 7 ++++--- src/api_cross/clsl/ApiUpLoad.ts | 9 +-------- src/api_s2c/conglinshoulie/ApiFind.ts | 3 ++- src/api_s2c/conglinshoulie/ApiOpen.ts | 6 ++++++ src/json/clsl_com.json5 | 14 +++++++------- src/public/scheduler/scheduler_clsl.ts | 22 +++++++++++++++------- src/setStartAfther.ts | 17 +++++++++-------- 7 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/api_cross/clsl/ApiFindEnemy.ts b/src/api_cross/clsl/ApiFindEnemy.ts index 743f42f..c097d8f 100644 --- a/src/api_cross/clsl/ApiFindEnemy.ts +++ b/src/api_cross/clsl/ApiFindEnemy.ts @@ -19,9 +19,10 @@ export default async function (call: ApiCall) { // 在自定范围内随机一个对手 let others = await G.mongodb.collection("clslCrossUser").aggregate([ { - $match: [ - { allStar: { $gte: starConf.fighter[0], $lte: starConf.fighter[1] } } - ], + $match: { + allStar: { $gte: starConf.fighter[0], $lte: starConf.fighter[1] } + } + }, { $sample: { size: 1 } } diff --git a/src/api_cross/clsl/ApiUpLoad.ts b/src/api_cross/clsl/ApiUpLoad.ts index 57a47fd..a91a9f9 100644 --- a/src/api_cross/clsl/ApiUpLoad.ts +++ b/src/api_cross/clsl/ApiUpLoad.ts @@ -16,14 +16,7 @@ export default async function (call: ApiCall) { { upsert: true, returnDocument: "after" } )).value; - let week = PublicShared.getToWeek(); - let group_time = G.gc.clsl_com.divideTime; - let week_zero_time = PublicShared.getToWeekMondayZeroTime(); - - if (G.time > week_zero_time + group_time) { - if (!a.group){ - - } + if (a.group){ // 分完组之后就可以更新排行榜了 if (allStar != undefined && ops.info) { let rank; if (Rank.list[`clslCross_${a.group}`]) { diff --git a/src/api_s2c/conglinshoulie/ApiFind.ts b/src/api_s2c/conglinshoulie/ApiFind.ts index 2309485..bd78755 100644 --- a/src/api_s2c/conglinshoulie/ApiFind.ts +++ b/src/api_s2c/conglinshoulie/ApiFind.ts @@ -56,7 +56,7 @@ export default async function (call: ApiCall) { let content = G.gc.clsl_com.email_dan.content; G.gc.clsl_com.danPrize.forEach(conf => { // 段位未达到 或者 奖励已经发放 - if (conf.star > curMaxStar || danPrize.includes[conf.star]) { + if (conf.star > curMaxStar || danPrize.includes(conf.star)) { return } @@ -67,6 +67,7 @@ export default async function (call: ApiCall) { title: title, content: content, prize: conf.prize, + contentInsertArr:[conf.title] }) danPrize.push(conf.star); diff --git a/src/api_s2c/conglinshoulie/ApiOpen.ts b/src/api_s2c/conglinshoulie/ApiOpen.ts index 4824215..d844979 100644 --- a/src/api_s2c/conglinshoulie/ApiOpen.ts +++ b/src/api_s2c/conglinshoulie/ApiOpen.ts @@ -18,6 +18,12 @@ export default async function (call: ApiCall) { fightWinNum: 0, buyFightNum: 0 }; + + // 隔周刷新星级 + if(ops?.refreshTime < PublicShared.getToWeekMondayZeroTime()){ + change.allStar = 0; + change.curMaxStar = 0; + } Object.assign(ops, change); diff --git a/src/json/clsl_com.json5 b/src/json/clsl_com.json5 index 1595c97..c57676d 100644 --- a/src/json/clsl_com.json5 +++ b/src/json/clsl_com.json5 @@ -32,13 +32,13 @@ ], //段位奖励 danPrize: [ - { star: 49, prize: [{ a: 'item', t: '605', n:3 },{ a: 'item', t: '29', n:10 },{ a: 'item', t: '631', n:3 },{ a: 'item', t: '40', n:1 }] }, - { star: 39, prize: [{ a: 'item', t: '605', n:2 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '631', n:2 }] }, - { star: 29, prize: [{ a: 'item', t: '606', n:3 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '631', n:1 }] }, - { star: 21, prize: [{ a: 'item', t: '606', n:2 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:1000 }] }, - { star: 13, prize: [{ a: 'item', t: '606', n:1 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:800 }] }, - { star: 7, prize: [{ a: 'item', t: '29', n:10 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:600 }] }, - { star: 0, prize: [{ a: 'item', t: '29', n:5 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:400 }] } + { star: 49, title: "clsl_7", prize: [{ a: 'item', t: '605', n:3 },{ a: 'item', t: '29', n:10 },{ a: 'item', t: '631', n:3 },{ a: 'item', t: '40', n:1 }] }, + { star: 39, title: "clsl_6", prize: [{ a: 'item', t: '605', n:2 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '631', n:2 }] }, + { star: 29, title: "clsl_5", prize: [{ a: 'item', t: '606', n:3 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '631', n:1 }] }, + { star: 21, title: "clsl_4", prize: [{ a: 'item', t: '606', n:2 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:1000 }] }, + { star: 13, title: "clsl_3", prize: [{ a: 'item', t: '606', n:1 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:800 }] }, + { star: 7, title: "clsl_2", prize: [{ a: 'item', t: '29', n:10 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:600 }] }, + { star: 0, title: "clsl_1", prize: [{ a: 'item', t: '29', n:5 },{ a: 'item', t: '29', n:5 },{ a: 'item', t: '39', n:400 }] } ], //王者排名邮件信息 email_rank: { diff --git a/src/public/scheduler/scheduler_clsl.ts b/src/public/scheduler/scheduler_clsl.ts index 73936bf..a26f447 100644 --- a/src/public/scheduler/scheduler_clsl.ts +++ b/src/public/scheduler/scheduler_clsl.ts @@ -44,9 +44,13 @@ export class SchedulerClslLocalCtor extends Scheduler { */ export class SchedulerClslCrossCtor extends Scheduler { id: schedulerType = 'clsl_cross_group'; + + num: number = 2; + + type: 'day' | 'week' = 'week'; time = G.gc.clsl_com.divideTime; name = '丛林猎手赛季区间划分 周四00:00'; - type: 'day' | 'week' = 'week'; + star = Object.values(G.gc.clsl_dan).slice(-1)[0].allStar; async read() { @@ -69,16 +73,16 @@ export class SchedulerClslCrossCtor extends Scheduler { // 每100个玩家划分一个区间 let groups: { [group: string]: { st: number, et: number, users: string[] } } = {}; - for (let i = 0; i < wzusers.length / 100; i++) { + for (let i = 0; i < wzusers.length / this.num; i++) { groups['group' + i] = { - st: wzusers[i * 100].info.player.cTime, - et: wzusers[(i + 1) * 100 - 1].info.player.cTime, - users: wzusers.slice(i * 100, (i + 1) * 100).map(u => u.uid), + st: wzusers[i * this.num].info.player.cTime, + et: wzusers[(i + 1) * this.num - 1].info.player.cTime, + users: wzusers.slice(i * this.num, (i + 1) * this.num).map(u => u.uid), } } // 剩余玩家 - let remaining_users = [].concat(wzusers.slice((wzusers.length / 100) * 100)); // 王者剩余玩家 + let remaining_users = [].concat(wzusers.slice((wzusers.length / this.num) * this.num)); // 王者剩余玩家 remaining_users = remaining_users.concat(users.filter(u => u.allStar < this.star)); // 非王者剩余玩家 for (let i = 0; i < remaining_users.length; i++) { for (let group in groups) { @@ -97,7 +101,11 @@ export class SchedulerClslCrossCtor extends Scheduler { await G.mongodb.collection("clslCrossGroup").updateOne({ week: week }, { $set: { groups: groups } }, { upsert: true }); // 初始化丛林猎手排行榜 - await RankClslCrossInit() + G.mongodb.collection('clslCrossUser').find({allStar:{$gte:this.star}}).toArray().then(users=>{ + users.forEach(u=>{ + new RankClslCross(u.group).addNew({valArr:[u.allStar, u.info.player.power], player:u.info, roles:u.info.roles}) + }) + }) await this.record(); } diff --git a/src/setStartAfther.ts b/src/setStartAfther.ts index f0ca5c4..25c609c 100644 --- a/src/setStartAfther.ts +++ b/src/setStartAfther.ts @@ -2,7 +2,7 @@ import { GanHaiRed } from './api_s2c/ganhai/ApiOpen'; import { FriendManage } from './public/friend/manage'; import { GHManage } from './public/gonghui/manage'; import { JJCFun } from './public/jjc'; -import { RankClslCross } from './public/rank/rank_clsl'; +import { RankClslCross, RankClslCrossInit } from './public/rank/rank_clsl'; //import { RankHbzbJfsCross, RankHbzbJfsLocal, RankHbzbZbsCross } from './public/rank/rank_hbzb_jfs'; import { RankKbzz } from './public/rank/rank_kbzz'; import { RankPower } from './public/rank/rank_power'; @@ -104,18 +104,19 @@ export async function startAfter() { }); } else if (G.argv.serverType == 'cross') { - RankKbzz.init(); - new RankClslCross(); - // new RankHbzbJfsCross().loadAllPlayer(); - // new RankHbzbZbsCross(); + RankClslCrossInit(); new RankWzryCross(); new SchedulerKbzzGroup().init(); - new Scheduler_hbzb_zbs_cross_clear().init(); - //new Scheduler_hbzb_corss_reset(); - new Scheduler_hbzb_zbs_cross_group().init(); + + new SchedulerClslPrize().init(); new SchedulerClslCrossCtor().init(); + new SchedulerClslLocalCtor ().init(); + + new Scheduler_hbzb_zbs_cross_clear().init(); + new Scheduler_hbzb_zbs_cross_group().init(); + new SchedulerWzryDlDstart().init(); new SchedulerWzryDlDjinji().init(); new SchedulerWzryZuanshiOne().init(); From 0e93358e74c5d096c2de15c43dc6bc939aaee5dc Mon Sep 17 00:00:00 2001 From: xcy Date: Thu, 28 Dec 2023 00:02:12 +0800 Subject: [PATCH 3/8] =?UTF-8?q?fix:=20=E4=B8=9B=E6=9E=97=E7=8C=8E=E6=89=8B?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/rank/ApiOpen.ts | 4 +-- src/public/scheduler/scheduler_clsl.ts | 42 ++++++++++++++++++++------ src/shared/protocols/rank/PtlOpen.ts | 2 +- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/api_s2c/rank/ApiOpen.ts b/src/api_s2c/rank/ApiOpen.ts index a5bd1fe..6708475 100644 --- a/src/api_s2c/rank/ApiOpen.ts +++ b/src/api_s2c/rank/ApiOpen.ts @@ -4,10 +4,10 @@ import { Rank } from '../../public/rank/rank'; import { ReqOpen, ResOpen } from "../../shared/protocols/rank/PtlOpen"; import { getToper50RankInfo } from "../hbzb/jfs/fun"; import { getZbsRankList } from "../hbzb/zbs/fun"; -import { re } from "mathjs"; export default async function (call: ApiCall) { - let obj = await rankOpenfun(call, call.req) + console.log("==============>", call.req) + let obj = await rankOpenfun(call, call.req); call.succ(obj); } diff --git a/src/public/scheduler/scheduler_clsl.ts b/src/public/scheduler/scheduler_clsl.ts index a26f447..0026577 100644 --- a/src/public/scheduler/scheduler_clsl.ts +++ b/src/public/scheduler/scheduler_clsl.ts @@ -73,17 +73,35 @@ export class SchedulerClslCrossCtor extends Scheduler { // 每100个玩家划分一个区间 let groups: { [group: string]: { st: number, et: number, users: string[] } } = {}; - for (let i = 0; i < wzusers.length / this.num; i++) { - groups['group' + i] = { - st: wzusers[i * this.num].info.player.cTime, - et: wzusers[(i + 1) * this.num - 1].info.player.cTime, - users: wzusers.slice(i * this.num, (i + 1) * this.num).map(u => u.uid), + let group_num = wzusers.length / this.num; + + // 非王者玩家 + let remaining_users = users.filter(u => u.allStar < this.star); + if (group_num >= 1) { + let tt = parseInt(group_num + '') + for (let i = 1; i <= tt; i++) { + groups['group' + i] = { + et: wzusers[i * this.num - 1].info.player.cTime, + st: wzusers[(i - 1) * this.num].info.player.cTime, + users: wzusers.slice((i - 1) * this.num, i * this.num).map(u => u.uid), + } + if (i == 1) { + groups['group1'].st = 0 + } + if (i == tt) { + groups['group' + i].et = G.time + 7 * 14 * 3600; + groups['group' + i].users = wzusers.slice((i - 1) * this.num).map(u => u.uid); + } + }; + } else { + groups['group0'] = { + st: 0, + et: G.time + 7 * 14 * 3600, + users: wzusers.map(u => u.uid), } } // 剩余玩家 - let remaining_users = [].concat(wzusers.slice((wzusers.length / this.num) * this.num)); // 王者剩余玩家 - remaining_users = remaining_users.concat(users.filter(u => u.allStar < this.star)); // 非王者剩余玩家 for (let i = 0; i < remaining_users.length; i++) { for (let group in groups) { if (remaining_users[i].info.player.cTime >= groups[group].st && remaining_users[i].info.player.cTime <= groups[group].et) { @@ -101,9 +119,13 @@ export class SchedulerClslCrossCtor extends Scheduler { await G.mongodb.collection("clslCrossGroup").updateOne({ week: week }, { $set: { groups: groups } }, { upsert: true }); // 初始化丛林猎手排行榜 - G.mongodb.collection('clslCrossUser').find({allStar:{$gte:this.star}}).toArray().then(users=>{ - users.forEach(u=>{ - new RankClslCross(u.group).addNew({valArr:[u.allStar, u.info.player.power], player:u.info, roles:u.info.roles}) + G.mongodb.collection('clslCrossUser').find({ allStar: { $gte: this.star } }).toArray().then(users => { + users.forEach(u => { + new RankClslCross(u.group).addNew({ + valArr: [u.allStar, u.info.player.power], + player: u.info.player, + roles: u.info.roles, + }) }) }) diff --git a/src/shared/protocols/rank/PtlOpen.ts b/src/shared/protocols/rank/PtlOpen.ts index f878176..fcc7e84 100644 --- a/src/shared/protocols/rank/PtlOpen.ts +++ b/src/shared/protocols/rank/PtlOpen.ts @@ -13,7 +13,7 @@ export type ResOpen = { }; export type rankType = 'jjc' | 'tanxian' | 'zhanli' | 'qjzzd' | 'hbzbLocal' | 'hbzbCross' | 'hbzbZbsCross' - | 'slzd1' | 'slzd2' | 'slzd3' | 'slzd4' | 'slzd5' | 'slzd6' | "clslCross" + | 'slzd1' | 'slzd2' | 'slzd3' | 'slzd4' | 'slzd5' | 'slzd6' | 'clslCross' | 'kbzz' | 'xszm' | 'zccg' | 'gbzl' | 'tujian' | 'wzryCross'; export type rankTypeObj = { From 381aeb1792895a1bc35ed6e47962cd191856d93c Mon Sep 17 00:00:00 2001 From: xcy Date: Mon, 1 Jan 2024 09:04:08 +0800 Subject: [PATCH 4/8] =?UTF-8?q?fix:=20=E4=B8=9B=E6=9E=97=E7=8C=8E=E6=89=8B?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/public/rank/rank.ts | 99 ++++++++++++++-------------- src/public/rank/rank_clsl.ts | 5 ++ src/setMongodb.ts | 10 ++- src/shared/protocols/rank/PtlOpen.ts | 2 +- 4 files changed, 65 insertions(+), 51 deletions(-) diff --git a/src/public/rank/rank.ts b/src/public/rank/rank.ts index fe7ed27..674cf04 100644 --- a/src/public/rank/rank.ts +++ b/src/public/rank/rank.ts @@ -139,6 +139,10 @@ export abstract class Rank { //将db里的数据,写入到 rank:xxx:sort里 //写入的单条数据为: {uid:score} + + // 首先清理redis中sort数据 在从数据库中初始化 + await G.ioredis.del(this.getRedisKeySort); + this.db.find({ type: this.type }, { projection: { "idKey": 1, @@ -253,60 +257,57 @@ export abstract class Rank { if (uids && uids.length > 0) { let res = await this.db.find({ idKey: { $in: uids }, type: this.getType() }).toArray() - switch (this.getType()) { - case "slzd1": - case "slzd2": - case "slzd3": - case "slzd4": - case "slzd5": - case "slzd6": - let ghid = []; - res = res.map(item => { - if (!item.data?.player?.ghid || item.data.utime + 60 < G.time) { - ghid.push(G.mongodb.conversionId(item.idKey)); - } - return item; - }) - if (ghid.length > 0) { - let ghinfo = await G.mongodb.collection("gonghui").find( - { _id: { $in: ghid } }, { projection: { name: 1 } } - ).toArray(); - ghinfo.forEach(item => { - let index = res.findIndex(x => x.idKey == item._id.toHexString()); - res[index].data.player = { - ghName: item.name, - ghId: item._id.toHexString(), - }; - this.db.updateOne({ idKey: item._id.toHexString(), type: this.getType() }, { $set: { "data.player": res[index].data.player } }); - }) + if (this.type.indexOf("slzd") != -1) { + let ghid = []; + res = res.map(item => { + if (!item.data?.player?.ghid || item.data.utime + 60 < G.time) { + ghid.push(G.mongodb.conversionId(item.idKey)); } - break; - default: // 排行数据更新逻辑 默认更新playerInfo - let updateUids = []; - res = res.map(item => { - // 没有player 或者 player 过期 - if (!item.data?.player || item.data.utime + 60 < G.time) { - updateUids.push(item.idKey); - } - return item; - }); - let newUserArr = await G.mongodb.collection('user').find( - { uid: { $in: updateUids } }, { projection: { _id: 0 } } + return item; + }) + if (ghid.length > 0) { + let ghinfo = await G.mongodb.collection("gonghui").find( + { _id: { $in: ghid } }, { projection: { name: 1 } } ).toArray(); - - newUserArr.forEach(item => { - // 每次遍历查找? - let index = res.findIndex(x => x.idKey == item.uid); - - res[index].data.player = item; - this.db.updateOne({ idKey: item.uid, type: this.getType() }, { $set: { "data.player": item } }); - - // 跟新redis score - // this.setRankData(item.uid, res[index].data as any); + ghinfo.forEach(item => { + let index = res.findIndex(x => x.idKey == item._id.toHexString()); + res[index].data.player = { + ghName: item.name, + ghId: item._id.toHexString(), + }; + this.db.updateOne({ idKey: item._id.toHexString(), type: this.getType() }, { $set: { "data.player": res[index].data.player } }); }) + } + } else if (this.type.indexOf('clslCross') != -1) { + // 丛林猎手 跨服排行榜 不需要更新 + } else { + let updateUids = []; + res = res.map(item => { + // 没有player 或者 player 过期 + if (!item.data?.player || item.data.utime + 60 < G.time) { + updateUids.push(item.idKey); + } + return item; + }); + + let newUserArr = await G.mongodb.collection('user').find( + { uid: { $in: updateUids } }, { projection: { _id: 0 } } + ).toArray(); + + newUserArr.forEach(item => { + // 每次遍历查找? + let index = res.findIndex(x => x.idKey == item.uid); + + res[index].data.player = item; + this.db.updateOne({ idKey: item.uid, type: this.getType() }, { $set: { "data.player": item } }); + + // 跟新redis score + // this.setRankData(item.uid, res[index].data as any); + }) } - return res.map(ele => ele.data).sort(this.compareSort) as any; + // 按照redis uids 排序顺序排序 + return res.sort((a, b) => uids.indexOf(a.idKey) - uids.indexOf(b.idKey)).map(ele => ele.data); } return [] } diff --git a/src/public/rank/rank_clsl.ts b/src/public/rank/rank_clsl.ts index 3849146..714a3b9 100644 --- a/src/public/rank/rank_clsl.ts +++ b/src/public/rank/rank_clsl.ts @@ -27,6 +27,11 @@ export class RankClslCross extends Rank { return Number(val) } + async getRankData(uid: string) { + let data: rankInfo; + return (await this.db.findOne({ "idKey": uid, "type": this.getType() })).data + } + async addNew(info: rankInfo) { // 积分大于配置的最小参数,更新数据 if (info.valArr[0] >= this.minStar) { diff --git a/src/setMongodb.ts b/src/setMongodb.ts index f7a267b..5573466 100644 --- a/src/setMongodb.ts +++ b/src/setMongodb.ts @@ -406,7 +406,15 @@ const crossIndexs: Partial<{ [k in keyof MongodbCollections]: IndexDescription[] ], clslCrossUser: [ { - key: {uid: 1}, unique: true + key: { uid: 1 }, + }, + { + key: { ttltime: 1 }, expireAfterSeconds: 7 * 24 * 3600 + } + ], + clslCrossGroup: [ + { + key: { week: 1 }, } ], rankList: [ diff --git a/src/shared/protocols/rank/PtlOpen.ts b/src/shared/protocols/rank/PtlOpen.ts index fcc7e84..f878176 100644 --- a/src/shared/protocols/rank/PtlOpen.ts +++ b/src/shared/protocols/rank/PtlOpen.ts @@ -13,7 +13,7 @@ export type ResOpen = { }; export type rankType = 'jjc' | 'tanxian' | 'zhanli' | 'qjzzd' | 'hbzbLocal' | 'hbzbCross' | 'hbzbZbsCross' - | 'slzd1' | 'slzd2' | 'slzd3' | 'slzd4' | 'slzd5' | 'slzd6' | 'clslCross' + | 'slzd1' | 'slzd2' | 'slzd3' | 'slzd4' | 'slzd5' | 'slzd6' | "clslCross" | 'kbzz' | 'xszm' | 'zccg' | 'gbzl' | 'tujian' | 'wzryCross'; export type rankTypeObj = { From 2b5be18ea5dc23d344c70f87317c7d095a3ca34d Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Wed, 3 Jan 2024 09:42:13 +0800 Subject: [PATCH 5/8] =?UTF-8?q?fix:=20=E4=B8=9B=E6=9E=97=E7=8C=8E=E6=89=8B?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_cross/clsl/ApiRank.ts | 4 +++- src/api_s2c/conglinshoulie/ApiOpen.ts | 5 +++-- src/shared/protocols/conglinshoulie/PtlOpen.ts | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/api_cross/clsl/ApiRank.ts b/src/api_cross/clsl/ApiRank.ts index ada7663..b63114e 100644 --- a/src/api_cross/clsl/ApiRank.ts +++ b/src/api_cross/clsl/ApiRank.ts @@ -10,14 +10,16 @@ export default async function (call: ApiCall) { if (G.time < week_zero_time + group_time) { call.succ({ rankList: [], myRank: { rank: -1, player: {}, valArr: [] } }) + return } let a = await G.mongodb.collection('clslCrossUser').findOne({ uid: call.req.uid }); - if (!a){ + if (!a || !a.group){ call.succ({ rankList: [], myRank: { rank: -1, player: {}, valArr: [] } }) + return } let rank: Rank; diff --git a/src/api_s2c/conglinshoulie/ApiOpen.ts b/src/api_s2c/conglinshoulie/ApiOpen.ts index d844979..e274418 100644 --- a/src/api_s2c/conglinshoulie/ApiOpen.ts +++ b/src/api_s2c/conglinshoulie/ApiOpen.ts @@ -18,9 +18,9 @@ export default async function (call: ApiCall) { fightWinNum: 0, buyFightNum: 0 }; - + // 隔周刷新星级 - if(ops?.refreshTime < PublicShared.getToWeekMondayZeroTime()){ + if (ops?.refreshTime < PublicShared.getToWeekMondayZeroTime()) { change.allStar = 0; change.curMaxStar = 0; } @@ -35,6 +35,7 @@ export default async function (call: ApiCall) { } call.succ({ + week: parseInt(PublicShared.getToWeek()) || 7, allStar: ops?.allStar || 0, danPrize: ops?.danPrize || [], curMaxStar: ops?.curMaxStar || 0, diff --git a/src/shared/protocols/conglinshoulie/PtlOpen.ts b/src/shared/protocols/conglinshoulie/PtlOpen.ts index d506509..2213dfe 100644 --- a/src/shared/protocols/conglinshoulie/PtlOpen.ts +++ b/src/shared/protocols/conglinshoulie/PtlOpen.ts @@ -21,4 +21,6 @@ export type ResOpen = { curMaxStar: number; /**段位奖励发放记录*/ danPrize: number[]; + + week?:number; // 返回给客户端用 }; \ No newline at end of file From a82e9c560e5f5a6115258640c47d9051d5e9ce4f Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Wed, 3 Jan 2024 10:04:27 +0800 Subject: [PATCH 6/8] =?UTF-8?q?fix:=20=E4=BB=8E=E6=9E=97=E7=8B=A9=E7=8C=8E?= =?UTF-8?q?open=E6=B7=BB=E5=8A=A0week?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/conglinshoulie/ApiOpen.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api_s2c/conglinshoulie/ApiOpen.ts b/src/api_s2c/conglinshoulie/ApiOpen.ts index e274418..2457846 100644 --- a/src/api_s2c/conglinshoulie/ApiOpen.ts +++ b/src/api_s2c/conglinshoulie/ApiOpen.ts @@ -35,7 +35,7 @@ export default async function (call: ApiCall) { } call.succ({ - week: parseInt(PublicShared.getToWeek()) || 7, + week: PublicShared.getWeek(G.time) || 7, allStar: ops?.allStar || 0, danPrize: ops?.danPrize || [], curMaxStar: ops?.curMaxStar || 0, From c8f9d0c7d708df19cec8709c95e3918546b2545f Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Thu, 4 Jan 2024 20:07:42 +0800 Subject: [PATCH 7/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E5=99=A8=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/public/scheduler/scheduler_clsl.ts | 44 +++++++++++++++----------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/public/scheduler/scheduler_clsl.ts b/src/public/scheduler/scheduler_clsl.ts index 0026577..ab256a5 100644 --- a/src/public/scheduler/scheduler_clsl.ts +++ b/src/public/scheduler/scheduler_clsl.ts @@ -1,11 +1,11 @@ -import { PublicShared } from '../../shared/public/public'; -import { EmailFun } from '../email'; -import { RankClslCross, RankClslCrossInit } from '../rank/rank_clsl'; -import { Scheduler, schedulerType } from './scheduler'; +import {PublicShared} from '../../shared/public/public'; +import {EmailFun} from '../email'; +import {RankClslCross} from '../rank/rank_clsl'; +import {Scheduler, schedulerType} from './scheduler'; /** * 丛林猎手赛季重置 -*/ + */ export class SchedulerClslLocalCtor extends Scheduler { id: schedulerType = 'clsl_cross_ctor'; @@ -25,11 +25,13 @@ export class SchedulerClslLocalCtor extends Scheduler { // 修改clslCrossUser表中的uid为del_uid_week 并且 设置ttltime为当前时间 await G.mongodb.collection('clslCrossUser').updateMany( - {}, { $rename: { "uid": `del_uid_${week}` }, $set: { "ttltime": new Date() } } + { + ttltime: {$exists: false} + }, {$rename: {"uid": `del_uid_${week}`}, $set: {"ttltime": new Date()}} ); // 获取分组信息 重置排行榜 - let groups = await G.mongodb.collection('clslCrossGroup').findOne({ week }); + let groups = await G.mongodb.collection('clslCrossGroup').findOne({week}); Object.keys(groups.groups).forEach((group) => { // 清理排行数据 new RankClslCross(group).clear(); @@ -38,10 +40,11 @@ export class SchedulerClslLocalCtor extends Scheduler { await this.record(); } } + /** * 丛林猎手赛季划分 * 达到王者段位的所有玩家 按照创号时间从早到晚排序 每100个玩家划分一个区间 -*/ + */ export class SchedulerClslCrossCtor extends Scheduler { id: schedulerType = 'clsl_cross_group'; @@ -60,7 +63,9 @@ export class SchedulerClslCrossCtor extends Scheduler { async start() { let week = PublicShared.getToWeek(); - let users = await G.mongodb.collection('clslCrossUser').find({}, { + let users = await G.mongodb.collection('clslCrossUser').find({ + ttltime: {$exists: false} + }, { projection: { "uid": 1, "allStar": 1, @@ -87,12 +92,13 @@ export class SchedulerClslCrossCtor extends Scheduler { } if (i == 1) { groups['group1'].st = 0 - } + } if (i == tt) { groups['group' + i].et = G.time + 7 * 14 * 3600; groups['group' + i].users = wzusers.slice((i - 1) * this.num).map(u => u.uid); } - }; + } + ; } else { groups['group0'] = { st: 0, @@ -112,18 +118,18 @@ export class SchedulerClslCrossCtor extends Scheduler { // 更新玩家分组id for (let group in groups) { - await G.mongodb.collection('clslCrossUser').updateMany({ uid: { $in: groups[group].users } }, { $set: { group: group } }); + await G.mongodb.collection('clslCrossUser').updateMany({uid: {$in: groups[group].users}}, {$set: {group: group}}); } // 记录分组 - await G.mongodb.collection("clslCrossGroup").updateOne({ week: week }, { $set: { groups: groups } }, { upsert: true }); + await G.mongodb.collection("clslCrossGroup").updateOne({week: week}, {$set: {groups: groups}}, {upsert: true}); // 初始化丛林猎手排行榜 - G.mongodb.collection('clslCrossUser').find({ allStar: { $gte: this.star } }).toArray().then(users => { + G.mongodb.collection('clslCrossUser').find({allStar: {$gte: this.star}}).toArray().then(users => { users.forEach(u => { - new RankClslCross(u.group).addNew({ - valArr: [u.allStar, u.info.player.power], - player: u.info.player, + new RankClslCross(u.group).addNew({ + valArr: [u.allStar, u.info.player.power], + player: u.info.player, roles: u.info.roles, }) }) @@ -136,7 +142,7 @@ export class SchedulerClslCrossCtor extends Scheduler { /** * 丛林猎手赛季发奖 -*/ + */ export class SchedulerClslPrize extends Scheduler { id: schedulerType = 'clsl_prize'; @@ -153,7 +159,7 @@ export class SchedulerClslPrize extends Scheduler { async start() { // 排名奖励 let group2users: { [group: string]: string[] } = {}; - (await G.mongodb.collection('clslCrossUser').find({ allStar: { $gte: this.star } }).toArray()).forEach(u => { + (await G.mongodb.collection('clslCrossUser').find({allStar: {$gte: this.star}}).toArray()).forEach(u => { if (u.group in group2users) { group2users[u.group].push(u.uid); } else { From b45eec43f95b8c3e5677c489e67c91c951d6fdc3 Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Sun, 31 Dec 2023 21:35:11 +0800 Subject: [PATCH 8/8] =?UTF-8?q?fix:=20=E4=B8=9B=E6=9E=97=E7=8C=8E=E6=89=8B?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_cross/clsl/ApiUpLoad.ts | 19 +++++++++++++++++-- src/api_s2c/conglinshoulie/ApiOpen.ts | 1 + src/public/rank/rank_clsl.ts | 2 +- src/public/scheduler/scheduler_clsl.ts | 4 +++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/api_cross/clsl/ApiUpLoad.ts b/src/api_cross/clsl/ApiUpLoad.ts index a91a9f9..677c596 100644 --- a/src/api_cross/clsl/ApiUpLoad.ts +++ b/src/api_cross/clsl/ApiUpLoad.ts @@ -16,13 +16,28 @@ export default async function (call: ApiCall) { { upsert: true, returnDocument: "after" } )).value; - if (a.group){ // 分完组之后就可以更新排行榜了 + // 周四 并且没有分组 更新玩家分组 + if ((PublicShared.getWeek(G.time) || 7) >= 4 && !a.group) { + // 查询分组数据 + let week = PublicShared.getToWeek(); + let group = await G.mongodb.collection('clslCrossGroup').findOne({ week: week }); + for (let groupid in group.groups) { + let groupinfo = group.groups[groupid]; + if (a.info.player.cTime >= groupinfo.st && a.info.player.cTime < groupinfo.et) { + a.group = groupid; + G.mongodb.collection('clslCrossUser').updateOne({ uid: uid }, { $set: { group: a.group } }); + break; + } + } + } + + if (a.group) { // 分完组之后就可以更新排行榜了 if (allStar != undefined && ops.info) { let rank; if (Rank.list[`clslCross_${a.group}`]) { rank = Rank.list[`clslCross_${a.group}`] } - else{ + else { rank = new RankClslCross(a.group) } rank.addNew({ diff --git a/src/api_s2c/conglinshoulie/ApiOpen.ts b/src/api_s2c/conglinshoulie/ApiOpen.ts index 2457846..7de2df1 100644 --- a/src/api_s2c/conglinshoulie/ApiOpen.ts +++ b/src/api_s2c/conglinshoulie/ApiOpen.ts @@ -22,6 +22,7 @@ export default async function (call: ApiCall) { // 隔周刷新星级 if (ops?.refreshTime < PublicShared.getToWeekMondayZeroTime()) { change.allStar = 0; + change.danPrize = []; change.curMaxStar = 0; } diff --git a/src/public/rank/rank_clsl.ts b/src/public/rank/rank_clsl.ts index 714a3b9..8da05d3 100644 --- a/src/public/rank/rank_clsl.ts +++ b/src/public/rank/rank_clsl.ts @@ -29,7 +29,7 @@ export class RankClslCross extends Rank { async getRankData(uid: string) { let data: rankInfo; - return (await this.db.findOne({ "idKey": uid, "type": this.getType() })).data + return (await this.db.findOne({ "idKey": uid, "type": this.getType() }))?.data } async addNew(info: rankInfo) { diff --git a/src/public/scheduler/scheduler_clsl.ts b/src/public/scheduler/scheduler_clsl.ts index ab256a5..b068a8b 100644 --- a/src/public/scheduler/scheduler_clsl.ts +++ b/src/public/scheduler/scheduler_clsl.ts @@ -125,7 +125,9 @@ export class SchedulerClslCrossCtor extends Scheduler { await G.mongodb.collection("clslCrossGroup").updateOne({week: week}, {$set: {groups: groups}}, {upsert: true}); // 初始化丛林猎手排行榜 - G.mongodb.collection('clslCrossUser').find({allStar: {$gte: this.star}}).toArray().then(users => { + G.mongodb.collection('clslCrossUser').find({ + allStar: {$gte: this.star}, ttltime: {$exists: false} + }).toArray().then(users => { users.forEach(u => { new RankClslCross(u.group).addNew({ valArr: [u.allStar, u.info.player.power],