Compare commits
5 Commits
63877a2664
...
ad9e3cca46
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ad9e3cca46 | ||
![]() |
cedce860c5 | ||
![]() |
cc6aad7223 | ||
![]() |
566c3aeb7b | ||
![]() |
8a69a4fc1e |
@ -240,7 +240,7 @@ export function ctor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Array.prototype.random = function (this: Array<any>) {
|
Array.prototype.random = function (this: Array<any>) {
|
||||||
return this[PublicShared.randomNum(0, this.length)];
|
return this[PublicShared.randomNum(0, this.length - 1)];
|
||||||
};
|
};
|
||||||
|
|
||||||
Array.prototype.intersection = function (this: Array<any>, other: Array<any>) {
|
Array.prototype.intersection = function (this: Array<any>, other: Array<any>) {
|
||||||
|
@ -63,7 +63,7 @@ export abstract class Rank {
|
|||||||
/**
|
/**
|
||||||
* 根据RankInfo数据,获取用于排名的积分值得
|
* 根据RankInfo数据,获取用于排名的积分值得
|
||||||
* 注:可能重写,具体根据type类型判断
|
* 注:可能重写,具体根据type类型判断
|
||||||
* @param info
|
* @param info
|
||||||
* @returns 积分值
|
* @returns 积分值
|
||||||
*/
|
*/
|
||||||
getValArr(info: rankInfo): number | string {
|
getValArr(info: rankInfo): number | string {
|
||||||
@ -84,7 +84,7 @@ export abstract class Rank {
|
|||||||
* 页面转换,根据page和offset转换出min和max
|
* 页面转换,根据page和offset转换出min和max
|
||||||
* @param page 页面
|
* @param page 页面
|
||||||
* @param offset 每页数量
|
* @param offset 每页数量
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
static pageToMin(page: number, offset: number) {
|
static pageToMin(page: number, offset: number) {
|
||||||
let res = {
|
let res = {
|
||||||
@ -131,7 +131,7 @@ export abstract class Rank {
|
|||||||
async cotr() {
|
async cotr() {
|
||||||
clusterRunOnce(async () => {
|
clusterRunOnce(async () => {
|
||||||
// redis已存在则不初始化
|
// redis已存在则不初始化
|
||||||
//if(await this.getRankLen() > 0) return
|
//if(await this.getRankLen() > 0) return
|
||||||
|
|
||||||
//将db里的数据,写入到 rank:xxx:sort里
|
//将db里的数据,写入到 rank:xxx:sort里
|
||||||
//写入的单条数据为: {uid:score}
|
//写入的单条数据为: {uid:score}
|
||||||
@ -158,7 +158,7 @@ export abstract class Rank {
|
|||||||
* 更新玩家的积分
|
* 更新玩家的积分
|
||||||
* @param uid uid,在rank里通常保存于idKey这个字段
|
* @param uid uid,在rank里通常保存于idKey这个字段
|
||||||
* @param data 积分数据,主要是需要里面的data.valArr字段
|
* @param data 积分数据,主要是需要里面的data.valArr字段
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async setRankData(uid: string, data: rankInfo) {
|
async setRankData(uid: string, data: rankInfo) {
|
||||||
let keySort = this.getRedisKeySort
|
let keySort = this.getRedisKeySort
|
||||||
@ -176,7 +176,7 @@ export abstract class Rank {
|
|||||||
/**
|
/**
|
||||||
* 获取单个用户的数据
|
* 获取单个用户的数据
|
||||||
* @param uid uid
|
* @param uid uid
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async getRankData(uid: string) {
|
async getRankData(uid: string) {
|
||||||
let data: rankInfo;
|
let data: rankInfo;
|
||||||
@ -208,8 +208,8 @@ export abstract class Rank {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取单个用户的排序分数
|
* 获取单个用户的排序分数
|
||||||
* @param uid
|
* @param uid
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async getRankScore(uid: string): Promise<number> {
|
async getRankScore(uid: string): Promise<number> {
|
||||||
let score = await G.redis.zScore(this.getRedisKeySort, uid)
|
let score = await G.redis.zScore(this.getRedisKeySort, uid)
|
||||||
@ -218,8 +218,8 @@ export abstract class Rank {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从redis中获取单个用户的排名 *降序
|
* 从redis中获取单个用户的排名 *降序
|
||||||
* @param uid
|
* @param uid
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async getRankSortByOne(uid: string): Promise<number> {
|
async getRankSortByOne(uid: string): Promise<number> {
|
||||||
let rank = await G.redis.zRevRank(this.getRedisKeySort, uid)
|
let rank = await G.redis.zRevRank(this.getRedisKeySort, uid)
|
||||||
@ -240,9 +240,9 @@ export abstract class Rank {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定排名范围的数据 *降序
|
* 获取指定排名范围的数据 *降序
|
||||||
* @param min
|
* @param min
|
||||||
* @param max
|
* @param max
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async getRankListRange(min: number = 0, max: number = 50): Promise<rankInfo[]> {
|
async getRankListRange(min: number = 0, max: number = 50): Promise<rankInfo[]> {
|
||||||
let uids = await this.getRankListIdKeyRange(min, max)
|
let uids = await this.getRankListIdKeyRange(min, max)
|
||||||
@ -250,6 +250,33 @@ export abstract class Rank {
|
|||||||
let res = await this.db.find({ idKey: { $in: uids }, type: this.getType() }).toArray()
|
let res = await this.db.find({ idKey: { $in: uids }, type: this.getType() }).toArray()
|
||||||
|
|
||||||
switch (this.getType()) {
|
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 } });
|
||||||
|
})
|
||||||
|
}
|
||||||
|
break;
|
||||||
default: // 排行数据更新逻辑 默认更新playerInfo
|
default: // 排行数据更新逻辑 默认更新playerInfo
|
||||||
let updateUids = [];
|
let updateUids = [];
|
||||||
res = res.map(item => {
|
res = res.map(item => {
|
||||||
@ -271,7 +298,7 @@ export abstract class Rank {
|
|||||||
this.db.updateOne({ idKey: item.uid, type: this.getType() }, { $set: { "data.player": item } });
|
this.db.updateOne({ idKey: item.uid, type: this.getType() }, { $set: { "data.player": item } });
|
||||||
|
|
||||||
// 跟新redis score
|
// 跟新redis score
|
||||||
this.setRankData(item.uid, res[index].data as any);
|
// this.setRankData(item.uid, res[index].data as any);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,8 +309,8 @@ export abstract class Rank {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从redis中获取指定排名范围的uid集合 *降序
|
* 从redis中获取指定排名范围的uid集合 *降序
|
||||||
* @param min
|
* @param min
|
||||||
* @param max
|
* @param max
|
||||||
* @returns uid集合数组
|
* @returns uid集合数组
|
||||||
*/
|
*/
|
||||||
async getRankListIdKeyRange(min: number = 0, max: number = 50): Promise<string[]> {
|
async getRankListIdKeyRange(min: number = 0, max: number = 50): Promise<string[]> {
|
||||||
@ -293,7 +320,7 @@ export abstract class Rank {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定类型的全部rank列表,返回为积分排序后的数组
|
* 获取指定类型的全部rank列表,返回为积分排序后的数组
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async getRankListAll(): Promise<rankInfo[]> {
|
async getRankListAll(): Promise<rankInfo[]> {
|
||||||
// let res = await G.redis.hGetAll(this.getRedisKey)
|
// let res = await G.redis.hGetAll(this.getRedisKey)
|
||||||
@ -308,7 +335,7 @@ export abstract class Rank {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 按排名获取全部的idKey
|
* 按排名获取全部的idKey
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async getRankListIdKeyAll(): Promise<string[]> {
|
async getRankListIdKeyAll(): Promise<string[]> {
|
||||||
let res = this.getRankListIdKeyRange(0, -1)
|
let res = this.getRankListIdKeyRange(0, -1)
|
||||||
@ -327,7 +354,7 @@ export abstract class Rank {
|
|||||||
// })
|
// })
|
||||||
// if(updateUid.length > 0) {
|
// if(updateUid.length > 0) {
|
||||||
// let newUserArr = await G.mongodb.collection('user').find({uid:{$in: updateUid}}).toArray()
|
// let newUserArr = await G.mongodb.collection('user').find({uid:{$in: updateUid}}).toArray()
|
||||||
// // let newUserArr = await G.redis.gets('user', ...updateUid.map(uid => [uid] as [string]))
|
// // let newUserArr = await G.redis.gets('user', ...updateUid.map(uid => [uid] as [string]))
|
||||||
// // let newUserArr = await G.mongodb.collection('user').find({uid:{$in: updateUid}}).toArray()
|
// // let newUserArr = await G.mongodb.collection('user').find({uid:{$in: updateUid}}).toArray()
|
||||||
// newUserArr.forEach(item => {
|
// newUserArr.forEach(item => {
|
||||||
// let index = rankList.findIndex( x => x.player.uid == item.uid);
|
// let index = rankList.findIndex( x => x.player.uid == item.uid);
|
||||||
@ -353,8 +380,8 @@ export abstract class Rank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 原逻辑前50(countMaxNum)名才更新数据(上榜),多余的数据会删除。
|
* 原逻辑前50(countMaxNum)名才更新数据(上榜),多余的数据会删除。
|
||||||
* @param info
|
* @param info
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
async addNew(info: rankInfo) {
|
async addNew(info: rankInfo) {
|
||||||
|
Loading…
Reference in New Issue
Block a user