修正没有正确更新分数的bug
This commit is contained in:
parent
a0bf2797b6
commit
b3afa40391
@ -164,7 +164,7 @@ class PuzzleController extends BaseController {
|
||||
if (history && !history.hasExpired()) {
|
||||
beginTime = history.begin
|
||||
if (!history.members.has(accountid)) {
|
||||
let rsp = await joinRoom(data)
|
||||
let rsp = await joinRoom({roomId: history.room})
|
||||
if (rsp.status != 200) {
|
||||
new RoomState().unlock(shop)
|
||||
throw new ZError(11, 'error create room')
|
||||
@ -196,7 +196,7 @@ class PuzzleController extends BaseController {
|
||||
history = new PuzzleSession({shop, status: 0, type: 1})
|
||||
let memberData = new PuzzleStatusClass()
|
||||
memberData.sessionId = sessionId
|
||||
history.members.set(accountid, new PuzzleStatusClass())
|
||||
history.members.set(accountid, memberData)
|
||||
history.room = roomId
|
||||
//TODO: 根据配置赋值
|
||||
history.total = 10
|
||||
@ -206,7 +206,7 @@ class PuzzleController extends BaseController {
|
||||
history.type = 1
|
||||
await history.save()
|
||||
new Schedule().beginSchedule(beginSecond, async function () {
|
||||
await startGame(roomId, history)
|
||||
await startGame(roomId, history.id)
|
||||
}, shop)
|
||||
new RoomState().unlock(shop)
|
||||
return roomId
|
||||
|
@ -9,6 +9,7 @@ import { Puzzle } from '../models/content/Puzzle'
|
||||
import { Schedule } from '../clock/Schedule'
|
||||
import { BaseConst } from '../constants/BaseConst'
|
||||
import { QCategoryCache } from './QCategoryCache'
|
||||
import { PuzzleSession } from '../models/match/PuzzleSession'
|
||||
|
||||
|
||||
export function transformRecord(records: any[]) {
|
||||
@ -45,12 +46,13 @@ export function checkSubFinish(history: any, qid: string) {
|
||||
/**
|
||||
* 开始游戏
|
||||
* @param {string} roomId
|
||||
* @param history
|
||||
* @param sessionId
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
export async function startGame(roomId: string, history: any) {
|
||||
await beginGame(roomId, {})
|
||||
export async function startGame(roomId: string, sessionId: string) {
|
||||
let history = await PuzzleSession.findById(sessionId)
|
||||
let records = await Puzzle.randomQuestions({}, history.total)
|
||||
await beginGame(roomId, {})
|
||||
history.questions = records.map(o => o._id)
|
||||
await history.save()
|
||||
new Schedule().beginSchedule(BaseConst.FIST_QUESTION_DELAY, async function () {
|
||||
@ -82,13 +84,19 @@ export async function sendOneQuestion(history: any) {
|
||||
history.current ++
|
||||
await history.save()
|
||||
new Schedule().beginSchedule(BaseConst.MATCH_ANSWER_TIME, async function (){
|
||||
let subHistory = await PuzzleSession.findById(history.id)
|
||||
let datas = []
|
||||
for (let [accountid, data] of history.members) {
|
||||
for (let [accountid, data] of subHistory.members) {
|
||||
if (!data.answer.has(qid)) {
|
||||
data.answer.set(qid, 0)
|
||||
data.errorCount++
|
||||
data.comboCount = 0
|
||||
datas.push({accountid, score: -1})
|
||||
}
|
||||
}
|
||||
await updateScore(history.room, datas)
|
||||
await sendOneQuestion(history)
|
||||
subHistory.markModified('members')
|
||||
await subHistory.save()
|
||||
await updateScore(subHistory.room, datas)
|
||||
await sendOneQuestion(subHistory)
|
||||
}, history.scheduleKey)
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ export async function createRoom(data) {
|
||||
* @return {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
export async function joinRoom(data) {
|
||||
const url = `${apiBase}/matchmake/joinById/puzzle_room`
|
||||
const url = `${apiBase}/matchmake/joinById/${data.roomId}`
|
||||
return axios.post(url, data)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user