SocketPlayer.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import PIFS from "../../PIFS";
  2. import MatchView from "../../Views/MatchView";
  3. import { JCMGO } from "../Core/JCMGO"
  4. export default class SocketPlayer extends JCMGO.SocketClient {
  5. public static quicklyMatch = false;
  6. constructor() {
  7. super();
  8. // this.connect("ws://192.168.101.3:10086/JCMiniGameOnline?gameId=test");
  9. this.connect("wss://www.9527fun.cn/JCMiniGameOnline?gameId=电锯惊魂");
  10. }
  11. protected onLoad() {
  12. console.warn("onLoad");
  13. this.requestMatchRoom();
  14. }
  15. protected onReload() {
  16. console.warn("onReload");
  17. }
  18. protected onDestroy() {
  19. console.warn("onDestroy");
  20. }
  21. protected onMiss() {
  22. console.warn("onMiss");
  23. }
  24. protected onRoomAddPlayer(e: JCMGO.BroadcastEvent<JCMGO.RoomAddPlayerBst>): void {
  25. window.gameSystem.onRoomAddPlayer(e.data);
  26. }
  27. protected onRoomRemovePlayer(e: JCMGO.BroadcastEvent<JCMGO.RoomRemovePlayerBst>): void {
  28. window.gameSystem.onRoomRemovePlayer(e.data);
  29. }
  30. protected onRoomEndMatching(e: JCMGO.BroadcastEvent<JCMGO.RoomEndMatchingBst>): void {
  31. window.gameSystem.completeMatching(e.data);
  32. window.gm.scheduleOnce(this.startFrameSync.bind(this), SocketPlayer.quicklyMatch ? 0 : 2);
  33. }
  34. protected onFrameSyncStart(): void {
  35. window.gameSystem.startGame();
  36. }
  37. protected onRecvFrame(e: JCMGO.BroadcastEvent<JCMGO.Frame>): void {
  38. window.gameSystem.handleFrame(e.data);
  39. }
  40. private _hasRequestMatchRoom = false;
  41. /**请求匹配进入房间 */
  42. public requestMatchRoom() {
  43. if (!MatchView.isGameInited) return;
  44. if (!this.isValid) return;
  45. if (this._hasRequestMatchRoom) return;
  46. this._hasRequestMatchRoom = true;
  47. this.singlePersonRandomMatching({
  48. playerInfo: PIFS.myPlayerInfo,
  49. matchRoomConfig: {
  50. type: "4人自由战斗",
  51. maxMembers: 4,
  52. syncFrameRate: 30,
  53. maxMatchingTime: SocketPlayer.quicklyMatch ? 0 : 6000
  54. }
  55. });
  56. }
  57. }