using System;
using System.Collections.Generic;
using System.Linq;
namespace ET.Server
{
///
/// 黄冈晃晃 出牌
///
[MessageHandler(SceneType.Game)]
public class C2G_HGHHDisCardHandler : AMRpcHandler
{
protected override async ETTask Run(Session session, C2G_HGHHDisCard request, G2C_HGHHDisCard response, Action reply)
{
Player player = session.GetComponent().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().Get(player.RoomId);
if (room == null)
{
response.Error = ErrorCode.ERR_OperationError;
response.Message = "请求的房间不存在或已解散...";
reply();
return;
}
// 玩家房间是否已开始
HGHHComponent hghhComponent = room.GetComponent();
if (hghhComponent != null && hghhComponent.State != 2)
{
response.Error = ErrorCode.ERR_OperationError;
response.Message = "房间不在游戏中,不可出牌...";
reply();
return;
}
// 玩家状态
if (player.State != 2)
{
response.Error = ErrorCode.ERR_OperationError;
response.Message = "玩家不在游戏中,不可出牌...";
reply();
return;
}
if (request.Card <= 0 || !HGHHConst.Values.Contains(request.Card))
{
response.Error = ErrorCode.ERR_OperationError;
response.Message = "出牌错误...";
reply();
return;
}
// 判断玩家是否可出牌
if (hghhComponent.CurrentPlayer.Id != player.Id)
{
response.Error = ErrorCode.ERR_OperationError;
response.Message = "不是当前操作玩家,出牌错误...";
reply();
return;
}
// 是否有动作,有动作无法出牌
if (player.ActInfo is { Count: > 0 })
{
response.Error = ErrorCode.ERR_OperationError;
response.Message = "有动作,请先操作动作,出牌错误...";
reply();
return;
}
// 出牌
hghhComponent.DisCard(room, player, request.Card, false);
// 返回
reply();
await ETTask.CompletedTask;
}
}
}