修改加入房间的逻辑
This commit is contained in:
parent
00866d0f7d
commit
7fb1ed3a5f
@ -9,7 +9,7 @@ import { ZError } from '../../common/ZError'
|
||||
import { BaseConst } from '../../constants/BaseConst'
|
||||
import { mission_vo } from '../../config/parsers/mission_vo'
|
||||
import {
|
||||
createRoom,
|
||||
createRoom, joinRoom,
|
||||
updateScore
|
||||
} from '../../services/WsSvr'
|
||||
import { RoomState } from '../../services/RoomState'
|
||||
@ -160,13 +160,31 @@ class PuzzleController extends BaseController {
|
||||
throw new RoomLockErr('')
|
||||
}
|
||||
new RoomState().lock(shop)
|
||||
let history = await PuzzleSession.findOne({ shop, status: 0, type: 1 })
|
||||
let history = await PuzzleSession.findOne({ shop, status: {$in: [0, 1]}, type: 1 })
|
||||
if (history && !history.hasExpired()) {
|
||||
new RoomState().unlock(shop)
|
||||
beginTime = history.begin
|
||||
history.members.set(accountid, new PuzzleStatusClass())
|
||||
await history.save()
|
||||
return roomId = history.room
|
||||
if (!history.members.has(accountid)) {
|
||||
let rsp = await joinRoom(data)
|
||||
if (rsp.status != 200) {
|
||||
new RoomState().unlock(shop)
|
||||
throw new ZError(11, 'error create room')
|
||||
}
|
||||
let memberData = new PuzzleStatusClass()
|
||||
sessionId = rsp.data?.sessionId
|
||||
memberData.sessionId = sessionId
|
||||
history.members.set(accountid, memberData)
|
||||
history.markModified('members')
|
||||
await history.save()
|
||||
new RoomState().unlock(shop)
|
||||
return roomId = history.room
|
||||
} else {
|
||||
let memberData = history.members.get(accountid)
|
||||
sessionId = memberData.sessionId
|
||||
roomId = history.room
|
||||
new RoomState().unlock(shop)
|
||||
return
|
||||
}
|
||||
|
||||
} else {
|
||||
let rsp = await createRoom(data)
|
||||
if (rsp.status != 200) {
|
||||
@ -176,6 +194,8 @@ class PuzzleController extends BaseController {
|
||||
roomId = rsp.data?.room?.roomId
|
||||
sessionId = rsp.data?.sessionId
|
||||
history = new PuzzleSession({shop, status: 0, type: 1})
|
||||
let memberData = new PuzzleStatusClass()
|
||||
memberData.sessionId = sessionId
|
||||
history.members.set(accountid, new PuzzleStatusClass())
|
||||
history.room = roomId
|
||||
//TODO: 根据配置赋值
|
||||
|
@ -37,6 +37,10 @@ export class PuzzleStatusClass {
|
||||
*/
|
||||
@prop({default: 0})
|
||||
maxCombo: number
|
||||
|
||||
@prop()
|
||||
sessionId: string
|
||||
|
||||
}
|
||||
// @ts-ignore
|
||||
export interface PuzzleSessionClass extends Base, TimeStamps {
|
||||
|
@ -60,6 +60,8 @@ export async function sendOneQuestion(history: any) {
|
||||
new Schedule().stopSchedule(history.scheduleKey)
|
||||
if (history.current >= history.questions.length) {
|
||||
console.log('match over')
|
||||
history.status = 9
|
||||
await history.save()
|
||||
await endGame(roomId, {})
|
||||
return
|
||||
}
|
||||
|
@ -110,6 +110,16 @@ export async function createRoom(data) {
|
||||
return axios.post(url, data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入房间
|
||||
* @param data
|
||||
* @return {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
export async function joinRoom(data) {
|
||||
const url = `${apiBase}/matchmake/joinById/puzzle_room`
|
||||
return axios.post(url, data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一条问题
|
||||
* @param {string} roomId
|
||||
|
Loading…
x
Reference in New Issue
Block a user