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