Browse Source

修改添加单位测试代码,直接走游戏服逻辑

大爷 1 year ago
parent
commit
d7355fd577

+ 49 - 8
DotNet/Hotfix/Scenes/Game/Handler/C2G_BattleNotifyHandler.cs

@@ -41,14 +41,6 @@ namespace ET.Server
                     Log.Debug("map not exist, abort cmd");
                     return;
                 }
-                var players = map.UnitPlayers.Values.ToArray();
-                if(players.Length == 0)
-                {
-                    Log.Debug("Player count == 0, abort cmd");
-                    return;
-                }
-                var rand = new Random();
-                var randunit = players[rand.Next(players.Length)];
 
                 long roomId = 0;
                 var maphash = GameMapComponent.Instance.rooms;
@@ -70,6 +62,29 @@ namespace ET.Server
                 }
 
                 var funcIndex = int.Parse(request.Message[5..]);
+                if(funcIndex == 8)
+                {
+                    string _openId = "xx";
+                    while (true)
+                    {
+                        _openId = (10000 + new Random().Next(99999999)).ToString();
+                        if (player.Map.GetUnitPlayerByOpenId(_openId) != null) continue;                        
+                        break;
+                    }
+                    var name = GetRandomPlayerName();
+                    var url = GetRandomUrl();
+                    string[] content = { "1", "2", "3", "4" };
+                    MessageHelper.SendActor(instanceid, new R2G_LiveComment() { OpenId = _openId, Url = url, RoomId = roomId, NickName = name, Content =  RandomGenerator.RandomArray(content)});
+                }
+
+                var players = map.UnitPlayers.Values.ToArray();
+                if (players.Length == 0)
+                {
+                    Log.Debug("Player count == 0, abort cmd");
+                    return;
+                }
+                var rand = new Random();
+                var randunit = players[rand.Next(players.Length)];
                 if (funcIndex == 7)
                 {
                     MessageHelper.SendActor(instanceid, new R2G_LiveLike() { OpenId = randunit.OpenId, RoomId = roomId, NickName = randunit.Name, Url = randunit.Url, Likes = 30 });
@@ -101,5 +116,31 @@ namespace ET.Server
             reply();
             await ETTask.CompletedTask;
         }
+
+        private string GetRandomPlayerName()
+        {
+            string[] names =
+            {
+                "好人", "小新", "精钢侠", "带投大戈", "奥仔", "袄特门", "兔比斯", "张剑闯天牙", "窝耗帅", "大白"
+            };
+
+            var rand = new Random();
+            var first = names[rand.Next(names.Length)];
+            return first + rand.Next(99);
+        }
+
+        private string GetRandomUrl()
+        {
+            string[] url =
+            {
+                "https://pic1.zhimg.com/v2-3f475a4727cdff2c7289ce3c728a0e67_r.jpg",
+                "https://img.zcool.cn/community/01cfd95d145660a8012051cdb52093.png@1280w_1l_2o_100sh.png",
+                "https://pic4.zhimg.com/v2-ceb6cc092425322d0b4cab403cd403d7_r.jpg",
+                "https://pic3.zhimg.com/50/v2-e1ad5394ae2d3b2dc9d04c1d7a63f0e6_hd.jpg",
+                "https://pic1.zhimg.com/v2-9ee4a6f411b9a8ff076c38f1dcb03024_b.jpg"
+            };
+            var rand = new Random();
+            return url[rand.Next(url.Length)];
+        }
     }
 }

+ 1 - 44
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/BattleMgr_Cmd.cs

@@ -50,51 +50,8 @@ namespace ET
                     }).Coroutine();
                     break;
                 case (int)KeyCode.F1:
-                    var units = new int[] { 101, 111, 121, 131 };
-                    var rand = new Random();
-                    foreach (var id in units)
-                    {
-                        var pos = GetRandomPos();
-                        session.Call(new C2G_AddUnitsToMap()
-                        {
-                            UnitId = id,
-                            Force = 1,
-                            X = (int)pos.X,
-                            Y = (int)pos.Y
-                        }).Coroutine();
-                    }
-                    break;
-                /*case (int)KeyCode.F2:
-                    var units2 = new int[] { 102, 112, 122, 132 };
-                    rand = new Random();
-                    for (int i = 0; i < 2; i++)
-                    {
-                        var pos = GetRandomPos();
-                        session.Call(new C2G_AddUnitsToMap()
-                        {
-                            UnitId = units2[rand.Next(units2.Length)],
-                            Force = 1,
-                            X = (int)pos.X,
-                            Y = (int)pos.Y
-                        }).Coroutine();
-                    }
+                    session.Call(new C2G_BattleNotify() { Message = "test:8" }).Coroutine();
                     break;
-                case (int)KeyCode.F3:
-                    var units3 = new int[] { 103, 113, 123, 133 };
-                    rand = new Random();
-                    for (int i = 0; i < 1; i++)
-                    {
-                        var pos = GetRandomPos();
-                        session.Call(new C2G_AddUnitsToMap()
-                        {
-                            UnitId = units3[rand.Next(units3.Length)],
-                            Force = 1,
-                            X = (int)pos.X,
-                            Y = (int)pos.Y
-                        }).Coroutine();
-                    }
-                    break;*/
-
                 case (int)KeyCode.F2:
                     session.Call(new C2G_BattleNotify() { Message = "test:1" }).Coroutine();
                     break;