import { _decorator, Component } from 'cc'; import { PlatformSession } from '../framework/platform/session.ts'; import { RoomRPCBus } from '../framework/platform/room-rpc-bus.ts'; import { EventBus } from '../framework/core/events.ts'; import type { NetClientEvents } from '../framework/net/net-client.ts'; import type { PlayerState } from '../framework/platform/stores/types.ts'; const { ccclass } = _decorator; const PLAYER_A: PlayerState = { playerid: 100, nickname: '甲', avatar: '', sex: 0, bean: 0, roomcard: 0, score: 0, charm: 0, taskstate: 0, advanced: 0, bankpower: 0, bank: 0, bankpwd: 0, ip: '', sign: null, tel: null, invitecode: null, initCard: 0, initBean: 0, } as any; const PLAYER_B: PlayerState = { playerid: 200, nickname: '乙', avatar: '', sex: 0, bean: 0, roomcard: 0, score: 0, charm: 0, taskstate: 0, advanced: 0, bankpower: 0, bank: 0, bankpwd: 0, ip: '', sign: null, tel: null, invitecode: null, initCard: 0, initBean: 0, } as any; @ccclass('RoomEventProbe') export class RoomEventProbe extends Component { start(): void { const bus = new EventBus(); const session = new PlatformSession(bus); session.room.state.subscribe((room) => { console.log('[RoomProbe] RoomStore changed:'); console.log(' inRoom=' + room.inRoom + ' roomcode=' + room.roomcode); console.log(' seat=' + room.seat + ' isowner=' + room.isowner); console.log(' state=' + room.state + ' isbattle=' + room.isbattle); console.log(' players.length=' + room.players.length); for (let i = 0; i < room.players.length; i++) { const p = room.players[i]; console.log(' players[' + i + ']=' + (p ? 'playerid=' + p.playerid : 'null')); } }); const roomBus = new RoomRPCBus(bus, session); roomBus.start(); console.log('[RoomProbe] RoomRPCBus started'); this.scheduleOnce(() => { // 0. 用 applyRecovery 设初始 4 玩家数组(seat 1 = 甲, seat 2 = 乙) console.log('[RoomProbe] init: applyRecovery 4 玩家数组'); session.room.applyRecovery({ roomcode: 'R1', seat: 1, isowner: 1, isbattle: 0, state: 0, players: [null, PLAYER_A, PLAYER_B, null] as any, } as any); this.scheduleOnce(() => { console.log('[RoomProbe] test 1: other_join_room (seat=3)'); bus.emit('message', { route: 'room', rpc: 'other_join_room', data: { seat: 3, playerid: 300, nickname: '丙' } as any } as any); this.scheduleOnce(() => { console.log('[RoomProbe] test 2: other_exit_room (seat=3)'); bus.emit('message', { route: 'room', rpc: 'other_exit_room', data: { seat: 3 } as any } as any); this.scheduleOnce(() => { console.log('[RoomProbe] test 3: self_apply_free_room'); bus.emit('message', { route: 'room', rpc: 'self_apply_free_room', data: { applyer: 1 } as any } as any); this.scheduleOnce(() => { console.log('[RoomProbe] test 4: free_room'); bus.emit('message', { route: 'room', rpc: 'free_room', data: { result: 1 } as any } as any); console.log('[RoomProbe] all 4 tests done'); }, 0.2); }, 0.2); }, 0.2); }, 0.2); }, 0.1); } }