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