ソースを参照

优化服务端代码

johnclot69 1 週間 前
コミット
37d86c6e9d

+ 23 - 23
DotNet/Hotfix/Helper/HGHuangHuangHelper.cs → DotNet/Hotfix/Helper/HGHHHelper.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     /// <summary>
     /// 黄冈晃晃胡牌工具类
     /// </summary>
-    public static class HGHuangHuangHelper
+    public static class HGHHHelper
     {
         /// <summary>
         /// 统计每个的数量
@@ -49,17 +49,17 @@ namespace ET.Server
                 if (count[val] == 4)
                 {
                     // 4张牌暗杠
-                    list.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.AN_GANG, val, player.Id));
+                    list.Add(new Struct.Kezi((int)HGHHConst.KeziType.AN_GANG, val, player.Id));
                 }
             }
             // 回杠
             foreach (Struct.Kezi kz in player.KeZi)
             {
-                if (kz.Type == (int)HGHuangHuangConst.KeziType.PENG)
+                if (kz.Type == (int)HGHHConst.KeziType.PENG)
                 {
                     if (count[kz.Card] == 1)
                     {
-                        list.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.HUI_GANG, kz.Card, player.Id));
+                        list.Add(new Struct.Kezi((int)HGHHConst.KeziType.HUI_GANG, kz.Card, player.Id));
                     }
                 }
             }
@@ -78,7 +78,7 @@ namespace ET.Server
             int num = CountCardNum(player.RemainCards, card);
             if (num == 3)
             {
-                list.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.MING_GANG, card, oth_uid));
+                list.Add(new Struct.Kezi((int)HGHHConst.KeziType.MING_GANG, card, oth_uid));
             }
             return list;
         }
@@ -95,7 +95,7 @@ namespace ET.Server
             int num = CountCardNum(player.RemainCards, card);
             if (num >= 2)
             {
-                list.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.PENG, card, oth_uid));
+                list.Add(new Struct.Kezi((int)HGHHConst.KeziType.PENG, card, oth_uid));
             }
             return list;
         }
@@ -110,19 +110,19 @@ namespace ET.Server
         public static List<Struct.Kezi> IsDiscardChi(Player player, int card, long oth_uid) {
             List<Struct.Kezi> list = new List<Struct.Kezi>();
             int[] count = CountCardsNum(player.RemainCards);
-            if (card < HGHuangHuangConst.DONG_FENG)
+            if (card < HGHHConst.DONG_FENG)
             {
-                if ((card - 2) >= HGHuangHuangConst.YI_WAN && count[card - 2] >= 1 && count[card - 1] >= 1)
+                if ((card - 2) >= HGHHConst.YI_WAN && count[card - 2] >= 1 && count[card - 1] >= 1)
                 {
-                    list.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.CHI, card - 2, oth_uid));
+                    list.Add(new Struct.Kezi((int)HGHHConst.KeziType.CHI, card - 2, oth_uid));
                 }
-                if ((card - 1) >= HGHuangHuangConst.YI_WAN && count[card - 1] >= 1 && count[card + 1] >= 1)
+                if ((card - 1) >= HGHHConst.YI_WAN && count[card - 1] >= 1 && count[card + 1] >= 1)
                 {
-                    list.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.CHI, card - 1, oth_uid));
+                    list.Add(new Struct.Kezi((int)HGHHConst.KeziType.CHI, card - 1, oth_uid));
                 }
                 if (count[card + 1] >= 1 && count[card + 2] >= 1)
                 {
-                    list.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.CHI, card, oth_uid));
+                    list.Add(new Struct.Kezi((int)HGHHConst.KeziType.CHI, card, oth_uid));
                 }
             }
             return list;
@@ -141,7 +141,7 @@ namespace ET.Server
             if (IsHu7Dui(tem))
             {
                 // 先检查七对
-                res.Type = HGHuangHuangConst.HU_7DUI;
+                res.Type = HGHHConst.HU_7DUI;
                 res.Jiang = 0;
                 return res;
             }
@@ -149,11 +149,11 @@ namespace ET.Server
             if (jiang != 0)
             {
                 // 最后检查平胡
-                res.Type = HGHuangHuangConst.HU_BASE;
+                res.Type = HGHHConst.HU_BASE;
                 res.Jiang = jiang;
                 return res;
             }
-            res.Type = HGHuangHuangConst.HU_DEFAULT;
+            res.Type = HGHHConst.HU_DEFAULT;
             res.Jiang = 0;
             return res;
         }
@@ -168,32 +168,32 @@ namespace ET.Server
         public static Struct.HuRes CheckHuType(List<Struct.Kezi> list, int[] cards, int card)
         {
             Struct.HuRes result = CheckHu(cards);
-            if (result.Type != HGHuangHuangConst.HU_DEFAULT)
+            if (result.Type != HGHHConst.HU_DEFAULT)
             {
                 int jiang = IsHuDuiDui(cards, list);// 检测对对胡
                 if (jiang != 0) {
                     if (CheckQingYiSe(list, cards)) {
-                        result.Type = HGHuangHuangConst.HU_QING_DUIDUI;
+                        result.Type = HGHHConst.HU_QING_DUIDUI;
                         result.Jiang = jiang;
                         return result;
                     } else {
                         // 碰碰胡
-                        result.Type = HGHuangHuangConst.HU_DUIDUI;
+                        result.Type = HGHHConst.HU_DUIDUI;
                         result.Jiang = jiang;
                         return result;
                     }
                 }
                 if (CheckQingYiSe(list, cards)) { // 清一色
-                    result.Type = HGHuangHuangConst.HU_QING;
+                    result.Type = HGHHConst.HU_QING;
                     result.Jiang = jiang;
                     return result;
                 }
                 jiang = IsPing(cards, list);
                 if (jiang != 0) {
-                    result.Type = HGHuangHuangConst.HU_PING;
+                    result.Type = HGHHConst.HU_PING;
                     return result;
                 } else {
-                    result.Type = HGHuangHuangConst.HU_BASE;
+                    result.Type = HGHHConst.HU_BASE;
                     return result;
                 }
             }
@@ -238,7 +238,7 @@ namespace ET.Server
         /// <param name="list">玩家刻子</param>
         /// <returns></returns>
         private static int IsHuDuiDui(int[] cards, List<Struct.Kezi> list) {
-            if (list.Any(kezi => kezi is { Type: (int)HGHuangHuangConst.KeziType.CHI }))
+            if (list.Any(kezi => kezi is { Type: (int)HGHHConst.KeziType.CHI }))
             {
                 return 0;
             }
@@ -316,7 +316,7 @@ namespace ET.Server
         {
             foreach (Struct.Kezi kezi in list)
             {
-                if (kezi.Type != (int)HGHuangHuangConst.KeziType.CHI)
+                if (kezi.Type != (int)HGHHConst.KeziType.CHI)
                 {
                     return 0;
                 }

+ 1 - 1
DotNet/Hotfix/Scenes/Game/Handler/HGHH/C2G_HGHHDisCardHandler.cs

@@ -61,7 +61,7 @@ namespace ET.Server
                 return;
             }
             
-            if (request.Card <= 0 || !HGHuangHuangConst.Values.Contains(request.Card))
+            if (request.Card <= 0 || !HGHHConst.Values.Contains(request.Card))
             {
                 response.Error = ErrorCode.ERR_OperationError;
                 response.Message = "出牌错误...";

+ 1 - 1
DotNet/Hotfix/Scenes/Game/Handler/HGHH/C2G_HGHHOperationHandler.cs

@@ -69,7 +69,7 @@ namespace ET.Server
                 return;
             }
             
-            if (request.OpType != 5 && (request.Card <= 0 || !HGHuangHuangConst.Values.Contains(request.Card)))
+            if (request.OpType != 5 && (request.Card <= 0 || !HGHHConst.Values.Contains(request.Card)))
             {
                 response.Error = ErrorCode.ERR_OperationError;
                 response.Message = "牌值错误...";

+ 38 - 38
DotNet/Hotfix/Scenes/Game/Room/HGHuangHuangComponentSystem.cs

@@ -42,7 +42,7 @@ namespace ET.Server
                 // 初始化牌库
                 for (int i = 0; i < 4; i++)
                 {
-                    foreach (int value in HGHuangHuangConst.Values)
+                    foreach (int value in HGHHConst.Values)
                     {
                         self.CardList.Add(value);
                     }
@@ -289,8 +289,8 @@ namespace ET.Server
             // 吃,碰,杠,胡,过
             bool hasAct = false;
             // 检测摸牌人动作, 校验摸牌是否胡
-            Struct.HuRes huRes = HGHuangHuangHelper.CheckHu(drawCardPlayer.RemainCards);
-            if (huRes.Type != HGHuangHuangConst.HU_DEFAULT)
+            Struct.HuRes huRes = HGHHHelper.CheckHu(drawCardPlayer.RemainCards);
+            if (huRes.Type != HGHHConst.HU_DEFAULT)
             {
                 hasAct = true;
                 drawCardPlayer.Act[3] = 1;
@@ -302,7 +302,7 @@ namespace ET.Server
             }
             // todo 玩家听牌状态不允许杠
             // 检测摸牌人动作, 校验摸牌是否杠
-            List<Struct.Kezi> gang = HGHuangHuangHelper.IsDrawGang(drawCardPlayer);
+            List<Struct.Kezi> gang = HGHHHelper.IsDrawGang(drawCardPlayer);
             if (gang is { Count: > 0 })
             {
                 hasAct = true;
@@ -412,13 +412,13 @@ namespace ET.Server
                             List<Struct.Kezi> chis = new List<Struct.Kezi>();
                             // todo 玩家听牌状态不允许有动作
                             // 出牌是否杠
-                            gangs = HGHuangHuangHelper.IsDiscardGang(otherPlayer, card, player.Id);
+                            gangs = HGHHHelper.IsDiscardGang(otherPlayer, card, player.Id);
                             // 出牌是否碰
-                            pengs = HGHuangHuangHelper.IsDiscardPeng(otherPlayer, card, player.Id);
+                            pengs = HGHHHelper.IsDiscardPeng(otherPlayer, card, player.Id);
                             // 出牌是否吃
                             if (otherPlayer.Pos == nextPos[0])
                             {
-                                chis = HGHuangHuangHelper.IsDiscardChi(otherPlayer, card, player.Id);
+                                chis = HGHHHelper.IsDiscardChi(otherPlayer, card, player.Id);
                             }
                             // 游戏中才会动作
                             if (otherPlayer.State == 2)
@@ -429,9 +429,9 @@ namespace ET.Server
                                 Array.Copy(otherPlayer.RemainCards, 0, tmpCards, 0, otherPlayer.RemainCards.Length);
                                 tmpCards = CardHelper.Add(tmpCards, card);
                                 // 校验胡牌
-                                Struct.HuRes huType = HGHuangHuangHelper.CheckHu(tmpCards);
+                                Struct.HuRes huType = HGHHHelper.CheckHu(tmpCards);
 
-                                if (huType.Type != HGHuangHuangConst.HU_DEFAULT)
+                                if (huType.Type != HGHHConst.HU_DEFAULT)
                                 {
                                     hasAct = true;
                                     act[3] = 1;
@@ -629,7 +629,7 @@ namespace ET.Server
                 return;
             }
 
-            if (self.DisCard >= HGHuangHuangConst.DONG_FENG)
+            if (self.DisCard >= HGHHConst.DONG_FENG)
             {
                 return;
             }
@@ -645,7 +645,7 @@ namespace ET.Server
 
             player.RemainCards = temp;
             // 刻子
-            player.KeZi.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.CHI, card, self.DisCardPlayer.Id));
+            player.KeZi.Add(new Struct.Kezi((int)HGHHConst.KeziType.CHI, card, self.DisCardPlayer.Id));
                 
             // 重置摸牌人
             self.DrawCardPlayer = player;
@@ -726,7 +726,7 @@ namespace ET.Server
             player.RemainCards = remainCards;
                 
             // 刻子
-            player.KeZi.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.PENG, self.DisCard, self.DisCardPlayer.Id));
+            player.KeZi.Add(new Struct.Kezi((int)HGHHConst.KeziType.PENG, self.DisCard, self.DisCardPlayer.Id));
                 
             // 重置摸牌人
             self.DrawCardPlayer = player;
@@ -759,7 +759,7 @@ namespace ET.Server
         /// <returns></returns>
         private static int GangPaiDraw(this HGHuangHuangComponent self, Room room, Player player, int card)
         {
-            int type = (int)HGHuangHuangConst.KeziType.DEFAULT;
+            int type = (int)HGHHConst.KeziType.DEFAULT;
             int[] remainCards = player.RemainCards;
             int num = CardHelper.CountCardNum(remainCards, card);
             if (num == 4)
@@ -770,12 +770,12 @@ namespace ET.Server
                 }
                 player.RemainCards = remainCards;
                 
-                player.KeZi.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.AN_GANG, card, player.Id));
+                player.KeZi.Add(new Struct.Kezi((int)HGHHConst.KeziType.AN_GANG, card, player.Id));
                 
                 self.GangPlayer = player;
                 self.GangPai = card;
-                self.GangType = (int)HGHuangHuangConst.KeziType.AN_GANG;
-                type = (int)HGHuangHuangConst.KeziType.AN_GANG;
+                self.GangType = (int)HGHHConst.KeziType.AN_GANG;
+                type = (int)HGHHConst.KeziType.AN_GANG;
             }
             else if (num == 1)
             {
@@ -788,21 +788,21 @@ namespace ET.Server
                 for (int i = 0; i < templist.Count; i++)
                 {
                     Struct.Kezi kz = templist[i];
-                    if (kz is not { Type: (int)HGHuangHuangConst.KeziType.PENG } || kz.Card != card)
+                    if (kz is not { Type: (int)HGHHConst.KeziType.PENG } || kz.Card != card)
                     {
                         continue;
                     }
 
                     player.KeZi.RemoveAt(i);
                     remainCards = CardHelper.Remove(remainCards, card);
-                    player.KeZi.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.HUI_GANG, card, player.Id));
+                    player.KeZi.Add(new Struct.Kezi((int)HGHHConst.KeziType.HUI_GANG, card, player.Id));
                 }
                 
                 player.RemainCards = remainCards;
                 self.GangPlayer = player;
                 self.GangPai = card;
-                self.GangType = (int)HGHuangHuangConst.KeziType.HUI_GANG;
-                type = (int)HGHuangHuangConst.KeziType.HUI_GANG;
+                self.GangType = (int)HGHHConst.KeziType.HUI_GANG;
+                type = (int)HGHHConst.KeziType.HUI_GANG;
             }
             return type;
         }
@@ -817,7 +817,7 @@ namespace ET.Server
         /// <returns></returns>
         private static int GangPaiDisCard(this HGHuangHuangComponent self, Room room, Player player, int card)
         {
-            const int type = (int)HGHuangHuangConst.KeziType.DEFAULT;
+            const int type = (int)HGHHConst.KeziType.DEFAULT;
             if (self.DisCardPlayer == null)
             {
                 return type;
@@ -828,13 +828,13 @@ namespace ET.Server
             {
                 player.RemainCards = CardHelper.Remove(player.RemainCards, card);
             }
-            player.KeZi.Add(new Struct.Kezi((int)HGHuangHuangConst.KeziType.MING_GANG, card, self.DisCardPlayer.Id));
+            player.KeZi.Add(new Struct.Kezi((int)HGHHConst.KeziType.MING_GANG, card, self.DisCardPlayer.Id));
 
             self.GangPlayer = player;
             self.GangPai = card;
-            self.GangType = (int)HGHuangHuangConst.KeziType.MING_GANG;
+            self.GangType = (int)HGHHConst.KeziType.MING_GANG;
             
-            return (int)HGHuangHuangConst.KeziType.MING_GANG;
+            return (int)HGHHConst.KeziType.MING_GANG;
         }
 
         /// <summary>
@@ -860,8 +860,8 @@ namespace ET.Server
                 int[] tmpCards = new int[p.RemainCards.Length];
                 Array.Copy(p.RemainCards, 0, tmpCards, 0, p.RemainCards.Length);
                 tmpCards = CardHelper.Add(tmpCards, card);
-                Struct.HuRes result = HGHuangHuangHelper.CheckHu(tmpCards);
-                if (result.Type != HGHuangHuangConst.HU_DEFAULT) {
+                Struct.HuRes result = HGHHHelper.CheckHu(tmpCards);
+                if (result.Type != HGHHConst.HU_DEFAULT) {
                     flag = true;
                     if (!self.CanHuIds.Contains(p.Id)) {
                         self.CanHuIds.Add(p.Id);
@@ -889,7 +889,7 @@ namespace ET.Server
         {
             if (card > 0 && self.IsCanPengGang(player))
             {
-                int type = (int)HGHuangHuangConst.KeziType.DEFAULT;
+                int type = (int)HGHHConst.KeziType.DEFAULT;
                 
                 if (self.DrawCardPlayer.Id == player.Id)
                 {
@@ -900,11 +900,11 @@ namespace ET.Server
                     type = self.GangPaiDisCard(room, player, card);
                 }
 
-                if (type != (int)HGHuangHuangConst.KeziType.DEFAULT)
+                if (type != (int)HGHHConst.KeziType.DEFAULT)
                 {
                     self.OperableList.Clear();
                     // bool flag = true;
-                    if (self.GangType == (int)HGHuangHuangConst.KeziType.HUI_GANG)
+                    if (self.GangType == (int)HGHHConst.KeziType.HUI_GANG)
                     {
                         if (self.CheckQangGangHu(room, self.GangPlayer, self.GangPai))
                         {
@@ -941,8 +941,8 @@ namespace ET.Server
         {
             if (self.OperableList.Contains(player.Id) && self.CanHuIds.Contains(player.Id))
             {
-                Struct.HuRes res = HGHuangHuangHelper.CheckHuType(player.KeZi, player.RemainCards, self.DrawCard);
-                if (res.Type != HGHuangHuangConst.HU_DEFAULT)
+                Struct.HuRes res = HGHHHelper.CheckHuType(player.KeZi, player.RemainCards, self.DrawCard);
+                if (res.Type != HGHHConst.HU_DEFAULT)
                 {
                     self.OperableList.Remove(player.Id);
                     self.CanHuIds.Remove(player.Id);
@@ -950,7 +950,7 @@ namespace ET.Server
                     // 将摸的牌从手牌中移除
                     player.RemainCards = CardHelper.Remove(player.RemainCards, self.DrawCard);
                     
-                    self.HuResult = self.GangPlayer != null && player.Id == self.GangPlayer.Id ? (int)HGHuangHuangConst.Result.GANGKAI : (int)HGHuangHuangConst.Result.ZIMO;
+                    self.HuResult = self.GangPlayer != null && player.Id == self.GangPlayer.Id ? (int)HGHHConst.Result.GANGKAI : (int)HGHHConst.Result.ZIMO;
                     
                     // 广播
                     foreach (Player p in room.GetAllPlayers().Values.Where(p => p != null))
@@ -993,12 +993,12 @@ namespace ET.Server
                     return;
                 }
 
-                foreach (Struct.Kezi kezi in gangPlayer.KeZi.Where(kezi => kezi.Card == self.GangPai && kezi.Type == (int)HGHuangHuangConst.KeziType.HUI_GANG))
+                foreach (Struct.Kezi kezi in gangPlayer.KeZi.Where(kezi => kezi.Card == self.GangPai && kezi.Type == (int)HGHHConst.KeziType.HUI_GANG))
                 {
-                    kezi.Type = (int)HGHuangHuangConst.KeziType.PENG;
+                    kezi.Type = (int)HGHHConst.KeziType.PENG;
                 }
 
-                self.HuResult = (int)HGHuangHuangConst.Result.QIANGGANG;
+                self.HuResult = (int)HGHHConst.Result.QIANGGANG;
             }
             else
             {
@@ -1008,7 +1008,7 @@ namespace ET.Server
                     self.DisCardPlayer.DisCards = CardHelper.Remove(self.DisCardPlayer.DisCards, self.DisCard);
                 }
 
-                self.HuResult = (int)HGHuangHuangConst.Result.DIANPAO;
+                self.HuResult = (int)HGHHConst.Result.DIANPAO;
             }
             player.HuCards.Add(self.GangPai);
             // 广播
@@ -1046,8 +1046,8 @@ namespace ET.Server
                 int[] tmpCards = new int[userCards.Length];
                 Array.Copy(userCards, 0, tmpCards, 0, userCards.Length);
                 tmpCards = CardHelper.Add(tmpCards, card);
-                Struct.HuRes res = HGHuangHuangHelper.CheckHuType(player.KeZi, tmpCards, card);
-                if (res.Type != HGHuangHuangConst.HU_DEFAULT)
+                Struct.HuRes res = HGHHHelper.CheckHuType(player.KeZi, tmpCards, card);
+                if (res.Type != HGHHConst.HU_DEFAULT)
                 {
                     if (!self.ClickHuIds.Contains(player.Id))
                     {

+ 1 - 1
DotNet/Model/Scenes/Game/HGHuangHuangConst.cs → DotNet/Model/Share/HGHHConst.cs

@@ -3,7 +3,7 @@
     /// <summary>
     /// 晃晃静态常量
     /// </summary>
-    public static class HGHuangHuangConst
+    public static class HGHHConst
     {
         /// <summary>
         /// 麻将对应数值