瀏覽代碼

增加一局游戏结束后,再来一局的功能

大爷 1 年之前
父節點
當前提交
cafa4d6766
共有 20 個文件被更改,包括 113 次插入128 次删除
  1. 二進制
      Unity/Assets/Res/FGUI/HUD_fui.bytes
  2. 二進制
      Unity/Assets/Res/FGUI/paiming_fui.bytes
  3. 2 7
      Unity/Assets/Scripts/Codes/Hotfix/Client/Login/LoginHelper.cs
  4. 0 8
      Unity/Assets/Scripts/Codes/Hotfix/Client/Module.meta
  5. 0 8
      Unity/Assets/Scripts/Codes/Hotfix/Client/Module/Message.meta
  6. 0 0
      Unity/Assets/Scripts/Codes/Hotfix/Client/Session/NetClientComponentSystem.cs
  7. 0 0
      Unity/Assets/Scripts/Codes/Hotfix/Client/Session/NetClientComponentSystem.cs.meta
  8. 7 27
      Unity/Assets/Scripts/Codes/Hotfix/Client/battle/BattleMgr.cs
  9. 36 39
      Unity/Assets/Scripts/Codes/Hotfix/Client/battle/BattleMgr_Cmd.cs
  10. 35 0
      Unity/Assets/Scripts/Codes/Hotfix/Client/battle/ReOpenGame.cs
  11. 11 0
      Unity/Assets/Scripts/Codes/Hotfix/Client/battle/ReOpenGame.cs.meta
  12. 2 2
      Unity/Assets/Scripts/Codes/Hotfix/Client/battle/unit/BattleUnit.cs
  13. 6 4
      Unity/Assets/Scripts/Codes/HotfixView/Client/Battle/GameoverHanler.cs
  14. 2 1
      Unity/Assets/Scripts/Codes/HotfixView/Client/EntryEvent3_InitClient.cs
  15. 0 1
      Unity/Assets/Scripts/Codes/HotfixView/Client/Scene/AfterCreateCurrentScene_AddComponent.cs
  16. 1 28
      Unity/Assets/Scripts/Codes/HotfixView/Client/Scene/GameObjectPool.cs
  17. 8 0
      Unity/Assets/Scripts/Codes/HotfixView/Client/UI/HUD/CreateHUD.cs
  18. 1 1
      Unity/Assets/Scripts/Codes/HotfixView/Client/UI/UIHelper.cs
  19. 1 0
      Unity/Assets/Scripts/Codes/Model/Client/EventTypeClient.cs
  20. 1 2
      Unity/Assets/Scripts/Codes/Model/Client/Scene/PlayerComponent.cs

二進制
Unity/Assets/Res/FGUI/HUD_fui.bytes


二進制
Unity/Assets/Res/FGUI/paiming_fui.bytes


+ 2 - 7
Unity/Assets/Scripts/Codes/Hotfix/Client/Login/LoginHelper.cs

@@ -62,14 +62,9 @@ namespace ET.Client
                 gateSession.AddComponent<PingComponent>();
                 clientScene.AddComponent<SessionComponent>().Session = gateSession;
                 var player = clientScene.GetComponent<PlayerComponent>();
-                //player.Token = r2CLogin.Token;
 
-                //var player = g2CLoginGate.Players[0];
-                //TODO:选角进入
-                //使用简化流程直接进入游戏
-                var ret = (G2C_BindPlayer)await gateSession.Call(new C2G_BindPlayer() { PlayerId = g2CLoginGate.Player.id });
-
-                //await EventSystem.Instance.PublishWait(EventType.LoginFinish.Clone(ret.Player));
+                player.PlayerId = g2CLoginGate.Player.id;
+                var ret = (G2C_BindPlayer)await gateSession.Call(new C2G_BindPlayer() { PlayerId = player.PlayerId });
 
                 EnterMapHelper.EnterMapAsync(clientScene, ret.Player, ret.Player.instanceId).Coroutine();
             }

+ 0 - 8
Unity/Assets/Scripts/Codes/Hotfix/Client/Module.meta

@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 83e42b45e303e71468c08f3d8f2d271a
-folderAsset: yes
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 8
Unity/Assets/Scripts/Codes/Hotfix/Client/Module/Message.meta

@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 6378fb95ea17e6d46b536062736457a5
-folderAsset: yes
-DefaultImporter:
-  externalObjects: {}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/Module/Message/NetClientComponentSystem.cs → Unity/Assets/Scripts/Codes/Hotfix/Client/Session/NetClientComponentSystem.cs


+ 0 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/Module/Message/NetClientComponentSystem.cs.meta → Unity/Assets/Scripts/Codes/Hotfix/Client/Session/NetClientComponentSystem.cs.meta


+ 7 - 27
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/BattleMgr.cs

@@ -20,18 +20,21 @@ namespace ET
         public ZoneLayer Layer;
 
         private readonly MemoryStream writeBuffer = new MemoryStream(2048);
-        private EventDispatcher<CommonAI.Zone.Event> eventHandler;
+        private EventDispatcher<CommonAI.Zone.Event> eventHandler = new();
         private static CommonLang.Geometry.Vector3 vecTemp = new();
-        private HashMap<int, BattleUnit> UnitTemplateIdHash = new();
 
         private int mapHeight;
         public int MapHeight { get { return mapHeight; } }
 
         public void Awake()
         {
-            eventHandler = new();
             registerEventHandler();
 
+            InitBattleLayer();
+        }
+
+        public void InitBattleLayer()
+        {
             Layer = TemplateManager.Factory.CreateClientZoneLayer(BattleResourceMgr.Instance.GameEditorTemplates, this);
             Layer.ActorSyncMode = SyncMode.ForceByServer;
 
@@ -133,21 +136,7 @@ namespace ET
                 }
                 unit.OnAwake(obj);
 
-                if (unit is BattleUnit bu)
-                {
-                    var tid = (obj as ZoneUnit).TemplateID;
-                    if (ConstGame.TowerTemplateIDs.Contains(tid))
-                    {
-                        if (UnitTemplateIdHash.ContainsKey((tid)))
-                        {
-                            Log.Error($"Already exist unit({tid}) @{obj.ObjectID}");
-                            return;
-                        }
-                        UnitTemplateIdHash.Add(tid, bu);
-                    }
-
-                    //Log.Debug($"OnObjectEnter: {bu.ZUnit.TemplateID}@{obj.ObjectID}");
-                }
+                //Log.Debug($"OnObjectEnter: {bu.ZUnit.TemplateID}@{obj.ObjectID}");
             }
         }
 
@@ -165,15 +154,6 @@ namespace ET
 
             unit.OnSleep();
             UnitMgr.Instance.RemoveUnit(obj.ObjectID);
-            if (unit is BattleUnit bu)
-            {
-                UnitTemplateIdHash.Remove(bu.ZUnit.TemplateID);
-            }
-        }
-
-        public BattleUnit GetUnitByTemplateID(int tid)
-        {
-            return UnitTemplateIdHash.ContainsKey(tid) ? UnitTemplateIdHash[tid] : null;
         }
 
         private void registerEventHandler()

+ 36 - 39
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/BattleMgr_Cmd.cs

@@ -46,63 +46,46 @@ namespace ET
                     break;
                 case (int)KeyCode.F1:
                     var units = new int[] { 101, 111, 121, 131 };
-                    var centerpos = GetCurBattleCenter();
                     var rand = new Random();
                     foreach (var id in units)
                     {
-                        float r = (float)Math.Sqrt(rand.Next(2500)) + 10;
-                        double ang = rand.Next(22) / 180.0f * Math.PI + Math.PI*150f/180f;
-                        float x = centerpos.X + (float)(r * Math.Cos(ang));
-                        float y = centerpos.Y - (float)(r * Math.Sin(ang));
-
+                        var pos = GetRandomPos(2);
                         session.Call(new C2G_AddUnitsToMap()
                         {
                             UnitId = id,
                             Force = 1,
-                            X = (int)x,
-                            Y = (int)y
+                            X = (int)pos.X,
+                            Y = (int)pos.Y
                         }).Coroutine();
                     }
                     break;
                 case (int)KeyCode.F2:
-                    centerpos = GetCurBattleCenter();
                     var units2 = new int[] { 102, 112, 122, 132 };
                     rand = new Random();
                     for (int i = 0; i < 2; i++)
                     {
-                        var id = units2[rand.Next(units2.Length)];
-                        float r = (float)Math.Sqrt(rand.Next(3136)) + 10;
-                        double ang = rand.Next(20) / 180.0f * Math.PI + Math.PI * 76f / 180f;
-                        float x = centerpos.X + (float)(r * Math.Cos(ang));
-                        float y = centerpos.Y - (float)(r * Math.Sin(ang));
-
+                        var pos = GetRandomPos(1);
                         session.Call(new C2G_AddUnitsToMap()
                         {
-                            UnitId = id,
+                            UnitId = units2[rand.Next(units2.Length)],
                             Force = 1,
-                            X = (int)x,
-                            Y = (int)y
+                            X = (int)pos.X,
+                            Y = (int)pos.Y
                         }).Coroutine();
                     }
                     break;
                 case (int)KeyCode.F3:
-                    centerpos = GetCurBattleCenter();
                     var units3 = new int[] { 103, 113, 123, 133 };
                     rand = new Random();
                     for (int i = 0; i < 1; i++)
                     {
-                        var id = units3[rand.Next(units3.Length)];
-                        float r = (float)Math.Sqrt(rand.Next(2500)) + 10;
-                        double ang = rand.Next(22) / 180.0f * Math.PI + Math.PI * 78f / 180f + Math.PI;
-                        float x = centerpos.X + (float)(r * Math.Cos(ang));
-                        float y = centerpos.Y - (float)(r * Math.Sin(ang));
-
+                        var pos = GetRandomPos(0);
                         session.Call(new C2G_AddUnitsToMap()
                         {
-                            UnitId = id,
+                            UnitId = units3[rand.Next(units3.Length)],
                             Force = 1,
-                            X = (int)x,
-                            Y = (int)y
+                            X = (int)pos.X,
+                            Y = (int)pos.Y
                         }).Coroutine();
                     }
                     break;
@@ -162,21 +145,35 @@ namespace ET
             //EventSystem.Instance.Publish<SoundMuteEvent>();
         }
 
-        //获得当前战场focus中心(当前塔位置)
+        //获得当前战场(当前塔位置),随机位置
         private Vector2 vecTemp = new Vector2();
-        private Vector2 GetCurBattleCenter()
+        private Vector2 GetRandomPos(int index)
         {
-            foreach(var tid in ConstGame.TowerTemplateIDs)
+            Vector2[] TowerPos = { new Vector2(){ X = 103, Y = 197 }, new Vector2() { X = 190, Y = 133 }, new Vector2() { X = 104, Y = 69 } };
+
+            var tower = TowerPos[index];
+            var rand = new Random();
+            float r;
+            double ang;
+            if(index == 0)
             {
-                var tower = BattleMgr.Instance.GetUnitByTemplateID(tid);
-                if(tower != null && !tower.IsDead)
-                {
-                    vecTemp.X = tower.ZUnit.X;
-                    vecTemp.Y = tower.ZUnit.Y;
-                    return vecTemp;
-                }
+                r = (float)Math.Sqrt(rand.Next(2500)) + 10;
+                ang = rand.Next(22) / 180.0f * Math.PI + Math.PI * 78f / 180f + Math.PI;
+            }
+            else if(index == 1)
+            {
+                r = (float)Math.Sqrt(rand.Next(3136)) + 10;
+                ang = rand.Next(20) / 180.0f * Math.PI + Math.PI * 76f / 180f;
             }
-            return new Vector2(0, 0);
+            else
+            {
+                r = (float)Math.Sqrt(rand.Next(2500)) + 10;
+                ang = rand.Next(22) / 180.0f * Math.PI + Math.PI * 150f / 180f;
+            }
+
+            vecTemp.X = tower.X + (float)(r * Math.Cos(ang));
+            vecTemp.Y = tower.Y - (float)(r * Math.Sin(ang));
+            return vecTemp;
         }
     }
 

+ 35 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/ReOpenGame.cs

@@ -0,0 +1,35 @@
+using ET.Client;
+using ET.EventType;
+
+namespace ET
+{
+    [Event]
+    public class ReOpenGame : BEvent<ReOpenGame>
+    {
+        protected override async ETTask OnEvent(ReOpenGame a)
+        {
+            UnitMgr.Instance.RecycleUnits();
+            BattleMgr.Instance.InitBattleLayer();
+
+            var session = PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().Session;
+
+            var ret = await session.Call(new C2G_BindPlayer() { PlayerId = PlayerComponent.Instance.PlayerId }) as G2C_BindPlayer;
+            if(ret.Error != ErrorCode.ERR_Success)
+            {
+                Log.Error($"login error: {ret.Error}:{ret.Message}");
+                return;
+            }
+
+            G2C_EnterMap g2CEnterMap = await session.Call(new C2G_EnterMap() { InstanceId = ret.Player.instanceId }) as G2C_EnterMap;
+            if (g2CEnterMap.Error != 0)
+            {
+                Log.Error(g2CEnterMap.Message);
+                return;
+            }
+
+            //告诉战斗服 i am ready,然后战斗服才会在场景创建其它单位
+            session.Send(new BattleClientReady());
+            EventSystem.Instance.Publish<ShowHUDEvent>();
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/ReOpenGame.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: bcb56e755d3ce7845998894a1296c99c
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 2
Unity/Assets/Scripts/Codes/Hotfix/Client/battle/unit/BattleUnit.cs

@@ -192,9 +192,9 @@ public class BattleUnit : BattleObject
             return;
         }
 
-        if (pgList.Count >= 3)
+        if (pgList.Count >= 4)
         {
-            Log.Error("wtf, more than 3 boss.");
+            Log.Error("wtf, more than 4 boss.");
             return;
         }
 

+ 6 - 4
Unity/Assets/Scripts/Codes/HotfixView/Client/Battle/GameoverHanler.cs

@@ -25,6 +25,7 @@ namespace ET
         protected override async ETTask OnEvent(EventType.GameoverEvent args)
         {
             IsGameOver = true;
+
             GComponent view;
             if(args.winForce == 1)
             {
@@ -49,7 +50,7 @@ namespace ET
                     RankList = null;
                     IsGameOver = false;
 
-                    GRoot.inst.RemoveChild(view);
+                    UIHelper.RemoveAllUiExceptSth();
                     EventSystem.Instance.Publish<ReOpenGame>();
                 });
             });
@@ -62,16 +63,17 @@ namespace ET
             var data = RankList;
 
             int i = 0;
+            GComponent chd;
             for (; i < data.Count; i++)
             {
-                var chd = list.GetChildAt(i).asCom;
-                if (chd == null)
+                if (i >= list.numChildren)
                 {
-                    chd = UIPackage.CreateObject("paiming", $"paiminsg_0{((i<3) ? (i+1) : 4)}").asCom;
+                    chd = UIPackage.CreateObject("paiming", $"paiming_0{((i<3) ? (i+1) : 4)}").asCom;
                     list.AddChild(chd);
                 }
                 else
                 {
+                    chd = list.GetChildAt(i).asCom;
                     chd.visible = true;
                 }
 

+ 2 - 1
Unity/Assets/Scripts/Codes/HotfixView/Client/EntryEvent3_InitClient.cs

@@ -7,11 +7,12 @@ namespace ET.Client
     {
         protected override async ETTask OnEvent(EntryEvent3 a)
         {
+            Game.AddSingleton<GameObjectPool>();
             Game.AddSingleton<GlobalViewMgr>();
             Game.AddSingleton<EffectMgr>();
             Game.AddSingleton<SoundManager>();
 
-            Scene clientScene = await SceneFactory.CreateClientScene( 1, "Game" );
+            await SceneFactory.CreateClientScene( 1, "Game" );
             await EventSystem.Instance.PublishWait<ShowLoginUIEvent>();
         }
     }

+ 0 - 1
Unity/Assets/Scripts/Codes/HotfixView/Client/Scene/AfterCreateCurrentScene_AddComponent.cs

@@ -8,7 +8,6 @@ namespace ET.Client
         protected override async ETTask OnEvent(AfterCreateCurrentScene a)
         {
             var scene = a.scene;
-            scene.AddComponent<GameObjectPool>();
             scene.AddComponent<ModelViewComponent>();
             //scene.AddComponent<OperaComponent>();
             await ETTask.CompletedTask;

+ 1 - 28
Unity/Assets/Scripts/Codes/HotfixView/Client/Scene/GameObjectPool.cs

@@ -10,35 +10,8 @@ using UnityEngine;
 
 namespace ET.Client
 {
-    [FriendOf(typeof(GameObjectPool))]
-    public static class GameObjectPoolSystem
+    public class GameObjectPool : Singleton<GameObjectPool>
     {
-        [ObjectSystem]
-        public class GameObjectPoolAwakeSystem : AwakeSystem<GameObjectPool>
-        {
-            protected override void Awake(GameObjectPool self)
-            {
-                GameObjectPool.Instance = self;
-            }
-        }
-
-        [ObjectSystem]
-        public class GameObjectPoolDestroySystem : DestroySystem<GameObjectPool>
-        {
-            protected override void Destroy(GameObjectPool self)
-            {
-                self.ClearCache();
-                GameObjectPool.Instance = null;
-            }
-        }
-    }
-
-    [ComponentOf(typeof(Scene))]
-    public class GameObjectPool : Entity, IAwake, IDestroy
-    {
-        [StaticField]
-        public static GameObjectPool Instance;
-
         private readonly HashMap<string, List<GameObject>> goPool = new();
         private readonly HashMap<string, AudioClip> audioPool = new();
         private readonly List<GComponent>headBarPool = new();

+ 8 - 0
Unity/Assets/Scripts/Codes/HotfixView/Client/UI/HUD/CreateHUD.cs

@@ -10,6 +10,7 @@ namespace ET.Client
         public static GProgressBar pgBoss1;
         public static GProgressBar pgBoss2;
         public static GProgressBar pgBoss3;
+        public static GProgressBar pgBoss4;
         public static GProgressBar pgTKLike;
         public static GList listRank;
         public static GComponent[] listGift = new GComponent[6];
@@ -27,6 +28,7 @@ namespace ET.Client
             HUDComonent.pgBoss1 = view.GetChild("HPBarBoss1") as GProgressBar;
             HUDComonent.pgBoss2 = view.GetChild("HPBarBoss2") as GProgressBar;
             HUDComonent.pgBoss3 = view.GetChild("HPBarBoss3") as GProgressBar;
+            HUDComonent.pgBoss4 = view.GetChild("HPBarBoss4") as GProgressBar;
             HUDComonent.pgTKLike = view.GetChild("EnergyBar") as GProgressBar;
             HUDComonent.listRank = view.GetChild("list_rank").asList;
             for( int i = 1; i <= 6; i++ )
@@ -38,7 +40,9 @@ namespace ET.Client
             HUDComonent.pgBoss1.visible = false;
             HUDComonent.pgBoss2.visible = false;
             HUDComonent.pgBoss3.visible = false;
+            HUDComonent.pgBoss4.visible = false;
             HUDComonent.pgTKLike.visible = false;
+            HUDComonent.pgTKLike.value = 0;
 
             var compIcon = view.GetChild("CompGifticon");
             var compTips = view.GetChild("CompTips");
@@ -83,6 +87,7 @@ namespace ET.Client
                 {
                     case HPRefresh.Index.Tower:
                         progress = HUDComonent.pgTower;
+                        HUDComonent.pgTKLike.visible = a.Visible;
                         break;
                     case HPRefresh.Index.Boss1:
                         progress = HUDComonent.pgBoss1;
@@ -93,6 +98,9 @@ namespace ET.Client
                     case HPRefresh.Index.Boss3:
                         progress = HUDComonent.pgBoss3;
                         break;
+                    case HPRefresh.Index.Boss4:
+                        progress = HUDComonent.pgBoss4;
+                        break;
                     case HPRefresh.Index.TiktokLike:
                         progress = HUDComonent.pgTKLike;
                         break;

+ 1 - 1
Unity/Assets/Scripts/Codes/HotfixView/Client/UI/UIHelper.cs

@@ -63,7 +63,7 @@ namespace ET.Client
 
         public static void RemoveAllUiExceptSth()
         {
-            string[] excepts = { "HeadBarRoot" };
+            string[] excepts = { "HeadBarRoot", "Loading" };
             var chds = GRoot.inst.GetChildren();
             foreach(var ch in chds)
             {

+ 1 - 0
Unity/Assets/Scripts/Codes/Model/Client/EventTypeClient.cs

@@ -197,6 +197,7 @@ namespace ET
                 Boss1,
                 Boss2,
                 Boss3,
+                Boss4,
                 TiktokLike
             }
             public Index HPIndex;

+ 1 - 2
Unity/Assets/Scripts/Codes/Model/Client/Scene/PlayerComponent.cs

@@ -6,7 +6,6 @@
         [StaticField]
         public static PlayerComponent Instance;
 
-        /** 登陆token **/
-        //public string Token { get; set; }
+        public long PlayerId { get; set; }
     }
 }