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