增加挑战累计积分的排行和奖励
This commit is contained in:
parent
3ffbcb44e0
commit
08c3e422c9
@ -172,7 +172,7 @@ class ExamController extends BaseController {
|
|||||||
session: history.id,
|
session: history.id,
|
||||||
}
|
}
|
||||||
await history.save()
|
await history.save()
|
||||||
await updateExamRank(rankObj)
|
const { total } = await updateExamRank(rankObj)
|
||||||
let { rankList, userRank, rankTotal } = await getRank({
|
let { rankList, userRank, rankTotal } = await getRank({
|
||||||
shop: history.shop,
|
shop: history.shop,
|
||||||
level: history.activityId,
|
level: history.activityId,
|
||||||
@ -187,7 +187,8 @@ class ExamController extends BaseController {
|
|||||||
let examData = await ShopExam.findById(history.activityId)
|
let examData = await ShopExam.findById(history.activityId)
|
||||||
let rewardList = []
|
let rewardList = []
|
||||||
if (examData && examData.rewardInfo && examData.rewardInfo.length > 0) {
|
if (examData && examData.rewardInfo && examData.rewardInfo.length > 0) {
|
||||||
let rewards = examData.getReward(statMap.score)
|
let rewards = examData.getReward(statMap.score, 0)
|
||||||
|
rewards = rewards.concat(examData.getReward(total, 1))
|
||||||
for (let reward of rewards) {
|
for (let reward of rewards) {
|
||||||
let geted = await UserReward.examRewardGeted(history, accountid, reward.id)
|
let geted = await UserReward.examRewardGeted(history, accountid, reward.id)
|
||||||
if (geted) {
|
if (geted) {
|
||||||
|
@ -60,6 +60,13 @@ export class ExamRewardClass extends Base {
|
|||||||
|
|
||||||
@prop({ default: 0 })
|
@prop({ default: 0 })
|
||||||
public count: number
|
public count: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 奖励类型
|
||||||
|
* @type {number} 0: 单局, 1: 累积
|
||||||
|
*/
|
||||||
|
@prop({ default: 0 })
|
||||||
|
public type: number
|
||||||
}
|
}
|
||||||
|
|
||||||
@dbconn()
|
@dbconn()
|
||||||
@ -211,7 +218,7 @@ export class ShopExamClass extends BaseModule {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public getReward(score: number) {
|
public getReward(score: number, type: number) {
|
||||||
if (!this.rewardInfo || this.rewardInfo.length === 0) {
|
if (!this.rewardInfo || this.rewardInfo.length === 0) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import { GameEnv } from '../config/GameEnv'
|
|||||||
import { Shop } from '../models/shop/Shop'
|
import { Shop } from '../models/shop/Shop'
|
||||||
import { mission_vo } from '../config/parsers/mission_vo'
|
import { mission_vo } from '../config/parsers/mission_vo'
|
||||||
import { ShopActivity } from '../models/shop/ShopActivity'
|
import { ShopActivity } from '../models/shop/ShopActivity'
|
||||||
import { getAccountRank, getRankCount, getRankList, updateRank } from './Rank'
|
import { getAccountRank, getRankCount, getRankList, updateRank, updateTotalRank } from './Rank'
|
||||||
import { PuzzleRank } from '../models/match/PuzzleRank'
|
import { PuzzleRank } from '../models/match/PuzzleRank'
|
||||||
import { UserReward } from '../models/UserReward'
|
import { UserReward } from '../models/UserReward'
|
||||||
import { GameUser } from '../models/GameUser'
|
import { GameUser } from '../models/GameUser'
|
||||||
@ -197,8 +197,11 @@ export async function updateExamRank({
|
|||||||
mode: number
|
mode: number
|
||||||
session: string
|
session: string
|
||||||
}) {
|
}) {
|
||||||
const totalKey = rankKey(shop, level, mode)
|
const singleKey = rankKey(shop, level, mode)
|
||||||
await updateRank(accountId, score, totalKey)
|
let single = await updateRank(accountId, score, singleKey)
|
||||||
|
const totalKey = rankKey(shop, level + '_total', mode)
|
||||||
|
let total = await updateTotalRank(accountId, score, totalKey)
|
||||||
|
return { single, total }
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getRank({
|
export async function getRank({
|
||||||
|
@ -26,6 +26,21 @@ export async function updateRank(accountId: string, score: number, subKey?: stri
|
|||||||
return Math.max(score, scoreOld)
|
return Math.max(score, scoreOld)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新累计的排行榜
|
||||||
|
* @param {string} accountId
|
||||||
|
* @param {number} score
|
||||||
|
* @param {string} subKey
|
||||||
|
* @return {Promise<number>}
|
||||||
|
*/
|
||||||
|
export async function updateTotalRank(accountId: string, score: number, subKey?: string) {
|
||||||
|
let scoreOld = await getAccountScore(accountId, subKey)
|
||||||
|
score += scoreOld
|
||||||
|
let scoreL = parseFloat(`${score | 0}.${MAX_TIME - Date.now()}`)
|
||||||
|
await new RedisClient().zadd(generateRankKey(subKey), scoreL, accountId)
|
||||||
|
return score
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取指定分数段的玩家
|
* 获取指定分数段的玩家
|
||||||
* @param {number} min
|
* @param {number} min
|
||||||
|
Loading…
x
Reference in New Issue
Block a user