玩家加入房间时, 带上自己信息
This commit is contained in:
parent
e9cd01b715
commit
4fb46bb48d
@ -29,6 +29,7 @@ import {
|
|||||||
} from '../../services/GameLogic'
|
} from '../../services/GameLogic'
|
||||||
import { Shop, validShopId } from '../../models/shop/Shop'
|
import { Shop, validShopId } from '../../models/shop/Shop'
|
||||||
import { ShopActivity } from '../../models/shop/ShopActivity'
|
import { ShopActivity } from '../../models/shop/ShopActivity'
|
||||||
|
import { GameUser } from '../../models/GameUser'
|
||||||
|
|
||||||
|
|
||||||
class PuzzleController extends BaseController {
|
class PuzzleController extends BaseController {
|
||||||
@ -226,6 +227,11 @@ class PuzzleController extends BaseController {
|
|||||||
}
|
}
|
||||||
let activity = await ShopActivity.findById(aid)
|
let activity = await ShopActivity.findById(aid)
|
||||||
let shopData = await Shop.fetchByID(shop)
|
let shopData = await Shop.fetchByID(shop)
|
||||||
|
let gameUser = await GameUser.getByAccountID(accountid)
|
||||||
|
if (gameUser) {
|
||||||
|
data.nickname = gameUser.nickname
|
||||||
|
data.avatar = gameUser.avatar
|
||||||
|
}
|
||||||
shop = shopData.id
|
shop = shopData.id
|
||||||
if (!activity) {
|
if (!activity) {
|
||||||
throw new ZError(13, 'activity not found')
|
throw new ZError(13, 'activity not found')
|
||||||
@ -243,7 +249,7 @@ class PuzzleController extends BaseController {
|
|||||||
beginTime = history.begin
|
beginTime = history.begin
|
||||||
sessionMatch = history.id
|
sessionMatch = history.id
|
||||||
if (!history.members.has(accountid)) {
|
if (!history.members.has(accountid)) {
|
||||||
let rsp = await joinRoom({roomId: history.room})
|
let rsp = await joinRoom(Object.assign(data, {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')
|
||||||
|
@ -3,7 +3,7 @@ import {
|
|||||||
getModelForClass,
|
getModelForClass,
|
||||||
index,
|
index,
|
||||||
modelOptions,
|
modelOptions,
|
||||||
prop
|
prop, ReturnModelType
|
||||||
} from '@typegoose/typegoose'
|
} from '@typegoose/typegoose'
|
||||||
import { BaseModule } from './Base'
|
import { BaseModule } from './Base'
|
||||||
|
|
||||||
@ -39,7 +39,10 @@ class GameUserClass extends BaseModule {
|
|||||||
@prop()
|
@prop()
|
||||||
public lockedTime?: Date;
|
public lockedTime?: Date;
|
||||||
|
|
||||||
|
public static async getByAccountID(this: ReturnModelType<typeof GameUserClass>, accountId: string) {
|
||||||
|
let records = await this.find({accountId}).limit(1)
|
||||||
|
return records.length > 0 ? records[0] : null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const GameUser = getModelForClass(GameUserClass, {existingConnection: GameUserClass.db});
|
export const GameUser = getModelForClass(GameUserClass, {existingConnection: GameUserClass.db});
|
||||||
|
@ -172,6 +172,26 @@ export async function updateScore(roomId: string, data: any) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户信息
|
||||||
|
* @param {string} roomId
|
||||||
|
* @param data
|
||||||
|
*/
|
||||||
|
export async function updateInfo(roomId: string, data: any) {
|
||||||
|
console.log(`updateInfo: ${roomId}, ${JSON.stringify(data)}`)
|
||||||
|
const url = `${apiBase}/room/call`
|
||||||
|
const args = [data]
|
||||||
|
const params = {
|
||||||
|
roomId,
|
||||||
|
method: 'updatePlayerInfo',
|
||||||
|
args: JSON.stringify(args)
|
||||||
|
}
|
||||||
|
return axios.post(url, params)
|
||||||
|
.then(res => {
|
||||||
|
return res.data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新游戏轮数
|
* 更新游戏轮数
|
||||||
* @param {string} roomId
|
* @param {string} roomId
|
||||||
|
Loading…
x
Reference in New Issue
Block a user