Browse Source

优化出牌逻辑

johnclot69 1 month ago
parent
commit
2540fa6c0b
1 changed files with 179 additions and 183 deletions
  1. 179 183
      DotNet/Hotfix/Scenes/Game/Room/HGHHComponentSystem.cs

+ 179 - 183
DotNet/Hotfix/Scenes/Game/Room/HGHHComponentSystem.cs

@@ -359,230 +359,226 @@ namespace ET.Server
             }
             }
             using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.PlayerOperation, player.Id))
             using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.PlayerOperation, player.Id))
             {
             {
-                if (self.CurrentPlayer.Id == player.Id && self.DrawCardPlayer.Id == player.Id)
+                if (self.CurrentPlayer.Id != player.Id || self.DrawCardPlayer.Id != player.Id)
                 {
                 {
-                    Log.Info($"出牌... 玩家ID:{player.Id}, 位置:{player.Pos}, 手牌大小:{player.RemainCards.Length}, 手牌信息: {string.Join(", ", player.RemainCards)}");
+                    return;
+                }
+
+                Log.Info($"出牌... 玩家ID:{player.Id}, 位置:{player.Pos}, 手牌大小:{player.RemainCards.Length}, 手牌信息: {string.Join(", ", player.RemainCards)}");
                     
                     
-                    // 自动出牌
-                    if (flag)
+                // 自动出牌
+                if (flag)
+                {
+                    if (self.PengPlayer != null && self.PengPlayer.Id == player.Id)
                     {
                     {
-                        if (self.PengPlayer != null && self.PengPlayer.Id == player.Id)
-                        {
-                            self.PengPlayer = null;
-                            int[] tmpCard = new int[player.RemainCards.Length];
-                            Array.Copy(player.RemainCards, 0, tmpCard, 0, player.RemainCards.Length);
-                            Array.Sort(tmpCard);
-                            card = tmpCard[^1];
-                        }
-                        else
-                        {
-                            card = player.RemainCards[^1];
-                        }
-
-                        // todo 真人托管状态
+                        self.PengPlayer = null;
+                        int[] tmpCard = new int[player.RemainCards.Length];
+                        Array.Copy(player.RemainCards, 0, tmpCard, 0, player.RemainCards.Length);
+                        Array.Sort(tmpCard);
+                        card = tmpCard[^1];
                     }
                     }
-                    
-                    if (!player.RemainCards.Contains(card))
+                    else
                     {
                     {
-                        Log.Error($"出牌错误,玩家的牌不在手中...");
-                        return;
+                        card = player.RemainCards[^1];
                     }
                     }
+
+                    // todo 真人托管状态
+                }
                     
                     
-                    // 玩家出牌
-                    player.RemainCards = CardHelper.Remove(player.RemainCards, card);
-                    player.DisCards = CardHelper.Add(player.DisCards, card);
-                    player.DiscardCount += 1;
-                    self.DisCard = card;
-                    self.DisCardPlayer = player;
-                    self.PengPlayer = null;
+                if (!player.RemainCards.Contains(card))
+                {
+                    Log.Error($"出牌错误,玩家的牌不在手中...");
+                    return;
+                }
                     
                     
-                    // // 给出牌人广播
-                    // MessageHelper.SendToClient(player, new G2C_HGHHDisCardPush(){info = ProtoHelper.RoomToProto(room, player, player)});
+                // 玩家出牌
+                player.RemainCards = CardHelper.Remove(player.RemainCards, card);
+                player.DisCards = CardHelper.Add(player.DisCards, card);
+                player.DiscardCount += 1;
+                self.DisCard = card;
+                self.DisCardPlayer = player;
+                self.PengPlayer = null;
                     
                     
-                    self.CanHuIds.Clear();
-                    self.ClickHuIds.Clear();
-                    self.OperableList.Clear();
-                    self.CanPgIds.Clear();
-                    self.CleanUserAct();
+                self.CanHuIds.Clear();
+                self.ClickHuIds.Clear();
+                self.OperableList.Clear();
+                self.CanPgIds.Clear();
+                self.CleanUserAct();
                     
                     
-                    // 检测其它三家的动作
-                    int[] nextPos = room.GetSorcPos(player.Pos);
-                    foreach (int index in nextPos)
+                // 检测其它三家的动作
+                int[] nextPos = room.GetSorcPos(player.Pos);
+                foreach (int index in nextPos)
+                {
+                    Player otherPlayer = self.Players[index];
+                    if (otherPlayer is not { State: 2 })
                     {
                     {
-                        Player otherPlayer = self.Players[index];
-                        if (otherPlayer is not { State: 2 })
-                        {
-                            continue;
-                        }
+                        continue;
+                    }
                         
                         
-                        // 吃,碰,杠,胡,过
-                        int[] act = new int[5];
-                        List<Struct.Kezi> gangs = new List<Struct.Kezi>();
-                        List<Struct.Kezi> pengs = new List<Struct.Kezi>();
-                        List<Struct.Kezi> chis = new List<Struct.Kezi>();
-                        // todo 玩家听牌状态不允许有动作
-                        // 出牌是否杠
-                        gangs = HGHHHelper.IsDiscardGang(otherPlayer, card, player.Id);
-                        // 出牌是否碰
-                        pengs = HGHHHelper.IsDiscardPeng(otherPlayer, card, player.Id);
-                        // 出牌是否吃
-                        if (otherPlayer.Pos == nextPos[0])
-                        {
-                            chis = HGHHHelper.IsDiscardChi(otherPlayer, card, player.Id);
-                        }
+                    // 吃,碰,杠,胡,过
+                    int[] act = new int[5];
+                    List<Struct.Kezi> gangs = new List<Struct.Kezi>();
+                    List<Struct.Kezi> pengs = new List<Struct.Kezi>();
+                    List<Struct.Kezi> chis = new List<Struct.Kezi>();
+                    // todo 玩家听牌状态不允许有动作
+                    // 出牌是否杠
+                    gangs = HGHHHelper.IsDiscardGang(otherPlayer, card, player.Id);
+                    // 出牌是否碰
+                    pengs = HGHHHelper.IsDiscardPeng(otherPlayer, card, player.Id);
+                    // 出牌是否吃
+                    if (otherPlayer.Pos == nextPos[0])
+                    {
+                        chis = HGHHHelper.IsDiscardChi(otherPlayer, card, player.Id);
+                    }
 
 
-                        bool hasAct = false;
+                    bool hasAct = false;
                                 
                                 
-                        int[] tmpCards = new int[otherPlayer.RemainCards.Length];
-                        Array.Copy(otherPlayer.RemainCards, 0, tmpCards, 0, otherPlayer.RemainCards.Length);
-                        tmpCards = CardHelper.Add(tmpCards, card);
-                        // 校验胡牌
-                        Struct.HuRes huType = HGHHHelper.CheckHu(tmpCards);
+                    int[] tmpCards = new int[otherPlayer.RemainCards.Length];
+                    Array.Copy(otherPlayer.RemainCards, 0, tmpCards, 0, otherPlayer.RemainCards.Length);
+                    tmpCards = CardHelper.Add(tmpCards, card);
+                    // 校验胡牌
+                    Struct.HuRes huType = HGHHHelper.CheckHu(tmpCards);
 
 
-                        if (huType.Type != HGHHConst.HU_DEFAULT)
+                    if (huType.Type != HGHHConst.HU_DEFAULT)
+                    {
+                        hasAct = true;
+                        act[3] = 1;
+                        // 放入可胡玩家列表
+                        if (!self.CanHuIds.Contains(otherPlayer.Id))
                         {
                         {
-                            hasAct = true;
-                            act[3] = 1;
-                            // 放入可胡玩家列表
-                            if (!self.CanHuIds.Contains(otherPlayer.Id))
-                            {
-                                self.CanHuIds.Add(otherPlayer.Id);
-                            }
-                            // 加入可操作玩家list
-                            if (!self.OperableList.Contains(otherPlayer.Id))
-                            {
-                                self.OperableList.Add(otherPlayer.Id);
-                            }
+                            self.CanHuIds.Add(otherPlayer.Id);
                         }
                         }
-                        // 是否杠
-                        if (gangs.Count > 0)
+                        // 加入可操作玩家list
+                        if (!self.OperableList.Contains(otherPlayer.Id))
                         {
                         {
-                            hasAct = true;
-                            act[2] = 1;
-                            foreach (Struct.Kezi kezi in gangs.Where(kezi => kezi is { Card: >= 0 }))
-                            {
-                                otherPlayer.ActInfo.Add(new Struct.Kezi(kezi.Type, kezi.Card, kezi.PlayerId));
-                            }
+                            self.OperableList.Add(otherPlayer.Id);
                         }
                         }
-                        // 是否碰
-                        if (pengs.Count > 0)
+                    }
+                    // 是否杠
+                    if (gangs.Count > 0)
+                    {
+                        hasAct = true;
+                        act[2] = 1;
+                        foreach (Struct.Kezi kezi in gangs.Where(kezi => kezi is { Card: >= 0 }))
                         {
                         {
-                            hasAct = true;
-                            act[1] = 1;
-                            foreach (Struct.Kezi kezi in pengs.Where(kezi => kezi is { Card: >= 0 }))
-                            {
-                                otherPlayer.ActInfo.Add(new Struct.Kezi(kezi.Type, kezi.Card, kezi.PlayerId));
-                            }
+                            otherPlayer.ActInfo.Add(new Struct.Kezi(kezi.Type, kezi.Card, kezi.PlayerId));
                         }
                         }
-                        // 是否吃
-                        if (chis.Count > 0)
-                        {
-                            hasAct = true;
-                            act[0] = 1;
-                            foreach (Struct.Kezi kezi in chis.Where(kezi => kezi is { Card: >= 0 }))
-                            {
-                                otherPlayer.ActInfo.Add(new Struct.Kezi(kezi.Type, kezi.Card, kezi.PlayerId));
-                            }
-                        }
-                        // 是否过
-                        if (hasAct) {
-                            act[4] = 1;
-                        }
-                        if (act[2] == 1 || act[1] == 1 || act[0] == 1) {
-                            // 加入可操作玩家list
-                            if (!self.OperableList.Contains(otherPlayer.Id)) {
-                                self.OperableList.Add(otherPlayer.Id);
-                            }
-                            // 加入可碰杠玩家集合
-                            if (!self.CanPgIds.Contains(otherPlayer.Id)) {
-                                self.CanPgIds.Add(otherPlayer.Id);
-                            }
-                        }
-                        // 设置玩家动作
-                        otherPlayer.Act = act;
-
-                        // // 广播其它三家
-                        // MessageHelper.SendToClient(otherPlayer, new G2C_HGHHDisCardPush(){info = ProtoHelper.RoomToProto(room, otherPlayer, player)});
                     }
                     }
-
-                    if (self.CanHuIds.Count <= 0)
+                    // 是否碰
+                    if (pengs.Count > 0)
                     {
                     {
-                        self.GangPlayer = null;
+                        hasAct = true;
+                        act[1] = 1;
+                        foreach (Struct.Kezi kezi in pengs.Where(kezi => kezi is { Card: >= 0 }))
+                        {
+                            otherPlayer.ActInfo.Add(new Struct.Kezi(kezi.Type, kezi.Card, kezi.PlayerId));
+                        }
                     }
                     }
-                    // 判断是否下家摸牌, 指定下家摸牌
-                    if (self.OperableList.Count == 0)
+                    // 是否吃
+                    if (chis.Count > 0)
                     {
                     {
-                        Player nextPlayer = null;
-                        foreach (int index in nextPos)
+                        hasAct = true;
+                        act[0] = 1;
+                        foreach (Struct.Kezi kezi in chis.Where(kezi => kezi is { Card: >= 0 }))
                         {
                         {
-                            Player tempPlayer = self.Players[index];
-                            if (tempPlayer is { State: 2 } && tempPlayer.Id != player.Id)
-                            {
-                                nextPlayer = tempPlayer;
-                                break;
-                            }
+                            otherPlayer.ActInfo.Add(new Struct.Kezi(kezi.Type, kezi.Card, kezi.PlayerId));
                         }
                         }
-                        // 有三家认输,就会有null
-                        if (nextPlayer == null)
-                        {
-                            self.GameOver(room);
+                    }
+                    // 是否过
+                    if (hasAct) {
+                        act[4] = 1;
+                    }
+                    if (act[2] == 1 || act[1] == 1 || act[0] == 1) {
+                        // 加入可操作玩家list
+                        if (!self.OperableList.Contains(otherPlayer.Id)) {
+                            self.OperableList.Add(otherPlayer.Id);
                         }
                         }
-                        else
+                        // 加入可碰杠玩家集合
+                        if (!self.CanPgIds.Contains(otherPlayer.Id)) {
+                            self.CanPgIds.Add(otherPlayer.Id);
+                        }
+                    }
+                    // 设置玩家动作
+                    otherPlayer.Act = act;
+                }
+
+                if (self.CanHuIds.Count <= 0)
+                {
+                    self.GangPlayer = null;
+                }
+                // 判断是否下家摸牌, 指定下家摸牌
+                if (self.OperableList.Count == 0)
+                {
+                    Player nextPlayer = null;
+                    foreach (int index in nextPos)
+                    {
+                        Player tempPlayer = self.Players[index];
+                        if (tempPlayer is { State: 2 } && tempPlayer.Id != player.Id)
                         {
                         {
-                            // 设置摸牌玩家
-                            self.DrawCardPlayer = nextPlayer;
-                            // 设置操作玩家
-                            self.CurrentPlayer = nextPlayer;
-                            // 摸牌
-                            self.Flag = false;
+                            nextPlayer = tempPlayer;
+                            break;
                         }
                         }
                     }
                     }
+                    // 有三家认输,就会有null
+                    if (nextPlayer == null)
+                    {
+                        self.GameOver(room);
+                    }
                     else
                     else
                     {
                     {
-                        long id = 0;
+                        // 设置摸牌玩家
+                        self.DrawCardPlayer = nextPlayer;
+                        // 设置操作玩家
+                        self.CurrentPlayer = nextPlayer;
+                        // 摸牌
+                        self.Flag = false;
+                    }
+                }
+                else
+                {
+                    long id = 0;
                         
                         
-                        if (self.CanHuIds.Count > 0)
-                        {
-                            id = self.CanHuIds.First();
-                        } else if (self.CanPgIds.Count > 0)
-                        {
-                            id = self.CanPgIds.First();
-                        }
-                        else
-                        {
-                            id = self.OperableList.First();
-                        }
+                    if (self.CanHuIds.Count > 0)
+                    {
+                        id = self.CanHuIds.First();
+                    } else if (self.CanPgIds.Count > 0)
+                    {
+                        id = self.CanPgIds.First();
+                    }
+                    else
+                    {
+                        id = self.OperableList.First();
+                    }
                         
                         
-                        Player tmpPlayer = room.GetPlayer(id);
-                        if (tmpPlayer != null)
-                        {
-                            self.CurrentPlayer = self.Players[tmpPlayer.Pos];
-                        }
+                    Player tmpPlayer = room.GetPlayer(id);
+                    if (tmpPlayer != null)
+                    {
+                        self.CurrentPlayer = self.Players[tmpPlayer.Pos];
                     }
                     }
+                }
                     
                     
-                    // 重置时间和流程标记
-                    self.Time = 0;
-                    self.Flag = false;
+                // 重置时间和流程标记
+                self.Time = 0;
+                self.Flag = false;
                     
                     
-                    // 给出牌人广播
-                    RoomInfo info = ProtoHelper.RoomToProto(room, player, self.CurrentPlayer);
-                    info.Time = 30;
-                    MessageHelper.SendToClient(player, new G2C_HGHHDisCardPush(){info = info});
+                // 给出牌人广播
+                RoomInfo info = ProtoHelper.RoomToProto(room, player, self.CurrentPlayer);
+                info.Time = 30;
+                MessageHelper.SendToClient(player, new G2C_HGHHDisCardPush(){info = info});
                     
                     
-                    // 给其他三家广播
-                    foreach (int index in nextPos)
+                // 给其他三家广播
+                foreach (int index in nextPos)
+                {
+                    Player otherPlayer = self.Players[index];
+                    if (otherPlayer == null)
                     {
                     {
-                        Player otherPlayer = self.Players[index];
-                        if (otherPlayer == null)
-                        {
-                            continue;
-                        }
-
-                        // 广播其它三家
-                        info = ProtoHelper.RoomToProto(room, otherPlayer, self.CurrentPlayer);
-                        info.Time = 30;
-                        MessageHelper.SendToClient(otherPlayer, new G2C_HGHHDisCardPush(){info = info});
+                        continue;
                     }
                     }
+
+                    // 广播其它三家
+                    info = ProtoHelper.RoomToProto(room, otherPlayer, self.CurrentPlayer);
+                    info.Time = 30;
+                    MessageHelper.SendToClient(otherPlayer, new G2C_HGHHDisCardPush(){info = info});
                 }
                 }
             }
             }
         }
         }