修改检查游戏结束的逻辑
This commit is contained in:
parent
a0f5746af8
commit
a2e8c877cd
@ -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:: 计算积分, 并更新排行榜
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user