From b3afa40391c68dc4a250eb187601ba4ef34e4687 Mon Sep 17 00:00:00 2001 From: zhl Date: Fri, 30 Apr 2021 15:19:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=B2=A1=E6=9C=89=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E6=9B=B4=E6=96=B0=E5=88=86=E6=95=B0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/puzzle.controller.ts | 6 +++--- src/services/GameLogic.ts | 20 ++++++++++++++------ src/services/WsSvr.ts | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/api/controllers/puzzle.controller.ts b/src/api/controllers/puzzle.controller.ts index b1c30b3..bf977c6 100644 --- a/src/api/controllers/puzzle.controller.ts +++ b/src/api/controllers/puzzle.controller.ts @@ -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 diff --git a/src/services/GameLogic.ts b/src/services/GameLogic.ts index d7a1e18..4c1a82f 100644 --- a/src/services/GameLogic.ts +++ b/src/services/GameLogic.ts @@ -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} */ -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) } diff --git a/src/services/WsSvr.ts b/src/services/WsSvr.ts index 7a5300d..343ade4 100644 --- a/src/services/WsSvr.ts +++ b/src/services/WsSvr.ts @@ -136,7 +136,7 @@ export async function createRoom(data) { * @return {Promise>} */ export async function joinRoom(data) { - const url = `${apiBase}/matchmake/joinById/puzzle_room` + const url = `${apiBase}/matchmake/joinById/${data.roomId}` return axios.post(url, data) }