修正检查所有人是否都已经答了当前题的bug

This commit is contained in:
zhl 2021-05-06 11:27:39 +08:00
parent 81ee1f0316
commit e480435aa4

View File

@ -1,5 +1,6 @@
import { import {
beginGame, closeRoom, beginGame,
closeRoom,
endGame, endGame,
sendQuestion, sendQuestion,
updateRound, updateRound,
@ -34,15 +35,22 @@ export function transformRecord(records: any[]) {
}) })
} }
/**
*
*
* @param history
* @param {string} qid
* @return {boolean}
*/
export function checkSubFinish(history: any, qid: string) { export function checkSubFinish(history: any, qid: string) {
let count = 0
for (let [key, val] of history.members) { for (let [key, val] of history.members) {
if (val.answer?.has(qid)) { if (!val.answer?.has(qid)) {
count ++ return false
} }
} }
return count >= history.questions.length; return true
} }
/** /**
* *
* @param {string} roomId * @param {string} roomId
@ -81,9 +89,9 @@ export async function sendOneQuestion(history: any) {
qdata.no = history.current qdata.no = history.current
await updateRound(roomId, history.current) await updateRound(roomId, history.current)
await sendQuestion(roomId, qdata) await sendQuestion(roomId, qdata)
history.current ++ history.current++
await history.save() await history.save()
new Schedule().beginSchedule(BaseConst.MATCH_ANSWER_TIME, async function (){ new Schedule().beginSchedule(BaseConst.MATCH_ANSWER_TIME, async function () {
let subHistory = await PuzzleSession.findById(history.id) let subHistory = await PuzzleSession.findById(history.id)
let datas = [] let datas = []
for (let [accountid, data] of subHistory.members) { for (let [accountid, data] of subHistory.members) {
@ -91,7 +99,7 @@ export async function sendOneQuestion(history: any) {
data.answer.set(qid, 0) data.answer.set(qid, 0)
data.errorCount++ data.errorCount++
data.comboCount = 0 data.comboCount = 0
datas.push({accountid, score: -1}) datas.push({ accountid, score: -1 })
} }
} }
subHistory.markModified('members') subHistory.markModified('members')