This commit is contained in:
DESKTOP-15R5JU0\legu 2023-11-17 21:55:32 +08:00
parent 3163d85652
commit 7d8dff9799
47 changed files with 1049 additions and 491 deletions

View File

@ -3,5 +3,8 @@ import { ReqRank, ResRank } from "../../cross/protocols/clsl/PtlRank";
import { Rank } from '../../public/rank/rank';
export default async function (call: ApiCall<ReqRank, ResRank>) {
call.succ(await Rank.list.clslCross.getRankList(call.req.gud.uid, call.req.gud));
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, { gud:call.req.gud, min, max }));
}

View File

@ -3,8 +3,7 @@ import { ReqRankUids, ResRankUids } from "../../cross/protocols/clsl/PtlRankUids
import { Rank } from '../../public/rank/rank';
export default async function (call: ApiCall<ReqRankUids, ResRankUids>) {
let rankList = await Rank.list.clslCross.getRankListAll()
call.succ({
uids: rankList.map(li => li.player.uid)
});
// 返回排名的uids, 应用场景是定时器发送奖励,不分页。
let uids = await Rank.list.clslCross.getRankListIdKeyAll()
call.succ({uids});
}

View File

@ -3,41 +3,58 @@ import { ReqGetEnemy, ResGetEnemy } from "../../../cross/protocols/hbzb/jfs/PtlG
import { Rank } from '../../../public/rank/rank';
import { formatNpcData } from '../../../shared/fightControl/fightFun';
import { PublicShared } from "../../../shared/public/public";
import { rankInfo } from "../../../shared/protocols/type";
export default async function (call: ApiCall<ReqGetEnemy, ResGetEnemy>) {
// TODO
let allPlayers = Rank.list.hbzbCross.allPlayer;
let user = allPlayers[call.req.uid];
if (!user) return call.succ({ enemy: [] });
// TODO ### debug allPlayer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
let allPlayers:rankInfo[] = <rankInfo[]>await Rank.list.hbzbCross.getRankListRange();
let user:rankInfo = <rankInfo>await Rank.list.hbzbCross.getRankData(call.req.uid);
if(!user?.player) {
// 写入默认参数到数据库
user = {
player: call.req.gud,
valArr: [1000]
}
await Rank.list.hbzbCross.addNew(user)
}
// if(!user?.player) return call.succ({ enemy: [] });
let conf = call.req.auto ? G.gc.hbzb.jfsMatchingAuto : G.gc.hbzb.jfsMatchingHand;
let rang = conf.map(val => {
return [PublicShared.eval(val.min, { zhanli: user.data.player.power }), PublicShared.eval(val.max, { zhanli: user.data.player.power })] as [number, number];
return [PublicShared.eval(val.min, { zhanli: user.player.power }), PublicShared.eval(val.max, { zhanli: user.player.power })] as [number, number];
});
let min = rang.slice(-1)[0][0];
let max = rang[0][1];
let players = Object.values(allPlayers).filter(p => {
return p.data.player.power >= min && p.data.player.power <= max && p.data.player.uid != call.req.uid;
let players = allPlayers.filter(p => {
return p.player.power >= min && p.player.power <= max && p.player.uid != call.req.uid;
});
let select: string[] = [];
let enemy = rang.map((r, index) => {
let es = players.filter(p => p.data.player.power >= r[0] && p.data.player.power <= r[1] && !select.includes(p.data.player.uid));
let es = players.filter(p => p.player.power >= r[0] && p.player.power <= r[1] && !select.includes(p.player.uid));
if (es.length > 0) {
let { uid, ...ops } = es.random();
select.push(uid);
return ops;
let ops = es.random();
if(ops) {
let data:any = {
data: {
player: ops.player,
roles: ops.roles
},
jifen: ops.valArr[0]
}
return data;
}
} else {
return {
data: getNpc(user.data.player.lv, index),
data: getNpc(user.player.lv, index),
jifen: 1000
};
}
});
call.succ({ enemy: enemy });
}
function getNpc(lv: number, index: number) {
let rang = G.gc.hbzb.jfsRefreshNpcId.find(v => lv >= v.lvs[0] && lv <= v.lvs[1]);
return formatNpcData(rang.npcs[index].random());
let res = formatNpcData(rang.npcs[index].random())
return res;
}

View File

@ -3,7 +3,12 @@ import { ReqGetRankList, ResGetRankList } from "../../../cross/protocols/hbzb/jf
import { Rank } from '../../../public/rank/rank';
export default async function (call: ApiCall<ReqGetRankList, ResGetRankList>) {
let rankList = await Rank.list.hbzbCross.getRankListAll()
// TODO
call.succ({ rankList: rankList, jifen: Rank.list.hbzbCross.allPlayer[call.req.uid]?.jifen || 1000 });
let page = call.req.page || 0
let offset = call.req.offset || -1 // 预防未查询到的调用,按原逻辑查询全部,避免引起未知问题
let {min, max} = Rank.pageToMin(page, offset)
let rankList = await Rank.list.hbzbCross.getRankListRange(min, max)
let myRankData = await Rank.list.hbzbCross.getRankData(call.conn.uid)
let jifen = myRankData?.valArr ? myRankData?.valArr[0] : 1000
// TODO ### debug
call.succ({ rankList: rankList, jifen: jifen });
}

View File

@ -1,22 +1,43 @@
import {ApiCall} from "tsrpc";
import {ReqGetEnemy, ResGetEnemy} from "../../../cross/protocols/hbzb/zbs/PtlGetEnemy";
import {Rank} from '../../../public/rank/rank';
import { rankInfo } from "../../../shared/protocols/type";
export default async function (call: ApiCall<ReqGetEnemy, ResGetEnemy>) {
let list = await Rank.list.hbzbZbsCross.getRankListAll();
let enemys = list.slice(0, 10);
let myRank = list.findIndex(e => e.player.uid == call.req.uid);
let enemys:rankInfo[] = await Rank.list.hbzbZbsCross.getRankListRange(0, 10);
enemys.forEach((_, i) => {
enemys[i].rank = i
})
let myRank:number = await Rank.list.hbzbZbsCross.getRankSortByOne(call.req.uid);
// 随机匹配其它对手
let rankArr = []
if (myRank > 8) {
if (myRank == 9) enemys.push(list.slice(10, 5).random());
else if (myRank == 10) enemys.push(list.slice(11, 5).random());
else {
let two = list.slice(10, myRank - 10).shuffle();
enemys.push(...two.slice(0, 2));
enemys.push(list.slice(myRank + 1, 5).random());
if(myRank < 10) {
let min = myRank + 1
let max = myRank + 6
let randomRank = Math.round(Math.random() * (max - min) + min)
rankArr.push(randomRank)
}
if (myRank > 10) {
let min = 10
let max = myRank
let arr = []
for(let i = 0; i < 5 || arr.length >= 3; i++) {
let randomRank = Math.round(Math.random() * (max - min) + min)
if(arr.indexOf(randomRank) == -1) arr.push(randomRank)
}
}
}
// 写入随机的对手
for(let rank of rankArr) {
let rankRange = await Rank.list.hbzbZbsCross.getRankSortDataByOne(rank);
if(rankRange) {
rankRange.rank = rank
enemys.push(rankRange)
}
}
call.succ({
enemy: enemys.map((e, i) => ({
@ -24,7 +45,7 @@ export default async function (call: ApiCall<ReqGetEnemy, ResGetEnemy>) {
player: e.player,
roles: e.roles
},
rank: i
rank: e.rank
})),
rank: myRank
});

View File

@ -3,6 +3,9 @@ import { ReqGetRankList, ResGetRankList } from "../../../cross/protocols/hbzb/zb
import { Rank } from '../../../public/rank/rank';
export default async function (call: ApiCall<ReqGetRankList, ResGetRankList>) {
let rankList = await Rank.list.hbzbZbsCross.getRankListAll();
let page = call.req.page || 0
let offset = call.req.offset || -1 // 预防未查询到的调用,按原逻辑查询全部,避免引起未知问题
let {min, max} = Rank.pageToMin(page, offset)
let rankList = await Rank.list.hbzbZbsCross.getRankListRange(min, max);
call.succ({ rankList: rankList });
}

View File

@ -2,14 +2,18 @@ import { ApiCall } from "tsrpc";
import { ReqRank, ResRank } from "../../cross/protocols/kbzz/PtlRank";
import { RankKbzz } from '../../public/rank/rank_kbzz';
export default async function (call: ApiCall<ReqRank, ResRank>) {
let page = call.req.page || 0
let offset = call.req.offset || -1 // 预防未查询到的调用,按原逻辑查询全部,避免引起未知问题
let _cunzai = await G.mongodb.collection('kbzzGroupTroop').findOne({})
if (!_cunzai) {
return call.error('', { code: -1, message: '功能未开放' })
}
let db = await G.mongodb.collection('kbzzGroupUser').findOne({ uid: call.req.uid });
let group = db?.group || 0;
let rank = await RankKbzz.groupList[group].getRankList(call.req.uid);
let {min, max} = RankKbzz.pageToMin(page, offset)
let rank = await RankKbzz.groupList[group].getRankList(call.req.uid, { min, max });
call.succ({
...rank

View File

@ -9,7 +9,10 @@ import { WangZheRongYaofun } from "../../public/wzry";
import { PublicShared } from "../../shared/public/public";
export default async function (call: ApiCall<ReqRank, ResRank>) {
let _r = await Rank.list.wzryCross.getRankList(call.req.gud.uid, call.req.gud)
let page = call.req.page || 0
let offset = call.req.offset || -1 // 预防未查询到的调用,按原逻辑查询全部,避免引起未知问题
let {min, max} = Rank.pageToMin(page, offset)
let _r = await Rank.list.wzryCross.getRankList(call.req.gud.uid, {gud: call.req.gud, min, max})
call.succ(_r);
}

View File

@ -16,7 +16,7 @@ export default async function (call: ApiCall<ReqRefresh, ResRefresh>) {
let change: ResRefresh['change'] = {};
change.useRefreshNum = dbData.data.useRefreshNum + 1;
let callRes = await G.clientCross.callApi('hbzb/jfs/GetEnemy', { uid: call.uid, auto: false });
let callRes = await G.clientCross.callApi('hbzb/jfs/GetEnemy', { uid: call.uid, auto: false, gud: call.conn.gud});
change.enemy = callRes.res.enemy.map(e => { return { ...e, result: null }; });
await G.mongodb.cPlayerInfo('hbzb').updateOne(

View File

@ -4,21 +4,42 @@ import { Rank } from '../../public/rank/rank';
import { ReqOpen, ResOpen } from "../../shared/protocols/rank/PtlOpen";
export default async function (call: ApiCall<ReqOpen, ResOpen>) {
let obj = await rankOpenfun(call, call.req)
call.succ(obj);
}
// ### debug 参数需调整req数组应使用types字段接收需增加分页参数,需前端配合优化redis存储暂不改。
// 参数需调整req数组应使用types字段接收需增加分页参数,需前端配合优化redis存储暂不改。
/**
*
* @param call
* @param req <array>
* @param req.type <array>
* @param req.page 0
* @param req.offset
* @returns
*/
export async function rankOpenfun(call, req: ReqOpen): Promise<ResOpen> {
let obj: ResOpen = {};
// 数组,兼容旧的参数
if(req instanceof Array) {
var types = req
var page = 0
var offset = 1
for (let type of req) {
} else {
var types = req.type
var page = req.page || 0
var offset = req.offset || 1
}
// 取排行范围
// 应用规则接口类如跨服统一使用page&offset, 接口内部需要min&max自行转换 调用函数使用min,max
const { min, max } = Rank.pageToMin(page, offset)
for (let type of types) {
switch (type) {
case 'jjc':
// 获取前50名ranklist数据
let rankList = await JJCFun.getRankList(0, 50);
let rankList = await JJCFun.getRankList(min, max);
// 获取自己的排名
let myRank = await JJCFun.getPlayerRank(call.uid)
// 获取自己的rank信息
@ -34,10 +55,10 @@ export async function rankOpenfun(call, req: ReqOpen): Promise<ResOpen> {
};
break;
case 'hbzbCross':
obj[type] = await Rank.list.hbzbLocal.getCrossRankList(call.uid);
obj[type] = await Rank.list.hbzbLocal.getCrossRankList(call.uid, page, offset);
break;
case 'hbzbZbsCross':
obj[type] = await Rank.list.hbzbLocal.getZbsRankList(call.uid);
obj[type] = await Rank.list.hbzbLocal.getZbsRankList(call.uid, page, offset);
break;
case 'slzd1':
case 'slzd2':
@ -45,25 +66,25 @@ export async function rankOpenfun(call, req: ReqOpen): Promise<ResOpen> {
case 'slzd4':
case 'slzd5':
case 'slzd6':
obj[type] = await Rank.list[type].getRankList(call.conn.gud.ghId);
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 });
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 });
let resCallClsl = await G.clientCross.callApi('clsl/Rank', { gud: call.conn.gud, page, offset});
obj[type] = resCallClsl.res;
break;
case 'wzryCross':
let resCallWzry = await G.clientCross.callApi('wzry/Rank', { gud: call.conn.gud });
let resCallWzry = await G.clientCross.callApi('wzry/Rank', { gud: call.conn.gud, page, offset});
obj[type] = resCallWzry.res;
break;
default:
obj[type] = await Rank.list[type].getRankList(call.uid);
obj[type] = await Rank.list[type].getRankList(call.uid, {min, max});
break;
}
}

View File

@ -37,13 +37,14 @@ export default async function (call: ApiCall<ReqFinsh, ResFinsh>) {
// 检测生成后续任务
let _follow = _con["followtask"]
let newTask: taskType
let newTask = {}
if (_follow) {
// 检测生成新任务
newTask = await TaskFun.setTaskInfo(call, _follow, _task)
}
// 设置数据
await TaskFun.setTask(call.uid, {taskid: taskid}, {finish: 1})
let _prize = await PlayerFun.sendPrize(call, _con["prize"])
_task["finish"] = 1
@ -53,7 +54,8 @@ export default async function (call: ApiCall<ReqFinsh, ResFinsh>) {
newtask: newTask
}
// G.server.sendMsgByUid(call.uid, 'msg_s2c/TaskChange', newTask)
HongDianChange.sendChangeKey(call.uid, ['taskhd', 'huodonghd'])
call.succ(data);
call.conn.sendMsg('msg_s2c/TaskChange', {..._task, finish: 1})
}

View File

@ -11,8 +11,8 @@ export default async function (call: ApiCall<ReqUpdateFight, ResUpdateFight>) {
let canChangeZr = G.gc.wangzherongyao.wangzhe.noupdate
let status = await WangZheRongYaofun.getWangZheStatus();
if (canChangeZr.includes(status.status) && (status.stime - 5 * 60) <= G.time && G.time <= (status.etime + 5 * 60)) {
// 每个状态开始的前5后5分钟 无法更换
// 每个状态开始的前5后5分钟 无法更换
if ((canChangeZr.includes(status.status + 1) && G.time >= (status.etime - 5 * 60)) || (canChangeZr.includes(status.status - 1) && G.time <= (status.stime + 5 * 60))) {
return call.error('', {code: -2, message: ''/* globalThis.lng.wzry_17 */});
}

View File

@ -4,6 +4,8 @@ import { player } from '../../../shared/protocols/user/type';
export type ReqRank = {
gud: player;
page?: number;
offset?: number;
};
export type ResRank = ResOpen[''];

View File

@ -1,8 +1,10 @@
import { joinFightData } from '../../../../shared/fightControl/fightType';
import { player } from '../../../../shared/protocols/user/type';
export type ReqGetEnemy = {
uid: string;
auto: boolean;
gud?: player;
};
export type ResGetEnemy = {

View File

@ -3,6 +3,8 @@ import { rankInfo } from '../../../../shared/protocols/type';
export type ReqGetRankList = {
uid: string;
page?: number;
offset?: number;
};
export type ResGetRankList = {

View File

@ -1,7 +1,10 @@
import { rankInfo } from '../../../../shared/protocols/type';
export type ReqGetRankList = {};
export type ReqGetRankList = {
page?:number;
offset?:number;
};
export type ResGetRankList = {
rankList: rankInfo[];

View File

@ -3,6 +3,8 @@ import { rankInfo } from '../../../shared/protocols/type';
export type ReqRank = {
uid: string;
page?: number;
offset?: number;
};
export type ResRank = {

View File

@ -2628,6 +2628,22 @@ export const serviceProto: ServiceProto<ServiceType> = {
"type": "Reference",
"target": "../../shared/protocols/user/type/player"
}
},
{
"id": 1,
"name": "page",
"type": {
"type": "Number"
},
"optional": true
},
{
"id": 2,
"name": "offset",
"type": {
"type": "Number"
},
"optional": true
}
]
},
@ -2829,6 +2845,15 @@ export const serviceProto: ServiceProto<ServiceType> = {
"type": {
"type": "Boolean"
}
},
{
"id": 2,
"name": "gud",
"type": {
"type": "Reference",
"target": "../../shared/protocols/user/type/player"
},
"optional": true
}
]
},
@ -2892,6 +2917,22 @@ export const serviceProto: ServiceProto<ServiceType> = {
"type": {
"type": "String"
}
},
{
"id": 1,
"name": "page",
"type": {
"type": "Number"
},
"optional": true
},
{
"id": 2,
"name": "offset",
"type": {
"type": "Number"
},
"optional": true
}
]
},
@ -3028,7 +3069,25 @@ export const serviceProto: ServiceProto<ServiceType> = {
}
},
"hbzb/zbs/PtlGetRankList/ReqGetRankList": {
"type": "Interface"
"type": "Interface",
"properties": [
{
"id": 0,
"name": "page",
"type": {
"type": "Number"
},
"optional": true
},
{
"id": 1,
"name": "offset",
"type": {
"type": "Number"
},
"optional": true
}
]
},
"hbzb/zbs/PtlGetRankList/ResGetRankList": {
"type": "Interface",
@ -3238,6 +3297,22 @@ export const serviceProto: ServiceProto<ServiceType> = {
"type": {
"type": "String"
}
},
{
"id": 1,
"name": "page",
"type": {
"type": "Number"
},
"optional": true
},
{
"id": 2,
"name": "offset",
"type": {
"type": "Number"
},
"optional": true
}
]
},
@ -3771,6 +3846,22 @@ export const serviceProto: ServiceProto<ServiceType> = {
"type": "Reference",
"target": "../../shared/protocols/user/type/player"
}
},
{
"id": 1,
"name": "page",
"type": {
"type": "Number"
},
"optional": true
},
{
"id": 2,
"name": "offset",
"type": {
"type": "Number"
},
"optional": true
}
]
},

View File

@ -4,6 +4,8 @@ import { player } from '../../../shared/protocols/user/type';
export type ReqRank = {
gud: player;
page?: number;
offset?: number;
};
export type ResRank = ResOpen[''];

View File

@ -307,15 +307,8 @@ EventEmitter.prototype.listeners = function (type) {
return ret;
};
EventEmitter.listenerCount = function (emitter, type) {
var ret;
if (!emitter._events || !emitter._events[type])
ret = 0;
else if (isFunction(emitter._events[type]))
ret = 1;
else
ret = emitter._events[type].length;
return ret;
EventEmitter.prototype.debug = function () {
console.log(this._events);
};
export const MyEvent = EventEmitter as any as {
@ -324,4 +317,6 @@ export const MyEvent = EventEmitter as any as {
once(type: any, callback: any): any;
off(type: any, callback: any, caller?: any): void;
emit(type: any, ...args: any[]): void;
debug(): any;
removeAllListeners(type?:any):void;
};

View File

@ -113,7 +113,6 @@ Object.defineProperties(BaseConnection.prototype, {
},
},
'gonghui': {
// ###debug GHManage 对象内同步转异步
// 涉及call.conn.gonghui对应引用变量处需增加await
async get(this: BaseConnection): Promise<GH> {
// return GHManage.list[this.gud.ghId];

View File

@ -105,6 +105,8 @@ class _G {
once(type: any, callback: any): any;
off(type: any, callback: any, caller?: any): void;
emit(type: any, ...args: any[]): void;
debug(): any;
removeAllListeners(type?:any):void;
} {
return MyEvent as any;
}

View File

@ -2482,6 +2482,7 @@
"break": 0,
"mask": 0,
"content": "zhuanchang",
"afterGuide": "100_180",
"intr": "转场",
"skip": 0
},

File diff suppressed because it is too large Load Diff

View File

@ -658,6 +658,11 @@
"a": "attr",
"t": "nexp",
"n": 500
},
{
"a": "item",
"t": "4",
"n": 1
}
],
"pval": 1,

View File

@ -104,7 +104,7 @@ export class JJCFun {
// 函数内max存在-1操作查自己需保持min=max
let rankList = await this.getRankList(rank, rank + 1)
let rankInfo = rankList[0]
return rankInfo
return rankInfo || {}
}
// 写入新玩家排名

View File

@ -90,17 +90,18 @@ export class PlayerFun {
static async cutNeed(call: call, val: atn[]) {
let needArr = PublicShared.mergePrize(val);
needArr.forEach(v => v.n *= -1);
let all = [];
let attr = needArr.filter(atn => atn.a == 'attr' && atn.n != 0);
if (attr.length > 0) {
await this.addAttr(call, attr);
all.push(this.addAttr(call, attr));
}
let item = needArr.filter(atn => atn.a == 'item' && atn.n != 0);
if (item.length > 0) {
await this.addItem(call, item);
all.push(this.addItem(call, item));
}
await Promise.all(all);
G.emit('USE_ITEM', call.conn.gud, needArr.map(need => {
return {...need, n: Math.abs(need.n)};
}));
@ -139,11 +140,15 @@ export class PlayerFun {
}> | atn[]) {
let change = {};
if (val instanceof Array) {
let all = [];
for (let atn of val) {
change[atn.t] = await this.getAtnNum(call, atn) + atn.n;
await this.changeAttr(call.conn.uid, change);
await this.upAttr(call, {...atn, n: change[atn.t]});
all.push( this.changeAttr(call.conn.uid, change) );
all.push( this.upAttr(call, {...atn, n: change[atn.t]}) );
//await this.changeAttr(call.conn.uid, change);
//await this.upAttr(call, {...atn, n: change[atn.t]});
}
await Promise.all(all);
} else {
change = val;
await this.changeAttr(call.conn.uid, change);
@ -237,13 +242,22 @@ export class PlayerFun {
call.addEventMsg('msg_s2c/ItemChange', atn.t, data);
} else {
if (item.num + atn.n <= 0) {
await G.redis.del('item', call.uid, atn.t);
await G.mongodb.collection('item').deleteOne({uid: call.uid, itemId: atn.t});
await Promise.all([
G.redis.del('item', call.uid, atn.t),
G.mongodb.collection('item').deleteOne({uid: call.uid, itemId: atn.t})
]);
//await G.redis.del('item', call.uid, atn.t);
//await G.mongodb.collection('item').deleteOne({uid: call.uid, itemId: atn.t});
call.addEventMsg('msg_s2c/ItemChange', atn.t, {num: 0});
} else {
await G.redis.set('item', call.uid, atn.t, 'lastTime', upObj.update.$set.lastTime);
await G.redis.numIncrBy('item', call.uid, atn.t, 'num', atn.n);
await G.mongodb.collection('item').updateOne(upObj.filter, upObj.update, upObj.options);
await Promise.all([
G.redis.set('item', call.uid, atn.t, 'lastTime', upObj.update.$set.lastTime),
G.redis.numIncrBy('item', call.uid, atn.t, 'num', atn.n),
G.mongodb.collection('item').updateOne(upObj.filter, upObj.update, upObj.options)
]);
// await G.redis.set('item', call.uid, atn.t, 'lastTime', upObj.update.$set.lastTime);
// await G.redis.numIncrBy('item', call.uid, atn.t, 'num', atn.n);
// await G.mongodb.collection('item').updateOne(upObj.filter, upObj.update, upObj.options);
call.addEventMsg('msg_s2c/ItemChange', atn.t, {
num: item.num + atn.n,
lastTime: upObj.update.$set.lastTime

View File

@ -46,9 +46,18 @@ export abstract class Rank {
abstract getType(): rankType;
abstract compare(other: rankInfo, cur: rankInfo): boolean;
abstract compareSort(a: rankInfo, b: rankInfo): number;
abstract getRankList(uid: string, gud?: player): Promise<ResOpen['']>;
abstract getRankList(uid: string, obj?: {gud?:player, min?: number, max?:number}): Promise<ResOpen['']>;
abstract getValArr(info: rankInfo): number|string; // 运算后的积分值,排名依据
// 页码转换为minmax
static pageToMin (page, offset) {
let res = {
min: page * offset,
max: page * offset + offset
}
return res
}
get db() {
return G.mongodb.collection('rankList');
}
@ -99,82 +108,109 @@ export abstract class Rank {
async getRankData(idKey: string) {
let key = this.getRedisKey
let data = await G.redis.hGet(key, idKey)
if(!data) {
if(!data || data.utime < (G.time - this.utimeTTL)) {
let type = this.getType()
let res = await this.db.findOne({isKey: idKey, type})
data = G.mongodb.conversionIdObj(res)
if(data) this.setRankData(idKey, data)
if(res) {
data = G.mongodb.conversionIdObj(res)
this.setRankData(idKey, data.data)
}
}
if(data) data
if(data) return data
return undefined
}
// 获取单个用户的排名 *倒叙
// 获取单个用户的排名 *降序
async getRankSortByOne(idKey: string):Promise<number> {
let rank = await G.redis.zRevRank(this.getRedisKeySort, idKey)
return rank || -1;
}
// 获取单个指定排名的用户数据 *降序
async getRankSortDataByOne(rank: number): Promise<rankInfo> {
let rankList:rankInfo[] = await this.getRankListRange(rank, rank + 1)
let rankInfo = rankList && rankList.length > 0 ? rankList[0] : {} as rankInfo
return rankInfo
}
// 获取排名长度
async getRankLen() {
return await G.redis.hLen(this.getRedisKey)
}
// 获取指定排名范围的数据 *降序
async getRankListRange(min:number = 0, max:number = 50): Promise<rankInfo[]> {
let idKeys = await this.getRankListIdKeyRange(min, max)
if(idKeys && idKeys.length > 0) {
let res = await G.redis.hmGet(this.getRedisKey, idKeys)
res = await this.checkData(res)
return res.sort(this.compareSort)
}
return undefined
}
// 获取指定排名范围的idKey *降序
async getRankListIdKeyRange(min:number = 0, max: number = 50): Promise<string[]> {
let idKeys = await G.redis.zRevRange(this.getRedisKeySort, min, max - 1)
return idKeys || []
}
// 获取指定类型的全部rank列表,返回为积分排序后的数组
async getRankListAll(): Promise<rankInfo[]> {
let res = await G.redis.hGetAll(this.getRedisKey)
if(res) {
// 如果是用户数据则比对utime更新数据
let updateUid = []
Object.keys(res).forEach(key => {
if(res[key].player?.uid && (res[key].utime || 0) < (G.time - this.utimeTTL)) {
// 更新数据
updateUid.push(res[key].player.uid)
}
})
if(updateUid.length > 0) {
let newUserArr = await G.mongodb.collection('user').find({uid: {$in: updateUid}}).toArray()
newUserArr.forEach(item => {
res[item.uid].player = item
res[item.uid].utime = G.time
this.setRankData(item.uid, res[item.uid])
})
}
// res = await this.checkData(res)
return Object.values(res).sort(this.compareSort)
}
return []
}
// 按排名获取全部的idKey
async getRankListIdKeyAll(): Promise<string[]> {
let res = this.getRankListIdKeyRange(0, -1)
return res
}
// 验证数据的过期时间,更新数据
async checkData(rankList: rankInfo[]): Promise<rankInfo[]> {
let updateUid = []
rankList.forEach((value,key) => {
// 仅针对用户表,公会表暂不考虑
if(rankList[key].player?.uid && (rankList[key].utime || 0) < (G.time - this.utimeTTL)) {
// 更新数据
updateUid.push(rankList[key].player.uid)
}
})
if(updateUid.length > 0) {
let newUserArr = await G.redis.gets('user', ...updateUid.map(uid => [uid] as [string]))
// G.mongodb.collection('user').find({uid: {$in: updateUid}}).toArray()
newUserArr.forEach(item => {
let index = rankList.findIndex( x => x.player.uid == item.uid)
rankList[index].player = item
this.setRankData(item.uid, rankList[index])
})
}
return rankList
}
async delRankData(idKey:string) {
G.redis.hDel(this.getRedisKey, idKey)
G.redis.zRem(this.getRedisKeySort, idKey)
}
// 前50(countMaxNum)名才更新数据(上榜),多余的数据会删除。
// 原逻辑前50(countMaxNum)名才更新数据(上榜),多余的数据会删除。
async addNew(info: rankInfo) {
this.queue.enqueue(async () => {
let rankList = await this.getRankListAll()
// 进入前50名才更新数据
if (rankList.length < this.countMaxNum || this.compare(rankList.slice(-1)[0], info)) {
// 原逻辑是更新数组内索引排名信息redis更新用户数据即可
await this.setRankData(info.player[this.findKey], info)
this.db.updateOne({ type: this.type, idKey: info.player[this.findKey] }, { $set: { data: info } }, { upsert: true });
// 超过50名时删除最后一名第51名
let myIndex = rankList.findIndex(li => li.player[this.findKey] == info.player[this.findKey]);
if (myIndex != -1) {
rankList[myIndex] = info;
} else {
rankList.push(info);
}
// 重新排序
rankList.sort(this.compareSort)
if (rankList.length > this.countMaxNum) {
let del = rankList.pop();
this.db.deleteOne({ type: this.type, idKey: del.player[this.findKey] });
this.delRankData(del.player[this.findKey])
}
}
await this.setRankData(info.player[this.findKey], info)
let myRank = await this.getRankSortByOne(info.player[this.findKey])
if(myRank < this.countMaxNum) this.db.updateOne({ type: this.type, idKey: info.player[this.findKey] }, { $set: { data: info } }, { upsert: true });
// 删除第50名以后的数据排名从0开始计算
let idKeys:string[] = await this.getRankListIdKeyRange(50, -1)
idKeys.forEach(idKey => {
this.db.deleteOne({ type: this.type, idKey: idKey });
this.delRankData(idKey)
})
});
}

View File

@ -23,8 +23,8 @@ export class RankClslCross extends Rank {
return info?.valArr[0] || 0
}
async getRankList(uid: string, gud: player) {
let rankList = await this.getRankListAll();
async getRankList(uid: string, {gud, min, max}) {
let rankList = await this.getRankListRange(min, max);
let rank = await this.getRankSortByOne(uid);
return {
@ -39,22 +39,19 @@ export class RankClslCross extends Rank {
async addNew(info: rankInfo) {
this.queue.enqueue(async () => {
let rankList = await this.getRankListAll()
// 积分大于配置的最小参数,更新数据
if (info.valArr[0] >= this.minStar) {
let myIndex = rankList.findIndex(li => li.player[this.findKey] == info.player[this.findKey]);
if (myIndex != -1) {
rankList[myIndex] = info;
} else {
rankList.push(info);
}
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 && rankList.find(li => li.player[this.findKey] == info.player[this.findKey])) {
// this.list.removeOne(li => li.player[this.findKey] == info.player[this.findKey]);
this.delRankData(info.player[this.findKey])
this.db.deleteOne({ type: this.type, idKey: info.player[this.findKey] });
// 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])
}
}
});
}

View File

@ -21,9 +21,10 @@ export class RankHbzbJfsLocal extends Rank {
getValArr(info: rankInfo):number|string {
return info?.valArr[0] || 0
}
async getRankList(uid: string) {
async getRankList(uid: string, {min, max}) {
let conn = G.server.uid_connections[uid];
let rankList = await this.getRankListAll();
// ###debug
let rankList = await this.getRankListRange(min, max);
return {
rankList: rankList,
@ -34,9 +35,9 @@ export class RankHbzbJfsLocal extends Rank {
}
};
}
async getCrossRankList(uid: string) {
async getCrossRankList(uid: string, page = 0, offset = 50) {
let conn = G.server.uid_connections[uid];
let callRes = await G.clientCross.callApi('hbzb/jfs/GetRankList', { uid: uid });
let callRes = await G.clientCross.callApi('hbzb/jfs/GetRankList', { uid: uid, page , offset });
let list = callRes.res.rankList;
let myRankIndex = list.findIndex(li => li.player.uid == uid);
@ -49,9 +50,9 @@ export class RankHbzbJfsLocal extends Rank {
}
};
}
async getZbsRankList(uid: string) {
async getZbsRankList(uid: string, page = 0, offset = 50) {
let conn = G.server.uid_connections[uid];
let callRes = await G.clientCross.callApi('hbzb/zbs/GetRankList', { uid: uid });
let callRes = await G.clientCross.callApi('hbzb/zbs/GetRankList', { page, offset });
let list = callRes.res.rankList;
let myRankIndex = list.findIndex(li => li.player.uid == uid);
@ -75,27 +76,39 @@ export class RankHbzbJfsCross extends RankHbzbJfsLocal {
getType(): rankType {
return 'hbzbCross';
}
async addNew(info: rankInfo) {
this.allPlayer[info.player.uid] = {
uid: info.player.uid,
jifen: info.valArr[0],
data: {
player: info.player,
roles: info.roles
}
};
G.mongodb.collection('hbzb_user_cross').updateOne({ uid: info.player.uid }, { $set: { jifen: info.valArr[0], data: this.allPlayer[info.player.uid].data } }, { upsert: true });
let data = {
player: info.player,
roles: info.roles
}
G.mongodb.collection('hbzb_user_cross').updateOne({ uid: info.player.uid }, { $set: { jifen: info.valArr[0], data: data } }, { upsert: true });
this.setRankData(info.player.uid, info)
Rank.prototype.addNew.call(this, info);
}
allPlayer: k_v<CollectionHbzbUserCross> = {};
// allPlayer: k_v<CollectionHbzbUserCross> = {};
// 初始化
async loadAllPlayer() {
if(await this.getRankLen() > 0) return
let players = await G.mongodb.collection('hbzb_user_cross').find().toArray();
players.forEach(p => {
let { _id, ...ops } = p;
this.allPlayer[ops.uid] = ops;
});
players.forEach(item => {
if(item.uid && item.data) {
// 格式与其它排行榜不同,同步格式。
let data:rankInfo = {
player: item.data.player,
roles: item.data.roles,
valArr: [item.jifen]
}
this.setRankData(item.uid, data)
}
})
}
// 添加默认数据
async addJfsLog(uid: string, fightLog: fightResult) {
if (uid.indexOf('npc') != -1) return;
FightFun.saveLog(uid, 'hbzbJfs', fightLog);
@ -123,9 +136,8 @@ export class RankHbzbZbsCross extends Rank {
return res
}
async changeRank(uid: string, toUid: string) {
let rankList = await this.getRankListAll();
let role1 = rankList.find(li => li.player.uid == uid);
let role2 = rankList.find(li => li.player.uid == toUid);
let role1 = await this.getRankData(uid);
let role2 = await this.getRankData(toUid);
if (role1 && role2 && role1.valArr[0] > role2.valArr[0]) {
let temp = role1.valArr[0];
@ -136,9 +148,10 @@ export class RankHbzbZbsCross extends Rank {
this.addNew(role2);
}
}
async getRankList(uid: string) {
let rankList = await this.getRankListAll();
let conn = rankList.find(li => li.player.uid == uid);
async getRankList(uid: string, {min, max}) {
let rankList = await this.getRankListRange(min, max);
// let conn = rankList.find(li => li.player.uid == uid);
let conn = await this.getRankData(uid)
return {
rankList: rankList,
@ -151,12 +164,13 @@ export class RankHbzbZbsCross extends Rank {
async addNew(info: rankInfo) {
this.queue.enqueue(async () => {
let rankList = await this.getRankListAll();
let myIndex = rankList.findIndex(li => li.player[this.findKey] == info.player[this.findKey]);
if (myIndex != -1) {
rankList[myIndex] = info;
}
// 原逻辑排名最高50条更新ranklist内排名数据
// let rankList = await this.getRankListRange();
// let myIndex = rankList.findIndex(li => li.player[this.findKey] == info.player[this.findKey]);
// if (myIndex != -1) {
// rankList[myIndex] = info;
// }
// 当前更新redis相关数据即可
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);

View File

@ -39,13 +39,14 @@ export class RankKbzz extends Rank {
return res
}
async getRankList(uid: string) {
let rankList = await this.getRankListAll();
async getRankList(uid: string, {min, max}) {
let rankList = await this.getRankListRange(min, max);
let gud = await this.getRankData(uid)
return {
rankList: rankList,
myRank: {
rank: await this.getRankSortByOne(uid),
player: {},
player: gud?.player || {},
valArr: [(await G.mongodb.collection('kbzzGroupUser').findOne({ uid: uid }))?.score || 1000]
}
};

View File

@ -17,9 +17,9 @@ export class RankPower extends Rank {
getValArr(info: rankInfo):number|string {
return info?.valArr[0] || 0
}
async getRankList(uid: string): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
async getRankList(uid: string, {min, max}): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
let conn = G.server.uid_connections[uid];
let rankList = await this.getRankListAll()
let rankList = await this.getRankListRange(min, max)
return {
rankList: rankList,

View File

@ -19,9 +19,10 @@ export class RankQjzzd extends Rank {
return info?.valArr[0] || 0
}
async getRankList(uid: string): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
async getRankList(uid: string, {min, max}): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
let conn = G.server.uid_connections[uid];
let rankList = await this.getRankListAll()
// debug
let rankList = await this.getRankListRange(min, max)
return {
rankList: rankList,
myRank: {

View File

@ -21,9 +21,10 @@ export class RankSlzd1 extends Rank {
return info?.valArr[0] || 0
}
async getRankList(ghid: string): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
let rankList = await this.getRankListAll()
let li = rankList.find(l => l.player.ghId == ghid);
async getRankList(ghid: string, { min, max }): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
let rankList = await this.getRankListRange( min, max )
// let li = rankList.find(l => l.player.ghId == ghid); // debug 查询自身数据
let li = await this.getRankData(ghid);
return {
rankList: rankList,
myRank: {

View File

@ -17,9 +17,9 @@ export class RankTanXian extends Rank {
getValArr(info: rankInfo):number|string {
return info?.valArr[0] || 0
}
async getRankList(uid: string): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
async getRankList(uid: string, { min, max }): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
let conn = G.server.uid_connections[uid];
let rankList = await this.getRankListAll()
let rankList = await this.getRankListRange(min, max)
return {
rankList: rankList,
myRank: {

View File

@ -21,9 +21,9 @@ export class RankTujian extends Rank {
return info?.valArr[0] || 0
}
async getRankList(uid: string): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
async getRankList(uid: string, { min, max }): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
let conn = G.server.uid_connections[uid];
let rankList = await this.getRankListAll();
let rankList = await this.getRankListRange(min, max);
return {
rankList: rankList,
myRank: {

View File

@ -23,15 +23,13 @@ export class RankWzryCross extends Rank {
}
async getPlayerRank(uid: string): Promise<number> {
let _r = await this.getRankListAll();
if (!Object.keys(_r).length) {
return -1
}
return _r.findIndex(li => li.player.uid == uid) + 1 || -1;
// 获取用户指定排名
let rank = await this.getRankSortByOne(uid)
return rank + 1; // 原逻辑有+1操作与其它地点取排名逻辑有差异
}
async getRankList(uid: string, gud: player) {
let rankList = await this.getRankListAll();
async getRankList(uid: string, {gud, min, max }) {
let rankList = await this.getRankListRange(min, max);
return {
rankList: rankList,

View File

@ -25,9 +25,9 @@ export class RankXszm extends Rank {
return res
}
async getRankList(uid: string): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
async getRankList(uid: string, { min, max }): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
let conn = G.server.uid_connections[uid];
let rankList = await this.getRankListAll();
let rankList = await this.getRankListRange(min, max);
return {
rankList: rankList,
myRank: {

View File

@ -21,9 +21,9 @@ export class RankZccg extends Rank {
return info?.valArr[0] || 0
}
async getRankList(uid: string): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
async getRankList(uid: string, { min, max }): Promise<{ rankList: rankInfo[]; myRank: rankInfo; }> {
let conn = G.server.uid_connections[uid];
let rankList = await this.getRankListAll();
let rankList = await this.getRankListRange(min, max);
return {
rankList: rankList,
myRank: {

View File

@ -24,7 +24,7 @@ export class SchedulerManage {
static onlyPm2() {
setInterval(() => {
Scheduler.schedulers.forEach(s => s.cheak()); // ### debug 方法奖励等定时器检测
Scheduler.schedulers.forEach(s => s.cheak());
}, 1000);
}
}

View File

@ -58,7 +58,7 @@ export class Scheduler_hbzb_zbs_local_prize extends Scheduler {
async start() {
let crossRank = (await G.clientCross.callApi('hbzb/zbs/GetRankList', { uid: '' })).res.rankList;
let crossRank = (await G.clientCross.callApi('hbzb/zbs/GetRankList', {})).res.rankList;
this.sendEmail(crossRank.map(rank => { return { uid: rank.player.uid, valArr: [...rank.valArr] }; }));
// crossRank.length > 0 && ChatFun.newMsg({
@ -123,13 +123,10 @@ export class Scheduler_hbzb_zbs_cross_ready extends Scheduler {
}
async start() {
let rankList = await Rank.list.hbzbCross.getRankListAll()
let top100 = await Rank.list.hbzbCross.getRankListRange(0, 100)
let zbsRankList = await Rank.list.hbzbZbsCross.getRankListAll()
let top100 = rankList.slice(0, 100);
let top100uids = top100.map(t => t.player.uid);
console.log(Rank.list.hbzbZbsCross);
top100.push(...zbsRankList.filter(l => !top100uids.includes(l.player.uid)).sort((a, b) => b.player.power - a.player.power));
zbsRankList = top100.map((v, i) => {

View File

@ -98,8 +98,14 @@ export class TaskFun {
static async setTaskVal(call: ApiCall, stype: number, val: number, chkCall: Function, chkval: number = 0, isinc: number = 0, alchangeVal: Function, arg) {
let uid = call.uid;
// let _unFinish = await this.getFinishByStype(call, stype, { finish: 0, "$where": "return this.pval > this.nval" });
let _unFinish = await this.getFinishByStype(call, stype, {finish: 0});
_unFinish = _unFinish.filter(x => x.pval > x.nval)
//let _unFinish = await this.getFinishByStype(call, stype, {finish: 0});
//_unFinish = _unFinish.filter(x => x.pval > x.nval)
let _unFinish = await this.getFinishByStype(call, stype, {
finish: 0, '$expr': {
$gt: ["$pval", "$nval"]
}
});
if (_unFinish.length == 0) return;
for (let index = 0; index < _unFinish.length; index++) {
const _task = _unFinish[index];
@ -138,6 +144,10 @@ export class TaskFun {
let _setData = {nval: _resVal};
let _where = {taskid: _task["taskid"]};
await this.setTask(uid, _where, _setData);
if (_resVal == _pval) {
call.conn.sendMsg('msg_s2c/TaskChange', {..._task, nval: _resVal})
}
}
}
@ -299,8 +309,8 @@ export class TaskFun {
*
*/
static async generateAllTask(call: ApiCall) {
let _r = await G.mongodb.collection(SHUJUKU).findOne({uid: call.uid});
if (_r) return;
let _r = await G.mongodb.collection(SHUJUKU).count({uid: call.uid});
if (_r > 0) return;
let _taskInfo = [];
let _con = G.gc.task;
for (let _type in _con) {
@ -320,9 +330,9 @@ export class TaskFun {
/**生成指定类型任务-初始化 */
static async reInitTask(call: ApiCall, type: string) {
// 查询类型任务是否存在
let _r = await G.mongodb.collection(SHUJUKU).findOne({uid: call.uid, type: ~~type});
let _r = await G.mongodb.collection(SHUJUKU).count({uid: call.uid, type: ~~type});
let _taskInfo = [];
if (!_r) {
if (_r == 0) {
let _con = G.gc.task;
// 数据不存在,未初始化,执行初始化
for (let _taskid in _con[type]) {
@ -333,7 +343,7 @@ export class TaskFun {
}
}
}
await this.insertTasks(call, _taskInfo);
_taskInfo.length > 0 && await this.insertTasks(call, _taskInfo);
return _taskInfo;
}
@ -412,11 +422,17 @@ export class TaskFun {
const element = Object.keys(_ttype)[index];
if ((element == "1" || element == "3") && call.conn.gud.lv < 7) continue;
let _values: number[] = _ttype[element];
let _where: {} = {uid: call.uid, type: {$in: _values}, finish: 0};
let _where: {} = {
uid: call.uid, type: {$in: _values}, finish: 0, '$expr': {
$lte: ["$pval", "$nval"]
}
};
let taskArr = await G.mongodb.collection(SHUJUKU).find(_where).toArray();
let _tmp = taskArr.filter(x => x.pval <= x.nval)
if (_tmp.length) {
//let taskArr = await G.mongodb.collection(SHUJUKU).find(_where).toArray();
let count = await G.mongodb.collection(SHUJUKU).count(_where);
//let _tmp = taskArr.filter(x => x.pval <= x.nval)
//if (_tmp.length) {
if (count > 0) {
_res.show = true;
_res.val.tasktypes.push(element);
}

View File

@ -1,8 +1,8 @@
import { ApiCall } from 'tsrpc';
import { formatNpcData } from '../shared/fightControl/fightFun';
import { hongdianVal } from '../shared/protocols/hongdian/PtlGet';
import { wangzherongyao_baoming, wangzherongyao_staus, wzry_info } from '../shared/protocols/wzry/PtlOpen';
import { PublicShared } from '../shared/public/public';
import {ApiCall} from 'tsrpc';
import {formatNpcData} from '../shared/fightControl/fightFun';
import {hongdianVal} from '../shared/protocols/hongdian/PtlGet';
import {wangzherongyao_baoming, wangzherongyao_staus, wzry_info} from '../shared/protocols/wzry/PtlOpen';
import {PublicShared} from '../shared/public/public';
export class WangZheRongYaofun {
@ -18,8 +18,8 @@ export class WangZheRongYaofun {
let _con = _tmp.wangzhe.timestatus;
let _weekOneTime = PublicShared.getToWeekMondayZeroTime();
let _res: wangzherongyao_staus = { // 默认比赛结束状态
status: 8,
stime: _weekOneTime + 7 * 24 * 3600,
status: _con[_con.length - 1].status + 1,
stime: _weekOneTime + _con[_con.length - 1].etime,
etime: _weekOneTime + 7 * 24 * 3600
};
for (let index = 0; index < _con.length; index++) {
@ -40,7 +40,7 @@ export class WangZheRongYaofun {
/**获取报名人数 */
static async getBaoMingNum() {
let zkey: string = PublicShared.getToWeek();
let _num = G.mongodb.collection('playerInfo', 'wzry').countDocuments({ isbm: 1 });
let _num = G.mongodb.collection('playerInfo', 'wzry').countDocuments({isbm: 1});
return _num;
}
@ -59,9 +59,12 @@ export class WangZheRongYaofun {
isjjzs: 0,
uid: call.uid,
};
let _mydata = await G.mongodb.collection('playerInfo', 'wzry').findOne({ uid: call.conn.uid, type: 'wzry' });
let _mydata = await G.mongodb.collection('playerInfo', 'wzry').findOne({uid: call.conn.uid, type: 'wzry'});
if (!_mydata) {
await G.mongodb.collection('playerInfo', 'wzry').updateOne({ uid: call.uid, type: 'wzry' }, { $set: _res }, { upsert: true });
await G.mongodb.collection('playerInfo', 'wzry').updateOne({
uid: call.uid,
type: 'wzry'
}, {$set: _res}, {upsert: true});
return _res;
} else {
delete _mydata._id;
@ -71,15 +74,15 @@ export class WangZheRongYaofun {
/**设置报名数据 */
static async setWzryBaoMing(call: ApiCall, setData: { [id: string]: any; }) {
await G.mongodb.cPlayerInfo("wzry").updateOne({ uid: call.uid, type: 'wzry' }, { $set: setData }, { upsert: true });
await G.mongodb.cPlayerInfo("wzry").updateOne({uid: call.uid, type: 'wzry'}, {$set: setData}, {upsert: true});
let data = await call.conn.getDefaultFightData();
let _res = await G.clientCross.callApi('wzry/BaoMing', { zkey: setData.zkey, data: data });
let _res = await G.clientCross.callApi('wzry/BaoMing', {zkey: setData.zkey, data: data});
return _res;
}
/**获取我的wzry战斗数据 */
static async getMyFight(call: ApiCall) {
let _res = await G.clientCross.callApi('wzry/WzFightData', { uid: call.uid, iswzfight: true });
let _res = await G.clientCross.callApi('wzry/WzFightData', {uid: call.uid, iswzfight: true});
if (_res.isSucc && _res.res.info) {
return _res.res.info;
}
@ -88,7 +91,7 @@ export class WangZheRongYaofun {
/**获取王者之巅数据 */
static async getWzzd(uid: string) {
let _res = await G.clientCross.callApi('wzry/WzFightData', { uid: uid, iswzzd: true });
let _res = await G.clientCross.callApi('wzry/WzFightData', {uid: uid, iswzzd: true});
return _res;
}
@ -103,7 +106,7 @@ export class WangZheRongYaofun {
/**获取wzry某一组数据 */
static async getFightGroup(call: ApiCall, where: {}) {
let _res = await G.clientCross.callApi('wzry/WzFightGroup', { where: where });
let _res = await G.clientCross.callApi('wzry/WzFightGroup', {where: where});
if (_res.isSucc && _res.res.info) {
return _res.res.info;
}
@ -112,8 +115,8 @@ export class WangZheRongYaofun {
/**wzry 结束 删除相关数据 */
static async delGroup() {
let _res = await G.clientCross.callApi('wzry/WzFightData', { uid: '', isdel: true });
await G.mongodb.collection('playerInfo', 'wzry').updateMany({ type: 'wzry' }, {
let _res = await G.clientCross.callApi('wzry/WzFightData', {uid: '', isdel: true});
await G.mongodb.collection('playerInfo', 'wzry').updateMany({type: 'wzry'}, {
$set: {
isdldrefre: 0,
isbm: 0,
@ -134,7 +137,7 @@ export class WangZheRongYaofun {
/**设置大乱斗战斗数据 */
static async setWzryDldFight(call: ApiCall, Fight: wangzherongyao_baoming) {
let data = Fight.data;
let _res = await G.clientCross.callApi('wzry/SetWzFight', { zkey: Fight.zkey, data: data, jifen: Fight.jifen });
let _res = await G.clientCross.callApi('wzry/SetWzFight', {zkey: Fight.zkey, data: data, jifen: Fight.jifen});
return _res.res;
}
@ -199,7 +202,7 @@ export class WangZheRongYaofun {
}
if (!_res.show && status.status == 15 && !_mydata?.isjingcai?.totalmoney) {
let _jcList = await WangZheRongYaofun.getFightGroup(call, { deep: { $gte: 5 } });
let _jcList = await WangZheRongYaofun.getFightGroup(call, {deep: {$gte: 5}});
if (_jcList) {
_res.show = true;
}

View File

@ -91,7 +91,7 @@ export class _redis implements redisJsonFun {
// this.logMsg = str;
// }
}
fromatKey(key: string, state: 'zAdd' | 'zRange' | 'zRem' | 'zRevRank' | 'zRank' | 'zCard' | 'hGet' | 'hGetAll' | 'hLen' | 'hSet' | 'hDel' | 'del' | 'numIncrBy' | 'type' | 'get' | 'set' | 'arrAppend' | 'arrPop' | 'arrLen' | 'arrInsert' | null) {
fromatKey(key: string, state: 'zAdd' | 'zRange' | 'zRevRange' | 'zRem' | 'zRevRank' | 'zRank' | 'zCard' | 'hGet' | 'hmGet' | 'hGetAll' | 'hLen' | 'hSet' | 'hDel' | 'del' | 'numIncrBy' | 'type' | 'get' | 'set' | 'arrAppend' | 'arrPop' | 'arrLen' | 'arrInsert' | null) {
let sid = G.config.serverId || 0;
let fmtKey = `${G.config.projectName}_${G.argv.serverType == 'cross' ? `corss${sid}` : sid}_${key}`;
state && this.log(state + ' ' + fmtKey, 'start');
@ -115,6 +115,16 @@ export class _redis implements redisJsonFun {
} catch (err) {}
return result
}
async hmGet() {
let _args = Array.from(arguments);
let result = await this.redis.hmGet(this.fromatKey(_args[0], 'hmGet'), _args[1]);
try{
for(let i in result) {
result[i] = JSON.parse(result[i])
}
} catch(err) {}
return result
}
async hGetAll() {
let _args = Array.from(arguments);
@ -168,6 +178,15 @@ export class _redis implements redisJsonFun {
let _args = Array.from(arguments);
return await this.redis.zRange(this.fromatKey(_args[0], 'zRange'), _args[1], _args[2])
}
async zRevRange() {
let _args = Array.from(arguments);
this.redis.zRange
return await this.redis.zRange(this.fromatKey(_args[0], 'zRange'), _args[1], _args[2], {REV: true})
}
/**
* key排名
@ -555,9 +574,12 @@ export interface redisJsonFun {
hGet<key extends hkeys<hStr1>>(key: key, hash:string): Promise<string>;
hGet<key extends hkeys<hObj1>>(key: key, hash:string): Promise<hObj1[key]>;
// 变量传key无法通过检测时不做强制key类型验证。
hGet<key extends string>(key: key, hash:string): Promise<any>;
hmGet<key extends hkeys<hObj1>>(key: key, hash:string[]): Promise<hObj1[key]>;
hmGet<key extends string>(key: key, hash:string[]): Promise<any>;
/**获取全部的hash数据 */
hGetAll<key extends hkeys<hObj1>>(key: key):Promise<any>;
@ -586,8 +608,12 @@ export interface redisJsonFun {
* @param key
*/
zRange<key extends skeys<sObj1>>(key: key, min: number, max: number): Promise<string[]>;
zRange<key extends string>(key: key, min: number, max: number): Promise<string[]>;
zRevRange<key extends skeys<sObj1>>(key: key, min: number, max: number): Promise<string[]>;
zRevRange<key extends string>(key: key, min: number, max: number): Promise<string[]>;
/**
* member排名数据

View File

@ -214,6 +214,7 @@ export class FightControl {
this.winSide = winside as 1 | 0;
this.record({ act: 'fightEnd', winSide: this.winSide });
this.event.removeAllListeners()
}
eachLiveRoles(callback: (role: Role) => void) {

View File

@ -3,7 +3,7 @@ import { rankInfo } from '../type';
/**
*
*/
export type ReqOpen = Array<rankType>;
export type ReqOpen = rankTypeObj|Array<rankType>;
export type ResOpen = {
[type: string]: {
@ -15,4 +15,10 @@ 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';
| 'zccg' | 'gbzl' | 'tujian' | 'wzryCross';
export type rankTypeObj = {
type?: rankType[],
page?: number,
offset?: number
}

View File

@ -18019,11 +18019,59 @@ export const serviceProto: ServiceProto<ServiceType> = {
"type": "Interface"
},
"rank/PtlOpen/ReqOpen": {
"type": "Array",
"elementType": {
"type": "Reference",
"target": "rank/PtlOpen/rankType"
}
"type": "Union",
"members": [
{
"id": 0,
"type": {
"type": "Reference",
"target": "rank/PtlOpen/rankTypeObj"
}
},
{
"id": 1,
"type": {
"type": "Array",
"elementType": {
"type": "Reference",
"target": "rank/PtlOpen/rankType"
}
}
}
]
},
"rank/PtlOpen/rankTypeObj": {
"type": "Interface",
"properties": [
{
"id": 0,
"name": "type",
"type": {
"type": "Array",
"elementType": {
"type": "Reference",
"target": "rank/PtlOpen/rankType"
}
},
"optional": true
},
{
"id": 1,
"name": "page",
"type": {
"type": "Number"
},
"optional": true
},
{
"id": 2,
"name": "offset",
"type": {
"type": "Number"
},
"optional": true
}
]
},
"rank/PtlOpen/rankType": {
"type": "Union",