ResLogin增加房间内其他玩家数据用于初始化
This commit is contained in:
@@ -50,6 +50,20 @@ export default async function (call: MsgCall<MsgReqLogin>) {
|
||||
lastLoginAt: player.lastLoginAt
|
||||
};
|
||||
|
||||
// 获取房间内其他在线玩家信息
|
||||
const otherOnlinePlayers = playerManager.getOnlinePlayers().filter(p => p.id !== playerId);
|
||||
const otherPlayersInfo: PlayerInfo[] = otherOnlinePlayers.map(p => ({
|
||||
id: p.id,
|
||||
name: p.name,
|
||||
position: gameToClientPosition(p.position),
|
||||
spawnPoint: gameToClientPosition(p.spawnPoint),
|
||||
hp: p.hp,
|
||||
maxHp: p.maxHp,
|
||||
isAlive: p.isAlive,
|
||||
createdAt: p.createdAt,
|
||||
lastLoginAt: p.lastLoginAt
|
||||
}));
|
||||
|
||||
// 广播玩家加入消息给其他在线玩家
|
||||
const { broadcastToAll } = await import('../utils/broadcast');
|
||||
|
||||
@@ -66,7 +80,8 @@ export default async function (call: MsgCall<MsgReqLogin>) {
|
||||
success: true,
|
||||
message: isNewPlayer ? '创建角色成功,欢迎来到游戏世界!' : '登录成功,欢迎回来!',
|
||||
player: playerInfo,
|
||||
isNewPlayer
|
||||
isNewPlayer,
|
||||
otherPlayers: otherPlayersInfo
|
||||
};
|
||||
|
||||
call.conn.sendMsg('ResLogin', response);
|
||||
|
||||
@@ -86,7 +86,7 @@ export default async function (call: MsgCall<MsgReqMove>) {
|
||||
timestamp: Date.now()
|
||||
};
|
||||
|
||||
broadcastToAll('MsgPlayerMove', moveMsg, call.conn.id);
|
||||
broadcastToAll('PlayerMove', moveMsg, call.conn.id);
|
||||
|
||||
// 返回成功结果
|
||||
call.conn.sendMsg('ResMove', {
|
||||
|
||||
Reference in New Issue
Block a user