修改检查游戏结束的逻辑

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