扫雷人数
This commit is contained in:
parent
1af8bc7315
commit
51c6e872f3
@ -607,7 +607,6 @@ export default {
|
|||||||
this.addLog('system', this.isSpectator ? '🔭 正在切入观察视角...' : '🚪 正在恢复战局...');
|
this.addLog('system', this.isSpectator ? '🔭 正在切入观察视角...' : '🚪 正在恢复战局...');
|
||||||
try {
|
try {
|
||||||
await nakamaManager.joinMatch(this.matchId);
|
await nakamaManager.joinMatch(this.matchId);
|
||||||
// 加入成功,确保缓存是最新的
|
|
||||||
uni.setStorageSync('minesweeper_last_match_id', this.matchId);
|
uni.setStorageSync('minesweeper_last_match_id', this.matchId);
|
||||||
this.addLog('system', '✅ 接入成功');
|
this.addLog('system', '✅ 接入成功');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -620,6 +619,13 @@ export default {
|
|||||||
uni.removeStorageSync('minesweeper_last_match_id');
|
uni.removeStorageSync('minesweeper_last_match_id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 加入大厅频道用于统计在线人数
|
||||||
|
this.joinLobby();
|
||||||
|
|
||||||
|
// 启动在线人数轮询
|
||||||
|
this.startOnlineCountPolling();
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[初始化错误]', e);
|
console.error('[初始化错误]', e);
|
||||||
this.addLog('system', '❌ 初始化失败: ' + e.message);
|
this.addLog('system', '❌ 初始化失败: ' + e.message);
|
||||||
@ -1086,6 +1092,24 @@ export default {
|
|||||||
console.warn('获取在线人数失败:', e);
|
console.warn('获取在线人数失败:', e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async joinLobby() {
|
||||||
|
try {
|
||||||
|
// 加入 minesweeper_lobby 频道, Type 1 (Room), Persistence True, Hidden False
|
||||||
|
await nakamaManager.joinChat('minesweeper_lobby', 1, true, false);
|
||||||
|
console.log('Successfully joined minesweeper lobby');
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to join lobby channel:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
startOnlineCountPolling() {
|
||||||
|
if (this.onlineCountInterval) clearInterval(this.onlineCountInterval);
|
||||||
|
this.fetchOnlineCount(); // Fetch immediately
|
||||||
|
this.onlineCountInterval = setInterval(() => {
|
||||||
|
if (this.isConnected) {
|
||||||
|
this.fetchOnlineCount();
|
||||||
|
}
|
||||||
|
}, 5000); // Poll every 5 seconds
|
||||||
|
},
|
||||||
getItemIcon(itemId) {
|
getItemIcon(itemId) {
|
||||||
const map = { medkit: '💊', bomb_timer: '⏰', poison: '☠️', shield: '🛡️', skip: '⏭️', magnifier: '🔍', knife: '🔪', revive: '💖', lightning: '⚡', chest: '📦', curse: '👻' };
|
const map = { medkit: '💊', bomb_timer: '⏰', poison: '☠️', shield: '🛡️', skip: '⏭️', magnifier: '🔍', knife: '🔪', revive: '💖', lightning: '⚡', chest: '📦', curse: '👻' };
|
||||||
return map[itemId] || '🎁';
|
return map[itemId] || '🎁';
|
||||||
|
|||||||
@ -379,6 +379,27 @@ class NakamaManager {
|
|||||||
return response.match;
|
return response.match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加入聊天频道
|
||||||
|
* @param target 频道名称 (e.g., "minesweeper_lobby")
|
||||||
|
* @param type 频道类型 (1=Room, 2=Direct, 3=Group)
|
||||||
|
* @param persistence 是否持久化
|
||||||
|
* @param hidden 是否隐身
|
||||||
|
*/
|
||||||
|
async joinChat(target, type, persistence, hidden) {
|
||||||
|
console.log(`[Nakama] Joining chat channel: ${target}`);
|
||||||
|
const response = await this._send({
|
||||||
|
channel_join: {
|
||||||
|
target: target,
|
||||||
|
type: type,
|
||||||
|
persistence: persistence,
|
||||||
|
hidden: hidden
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console.log('[Nakama] Joined channel:', response.channel?.id);
|
||||||
|
return response.channel;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调用 RPC
|
* 调用 RPC
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user