修改检查游戏结束的逻辑

This commit is contained in:
zhl 2021-05-11 11:35:21 +08:00
parent a0f5746af8
commit a2e8c877cd
2 changed files with 22 additions and 8 deletions

View File

@ -19,7 +19,8 @@ import { retry } from '../../utils/promise.util'
import { RoomLockErr } from '../../common/RoomLockErr'
import { Schedule } from '../../clock/Schedule'
import {
calcScore, calcSingleScore,
calcPvpScore,
calcSingleScore,
checkSingleFinish, fetchLevelCfg, fetchSinglePuzzleType,
startGame,
transformRecord, updateSingleRank
@ -36,7 +37,7 @@ class PuzzleController extends BaseController {
async list(req, res) {
let { shop, level, accountid, type } = req.params
level = +level || 1
if (!shop || isObjectId(shop)) {
if (!shop || !isObjectId(shop)) {
throw new ZError(10, '没有店铺id或者店铺id格式不正确, 测试使用: 607ff59d4a4e16687a3b7079')
}
const cfg = fetchLevelCfg(level)
@ -112,7 +113,7 @@ class PuzzleController extends BaseController {
history.markModified('members')
await history.save()
if (mode == 1) {
let score = result ? calcScore(history.scheduleKey, statMap.comboCount) : 0
let score = result ? calcPvpScore(history.scheduleKey, statMap.comboCount) : 0
await broadcast(history.room, 'answer', {accountid, result, score})
await updateScore(history.room, [{accountid, score }])
@ -120,7 +121,7 @@ class PuzzleController extends BaseController {
// await sendOneQuestion(history)
// }
} else if (mode == 0) {
let result = checkSingleFinish(history)
let result = checkSingleFinish(history, accountid)
if (result) {
history.status = 9
//TODO:: 计算积分, 并更新排行榜

View File

@ -111,7 +111,7 @@ export async function sendOneQuestion(history: any) {
}
export function calcScore(timeKey: string, combo: number) {
export function calcPvpScore(timeKey: string, combo: number) {
const time = new Schedule().getLeftTime(timeKey)
const cfg = new GameEnv()
return cfg.pvpBaseScore + time / 100 * cfg.pvpTimeRate + combo * cfg.pvpComboRate
@ -144,12 +144,25 @@ export async function updateSingleRank({shop, level, accountId, score, session,
}
/**
* TODO::
*
* @param history
* @param {string} accountId
* @return {number} 0: 未结束, -1: 失败, 1: 胜利
*/
export function checkSingleFinish(history: any) {
export function checkSingleFinish(history: any, accountId: string): number {
if (history.hasExpired()) {
return -1
}
let cfg = fetchLevelCfg(history.level)
let stat = history.members.get(accountId)
if (stat.rightCount >= cfg.enemy) {
return 1
}
if (stat.errorCount >= cfg.hp) {
return -1
}
return false
return 0
}
/**