C2G_HGHHReadyHandler.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace ET.Server
  5. {
  6. /// <summary>
  7. /// 黄冈晃晃 准备
  8. /// </summary>
  9. [MessageHandler(SceneType.Game)]
  10. public class C2G_HGHHReadyHandler : AMRpcHandler<C2G_HGHHReady, G2C_HGHHReady>
  11. {
  12. protected override async ETTask Run(Session session, C2G_HGHHReady request, G2C_HGHHReady response, Action reply)
  13. {
  14. Player player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
  15. if (player == null)
  16. {
  17. response.Error = ErrorCode.ERR_OperationError;
  18. response.Message = "玩家不存在或离线...";
  19. reply();
  20. return;
  21. }
  22. // 玩家是否进入房间
  23. if (player.RoomId <= 0)
  24. {
  25. response.Error = ErrorCode.ERR_OperationError;
  26. response.Message = "玩家不在房间,不可准备...";
  27. reply();
  28. return;
  29. }
  30. Scene scene = session.DomainScene();
  31. // 房间是否能找到
  32. Room room = scene.GetComponent<GameRoomComponent>().Get(player.RoomId);
  33. if (room == null)
  34. {
  35. response.Error = ErrorCode.ERR_OperationError;
  36. response.Message = "请求的房间不存在或已解散...";
  37. reply();
  38. return;
  39. }
  40. // 玩家房间是否已开始
  41. HGHuangHuangComponent hgHuangHuangComponent = room.GetComponent<HGHuangHuangComponent>();
  42. if (hgHuangHuangComponent != null && hgHuangHuangComponent.State != 0)
  43. {
  44. response.Error = ErrorCode.ERR_OperationError;
  45. response.Message = "房间已开始,不可准备...";
  46. reply();
  47. return;
  48. }
  49. player.State = 1;
  50. Log.Info($"id:{player.Id}, 玩家:{player.Name}, 状态:已准备,通知所有玩家");
  51. // 广播
  52. foreach (Player p in room.GetAllPlayers().Values.Where(p => p != null))
  53. {
  54. MessageHelper.SendToClient(p, new G2C_HGHHReadyPush(){info = ProtoHelper.RoomToProto(room, p, null)});
  55. }
  56. // 返回
  57. response.IsReady = true;
  58. reply();
  59. await ETTask.CompletedTask;
  60. }
  61. }
  62. }