1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ET.Server
- {
- /// <summary>
- /// 黄冈晃晃 准备
- /// </summary>
- [MessageHandler(SceneType.Game)]
- public class C2G_HGHHReadyHandler : AMRpcHandler<C2G_HGHHReady, G2C_HGHHReady>
- {
- protected override async ETTask Run(Session session, C2G_HGHHReady request, G2C_HGHHReady response, Action reply)
- {
- Player player = session.GetComponent<SessionPlayerComponent>().GetMyPlayer();
- if (player == null)
- {
- response.Error = ErrorCode.ERR_OperationError;
- response.Message = "玩家不存在或离线...";
- reply();
- return;
- }
-
- // 玩家是否进入房间
- if (player.RoomId <= 0)
- {
- response.Error = ErrorCode.ERR_OperationError;
- response.Message = "玩家不在房间,不可准备...";
- reply();
- return;
- }
- Scene scene = session.DomainScene();
-
- // 房间是否能找到
- Room room = scene.GetComponent<GameRoomComponent>().Get(player.RoomId);
- if (room == null)
- {
- response.Error = ErrorCode.ERR_OperationError;
- response.Message = "请求的房间不存在或已解散...";
- reply();
- return;
- }
-
- // 玩家房间是否已开始
- HGHuangHuangComponent hgHuangHuangComponent = room.GetComponent<HGHuangHuangComponent>();
- if (hgHuangHuangComponent != null && hgHuangHuangComponent.State != 0)
- {
- response.Error = ErrorCode.ERR_OperationError;
- response.Message = "房间已开始,不可准备...";
- reply();
- return;
- }
- player.State = 1;
-
- Log.Info($"id:{player.Id}, 玩家:{player.Name}, 状态:已准备,通知所有玩家");
-
- // 广播
- foreach (Player p in room.GetAllPlayers().Values.Where(p => p != null))
- {
- MessageHelper.SendToClient(p, new G2C_HGHHReadyPush(){info = ProtoHelper.RoomToProto(room, p, null)});
- }
-
- // 返回
- response.IsReady = true;
- reply();
- await ETTask.CompletedTask;
- }
- }
- }
|